Git Product home page Git Product logo

image_similarity's Introduction

Image Similarity using PyTorch

CI Tests Check Formatting Deploy mkdocs PyPi Release Install Package

Auto-encoder based Image-Similarity Engine

Blog Post is here

Dataset is available over Kaggle

Published in Official PyTorch Medium Channel. Thank you PyTorch team !

  • Builds a simple Convolutional Auto-encoder based Image similarity engine.
  • This solves the problem of finding similar images using unsupervised learning. There are no labels for images.

Tasks that it can do.

  • Similar images using Auto-encoders.
  • Similar image search from image features.
  • Clustering similar images.

Repostory Structure.

=== data                        Read data from here. It is in gitignore so it won't appear here.
=== docs                        Documentation using mkdocs.
=== image_similarity
====== cluster_images.py        Clusters the embeddings learnt using PCA and T-SNE.
====== torch_data.py            Contains Dataset class to create PyTorch dataset from folder.
====== torch_model.py           Convolutional Auto-enocder Model.
====== torch_engine.py          Train_step and validation_step for training.
====== torch_train.py           Trainng script. Trains Auto-enocder and saves the embeddings.
====== torch_infer.py           Contains inference code
====== config.py                Configurations of models and paths.
====== torch_inference.ipynb    Inference code in .ipynb to play with.
====== torch_train.ipynb        Stand-alone code to train in Jupyter.
=== tests                       Contains tests for CI

Documentation

Please visit here for documentation.

It contains detailed description of work.

Image similarity Outputs

Some sample outputs of recommendations.

Output 1

Output 2

More outputs can be found in outputs folder.

Models

  • Some models trained using a sample dataset are given in this link.
  • It contains encoder, decoder and numpy embeddings generated from auto-enocoders.
  • These are obtained by running torch_train.py script.

image_similarity's People

Contributors

jonathansum avatar oke-aditya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

image_similarity's Issues

UnboundLocalError: local variable 'loss' referenced before assignment

I was trying to test an image using the train-image-inference.ipynb file. But in the last block of code, I am getting an error.


ValueError Traceback (most recent call last)
in ()
10 embedding = np.load(EMBEDDING_PATH, allow_pickle=True)
11
---> 12 indices_list = compute_similar_images(TEST_IMAGE_PATH, NUM_IMAGES, embedding, device)
13 plot_similar_images(indices_list)

7 frames
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/pairwise.py in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy)
153 raise ValueError("Incompatible dimension for X and Y matrices: "
154 "X.shape[1] == %d while Y.shape[1] == %d" % (
--> 155 X.shape[1], Y.shape[1]))
156
157 return X, Y

ValueError: Incompatible dimension for X and Y matrices: X.shape[1] == 65536 while Y.shape[1] == 262144

Please help me how to solve this issue

Animals dataset

Hi @oke-aditya,
Thanks for your great work and thanks for making it available for the community. The blog post is just fantastic. Indeed, I opened this issue to ask for the animal dataset you used. I reproduced the code and I need the dataset to run it, please if it is possible to share it with us. Thanks again!

problem in train code ,embedding = torch.cat((embedding, enc_output), 0)

embedding = torch.cat((embedding, enc_output), 0)
why cat embedding and enc_output?
and my log has some problem.

log:
torch.Size([1, 64, 64, 64]) embedding value
100%|██████████| 2/2 [00:00<00:00, 2.10it/s]
torch.Size([8, 64, 32, 32]) output for enc_output
why not use enc_output only?

Miss encoder checkpoint

Hi you, Can I get encoder model trained?
In this link you give have not encoder model checkpoint.

Thank you and best regards.

Fine-tuning

I'm working on cat facial recognition. so my first idea was to calculate the distance between two embedded cat faces.
Is it possible to retrain/fine tune the embedding models for such task ?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.