日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PyTorch - torchvision - datasets

發布時間:2024/5/17 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PyTorch - torchvision - datasets 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

所有的數據集都是torch.utils.data.Dataset的子類,即它們實現了__getitem__和__len__方法。

因此,它們都可以傳遞給torch.utils.data.DataLoader通過torch.multiprocessing使用多線程并行加載多個樣本。

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)

參數

  • root (string) – 圖片下載到的根目錄。
  • annFile (string) – json注釋文件的路徑。
  • transform (callable, optional) – 一種接受PIL圖像并返回轉換后的版本的function/transform。例如:transforms.ToTensor
  • target_transform (callable, optional) – 接受目標并對其進行轉換的function/transform。
  • transforms (callable, optional) – 一種以輸入樣本及其目標為輸入并返回轉換版本的function/transform。

總結

以上是生活随笔為你收集整理的PyTorch - torchvision - datasets的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。