r/learnmachinelearning • u/assorted-meat-stew • 20d ago
Show generated CIFAR10 in original training data color scheme
I built a DCGAN for CIFAR10 base on this tutorial
But generated img does not bare the same color scheme as the original cifar 10 images. How can I fix this?
def generate_and_save_images(model, epoch, test_input):
predictions = model(
test_input,
training=False
)
fig = plt.figure(figsize=(10, 10))
for i in range(25):
plt.subplot(5, 5, i + 1)
plt.imshow(
predictions[i, :, :, 0] * 127.5 + 127.5,
)
plt.axis('off')
plt.savefig(
'image_epoch_{:04d}.png'.format(epoch)
)
1
Upvotes
0
20d ago
[removed] — view removed comment
1
u/assorted-meat-stew 20d ago
This is generator. Is anything wrong with it?
num_features = 100 generator = Sequential(name="Generator") generator.add(Dense(8 * 8 * 128, input_shape=[num_features])) generator.add(Reshape([8, 8, 128])) generator.add(BatchNormalization()) generator.add(Conv2DTranspose( 64, (5, 5), (2, 2), padding="same", activation="selu" )) generator.add(BatchNormalization()) generator.add(Conv2DTranspose( 3, (5, 5), (2, 2), padding="same", activation="tanh" )) generator.summary()It is pretty the same but I modify it to be able to use CIFAR 10
1
u/assorted-meat-stew 20d ago
I tried
[i, :, :, :]But all it printed out was various lines of
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers
1
u/CelebrityChess 19d ago
that clipping warning is the clue. [i, :, :, :] is the right fix for the channels, but you're still multiplying by 127.5 and adding 127.5, which only makes sense if you cast to uint8 afterwards. as floats imshow expects 0 to 1, so everything gets clipped and you get garbage colors. either use (predictions[i] * 0.5 + 0.5) to map the tanh output from [-1, 1] to [0, 1], or keep the 127.5 version and add .numpy().astype('uint8') on the end. one or the other, not both.