簡體   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