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

1. Use PIL to save the picture, the first few lines of the save code are

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')

The following error occurred

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

The error position here is: im = Image.fromarray(im_h). The previous code performed complex image preprocessing on im_h, but it was converted to an image by mistake. This is because fromarray will convert the image to uint8 by default (that is, the image format in which each channel of RGB is represented by 8bit). Once the input np array is not in this format, it cannot be converted normally. So we need to change to

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

or it could be

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

2. Activation functions ReLU, Leaky ReLU, PReLU and RReLU

This article speaks good activation function ReLU, Leaky ReLU, PReLU and RReLU

Guess you like

Origin blog.csdn.net/eight_Jessen/article/details/108767191