PyTorch - torchvision - datasets
生活随笔
收集整理的這篇文章主要介紹了
PyTorch - torchvision - datasets
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
所有的數(shù)據(jù)集都是torch.utils.data.Dataset的子類,即它們實(shí)現(xiàn)了__getitem__和__len__方法。
因此,它們都可以傳遞給torch.utils.data.DataLoader通過(guò)torch.multiprocessing使用多線程并行加載多個(gè)樣本。
imagenet_data = torchvision.datasets.ImageNet('path/to/imagenet_root/') data_loader = torch.utils.data.DataLoader(imagenet_data,batch_size=4,shuffle=True,num_workers=args.nThreads)COCO
NOTE
以下要求安裝COCO API。
Captions
Class
torchvision.datasets.CocoCaptions(root, annFile, transform=None, target_transform=None, transforms=None)
Example
import torchvision.datasets as dset import torchvision.transforms as transforms cap = dset.CocoCaptions(root = 'dir where images are',annFile = 'json annotation file',transform=transforms.ToTensor())print('Number of samples: ', len(cap)) img, target = cap[3] # load 4th sampleprint("Image Size: ", img.size()) print(target)Output:
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']Detection
Class
torchvision.datasets.CocoDetection(root, annFile, transform=None, target_transform=None, transforms=None)
參數(shù)
- root (string) – 圖片下載到的根目錄。
- annFile (string) – json注釋文件的路徑。
- transform (callable, optional) – 一種接受PIL圖像并返回轉(zhuǎn)換后的版本的function/transform。例如:transforms.ToTensor
- target_transform (callable, optional) – 接受目標(biāo)并對(duì)其進(jìn)行轉(zhuǎn)換的function/transform。
- transforms (callable, optional) – 一種以輸入樣本及其目標(biāo)為輸入并返回轉(zhuǎn)換版本的function/transform。
總結(jié)
以上是生活随笔為你收集整理的PyTorch - torchvision - datasets的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 234. Palindrome Link
- 下一篇: 1365. How Many Numbe