本文簡要介紹python語言中 torchvision.datasets.CocoCaptions
的用法。
用法:
class torchvision.datasets.CocoCaptions(root: str, annFile: str, transform: Optional[Callable] = None, target_transform: Optional[Callable] = None, transforms: Optional[Callable] = None)
root(string) -圖像下載到的根目錄。
annFile(string) -json 注釋文件的路徑。
transform(可調用的,可選的) -接受 PIL 圖像並返回轉換版本的函數/轉換。例如,
transforms.ToTensor
target_transform(可調用的,可選的) -接收目標並對其進行轉換的函數/轉換。
transforms(可調用的,可選的) -將輸入樣本及其目標作為條目並返回轉換版本的函數/轉換。
MS Coco Captions 數據集。
示例
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 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']
參數:
相關用法
- Python PyTorch Collator用法及代碼示例
- Python PyTorch ConvTranspose3d用法及代碼示例
- Python PyTorch Conv1d用法及代碼示例
- Python PyTorch CosineAnnealingWarmRestarts.step用法及代碼示例
- Python PyTorch ContinuousBernoulli用法及代碼示例
- Python PyTorch ConstantPad2d用法及代碼示例
- Python PyTorch ComplexNorm用法及代碼示例
- Python PyTorch ConvTranspose2d用法及代碼示例
- Python PyTorch Concater用法及代碼示例
- Python PyTorch Compose用法及代碼示例
- Python PyTorch ConstantLR用法及代碼示例
- Python PyTorch Conv2d用法及代碼示例
- Python PyTorch CosineSimilarity用法及代碼示例
- Python PyTorch ConstantPad1d用法及代碼示例
- Python PyTorch ConstraintRegistry.register用法及代碼示例
- Python PyTorch Conv3d用法及代碼示例
- Python PyTorch ConstantPad3d用法及代碼示例
- Python PyTorch CSVParser用法及代碼示例
- Python PyTorch CrossEntropyLoss用法及代碼示例
- Python PyTorch ChannelShuffle用法及代碼示例
- Python PyTorch CSVDictParser用法及代碼示例
- Python PyTorch Cityscapes用法及代碼示例
- Python PyTorch ChainedScheduler用法及代碼示例
- Python PyTorch Cauchy用法及代碼示例
- Python PyTorch CriteoIterDataPipe用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torchvision.datasets.CocoCaptions。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。