TenCrop¶
- class torchvision.transforms.TenCrop(size, vertical_flip=False)[源代码]¶
将给定图像裁剪为四个角和中心部分,以及它们的翻转版本(默认为水平翻转)。如果图像是 torch Tensor,则期望其形状为 […, H, W],其中 … 表示任意数量的前导维度
注意
此变换返回一个图像元组,这可能导致您的 Dataset 返回的输入和目标数量不匹配。请参见下方示例以了解如何处理这种情况。
- 参数:
示例
>>> 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