chenyuntc / pytorch-book

PyTorch tutorials and fun projects including neural talk, neural style, poem writing, anime generation (《深度学习框架PyTorch:入门与实战》)
MIT License
11.99k stars 3.73k forks source link

第五章使用transforms优化的DogCat问题 #196

Open gfdskl opened 4 years ago

gfdskl commented 4 years ago

书上第138页中,当不提供transforms参数时,返回的data是image类型的,不能够直接使用。 修改建议: def __getitem__(self,index): img_path = self.imgs[index] label = 1 if 'dog' in img_path.split('/')[-1] else 0 pil_img = Image.open(img_path) if self.transforms: data = self.transforms(pil_img) else: array = np.asarray(pil_img) data = t.from_numpy(array) return data,label