pytorch torchvision.datasets.CocoCaptions on Linux

中文pytorch网址:https://ptorch.com/docs/1/datasets#coco

1、首先安装COCO API。参考自:https://github.com/cocodataset/cocoapi/issues/14

git clone https://github.com/pdollar/coco.git

cd coco/PythonAPI

make

python setup.py install


2、下载数据。http://cocodataset.org/#download


3、testing.py里写入

import torchvision.datasets as dset
import torchvision.transforms as transforms
cap = dset.CocoCaptions(root = 'images/val2017',
                        annFile = 'annotations/captions_val2017.json',
                        transform=transforms.ToTensor())

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

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


4、运行及输出结果$ python testing.py                                                                                                 
loading annotations into memory...
Done (t=0.07s)
creating index...
index created!
Number of samples:  5000
Image Size:  torch.Size([3, 480, 640])
['A person on a skateboard and bike at a skate park.', 'A man on a skateboard performs a trick at the skate park', 'A skateboarder jumps into the air as he performs a skateboard trick.', 'Athletes performing tricks on a BMX bicycle and a skateboard.', 'a man falls off his skateboard in a skate park.']


你可能感兴趣的:(pytorch)