Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change scipy.misc.imresize() to PIL.Image.resize() #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

guplersaxanoid
Copy link

scipy.misc.imresize() was depreciated in SciPy 1.0.0, and was removed in 1.3.0.

replacement of depreciated scipy.misc.imresize with PIL.Image.resize()
@@ -184,7 +184,7 @@ def evaluate():
tl.vis.save_image(valid_lr_img[0], os.path.join(save_dir, 'valid_lr.png'))
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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants