Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Get Image Embedding Vector and Store it in DATABASE #740

Open
cepa995 opened this issue Apr 28, 2024 · 3 comments
Open

Get Image Embedding Vector and Store it in DATABASE #740

cepa995 opened this issue Apr 28, 2024 · 3 comments

Comments

@cepa995
Copy link

cepa995 commented Apr 28, 2024

Hi,

I am trying to get image embeddings from SAM and save them in a Database, but I am a bit confused with the embedding size.

For example:
image

I see that size is [1, 256, 64, 64]. This is because of the batch size, correct? The embedding should be (1, 256), right?

How can I safely retrieve the correct embedding vector?

@raoxinyu4977
Copy link

The input image has an original size of (1, 3, 1024, 1024). After passing through the VIT encoder (patch_size=16, out_channels=256), the output shape is (1, 256, 1024/16, 1024/16), which then reshapes to (1, 64*64, 256) during subsequent self-attention processing.

@cepa995
Copy link
Author

cepa995 commented Apr 29, 2024

Aha, I see. So it is not typical image encoding into a single vector, such as CLIP does, but a matrix instead.

Does that mean that there is no use in using these image encodings to compute similarity between two images?

@heyoeyo
Copy link

heyoeyo commented May 2, 2024

Does that mean that there is no use in using these image encodings to compute similarity between two images?

The embeddings are always going to be the same shape, so if you wanted to treat them as a single vector to make comparison easier, they could always be combined. For example just by stacking them, averaging, taking the max of each feature etc. or maybe even building a model that merges them into a single vector for a specific use case.

Alternatively, the comparison could be made in 2D, to get a measure of spatial similarity between two images.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants