【发布时间】:2019-05-01 08:48:22
【问题描述】:
我正在使用来自 github 的代码 https://github.com/eriklindernoren/Keras-GAN/blob/master/gan/gan.py
The demo code show 25 generated image in one single image file. 但我想将原始大小的每张图像打印为 png 文件。我尝试了几种方法,例如
plt.imshow()
或
cv2.imwrite()
但是,他们没有工作。如果没有子图图像,我无法打印正确的图像。
这是打印图像的部分:
def sample_images(self, epoch):
r, c = 5, 5
noise = np.random.normal(0, 1, (r * c, self.latent_dim))
gen_imgs = self.generator.predict(noise)
# Rescale images 0 - 1
gen_imgs = 0.5 * gen_imgs + 0.5
fig, axs = plt.subplots(r, c)
cnt = 0
for i in range(r):
for j in range(c):
axs[i,j].imshow(gen_imgs[cnt, :,:,0], cmap='gray')
axs[i,j].axis('off')
cnt += 1
fig.savefig("images/%d.png" % epoch)
plt.close()
非常感谢。
【问题讨论】:
标签: python matplotlib subplot