Source code of the paper Multi-granularity Part Sampling Attention for Fine-grained Visual Classification
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
conda install numpy matplotlib pandas tensorboard scipy tqdm
pip install yacs opencv-python opencv-contrib-python timm einops gpustat
You may specific your dataset path in the /config/{settting}.yaml
under data/datasets
. Then please check if there is any conflict with the ip in line 103 of settings/setup_functions.py
.
- Put the pre-trained model (22k 1k for Stanford Dog, and 22k for others) in
/pretrained/
, and rename it toSwin Base 1k.pth
for Dog andSwin Base.pth
for others. - Change the log name and cuda visible by modifing line 13,14 in
/setup.py
. - Running the following code according to you pytorch version:
python -m main.py
python -m torch.distributed.launch --nproc_per_node 2 main.py
torchrun --nproc_per_node 2 main.py
You need to change the number behind the -nproc_per_node
to your number of GPUs.
if this code is helpful to you, please cite as the following format
@ARTICLE{10638479,
author={Wang, Jiahui and Xu, Qin and Jiang, Bo and Luo, Bin and Tang, Jinhui},
journal={IEEE Transactions on Image Processing},
title={Multi-Granularity Part Sampling Attention for Fine-Grained Visual Classification},
year={2024},
volume={33},
number={},
pages={4529-4542},
keywords={Feature extraction;Semantics;Visualization;Shape;Location awareness;Attention mechanisms;Transformers;Fine-grained visual classification;multi-granularity;part sampling;attention mechanism},
doi={10.1109/TIP.2024.3441813}
}