【发布时间】: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