Skip to content

tensorflow2 implementation of SnapMix as described in SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data

License

Notifications You must be signed in to change notification settings

wangermeng2021/SnapMix-tensorflow2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnapMix-tensorflow2

A Tensorflow2.x implementation of SnapMix as described in SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data

Features

  • mixup
  • cutmix
  • snapmix
  • resnet50,resnet101
  • efficientB0~B7
  • warmup
  • cosinedecay lr scheduler
  • step lr scheduler
  • concat-max-and-average-pool
  • custom dataset training

Installation

1. Clone project

git clone https://github.com/wangermeng2021/SnapMix-tensorflow2.git
cd SnapMix-tensorflow2

2. Install environment

  • install tesnorflow ( skip this step if it's already installed)
  • pip install -r requirements.txt
    

3. Download dataset

  • Download cub dataset
    wget http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz -P dataset/
    tar -xzf dataset/CUB_200_2011.tgz -C dataset/
    mv dataset/CUB_200_2011 dataset/cub
    
  • Download cars dataset
    wget http://imagenet.stanford.edu/internal/car196/cars_train.tgz -P dataset/cars/
    wget http://imagenet.stanford.edu/internal/car196/cars_test.tgz -P dataset/cars/
    wget https://ai.stanford.edu/~jkrause/cars/car_devkit.tgz -P dataset/cars/
    tar -xzf  dataset/cars/cars_train.tgz -C dataset/cars
    tar -xzf  dataset/cars/cars_test.tgz -C dataset/cars
    tar -xzf  dataset/cars/car_devkit.tgz -C dataset/cars
    wget http://imagenet.stanford.edu/internal/car196/cars_test_annos_withlabels.mat -P dataset/cars/devkit/
    

Training

  • For training on cub dataset,use:
    python train.py --dataset cub --dataset-dir dataset/cub --model ResNet50 --augment snapmix
    
  • For training on Cars dataset,use:
    python train.py --dataset cars --dataset-dir dataset/cars --model ResNet50 --augment snapmix
    
  • For training on your custom dataset,use:
    python train.py --dataset custom --dataset-dir your_dataset_root_directory  --model ResNet50  --augment snapmix
    
    you can try it on a toy dataset(No need to download dataset,it's already included in project:dataset/cat_dog):
    python train.py --dataset custom --dataset-dir dataset/cat_dog --model ResNet50  --augment snapmix
    
    your_dataset_root_directory:
    train
            class1_name
                   xxx.jpg
                   xxx.jpg
                   ...
           class2_name
                   xxx.jpg
                   xxx.jpg
                   ...
           ...
    valid
           class1_name
                   xxx.jpg
                   xxx.jpg
                   ...
           class2_name
                   xxx.jpg
                   xxx.jpg
                   ...
           ...

Evaluation results(RTX2080,epochs=300,batch_size=16):

model cat_dog cars cub
ResNet50+cutmix 0.958
ResNet50+snapmix 0.979
EfficientNetB0+mixup 0.968
EfficientNetB0+cutmix 0.979
EfficientNetB0+snapmix 0.979
EfficientNetB3+cutmix 0.958
EfficientNetB3+snapmix 1.0

References

About

tensorflow2 implementation of SnapMix as described in SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages