• Stars
    star
    165
  • Rank 227,597 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PyTorch Implementation Of WS-DAN(See Better Before Looking Closer: Weakly Supervised Data Augmentation Network for Fine-Grained Visual Classification)

PyTorch Implementation Of WS-DAN

Introduction

This is a PyTorch implementation of the paper "See Better Before Looking Closer: Weakly Supervised Data Augmentation Network for Fine-Grained Visual Classification". It also has an official TensorFlow implementation WS_DAN. The core part of the code refers to the official version, and finally๏ผŒthe performance almost reaches the results reported in the paper.

Environment

  • Ubuntu 16.04, GTX 1080 8G * 2, cuda 8.0
  • Anaconda with Python=3.6.5, PyTorch=0.4.1, torchvison=0.2.1, etc.
  • Some third-party dependencies may be installed with pip or conda when needed.

Result

Dataset ACC(this repo) ACC Refine(this repo) ACC(paper)
CUB-200-2011 88.20 89.30 89.4
FGVC-Aircraft 93.15 93.22 93.0
Stanford Cars 94.13 94.43 94.5
Stanford Dogs 86.03 86.46 92.2

You can download pretrained models from WS_DAN_Onedrive

Install

  1. Clone the repo
git clone https://github.com/wvinzh/WS_DAN_PyTorch
  1. Prepare dataset
  • Download the following datasets.
Dataset Object Category Training Testing
CUB-200-2011 Bird 200 5994 5794
Stanford-Cars Car 100 6667 3333
fgvc-aircraft Aircraft 196 8144 8041
Stanford-Dogs Dogs 120 12000 8580
  • Extract the data like following:
Fine-grained
โ”œโ”€โ”€ CUB_200_2011
โ”‚ย ย  โ”œโ”€โ”€ attributes
โ”‚ย ย  โ”œโ”€โ”€ bounding_boxes.txt
โ”‚ย ย  โ”œโ”€โ”€ classes.txt
โ”‚ย ย  โ”œโ”€โ”€ image_class_labels.txt
โ”‚ย ย  โ”œโ”€โ”€ images
โ”‚ย ย  โ”œโ”€โ”€ images.txt
โ”‚ย ย  โ”œโ”€โ”€ parts
โ”‚ย ย  โ”œโ”€โ”€ README
โ”œโ”€โ”€ Car
โ”‚ย ย  โ”œโ”€โ”€ cars_test
โ”‚ย ย  โ”œโ”€โ”€ cars_train
โ”‚ย ย  โ”œโ”€โ”€ devkit
โ”‚ย ย  โ””โ”€โ”€ tfrecords
โ”œโ”€โ”€ fgvc-aircraft-2013b
โ”‚ย ย  โ”œโ”€โ”€ data
โ”‚ย ย  โ”œโ”€โ”€ evaluation.m
โ”‚ย ย  โ”œโ”€โ”€ example_evaluation.m
โ”‚ย ย  โ”œโ”€โ”€ README.html
โ”‚ย ย  โ”œโ”€โ”€ README.md
โ”‚ย ย  โ”œโ”€โ”€ vl_argparse.m
โ”‚ย ย  โ”œโ”€โ”€ vl_pr.m
โ”‚ย ย  โ”œโ”€โ”€ vl_roc.m
โ”‚ย ย  โ””โ”€โ”€ vl_tpfp.m
โ”œโ”€โ”€ dogs
โ”‚ย ย  โ”œโ”€โ”€ file_list.mat
โ”‚ย ย  โ”œโ”€โ”€ Images
โ”‚ย ย  โ”œโ”€โ”€ test_list.mat
โ”‚ย ย  โ””โ”€โ”€ train_list.mat
  • Prepare the ./data folder: generate file list txt (using ./utils/convert_data.py) and do soft link.
python utils/convert_data.py  --dataset_name bird --root_path .../Fine-grained/CUB_200_2011
โ”œโ”€โ”€ data
โ”‚ย ย  โ”œโ”€โ”€ Aircraft -> /your_root_path/Fine-grained/fgvc-aircraft-2013b/data
โ”‚ย ย  โ”œโ”€โ”€ aircraft_test.txt
โ”‚ย ย  โ”œโ”€โ”€ aircraft_train.txt
โ”‚ย ย  โ”œโ”€โ”€ Bird -> /your_root_path/Fine-grained/CUB_200_2011
โ”‚ย ย  โ”œโ”€โ”€ bird_test.txt
โ”‚ย ย  โ”œโ”€โ”€ bird_train.txt
โ”‚ย ย  โ”œโ”€โ”€ Car -> /your_root_path/Fine-grained/Car
โ”‚ย ย  โ”œโ”€โ”€ car_test.txt
โ”‚ย ย  โ”œโ”€โ”€ car_train.txt
โ”‚ย ย  โ”œโ”€โ”€ Dog -> /your_root_path/Fine-grained/dogs
โ”‚ย ย  โ”œโ”€โ”€ dog_test.txt
โ”‚ย ย  โ””โ”€โ”€ dog_train.txt

Usage

  • Train
python train_bap.py train\
    --model-name inception \
    --batch-size 12 \
    --dataset car \
    --image-size 512 \
    --input-size 448 \
    --checkpoint-path checkpoint/car \
    --optim sgd \
    --scheduler step \
    --lr 0.001 \
    --momentum 0.9 \
    --weight-decay 1e-5 \
    --workers 4 \
    --parts 32 \
    --epochs 80 \
    --use-gpu \
    --multi-gpu \
    --gpu-ids 0,1 \

A simple way is to use sh train_bap.sh or run backgroud with logs using cmd nohup sh train_bap.sh 1>train.log 2>error.log &

  • Test
python train_bap.py test\
    --model-name inception \
    --batch-size 12 \
    --dataset car \
    --image-size 512 \
    --input-size 448 \
    --checkpoint-path checkpoint/car/model_best.pth.tar \
    --workers 4 \
    --parts 32 \
    --use-gpu \
    --multi-gpu \
    --gpu-ids 0,1 \