TypeError:无法处理此数据类型:(1,1,3),<;f4 [英] TypeError: Cannot handle this data type: (1, 1, 3), <f4
本文介绍了TypeError:无法处理此数据类型:(1,1,3),<;f4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
temp_image为(600,600,3),取值范围为0到1。
def pro_process(temp_img, input_size):
img = np.asarray(temp_img).astype('float32')
img = np.array(Image.fromarray(img).resize((input_size, input_size)).convert(3))
return img
它显示以下错误:
Traceback (most recent call last):
File "S:Program FilesPython36libsite-packagesPILImage.py", line 2681, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 3), '<f4')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "H:OneDrivesynchronization codeDeveloping collectionPythonMNet_DeepCDR-mastermnet_deep_cdr_ide
unStep_3_MNet_test.py", line 56, in <module>
temp_img = pro_process(Disc_flat, CDRSeg_size)
File "S:Program FilesPython36libsite-packagesmnet_deep_cdrmnet_utils.py", line 18, in pro_process
img = np.array(Image.fromarray(img).resize((input_size, input_size)).convert(3))
File "S:Program FilesPython36libsite-packagesPILImage.py", line 2683, in fromarray
raise TypeError("Cannot handle this data type: %s, %s" % typekey)
TypeError: Cannot handle this data type: (1, 1, 3), <f4
项目链接:https://github.com/HzFu/MNet_DeepCDR
错误是什么以及如何修复?
根据此链接:PIL TypeError: Cannot handle this data type我已更新代码,但仍有错误
def pro_process(temp_img, input_size):
print(temp_img.shape)
img = np.asarray(temp_img).astype('float32')
img = np.array(Image.fromarray((img * 255).astype(np.uint8)).resize((input_size, input_size)).convert(3))
return img
错误:
Traceback (most recent call last):
File "H:OneDrivesynchronization codeDeveloping collectionPythonMNet_DeepCDR-mastermnet_deep_cdr_ide
unStep_3_MNet_test.py", line 56, in <module>
temp_img = pro_process(Disc_flat, CDRSeg_size)
File "S:Program FilesPython36libsite-packagesmnet_deep_cdrmnet_utils.py", line 18, in pro_process
img = np.array(Image.fromarray((img * 255).astype(np.uint8)).resize((input_size, input_size)).convert(3))
File "S:Program FilesPython36libsite-packagesPILImage.py", line 995, in convert
im = self.im.convert(mode, dither)
TypeError: argument 1 must be str, not int
推荐答案
错误消息似乎是在抱怨形状,但实际上是关于数据类型。乘以255,然后更改为uint8,为我解决了此问题:
random_array = np.random.random_sample(content_array.shape) * 255
random_array = random_array.astype(np.uint8)
random_image = Image.fromarray(random_array)
这篇关于TypeError:无法处理此数据类型:(1,1,3),<;f4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文