捷徑

TenCrop

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

將給定的影像裁剪為四個角落和中心裁剪,再加上這些的翻轉版本(預設使用水平翻轉)。如果影像為 torch Tensor,則預期其形狀為 […, H, W],其中 … 表示任意數量的 leading dimensions

注意

此轉換會傳回影像元組,而且您 Dataset 傳回的輸入和目標數量可能不符。請參閱下方範例,了解如何處理此問題。

參數:
  • 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 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深度教學課程

檢視教學課程

資源

尋找開發資源並取得您的問題解答

檢視資源