Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复';AssertionError:输入图像应该是float64(32)并且在[-1.0,1.0]的范围内';_Python_Tensorflow - Fatal编程技术网

Python 如何修复';AssertionError:输入图像应该是float64(32)并且在[-1.0,1.0]的范围内';

Python 如何修复';AssertionError:输入图像应该是float64(32)并且在[-1.0,1.0]的范围内';,python,tensorflow,Python,Tensorflow,我在学校的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/Plea

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

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

to_range期望您的输入由-1.0到1.0范围内的浮点组成。尝试检查输入内容以查看其格式,它们可能已经是0到255之间的整数。
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