How can one find the most similar image in the input data training set to the output of a tensorflow implementation of Deep Convolutional Generative Adversarial Networks?

If I use DCGAN, faces will be learned and I want to find the most similar image to the output from the within the training set.

Edit: Question to the practical: DCGAN: How to nearest neighbor on the training set in sense of compressed sensing?

  • $\begingroup$ Is there some context for this question? As of now, it reads "how do I use nearest neighbours", more or less, which is too broad. What does it have to do with GANs? $\endgroup$ Nov 3, 2017 at 19:05
  • $\begingroup$ @MatthewDrury This is not a trivial task and it does very much have something to do with GANs. Please see my answer and let me know if something is unclear. $\endgroup$
    – pir
    Nov 4, 2017 at 6:49
  • $\begingroup$ @pir That may be true, but it wasn't really my point. As it is asked now, the non-triviality and connection to GAN's is only accessible to domain experts. This makes it a an unfortunately narrow question in the context of our site. It would be very nice to have a rich description for in the question for people like me, who have a diverse set of interests, but no deep knowledge on GANs. $\endgroup$ Nov 4, 2017 at 17:55

1 Answer 1


This is not a trivial task and to my knowledge, there's no clearly superior way of doing this. You can't just use nearest neighbours in pixel space as the GAN can easily just have shifted the output a few pixels to either side, making the per pixel difference very high. The best approach is probably to find nearest neighbours in a compressed representation space such as the latent code vector of a convolutional autoencoder. Some GANs also have autoencoder-like architectures, making it easy to compare in their latent code space.

  • $\begingroup$ hey, can you give me more details about the "compressed representation space" $\endgroup$
    – Peter
    Nov 4, 2017 at 16:18
  • $\begingroup$ If you search for a convolutional autoencoder, it should be clear from the illustration/descrption. It's a single fixed-size vector that contains the information from the input. This vector is then used to reconstruct the input. $\endgroup$
    – pir
    Nov 4, 2017 at 16:20

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.