遇到的问题 数据是png图像的时候,如果用PIL读取图像,获得的是单通道的,不是多通道的。虽然使用opencv读取图片可以获得三通道图像数据,如下: def __getitem__(self, idx): image_root = self.train_image_file_paths[idx] image_name = image_root.split(os.path.sep)[-1] image = cv.imread(image_root) if self.transform is not None: image = self.transform(image) label = ohe.encode(image_name.split('_')[0]) return image, label 但是会出现报错: TypeError: img should be PIL Image. Got <class 'numpy.ndarray'> File "c:/Users/pprp/Desktop/pytorch-captcha-recognition-master/captcha_train.py", line 77, in <module> main(args) File "c:/Users/pprp/Desktop/pytorch-captcha-recognition