【问题标题】:colored images being converted to [1,1,1] for every pixel每个像素都将彩色图像转换为 [1,1,1]
【发布时间】:2020-11-07 16:44:06
【问题描述】:

我正在使用生成器来制作图像。我尝试在训练之前打印出生成器图像,它似乎按预期输出了 RGB 的随机值。但是,我用来保存显示训练中每个步骤的函数显示“使用 RGB 数据将输入数据剪切到 imshow 的有效范围(浮点数为 [0..1] 或整数为 [0..255])。”

如果需要,我可以包含完整的代码,但它真的很长。所以现在这里是显示每个 epoch 后图像的函数。

def generate_and_save_images(model, epoch, test_input):
  predictions = model(test_input, training=False)

  fig = plt.figure(figsize=(16,16))

  for i in range(predictions.shape[0]):
      print(predictions)
      plt.subplot(4, 4, i+1)
      plt.imshow(predictions[i, :, :, :] * 127.5 + 127.5)
      plt.axis('off')

  plt.show()

这是它打印的内容。当然,这只是其中的一部分。

[[[[-0.08561043 -0.16898969 -0.04297004]
   [-0.27353853 -0.11766727 -0.05380717]
   [-0.0349301   0.01892653 -0.02630406]
   ...

但是,图中显示的图像的每个像素都有 [1,1,1]。我不知道这里发生了什么。

【问题讨论】:

  • 如果您的数组是形状 3 并且类型为浮点数,imshow 假定它是介于 0 和 1 之间的 RGB 值。但是,您的值远远超过 1,因此它们被截断为 1。您应该尝试将数组类型更改为整数,例如通过添加 ().astype(int)

标签: image tensorflow matplotlib colors generator


【解决方案1】:

由于您的数组包含浮点数,您应该将值标准化为区间 [0–1],而不是 0–255。

你可以试试:

img = predictions[i, :, :, :]
img = (imp-np.min(img))/np.ptp(img)
plt.imshow(img)

【讨论】:

    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多