Given groups=1, weight of size [1, 3, 7, 7], expected input[9, 4, 235, 235] to have 3 channels, but got 4 channels instead
问题:主要是图像的mode 的问题,代码中要求的是 RGB 三通道,而我输入的图像是 RGBA 四通道的。
解决方法:
if os.path.isfile(self.config.img):
image = Image.open(self.config.img)
if image.mode != 'RGB':
image = image.convert('RGB')
完美解决!