捷徑

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 資料集。

它需要安裝 COCO API

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

  • annFile (字串) – 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) – 索引

回傳:

樣本與元數據,可選擇性地經由各自的轉換(transforms)處理。

回傳類型:

(Any)

文件

存取 PyTorch 的完整開發者文件

查看文件

教學

取得為初學者和進階開發者準備的深入教學

查看教學

資源

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

查看資源