alibi-detect icon indicating copy to clipboard operation
alibi-detect copied to clipboard

How to get the encoded results/embeddings in Outlier Detection?

Open ahmadSum1 opened this issue 1 year ago • 2 comments

I can see from the API reference/examples that I can get the reconstructed image using the calling the od.vae(input_image) function. Is there a way to get the latent codes/output of the encoder?

ahmadSum1 avatar May 25 '23 00:05 ahmadSum1

Hey @ahmadSum1, Assuming you've followed the examples here then you can get the latent codes using the following:

z_mean, z_log_var, z = od.vae.encoder(input_image)

Internally we use the reparameterization trick, so z_mean and z_log_var_z parameterize a normal distribution in the latent space, and z is a latent code sampled from this distribution. I'd use z_mean as the latent code as it'll behave deterministically.

Can I ask what your use case is? We've not particularly written the VAE behaviour to make the above easy for users but if there's a good reason to update the docs or code we'd be interested to hear.

mauicv avatar May 25 '23 08:05 mauicv

Hello @mauicv , Thanks for the prompt response. I am trying to plot the PCA/TSNE results on the latent space. I believe it will be an important feature to provide these built-in or at least document the way to access the submodules. I.e., histogram plotting of the embeddings, to see how different code size affect the performance.

ahmadSum1 avatar May 25 '23 12:05 ahmadSum1