DataLoader问题TypeError: ‘tuple‘ object is not callable
程序员文章站
2022-05-29 08:03:54
...
问题描述
DataLoader迭代出来的image或者label报错。
问题原因及措施
class face_dataset(data.Dataset):
def __init__(self):
self.file_path = './data/faces/'
f=open("final_train_tag_dict.txt","r")
self.label_dict=eval(f.read())
f.close()
def __getitem__(self,index):
label = list(self.label_dict.values())[index-1]
img_id = list(self.label_dict.keys())[index-1]
img_path = self.file_path+str(img_id)+".jpg"
img = np.array(Image.open(img_path))
return img,label
def __len__(self):
return len(self.label_dict)
在__getitem__
里面的返回值是一个字符,得转换成数字或者tensor的格式。
推荐阅读
-
TypeError: POST data should be bytes, an iterable of bytes, or a file object.制作有道翻译小翻译软件的问题解决方法
-
python 3.6.2 TypeError: 'range' object doesn't support item deletion问题解决
-
解决Flask错误“TypeError: 'bool' object is not callable”
-
成功解决TypeError: ‘tuple‘ object is not callable
-
TypeError系列之:TypeError: 'tuple' object is not callable.
-
Django关于TypeError: 'tuple' object is not callable解决方式
-
TypeError: ‘tuple‘ object is not callable
-
python: tuple object is not callable
-
关于Numpy array类型 TypeError: 'tuple' object is not callable
-
TypeError: ‘tuple‘ object is not callable