0
$\begingroup$

I'm working on a Gan. Based on different papers, I use a Tanh activation function on the last layer of the generator. Which produces [-1,1] outputs.

To make this coherent, I use image normalization with cv2:

cv2.normalize(image, image, alpha=-1, beta=1, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_32F)

Example:

origin image: enter image description here

normalized image: enter image description here

(first image is 32,32, second is probably 128,128 it is for the sake of demonstration)

We can clearly see the colours are not the same. After training the models for 10 hours. I can generate all this images, which are interesting: enter image description here

Here's how I generate and plot my images:

latent_points = generate_latent_points(100, 20)
generated = generator_model.predict(latent_points)

plt.figure(figsize=(10,10))
for i in range(generated.shape[0]):
    plt.subplot(4, 5, i+1)
    image = generated[i, :, :, :]
    image = np.reshape((image), [32, 32, 3])
    plt.imshow(image, vmin=-1, vmax=1)
    plt.axis('off')
plt.tight_layout()

My question: is this kind of result normal? is it the way I normalize images that is wrong, or should I apply some transformation after the generation?

$\endgroup$
3
  • $\begingroup$ If you use normalized images to train your GAN on the GAN will learn to produce images in that same range. If you want see the result in the original value range you will have to apply the inverse transform to the output of the model. $\endgroup$
    – Oxbowerce
    Commented Jan 20, 2022 at 13:48
  • $\begingroup$ It's the process of "inverse transform" that I don't understand in this case. The transformartion is done on each input image, each with its max/min. How can that be reproduced on the output image generated by the Gan? $\endgroup$
    – Bouji
    Commented Jan 20, 2022 at 13:56
  • $\begingroup$ You generally perform the transformations based on the attributes of the whole dataset instead of a specific sample. So if the value range of the whole dataset is 0-255 but a single image has values in the range 0-120 you transform the image based on the 0-255 range. When the GAN creates new images you can then use the 0-255 to perform the inverse transformation. $\endgroup$
    – Oxbowerce
    Commented Jan 20, 2022 at 14:09

1 Answer 1

0
$\begingroup$

it looks like color space inversion to BGR. Just reverse it using cv2.cvtColor(image, cv2.COLOR_BGR2RGB) and you are good to go.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.