This is a Streamlit application that allows us to find similar images based on a query image. The application utilizes a pre-trained ResNet-18 model for feature extraction and computes similarity scores to identify similar images from a given directory of images.
Before running the application, we have to install the following dependencies:
- Python
- PyTorch
- torchvision
- Pillow (PIL)
- numpy
- scipy
- streamlit
We can install these dependencies using pip
.
-
Download the code.
-
Organize your images in a directory and set the
image_dir
variable in the code to the path of this directory. -
Set the desired configuration options such as
similar_image_size
,selected_metric
, andthreshold
according to your requirements. -
Run the application:
streamlit run app.py
-
In the Streamlit app, we can upload a query image by clicking the "Upload a query image" button.
-
The application will process the query image and display the most similar images based on the chosen similarity metric and threshold.
-
image_dir
: The directory containing the images we want to search for similarities. -
similar_image_size
: The size at which similar images are displayed in the application. Adjust this value to your preference. -
selected_metric
: The similarity metric used to calculate the distance between embeddings. The default is "euclidean," but we can choose other metrics such as "cosine." -
threshold
: The threshold value for considering an image as similar. Images with a distance less than this threshold are considered similar.