GAN 只生成黄色/绿色/蓝色的图像,而不是原始图像

青葱年少 tensorflow 522

原文标题GAN generates images only in yellow/green/blue, rather than original images

我正在尝试使用 GAN 从卫星图像中生成图像。尽管原始图像是使用 3 个颜色通道导入的,但模型在前 300-500 个 epoch 中生成的图像通常具有非常不同的配色方案:黄色、绿色和蓝色。请参阅下面的示例:enter image description here我的期望是图像通常与源图像具有相似的配色方案,即使从训练开始也是如此。所以我的问题是:这是正常行为吗?如果不是,可能是什么原因造成的?

导入数据集的代码是:

def create_training_data():
    for img in os.listdir(path):
        try:
            img_array = cv2.imread(os.path.join(path,img), 1)
            new_array = cv2.resize(img_array, (200, 200))
            training_data.append([new_array])
        except Exception as e:
            pass

保存生成图像的代码是:

def save_imgs(epoch):
    noise = np.random.normal(0, 1, (1, 100))
    gen_imgs = generator.predict(noise)
    gen_imgs = 0.5 * gen_imgs + 0.5 #rescaling
    img_array = np.reshape(gen_imgs, (1,200,200,3))
    plt.imshow(img_array[0,:,:,0])
    plt.axis('off')
    plt.savefig("generated/generated_%d.png" % epoch)
    plt.close()

我主要基于这个框架的代码示例。

会不会是在最初的几百个 epoch 中,生成器没有学习颜色? (到目前为止,我只训练了 500 个 epoch,开始看到结果并了解颜色问题背后的原因)。

或者可能是根本没有足够的训练数据? (我从 200 张图像的适度数据集开始,再次只是为了开始试验。)

任何建议表示赞赏。干杯!

原文链接:https://stackoverflow.com//questions/71465548/gan-generates-images-only-in-yellow-green-blue-rather-than-original-images

回复

我来回复
  • AloneTogether的头像
    AloneTogether 评论

    您似乎只显示一个频道。也许尝试:

    import tensorflow as tf
    import matplotlib.pyplot as plt
    
    img_array = tf.random.normal((1,200,200,3))
    plt.imshow(img_array[0,:,:,:])
    

    enter image description here

    2年前 0条评论
  • JDornheim的头像
    JDornheim 评论

    颜色不是由 GAN 生成的,它只是 viridis 颜色图,当您可视化灰度图像时将其选为默认值,这就是您在此处切片第 0 个通道所做的:plt.imshow(img_array[0,:,:,0])。如果你这样做plt.imshow(img_array[0,:,:,:])会发生什么?

    关于颜色图的更多信息:https://matplotlib.org/stable/tutorials/colors/colormaps.html

    2年前 0条评论