Skip to content

Commit

Permalink
update image classification
Browse files Browse the repository at this point in the history
  • Loading branch information
Lupin1998 committed Jan 13, 2023
1 parent 74ffbfc commit c0daabf
Show file tree
Hide file tree
Showing 13 changed files with 1,466 additions and 1,519 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ venv.bak/
bash
data
data_set
detection/data
segmentation/data
output/
work_dirs/
workspace/
tools/exp_bash/
Expand All @@ -129,4 +132,5 @@ tensorboard.sh
*.json

# temp
moganet_tiny_sz224_2xb128_accu4_ep300/
detection
segmentation
8 changes: 4 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ Install [Pytorch](https://pytorch.org/)>=1.8.0, [torchvision](https://pytorch.or
pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
```

Clone this repo and install required packages:
Clone this repo and install required packages. You can install [apex-amp](https://github.com/NVIDIA/apex) if you want to use fp16 with Pytorch<=1.6.0.
```
git clone https://github.com/Westlake-AI/MogaNet
pip install timm tensorboardX six
pip install timm fvcore
```

The results in the paper are produced with `torch==1.10.0+cu111 torchvision==0.11.0+cu111 timm==0.6.12`.
The results in this repository are produced with `torch==1.10.0+cu111 torchvision==0.11.0+cu111 timm==0.6.12`, and we adopt amp fp16 for fast training.

## Dataset Preparation

Download the [ImageNet-1K](http://image-net.org/) classification dataset and structure the data as follows:
Download the [ImageNet-1K](http://image-net.org/) classification dataset ([train](https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_train.tar) and [val](https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar)) and structure the data as follows. You can extract ImageNet with this [script](https://gist.github.com/BIGBALLON/8a71d225eff18d88e469e6ea9b39cef4).
```
│imagenet/
├──train/
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2022-2023 CAIRI AI Lab.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ We propose **MogaNet**, a new family of efficient ConvNets, to pursue informativ
We plan to release implementations of MogaNet in a few months. Please watch us for the latest release. Currently, this repo is reimplemented according to our official implementations in [OpenMixup](https://github.com/Westlake-AI/openmixup/), and we are working on cleaning up experimental results and code implementations.

- [x] ImageNet-1K Training Code
- [ ] ImageNet-1K Fine-tuning Code
- [ ] Downstream Transfer to Object Detection and Instance Segmentation on COCO
- [ ] Downstream Transfer to Semantic Segmentation on ADE20K
- [ ] Image Classification on Google Colab and Web Demo
Expand All @@ -57,7 +56,7 @@ Please check [INSTALL.md](INSTALL.md) for installation instructions.

## Training

See [TRAINING.md](TRAINING.md) for ImageNet-1K training instructions, or refer to our [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/classification/imagenet/moganet/) implementations. We have released pre-trained models on [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/classification/imagenet/moganet/) in [moganet-in1k-weights](https://github.com/Westlake-AI/openmixup/releases/tag/moganet-in1k-weights).
See [TRAINING.md](TRAINING.md) for ImageNet-1K training instructions, or refer to our [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/classification/imagenet/moganet/) implementations. We released pre-trained models on [OpenMixup](https://github.com/Westlake-AI/openmixup/tree/main/configs/classification/imagenet/moganet/) in [moganet-in1k-weights](https://github.com/Westlake-AI/openmixup/releases/tag/moganet-in1k-weights). We have also reproduced ImageNet results with this repo and released `args.yaml` / `summary.csv` / `model.pth.tar`.

## Results and Pre-trained Models

Expand Down
82 changes: 44 additions & 38 deletions TRAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ We provide ImageNet-1K training commands here. Please check [INSTALL.md](INSTALL

## ImageNet-1K Training

Taking MogaNet-T as an example, you can use the following command to run this experiment on a single machine:
Taking MogaNet-T as an example, you can use the following command to run this experiment on a single machine (8GPUs):
```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_tiny --input_size 224 --drop_path 0.1 \
--batch_size 128 --lr 1e-3 --weight_decay 0.04 --update_freq 1 \
--aa rand-m7-mstd0.5-inc1 --mixup 0.1 \
--model_ema false --model_ema_eval false \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.04 \
--aa rand-m7-mstd0.5-inc1 --crop_pct 0.9 --mixup 0.1 \
--amp --native_amp \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```

- Here, the effective batch size = `--nproc_per_node` * `--batch_size` * `--update_freq`. In the example above, the effective batch size is `8*128*1 = 1024`. Running on one machine, we can increase `update_freq` and reduce `--batch_size` to avoid OOM issues while keeping the total batch size unchanged.
- Here, the effective batch size = `--nproc_per_node` * `--batch_size`. In the example above, the effective batch size is `8*128 = 1024`. Running on one machine, we can reduce `--batch_size` and use `--amp` to avoid OOM issues while keeping the total batch size unchanged.

To train other MogaNet variants, `--model` and `--drop_path` need to be changed. Examples with single-machine commands are given below:

Expand All @@ -27,12 +27,13 @@ MogaNet-XT
Single-machine (8GPUs) with the input size of 224:

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_xtiny --input_size 224 --drop_path 0.05 \
--batch_size 128 --lr 1e-3 --weight_decay 0.03 --update_freq 1 \
--aa rand-m7-mstd0.5-inc1 --mixup 0.1 \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.03 \
--aa rand-m7-mstd0.5-inc1 --crop_pct 0.9 --mixup 0.1 \
--amp --native_amp \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```
</details>

Expand All @@ -43,23 +44,25 @@ MogaNet-Tiny
Single-machine (8GPUs) with the input size of 224:

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_tiny --input_size 224 --drop_path 0.1 \
--batch_size 128 --lr 1e-3 --weight_decay 0.04 --update_freq 1 \
--aa rand-m7-mstd0.5-inc1 --mixup 0.1 \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.04 \
--aa rand-m7-mstd0.5-inc1 --crop_pct 0.9 --mixup 0.1 \
--amp --native_amp \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```

Single-machine (8GPUs) with the input size of 256:

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_tiny --input_size 256 --drop_path 0.1 \
--batch_size 128 --lr 1e-3 --weight_decay 0.04 --update_freq 1 \
--aa rand-m7-mstd0.5-inc1 --mixup 0.1 \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.04 \
--aa rand-m7-mstd0.5-inc1 --crop_pct 0.9 --mixup 0.1 \
--amp --native_amp \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```
</details>

Expand All @@ -70,12 +73,13 @@ MogaNet-Small
Single-machine (8GPUs) with the input size of 224 with EMA (you can evaluate it without EMA):

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_small --input_size 224 --drop_path 0.1 \
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
--model_ema true --model_ema_eval true \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
--crop_pct 0.9 \
--model_ema --model_ema_decay 0.9999 \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```
</details>

Expand All @@ -86,12 +90,13 @@ MogaNet-Base
Single-machine (8GPUs) with the input size of 224 with EMA:

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_base --input_size 224 --drop_path 0.2 \
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
--model_ema true --model_ema_eval true \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
--crop_pct 0.9 \
--model_ema --model_ema_decay 0.9999 \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```
</details>

Expand All @@ -102,11 +107,12 @@ MogaNet-Large
Single-machine (8GPUs) with the input size of 224 with EMA:

```
python -m torch.distributed.launch --nproc_per_node=8 main.py \
python -m torch.distributed.launch --nproc_per_node=8 train.py \
--model moganet_large --input_size 224 --drop_path 0.3 \
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
--model_ema true --model_ema_eval true \
--data_path /path/to/imagenet-1k \
--output_dir /path/to/save_results
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
--crop_pct 0.9 \
--model_ema --model_ema_decay 0.9999 \
--data_dir /path/to/imagenet-1k \
--experiment /path/to/save_results
```
</details>
97 changes: 0 additions & 97 deletions datasets.py

This file was deleted.

Loading

0 comments on commit c0daabf

Please sign in to comment.