每个像素的彩色图像被转换为 [1,1,1]
colored images being converted to [1,1,1] for every pixel
我正在使用生成器制作图像。我尝试在训练前打印生成器图像,它似乎按预期输出 RGB 的随机值。但是,我用来保存显示训练中每个步骤的函数说“将输入数据剪切到 imshow 的有效范围,使用 RGB 数据([0..1] 表示浮点数或 [0..255] 表示整数)。”
如果需要,我可以包含完整的代码,但它真的很长。所以现在这里是显示每个纪元后图像的函数。
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]。我不知道这里发生了什么。
由于您的数组包含浮点数,您应该将值标准化为区间 [0–1],而不是 0–255。
你可以试试:
img = predictions[i, :, :, :]
img = (imp-np.min(img))/np.ptp(img)
plt.imshow(img)
我正在使用生成器制作图像。我尝试在训练前打印生成器图像,它似乎按预期输出 RGB 的随机值。但是,我用来保存显示训练中每个步骤的函数说“将输入数据剪切到 imshow 的有效范围,使用 RGB 数据([0..1] 表示浮点数或 [0..255] 表示整数)。”
如果需要,我可以包含完整的代码,但它真的很长。所以现在这里是显示每个纪元后图像的函数。
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]。我不知道这里发生了什么。
由于您的数组包含浮点数,您应该将值标准化为区间 [0–1],而不是 0–255。
你可以试试:
img = predictions[i, :, :, :]
img = (imp-np.min(img))/np.ptp(img)
plt.imshow(img)