Reputation: 101
I am running code for CycleGAN on tensorflow on my school's HPC. The code I was running worked last week, but then it stopped working this week. I believe it might be due to an update to one of the modules but I am not sure.
Traceback (most recent call last):
File "test.py", line 55, in <module>
im.imwrite(im.immerge(a_img_opt, 1, 3), a_save_dir + '/' + img_name)
File "/home/kseelma/PleaseWork/image_utils.py", line 46, in imwrite
return scipy.misc.imsave(path, _to_range(image, 0, 255, np.uint8))
File "/home/kseelma/PleaseWork/image_utils.py", line 14, in _to_range
'The input images should be float64(32) and in the range of [-1.0, 1.0]!'
AssertionError: The input images should be float64(32) and in the range of [-1.0, 1.0]!
This is the problem and the methods imwrite and immerge are shown below
def imwrite(image, path):
# save an [-1.0, 1.0] image
return scipy.misc.imsave(path, _to_range(image, 0, 255, np.uint8))
def immerge(images, row, col):
"""Merge images.
merge images into an image with (row * h) * (col * w)
`images` is in shape of N * H * W(* C=1 or 3)
"""
if images.ndim == 4:
c = images.shape[3]
elif images.ndim == 3:
c = 1
h, w = images.shape[1], images.shape[2]
if c > 1:
img = np.zeros((h * row, w * col, c))
else:
img = np.zeros((h * row, w * col))
for idx, image in enumerate(images):
i = idx % col
j = idx // col
img[j * h:j * h + h, i * w:i * w + w, ...] = image
return img
Upvotes: 0
Views: 387
Reputation: 33
The image your CycleGAN is saving i.e the image returned by the model has values less than -1 or greater than 1. CycleGAN's last layer in generator is a tanh whose range is between -1 to 1. Hence make sure the last layer of your generator is tanh, or a function whose range is between -1 to +1.
Upvotes: 1