from torch.utils.data import Dataset,DataLoader
import numpy as np
import cv2
import os
from PIL import Image
class Data(Dataset):
def __init__(self):
self.path=r'C:\Users\hasee\Desktop\python\image'
self.image_list=os.listdir(self.path)
def __len__(self):
return len(self.iamge_list)
def __getitem__(self,index):
im_id=self.image_list[index]
img=cv2.imread(os.path.join(self.path,im_id))
return img
data = Data()
# 查看数据
print("data index 10 : ",data[2])
dataloader = DataLoader(data,batch_size=3,shuffle=False)
for x,y in dataloader:
print("x",x)
print("y",y)
在使用torch dataset 初始化类报了这个错误,AttributeError: 'Data' object has no attribute 'iamge_list',结果是出来了一部分