TenCrop¶
- class torchvision.transforms.TenCrop(size, vertical_flip=False)[源代码]¶
将给定的图像裁剪成四个角和中心裁剪,再加上这些的翻转版本(默认使用水平翻转)。如果图像是 torch Tensor,则应具有 […, H, W] 形状,其中 … 表示任意数量的前导维度
注意
此转换返回图像元组,并且您数据集返回的输入和目标数量可能不匹配。请参阅下文,了解如何处理这种情况的示例。
- 参数:
示例
>>> transform = Compose([ >>> TenCrop(size), # this is a tuple of PIL Images >>> Lambda(lambda crops: torch.stack([PILToTensor()(crop) for crop in crops])) # returns a 4D tensor >>> ]) >>> #In your test loop you can do the following: >>> input, target = batch # input is a 5d tensor, target is 2d >>> bs, ncrops, c, h, w = input.size() >>> result = model(input.view(-1, c, h, w)) # fuse batch size and ncrops >>> result_avg = result.view(bs, ncrops, -1).mean(1) # avg over crops