A-Ijishakin / Contrast-DiffAE

9 stars 3 forks source link

Regarding the t-SNE image #1

Open Vummal opened 6 months ago

Vummal commented 6 months ago

Hi,

I have read your paper. I am interested in your t-SNE image. Is it possible to share the code to get it or the way to get it? You will be very appreciated. Thanks a lot.

A-Ijishakin commented 6 months ago

Hello and thanks for reading the paper.

Below is some code which can be used to make the t-SNE plot, assuming that you have the encoder trained and a dataloader which loads in img's one by one:

from sklearn.manifold import TSNE import seaborn as sns

set the latent dimension

latent_dim = 512 embeddings = [] classes = []

loop through images, encode them and then append the result

for img, class in dataloader: embeddings.append(encoder(img)) classes.append(class)

put on the cpu and convert into numpy arrays

embeddings = [emb.cpu().numpy().reshape(latent_dim) for emb in embeddings]

instantiate TSNE embedder

reducer = TSNE(n_components=2, perplexity=30, learning_rate=200, n_iter=1000, random_state=42)

fit TSNE

embedding = reducer.fit_transform(embeddings)

plot

sns.scatterplot(x=embedding[:,0], y=embedding[:,1], hue=classes, palette="deep") plt.title('TSNE Embedding') plt.show()

Vummal commented 6 months ago

Thanks for sharing! I will try it.