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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import time
import random
import numpy as np
import scipy, multiprocessing
import tensorflow as tf
import tensorlayer as tl
from model import get_G, get_D
from config import config
from PIL import Image

###====================== HYPER-PARAMETERS ===========================###
## Adam
Expand Down Expand Up @@ -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.

tl.vis.save_image(out_bicu, os.path.join(save_dir, 'valid_bicubic.png'))


Expand Down