我正在学校的HPC上的Tensorflow上运行CycleGAN的代码。上周我运行的代码正常运行,但本周停止运行。我相信这可能是由于其中一个模块的更新引起的,但我不确定。
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]!
这是问题所在,下面显示了imwrite和immerge的方法
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
答案 0 :(得分:0)
您的CycleGAN正在保存的图像,即模型返回的图像的值小于-1或大于1。CycleGAN在生成器中的最后一层是 tanh ,范围在-1至1之间因此,请确保生成器的最后一层为tanh或范围在-1至+1之间的函数。