报错:
原因:
因为我下载的图片是4通道的:通过下面打印出来的结果可知是RGBA四通道的。
解决方法:
但是网络的输入需要RGB三通道,因此需要使用下列方法进行转换:
image_path = "../imgs/dog.png"
image = Image.open(image_path)
image = image.convert("RGB")
print(image) # size=455x297
可以发现转换后的格式为:
报错:
原因:
因为我下载的图片是4通道的:通过下面打印出来的结果可知是RGBA四通道的。
解决方法:
但是网络的输入需要RGB三通道,因此需要使用下列方法进行转换:
image_path = "../imgs/dog.png"
image = Image.open(image_path)
image = image.convert("RGB")
print(image) # size=455x297
可以发现转换后的格式为: