快捷方式

TenCrop

class torchvision.transforms.TenCrop(size, vertical_flip=False)[源代码]

将给定的图像裁剪成四个角和中心裁剪,再加上这些的翻转版本(默认使用水平翻转)。如果图像是 torch Tensor,则应具有 […, H, W] 形状,其中 … 表示任意数量的前导维度

注意

此转换返回图像元组,并且您数据集返回的输入和目标数量可能不匹配。请参阅下文,了解如何处理这种情况的示例。

参数:
  • size (sequenceint) – 裁剪的所需输出大小。如果 size 是 int 而不是像 (h, w) 这样的序列,则会进行方形裁剪 (size, size)。如果提供长度为 1 的序列,则会将其解释为 (size[0], size[0])。

  • vertical_flip (bool) – 使用垂直翻转而不是水平翻转

示例

>>> 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
forward(img)[源代码]
参数:

img (PIL ImageTensor) – 要裁剪的图像。

返回:

10 个图像的元组。图像可以是 PIL Image 或 Tensor

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得您的问题解答

查看资源