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 (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']
- 特殊成员: