A Tensorflow2.x implementation of SnapMix as described in SnapMix: Semantically Proportional Mixing for Augmenting Fine-grained Data
- mixup
- cutmix
- snapmix
- resnet50,resnet101
- efficientB0~B7
- warmup
- cosinedecay lr scheduler
- step lr scheduler
- concat-max-and-average-pool
- custom dataset training
git clone https://github.com/wangermeng2021/SnapMix-tensorflow2.git
cd SnapMix-tensorflow2
- install tesnorflow ( skip this step if it's already installed)
-
pip install -r requirements.txt
- 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/
- 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:
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 your_dataset_root_directory --model ResNet50 --augment snapmix
your_dataset_root_directory:python train.py --dataset custom --dataset-dir dataset/cat_dog --model ResNet50 --augment snapmix
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
...
...
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 |