快捷方式

FiveCrop

class torchvision.transforms.FiveCrop(size)[原始檔]

將給定的影像裁剪為四個角和中心區域。如果影像是 torch Tensor,其形狀應為 […, H, W],其中 … 表示任意數量的前導維度

注意

此變換返回一個影像元組,這可能導致您的 Dataset 返回的輸入和目標數量不匹配。請參閱下文了解如何處理此問題。

引數:

size (sequenceint) – 期望的裁剪輸出尺寸。如果 size 是 int 而非 (h, w) 這樣的 sequence,則將建立一個尺寸為 (size, size) 的正方形裁剪。如果提供長度為 1 的 sequence,則將其解釋為 (size[0], size[0])。

示例

>>> transform = Compose([
>>>    FiveCrop(size), # this is a list 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

使用 FiveCrop 的示例

變換圖示

變換圖示
forward(img)[原始檔]
引數:

img (PIL 影像Tensor) – 要裁剪的影像。

返回值:

5 個影像的元組。影像可以是 PIL 影像或 Tensor

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

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

檢視教程

資源

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

檢視資源