Skip to content

Fine-tune pre-trained models including AlexNet and ResNet-50 for image retrieval (based on the BJTU Visual Impression Dataset).

Notifications You must be signed in to change notification settings

Luchicken/Fine-tuning-a-Pre-trained-Model-for-Image-Retrieval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Retrieval

北京交通大学2024春季《计算机视觉基础》

交大视觉印象数据集2024

1. Prepare training dataset

Put the data under ${DATA_ROOT}. The prepared directory would look like:

${DATA_ROOT}
├── base
│   ├── fh
│   ├── mh
│   ...
│   ├── zx
│   ├── util_pic
├── query
│   ├── fh
│   ├── mh
│   ...
│   ├── zx

${DATA_ROOT} is set to ./data by default, which can be modified via hydra command line interface --data '/your/data/path'.

Run split.py first to split the images in util_pic by label (totally 17 classes). Then delete util_pic.

Now we have a training dataset (is set to ./data/base by default) containing 6445 images of 25 categories.

2. Fine-tuning

  • Prepare the environment
conda activate your_enviroment
cd /your/path/to/your_project
  • AlexNet w/o latent layer
python finetune.py --model alexnet --batchsize 64 --lr 0.001 --num_epochs 300 --data './your/data/path' --seed 42
python finetune.py --model alexnet --batchsize 64 --lr 0.001 --num_epochs 300 --data './your/data/path' --seed 42 --latent_layer --latent_size 48
  • ResNet-50 w/o latent layer
python finetune.py --model resnet --batchsize 64 --lr 0.001 --num_epochs 300 --data './your/data/path' --seed 42
  • Memory Usage

    Running on NVIDIA GeForce RTX 3090.

    image-20240530095653230

3. Retrieval

Adding --plot to the command line will export the retrieved images for each image in the query set. You can find them in ./plots/your_model_name/[20/40/60].

  • AlexNet w/o latent layer
python retrieval.py --model alexnet --data './your/data/path' --dist [cos/euclidean] [--plot]
  • AlexNet w/ latent layer
python retrieval.py --model alexnet --data './your/data/path' --latent_layer --dist [cos/euclidean] [--plot]
  • ResNet-50 w/o latent layer
python retrieval.py --model resnet --data './your/data/path' --dist [cos/euclidean] [--plot]

Example of results

  • AlexNet w/o latent layer (cosine_similarity)

    08.png in ./plots/your_model_name/20.

    08

    [email protected] in ./plots/your_model_name.

    P@K

  • AlexNet w/o latent layer (euclidean_dist)

    P@K

  • AlexNet w/ latent layer (binary + cosine_similarity)

    08.png in ./plots/your_model_name/20.

    08

    [email protected] in ./plots/your_model_name.

    P@K

  • AlexNet w/ latent layer (binary + euclidean_dist)

    P@K

  • ResNet-50 w/o latent layer (cosine_similarity)

    16.png in ./plots/your_model_name/60.

    16

    [email protected] in ./plots/your_model_name.

    P@K

  • ResNet-50 w/o latent layer (euclidean_dist)

    P@K

About

Fine-tune pre-trained models including AlexNet and ResNet-50 for image retrieval (based on the BJTU Visual Impression Dataset).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages