第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PyTorch TypeError:“ToTensor”對(duì)象不可迭代

PyTorch TypeError:“ToTensor”對(duì)象不可迭代

神不在的星期二 2023-02-22 15:37:52
我試圖在每次迭代時(shí)打印圖像名稱。但是,我收到錯(cuò)誤 TypeError: 'ToTensor' object is not iterable。請(qǐng)告訴我我要去哪里?非常感謝from torchvision import datasetsimport torch.utils.datafrom torch.utils.data import DataLoaderfrom torchvision import transformsfrom dataset2 import CellsDatasetfrom torchvision import datasetsimport torchimport torchvisionimport torchvision.transforms as transformsclass ImageFolderWithPaths(datasets.ImageFolder):    """Custom dataset that includes image file paths. Extends    torchvision.datasets.ImageFolder    """# override the __getitem__ method. this is the method that dataloader callsdef __getitem__(self, index):    # this is what ImageFolder normally returns     original_tuple = super(ImageFolderWithPaths, self).__getitem__(index)    # the image file path    path = self.imgs[index][0]    # make a new tuple that includes original and the path    tuple_with_path = (original_tuple + (path,))    return tuple_with_path# EXAMPLE USAGE:# instantiate the dataset and dataloaderdata_dir = "/Users/nubstech/Documents/GitHub/CellCountingDirectCount/Eddata/"dataset = ImageFolderWithPaths(data_dir) # our custom dataset#dataloader = DataLoader(dataset)transform = transforms.Compose([    # you can add other transformations in this list    transforms.ToTensor()])dataset = DataLoader(data_dir, transforms.Compose(transforms.ToTensor()))dataloader = torch.utils.DataLoader(dataset)# iterate over datafor inputs, labels, paths in dataloader:    # use the above variables freely   print(inputs, labels, paths)
查看完整描述

1 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

這是因?yàn)?code>transforms.Compose()需要是一個(gè)列表(可能也接受了其他一些迭代)。問(wèn)題在這里:

dataset = DataLoader(data_dir, transforms.Compose(transforms.ToTensor()))

嘗試:

transforms = transforms.Compose([transforms.ToTensor()])

這將創(chuàng)建一個(gè)可調(diào)用對(duì)象,您可以在其中傳遞數(shù)據(jù)。


查看完整回答
反對(duì) 回復(fù) 2023-02-22
  • 1 回答
  • 0 關(guān)注
  • 297 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)