PIL,Cannot handle this data type;ReLU,PReLU,LeakyReLU

1、使用PIL保存图片,保存代码的前几行是

im_h = im_h*255.
im_h = np.clip(im_h, 0., 255.)
im_h = im_h.transpose(1,2,0).astype(np.float32)
im = Image.fromarray(im_h)
im.save('out.png')

出现了下面的报错

Traceback (most recent call last):
File "/anaconda3/envs/py36/lib/python3.6/site-packages/PIL/Image.py", line 2749, in fromarray
 mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1, 3), '<f4')
Traceback (most recent call last):
  File "eval.py", line 89, in <module>
    im = Image.fromarray(im_h)
  File "/home/lab-cao.qiaoyu/anaconda3/envs/py36/lib/python3.6/site-packages/PIL/Image.py", line 2751, in fromarray
The above exception was the direct cause of the following exception:
    raise TypeError("Cannot handle this data type: %s, %s" % typekey) from e
TypeError: Cannot handle this data type: (1, 1, 3), <f4

这里的错误位置是:im = Image.fromarray(im_h)。前面的代码对im_h进行了复杂的图像预处理,但是转为图像出了错。这是因为fromarray默认会将图像转为uint8类型(也就是RGB每个通道由8bit表示的图像格式),一旦输入的np数组不是这个格式,就无法正常转化。因此我们需要改成

im = Image.fromarray(np.uint8(im_h))

或者是

im = Image.fromarray(np.uint8(im_h)).convert('RGB')

2、激活函数ReLU、Leaky ReLU、PReLU和RReLU

这篇文章讲得不错 激活函数ReLU、Leaky ReLU、PReLU和RReLU

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值