DynamicMLP: A Python Tool for Fine-Grained Image Classification

Code for 'Dynamic MLP for Fine-Grained Image Classification by Leveraging Geographical and Temporal Information'

Dynamic MLP, which is parameterized by the learned embeddings of variable locations and dates to help fine-grained image classification.

Requirements

Experiment Environment

  • python 3.6
  • pytorch 1.7.1+cu101
  • torchvision 0.8.2

Get pretrained models for SK-Res2Net following here.
Get datasets following here.

Train the model

1. Train image-only model

Specify --image_only for training image-only models.

ResNet-50 (67.924% Top-1 acc)

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python3 train.py \
--name res50_image_only \
--data 'inat21_mini' \
--data_dir 'path/to/your/data' \
--model_file 'resnet' \
--model_name 'resnet50' \
--pretrained \
--batch_size 512 \
--start_lr 0.04 \
--image_only

SK-Res2Net-101 (76.102% Top-1 acc)

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python3 train.py \
--name sk2_image_only \
--data 'inat21_mini' \
--data_dir 'path/to/your/data' \
--model_file 'sk2res2net' \
--model_name 'sk2res2net101' \
--pretrained \
--batch_size 512 \
--start_lr 0.04 \
--image_only

2. Train dynamic MLP model

ResNet-50 (78.751% Top-1 acc)

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python3 train.py \
--name res50_dynamic_mlp \
--data 'inat21_mini' \
--data_dir 'path/to/your/data' \
--model_file 'resnet_dynamic_mlp' \
--model_name 'resnet50' \
--pretrained \
--batch_size 512 \
--start_lr 0.04

SK-Res2Net-101 (84.694% Top-1 acc)

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python3 train.py \
--name sk2_dynamic_mlp \
--data 'inat21_mini' \
--data_dir 'path/to/your/data' \
--model_file 'sk2res2net_dynamic_mlp' \
--model_name 'sk2res2net101' \
--pretrained \
--batch_size 512 \
--start_lr 0.04

Test the model

Specify --resume and --evaluate for inference and --image_only for testing image-only models.

python3 train.py \
  --name sk2_dynamic_mlp \
  --data 'inat21_mini' \
  --data_dir 'path/to/your/data' \
  --model_file 'sk2res2net_dynamic_mlp' \
  --model_name 'sk2res2net101' \
  --resume 'path/to/your/checkpoint' \
  --evaluate

Model Zoo

iNaturalist 2021 mini (90 epoch)

BackboneSizeAcc@1LogDownload
ResNet-5022467.924logmodel
+ Dynamic MLP22478.751logmodel
SK-Res2Net-10122476.102logmodel
+ Dynamic MLP22484.694logmodel

Download details:

Author: ylingfeng
Source: https://github.com/ylingfeng/DynamicMLP

#python 

DynamicMLP: A Python Tool for Fine-Grained Image Classification
1.65 GEEK