jerryli27 / TwinGAN

Twin-GAN -- Unpaired Cross-Domain Image Translation with Weight-Sharing GANs
Apache License 2.0
719 stars 99 forks source link

How to use the corresponding encoder to extract the latent embeddings? #18

Open c1a1o1 opened 5 years ago

c1a1o1 commented 5 years ago

For each domain, we use the corresponding encoder to extract the latent embeddings. For each image in domain X1, we find the nearest neighbors in domain X2 by calculating the cosine distances between the flattened embeddings.

How to implement this part with code? Thank you!

jerryli27 commented 5 years ago

sorry for the late reply!

That part is a proof of concept showing that the latent space is shared among two domains. I did not release that part because the code was quite messy. What you can do is: you can modify inference/image_translation_infer.py to get the latent embedding tensor. (See the encoder output in nets/pggan.py, and try to find the name of the tensor op here: end_points['before_classification'] = net)

Replace FLAGS.output_tensor_name with the tensor name you found.

# Get input and output tensors
self.output = tf.get_default_graph().get_tensor_by_name(FLAGS.output_tensor_name)

After that, save the embedding for each image and do nearest neighbor search using scipy.