change scipy.misc.imresize() to PIL.Image.resize()#179
change scipy.misc.imresize() to PIL.Image.resize()#179guplersaxanoid wants to merge 2 commits intotensorlayer:masterfrom
scipy.misc.imresize() to PIL.Image.resize()#179Conversation
replacement of depreciated scipy.misc.imresize with PIL.Image.resize()
| tl.vis.save_image(valid_hr_img, os.path.join(save_dir, 'valid_hr.png')) | ||
|
|
||
| out_bicu = scipy.misc.imresize(valid_lr_img[0], [size[0] * 4, size[1] * 4], interp='bicubic', mode=None) | ||
| out_bicu = np.array(Image.fromarray(valid_lr_img[0]).resize((size[0] * 4, size[1] * 4), resample=Image.BICUBIC)) |
There was a problem hiding this comment.
I ran into the following error after applying this change.
Traceback (most recent call last):`
File "C:\Users\chuzh\venv\lib\site-packages\PIL\Image.py", line 2645, 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 ".\train.py", line 210, in
evaluate()
File ".\train.py", line 192, in evaluate
out_bicu = np.array(Image.fromarray(valid_lr_img[0]).resize((size[0] * 4, size[1] * 4), resample=Image.BICUBIC))
File "C:\Users\chuzh\venv\lib\site-packages\PIL\Image.py", line 2647, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type
Once I changed this line
out_bicu = np.array(Image.fromarray(valid_lr_img[0]).resize((size[0] * 4, size[1] * 4), resample=Image.BICUBIC))
to
out_bicu = np.array(Image.fromarray(((valid_lr_img[0] + 1)*127.5).astype(np.uint8)).resize((size[1] * 4, size[0] * 4), resample=Image.BICUBIC))
everything works correctly.
This is due to the fact that Image.fromarray( ) function only takes in numpy array whose elements are uint8 data type.
scipy.misc.imresize()was depreciated in SciPy 1.0.0, and was removed in 1.3.0.