Image Similarity using Deep Ranking
For this particular implementation of Deep Ranking we are using TinyImageNet as our training dataset. Download the TinyImageNet dataset here
Change the folder structure of the validation set by running:
python transform_validation.py
This will aid later when generating the image embeddings
Now to sample triplets we run:
python triplet_sampler.py --training 1 --num_pos_images 1 --num_neg_images 1
Our command-line arugments are as follows:
This should generate training_triplet_sample.csv
or val_triplet_sample.csv
based on the argument provided.
To implement we use a pre-trained ResNet-101 with two sub-sampling layers. We finetune the earlier layers of the ResNet and train the rest. The PyTorch implementation can be found in the file deep_rank_net.py
To train the network run:
python train_net.py --epochs 1 --optim sgd
Our command-line arugments are as follows:
sgd
or adam
or rms
. Will default to sgd
.Other hyperparameters are set inside the file. These include BATCH_SIZE=25
and LEARNING_RATE=0.001
This should generate a fully trained model file called deepranknet.model
and other intermediate files called temp_*.model
To generate embeddings:
python gen_emebeddings.py
This will generate the train and test embeddings in the files train_embedding.txt
and test_embedding.txt
respectively.
To evaluate the model run:
python eval.py
If you wish to change the architecture, change the hyperparameters or understand the implementation further see the report file