# Tutorials/materials for fast image retrieval tasks

**URL:** <https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051>\
**Category:** General Discussion\
**Tags:** education, learning, keras\
**Created:** [June 16, 2021, 10:26am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051 "2021-06-16T10:26:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sayak\_Paul](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sayak_paul/32/13002_2.png) [@Sayak\_Paul](https://discuss.ai.google.dev/u/Sayak_Paul)\
**Post date:** [June 16, 2021, 10:26am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/1 "2021-06-16T10:26:36Z")

</div>

Hi all.

Looking for resources/materials that build on TensorFlow/Keras (preferably) for doing scalable image similarity searches.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 16, 2021, 11:05am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/2 "2021-06-16T11:05:44Z")

</div>

With Keras you can take a look at:

- [Investigating the Vision Transformer Model for Image Retrieval Tasks](https://arxiv.org/abs/2101.03771)  
\*[DELF tutorial](https://www.tensorflow.org/hub/tutorials/tf_hub_delf_module)

More in general I suggest you an overview:

> **[Deep Learning for Instance Retrieval: A Survey](https://arxiv.org/abs/2101.11282)**
>
> In recent years a vast amount of visual content has been generated and shared from many fields, such as social media platforms, medical imaging, and robotics. This abundance of content creation and sharing has introduced new challenges, particularly...

---

<div class="post-metadata">

**Author:** ![Sayak\_Paul](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sayak_paul/32/13002_2.png) [@Sayak\_Paul](https://discuss.ai.google.dev/u/Sayak_Paul)\
**Post date:** [June 16, 2021, 11:27am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/3 "2021-06-16T11:27:26Z")

</div>

Thanks @Bhack.

I am aware of the DELF model but I don’t want to go that route, I would rather prefer good old embeddings (within a reduced space with something like random projections), and then applying approximate nearest neighbors.

Thanks for the survey paper, will look into it. Maybe a TFX example on this might be very helpful given the practical relevancy. Cc: @Robert\_Crowe

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 16, 2021, 12:00pm UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/4 "2021-06-16T12:00:05Z")

</div>

> [@Sayak\_Paul](#):
>
> good old embeddings

When you have created your more or less efficient embedding e.g.:

> **[Keras documentation: Metric learning for image similarity search](https://keras.io/examples/vision/metric_learning/)**
>
> Keras documentation

[https://keras.io/examples/nlp/nl\_image\_search/](https://keras.io/examples/nlp/nl_image_search/)

> **[Keras documentation: Image similarity estimation using a Siamese Network with...](https://keras.io/examples/vision/siamese_network/)**
>
> Keras documentation

Then, you can use almost the same pipeline as in text:

> **[Overview of Vertex AI Vector Search  |  Google Cloud](https://cloud.google.com/vertex-ai/docs/vector-search/overview)**

---

<div class="post-metadata">

**Author:** ![Sayak\_Paul](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sayak_paul/32/13002_2.png) [@Sayak\_Paul](https://discuss.ai.google.dev/u/Sayak_Paul)\
**Post date:** [June 16, 2021, 1:02pm UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/5 "2021-06-16T13:02:53Z")

</div>

Thanks.

I am quite familiar with the Keras examples that you shared. In fact, I myself have one:

> **[GitHub - sayakpaul/A-Barebones-Image-Retrieval-System: This project presents a simple framework to...](https://github.com/sayakpaul/A-Barebones-Image-Retrieval-System)**
>
> This project presents a simple framework to retrieve images similar to a query image.

All of them demonstrate workflows which is why I wanted to know about solutions that focus on scalability and depth. Thanks for the GCP one.

---

<div class="post-metadata">

**Author:** ![Bhack](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bhack/32/6388_2.png) [@Bhack](https://discuss.ai.google.dev/u/Bhack)\
**Post date:** [June 16, 2021, 5:38pm UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/6 "2021-06-16T17:38:18Z")

</div>

Is that also this domain Is quite large and It has evolved a little bit over the time.

As you can see from the mentioned survey and also in:

> **[A Decade Survey of Content Based Image Retrieval using Deep Learning](https://arxiv.org/abs/2012.00641)**
>
> The content based image retrieval aims to find the similar images from a large scale dataset against a query image. Generally, the similarity between the representative features of the query image and dataset images is used to rank the images for...

---

<div class="post-metadata">

**Author:** ![ShivamShrirao](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/shivamshrirao/32/7209_2.png) [@ShivamShrirao](https://discuss.ai.google.dev/u/ShivamShrirao)\
**Post date:** [June 17, 2021, 12:39am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/7 "2021-06-17T00:39:51Z")

</div>

Well if Tensorflow/keras isn’t a necessity you can try CLIP model by OpenAI. It is quite robust and has good generalizability. You can pre calculate all the images embeddings and calculate cosine similarity with your query image. For huge number of images at large scale you can use Approximate Nearest Neighbor with Hnswlib:

> **[GitHub - nmslib/hnswlib: Header-only C++/python library for fast...](https://github.com/nmslib/hnswlib)**
>
> Header-only C++/python library for fast approximate nearest neighbors

or Faiss:

> **[GitHub - facebookresearch/faiss: A library for efficient similarity search and...](https://github.com/facebookresearch/faiss)**
>
> A library for efficient similarity search and clustering of dense vectors.

or Annoy:

> **[GitHub - spotify/annoy: Approximate Nearest Neighbors in C++/Python...](https://github.com/spotify/annoy)**
>
> Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk

CLIP is usually used by encoding the text to same embedding domain as images, but it should work within images itself too since they are in same domain.

---

<div class="post-metadata">

**Author:** ![Sayak\_Paul](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sayak_paul/32/13002_2.png) [@Sayak\_Paul](https://discuss.ai.google.dev/u/Sayak_Paul)\
**Post date:** [June 17, 2021, 1:26am UTC](https://discuss.ai.google.dev/t/tutorials-materials-for-fast-image-retrieval-tasks/28051/8 "2021-06-17T01:26:04Z")

</div>

Thanks for your suggestions. Using ANN has been on my mind from the beginning. After looking for a few other options I also saw NGT which seems to be producing the best results too.

For within image domain pre-training, I would rather prefer the recent self-supervised methods like DINO because they are well formulated and we’ll established. DINO is also particularly good at this task.

Just as an FYI, one of the Keras links above (shared by @Bhack) actually shows you how to implement a CLIP like model minimally. If you haven’t, definitely check that out 🙂
