r/learnmachinelearning • u/assorted-meat-stew • 28d 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
1
u/CelebrityChess 27d 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.
0
u/[deleted] 28d ago
[removed] — view removed comment