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:
- training: 0 or 1 to sample from train or validation set
- num_pos_images: the number of positive images per query image
- num_neg_images: the number of negative images per query image
This should generate
training_triplet_sample.csv
orval_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:
- epochs: the number of training epochs to run
- optim: thee optimizer to use, can be
sgd
oradam
orrms
. Will default tosgd
.
Other hyperparameters are set inside the file. These include
BATCH_SIZE=25
andLEARNING_RATE=0.001
This should generate a fully trained model file calleddeepranknet.model
and other intermediate files calledtemp_*.model
-
To generate embeddings:
python gen_emebeddings.py
This will generate the train and test embeddings in the files
train_embedding.txt
andtest_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