TypeError: Cannot handle this data type: (1, 1, 3), <f4
img = Image.fromarray(img)
解决方法:
img = img.transpose((1, 2, 0))
#img为numpy数组,先进行维度转换(c,h,w)->(h,w,c)
print('img.shape:', img.shape)
#输出shape:(256,256,3)
img = Image.fromarray(np.uint8(img))
# “img”的NumPy ndarray对象转换为一个PIL,nunit8格式