快捷方式

CocoCaptions

class torchvision.datasets.CocoCaptions(root: Union[str, Path], annFile: str, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, transforms: Optional[Callable] = None)[source]

MS Coco Captions 資料集。

它需要安裝 pycocotools,可以透過 pip install pycocotoolsconda install conda-forge::pycocotools 進行安裝。

引數:
  • root (str or pathlib.Path) – 下載影像的根目錄。

  • annFile (string) – json 標註檔案的路徑。

  • transform (callable, optional) – 一個函式/轉換,接受 PIL 影像並返回轉換後的版本。例如,transforms.PILToTensor

  • target_transform (callable, optional) – 一個函式/轉換,接受目標並對其進行轉換。

  • transforms (callable, optional) – 一個函式/轉換,接受輸入樣本及其目標作為輸入,並返回轉換後的版本。

示例

import torchvision.datasets as dset
import torchvision.transforms as transforms
cap = dset.CocoCaptions(root = 'dir where images are',
                        annFile = 'json annotation file',
                        transform=transforms.PILToTensor())

print('Number of samples: ', len(cap))
img, target = cap[3] # load 4th sample

print("Image Size: ", img.size())
print(target)

輸出

Number of samples: 82783
Image Size: (3L, 427L, 640L)
[u'A plane emitting smoke stream flying over a mountain.',
u'A plane darts across a bright blue sky behind a mountain covered in snow',
u'A plane leaves a contrail above the snowy mountain top.',
u'A mountain that has a plane flying overheard in the distance.',
u'A mountain view with a plume of smoke in the background']
特殊成員:

__getitem__(index: int) Tuple[Any, Any]
引數:

index (int) – 索引

返回:

樣本和元資料,可選地由相應的轉換進行轉換。

返回型別:

(Any)

文件

訪問全面的 PyTorch 開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並解答您的疑問

檢視資源