Skip to content

Commit c0daabf

Browse files
committed
update image classification
1 parent 74ffbfc commit c0daabf

File tree

13 files changed

+1466
-1519
lines changed

13 files changed

+1466
-1519
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ venv.bak/
114114
bash
115115
data
116116
data_set
117+
detection/data
118+
segmentation/data
119+
output/
117120
work_dirs/
118121
workspace/
119122
tools/exp_bash/
@@ -129,4 +132,5 @@ tensorboard.sh
129132
*.json
130133

131134
# temp
132-
moganet_tiny_sz224_2xb128_accu4_ep300/
135+
detection
136+
segmentation

INSTALL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ Install [Pytorch](https://pytorch.org/)>=1.8.0, [torchvision](https://pytorch.or
1414
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
1515
```
1616

17-
Clone this repo and install required packages:
17+
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.
1818
```
1919
git clone https://github.com/Westlake-AI/MogaNet
20-
pip install timm tensorboardX six
20+
pip install timm fvcore
2121
```
2222

23-
The results in the paper are produced with `torch==1.10.0+cu111 torchvision==0.11.0+cu111 timm==0.6.12`.
23+
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.
2424

2525
## Dataset Preparation
2626

27-
Download the [ImageNet-1K](http://image-net.org/) classification dataset and structure the data as follows:
27+
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).
2828
```
2929
│imagenet/
3030
├──train/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

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

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ We propose **MogaNet**, a new family of efficient ConvNets, to pursue informativ
4444
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.
4545

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

5857
## Training
5958

60-
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).
59+
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`.
6160

6261
## Results and Pre-trained Models
6362

TRAINING.md

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ We provide ImageNet-1K training commands here. Please check [INSTALL.md](INSTALL
44

55
## ImageNet-1K Training
66

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

18-
- 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.
18+
- 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.
1919

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

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

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

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

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

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

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

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

7275
```
73-
python -m torch.distributed.launch --nproc_per_node=8 main.py \
76+
python -m torch.distributed.launch --nproc_per_node=8 train.py \
7477
--model moganet_small --input_size 224 --drop_path 0.1 \
75-
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
76-
--model_ema true --model_ema_eval true \
77-
--data_path /path/to/imagenet-1k \
78-
--output_dir /path/to/save_results
78+
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
79+
--crop_pct 0.9 \
80+
--model_ema --model_ema_decay 0.9999 \
81+
--data_dir /path/to/imagenet-1k \
82+
--experiment /path/to/save_results
7983
```
8084
</details>
8185

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

8892
```
89-
python -m torch.distributed.launch --nproc_per_node=8 main.py \
93+
python -m torch.distributed.launch --nproc_per_node=8 train.py \
9094
--model moganet_base --input_size 224 --drop_path 0.2 \
91-
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
92-
--model_ema true --model_ema_eval true \
93-
--data_path /path/to/imagenet-1k \
94-
--output_dir /path/to/save_results
95+
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
96+
--crop_pct 0.9 \
97+
--model_ema --model_ema_decay 0.9999 \
98+
--data_dir /path/to/imagenet-1k \
99+
--experiment /path/to/save_results
95100
```
96101
</details>
97102

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

104109
```
105-
python -m torch.distributed.launch --nproc_per_node=8 main.py \
110+
python -m torch.distributed.launch --nproc_per_node=8 train.py \
106111
--model moganet_large --input_size 224 --drop_path 0.3 \
107-
--batch_size 128 --lr 1e-3 --weight_decay 0.05 --update_freq 1 \
108-
--model_ema true --model_ema_eval true \
109-
--data_path /path/to/imagenet-1k \
110-
--output_dir /path/to/save_results
112+
--epochs 300 --batch_size 128 --lr 1e-3 --weight_decay 0.05 \
113+
--crop_pct 0.9 \
114+
--model_ema --model_ema_decay 0.9999 \
115+
--data_dir /path/to/imagenet-1k \
116+
--experiment /path/to/save_results
111117
```
112118
</details>

datasets.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)