这是我的代码行:
cam_gb = Image.fromarray(cam_gb)
在这里,
cam_gb
的类型为 numpy.ndarray
、dtype float64
和形状 (3, 224, 224)
。所以当我运行这个时,我收到一个错误:
File "\site-packages\PIL\Image.py", line 3073, in fromarray
raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 224), <f8
即使我将
cam_gb
从形状 (3, 224, 224)
转置为 (224, 224, 3)
,我也会遇到同样的错误。
我也尝试过:
cam_gb = Image.fromarray(cam_gb.astype(np.uint8))
我收到此错误:
File "\lib\site-packages\PIL\Image.py", line 3073, in fromarray
raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 224), |u1
我也尝试过:
cam_gb = Image.fromarray((cam_gb * 255).astype(np.uint8))
但出现此错误:
File "\lib\site-packages\PIL\Image.py", line 3073, in fromarray
raise TypeError(msg) from e
TypeError: Cannot handle this data type: (1, 1, 224), |u1
请帮忙。 谢谢
我想尝试一下:
cam_gb_on_image = Image.alpha_composite(original_image, cam_gb)