自制深度学习照片数据集
data_list = list()
label_list = list()
files = 照片文件夹
for file,i in enumrate(files):
label_tensor = torch.tensor([i])
imgs = os.listdir(file)
for img in imgs:
image = PIL.Image.open(img) #格式:np
或:
image = cv2.imread(img) #格式:np
image_tesnor = transform(image) #格式:tensor
data_list.append(image_tensor)
label_list.append(label_tensor)
data = torch.stack(data_list)
label = torch.stack(label_list)
评论