快捷方式

TenCrop

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

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

注意

此變換返回一個影像元組,並且您的 Dataset 返回的輸入和目標數量可能不匹配。有關如何處理此問題,請參閱下面的示例。

引數:
  • size (sequenceint) – 裁剪的期望輸出尺寸。如果 size 是一個整數而不是像 (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 開發者文件

檢視文件

教程

為初學者和高階開發者提供深入的教程

檢視教程

資源

查詢開發資源並讓您的問題得到解答

檢視資源