繁体   English   中英

如何解决“ AssertionError:输入图像应为float64(32),且范围为[-1.0,1.0]!”

[英]How to fix 'AssertionError: The input images should be float64(32) and in the range of [-1.0, 1.0]!'

我正在学校的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]!

这就是问题所在,下面显示了写入和浸入的方法

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

您的CycleGAN正在保存的图像,即模型返回的图像的值小于-1或大于1。CycleGAN在生成器中的最后一层是tanh,其范围介于-1到1之间。因此,请确保生成器的最后一层是tanh,或范围在-1到+1之间的函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM