Home > Mobile >  GAN generates images only in yellow/green/blue, rather than original images
GAN generates images only in yellow/green/blue, rather than original images

Time:03-15

I am experimenting with generating images using GANs from satellite images. Even though original images are imported with 3 colour channels, the images generated by the model in the first 300-500 epochs generally have a quite distinct colour scheme: yellow, green and blue. See examples below: enter image description here My expectations were the images would generally have similar colour schemes to the source images, even from the start of training. So my question is: is this normal behaviour and if not what could be causing it?

The code for importing the dataset is:

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

And the code for saving generated images is:

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()

I'm basing largely on this framework for enter image description here

CodePudding user response:

The colors are not generated by the GAN, it's just the viridis colormap, which is chosen as the default when you visualize greyscale images, which is what you do by slicing the 0th channel here: plt.imshow(img_array[0,:,:,0]). what happens if you do plt.imshow(img_array[0,:,:,:]) instead?

More information about colormaps: https://matplotlib.org/stable/tutorials/colors/colormaps.html

  • Related