快捷方式

TenCrop

class torchvision.transforms.TenCrop(size, vertical_flip=False)[原始碼]

將給定影像裁剪為四個角和中心部分,以及它們的翻轉版本(預設為水平翻轉)。如果影像是 torch Tensor,則期望其形狀為 […, H, W],其中 … 表示任意數量的前導維度

注意

此變換返回一個影像元組,這可能導致您的 Dataset 返回的輸入和目標數量不匹配。請參見下方示例以瞭解如何處理這種情況。

引數:
  • size (sequence or int) – 期望的裁剪輸出尺寸。如果 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 Image or Tensor) – 要裁剪的影像。

返回:

包含 10 張影像的元組。影像可以是 PIL Image 或 Tensor

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源