Requirements : The Code was run on Virtual Machine with 52 GB RAM which is NVIDIA GPU enabled which helped us to train VGG16, ResNet50 and Inceptionv3 models. Repository Structure : The ‘Notebook’ Directory Contains 3 .ipny files (Jupyter Notebook). The ‘Sample Retrieval’ Directory Contains 3 Folders [CBIR, Oxford, Paris] which contain sample retrieved images from Best Model on 5 Test Images from each Dataset. How to Run the Code : Use latest Version python == 3.9.5 ,GPU must be enabled in order to Perform Tuning using Transfer Learning . To run the Code : Make sure to load all the Libraries, numpy, pandas, matplotlib, tensorflow. We will show how to run our code on CBIR Dataset.
-
Download the Dataset.
-
Make sure you are in Dataset Directory and run the Cell in order to generate ‘class-mappings’ dictionary.
-
Perform Data cleaning if Necessary then Run the Further Cell to Generate X.npy and y.npy.
-
Perform train-test-split and Generate Train and Test Data.
-
Import Pretrained Model [VGG16, ResNet50, Inceptionv3 ] from Keras.applications, Initialize it with ImageNet weights.
-
Set Last Layers for the Model by Layers.trainable to ‘true’.
-
Train the model for 50/100 epochs for Hyperparameter Tuning
-
Save the Model
-
Extract Feature for every image By removing the Last layer of Model, Save those Features.
-
Make ‘temp’ dictionary which contains Mapping of Image_path to Label.
-
Perform PCA Dimensionality Reduction on Extracted Features.
-
Save the PCA Features in Database.
-
Now Take random Test image from ‘temp’ and Run the ‘def evaluation():’ function.
-
Hurray!! You got a great Image Retrieval.