Python Pillow Image.convert TypeError:参数1必须是str,而不是int
我正试着用这个做一个模型。并获取以下错误:Python Pillow Image.convert TypeError:参数1必须是str,而不是int,python,image,python-imaging-library,Python,Image,Python Imaging Library,我正试着用这个做一个模型。并获取以下错误: Traceback (most recent call last): File "denet_glaucoma_screen/Demo_DENet_GlaucomaScreen.py", line 72, in <module> org_img = np.array(Image.fromarray(org_img).resize((2048, int(org_img.shape[1] * img_scale))).convert
Traceback (most recent call last):
File "denet_glaucoma_screen/Demo_DENet_GlaucomaScreen.py", line 72, in <module>
org_img = np.array(Image.fromarray(org_img).resize((2048, int(org_img.shape[1] * img_scale))).convert(3))
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 975, in convert
im = self.im.convert(mode, dither)
TypeError: argument 1 must be str, not int
看着我不明白为什么那边会有3
我试图将3
更改为“3”
,“RGB”
,甚至关闭整个转换
,但我遇到了各种错误,例如无法处理该类型的数据
或类似的错误
- 更新1:
org\u img=np.array(Image.fromarray(org\u img).resize((2048,int(org\u img.shape[1]*img\u scale)))。convert(3))
到
org\u img=np.array(Image.fromarray(org\u img).resize((2048,int(org\u img.shape[1]*img\u scale),3))
但我得到了以下错误:
File "denet_glaucoma_screen/Demo_DENet_GlaucomaScreen.py", line 74, in <module>
img_scale), 3)))
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 1745, in resize
return self._new(self.im.resize(size, resample, box))
TypeError: argument 1 must be sequence of length 2, not 3
- 更新3: 已尝试运行:
File "denet_glaucoma_screen/Demo_DENet_GlaucomaScreen.py", line 73, in <module>
org_img = np.array(Image.fromarray(org_img, mode='RGB').resize((2048, int(org_img.shape[1]*img_scale), 3)))
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 1745, in resize
return self._new(self.im.resize(size, resample, box))
TypeError: argument 1 must be sequence of length 2, not 3
文件“denet\u GlaucomaScreen\u screen/Demo\u denet\u GlaucomaScreen.py”,第73行,在
org\u img=np.array(Image.fromarray(org\u img,mode='RGB').resize((2048,int(org\u img.shape[1]*img\u scale),3)))
文件“/usr/local/lib/python3.6/dist-packages/PIL/Image.py”,第1745行,调整大小
返回self.\u新建(self.im.resize(大小、重采样、框))
TypeError:参数1必须是长度为2的序列,而不是长度为3的序列
您错误地更改了原始回购协议的代码。这就是他们为组织img所做的:
org_img = scipy.misc.imresize(org_img, (2048, int(org_img.shape[1]*img_scale), 3))
来自scipy
的imresize
已折旧。如果查看旧的scipy
函数的代码和文档,可以看到它们正在传递数组和的org\u img
(2048,int(org\u img.shape[1]*img\u scale),3)
对于大小-即3是指定大小的元组的一部分-他们没有像您在代码中尝试做的那样将其用作转换的模式
由于这是三维的,因此根据resize上的3个维度,scipy
文档会显示:
对于三维和四维阵列,模式将分别设置为“RGB”和“RGBA”
所以你想要:
numpy.array(Image.fromarray(org_img, mode='RGB').resize((2048, int(org_img.shape[1]*img_scale))))
@新的-你能用mode='RGB
试试吗-看看我的最新答案吗!请看我的更新。再次感谢您抽出宝贵的时间@新来的没问题!能否尝试调用Image.fromarray()
函数中的mode='RGB
?我为此更新了。我在文档中找不到“从枕头调整大小”是否接受三维调整大小。。。好像是这样should@new_one好的,.resize
只能调整两个维度的大小。只需将这三个完全去掉,看看模式='RGB'
是否会遇到无法处理您最初尝试剪切这三个是时遇到的那种类型的数据错误!!!!它跑了。把3个拿出来,剩下的由RGB负责。你是最棒的。
File "denet_glaucoma_screen/Demo_DENet_GlaucomaScreen.py", line 73, in <module>
org_img = np.array(Image.fromarray(org_img, mode='RGB').resize((2048, int(org_img.shape[1]*img_scale), 3)))
File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 1745, in resize
return self._new(self.im.resize(size, resample, box))
TypeError: argument 1 must be sequence of length 2, not 3
org_img = scipy.misc.imresize(org_img, (2048, int(org_img.shape[1]*img_scale), 3))
numpy.array(Image.fromarray(org_img, mode='RGB').resize((2048, int(org_img.shape[1]*img_scale))))