Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions configs/convnext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# ConvNeXt
> [A ConvNet for the 2020s](https://arxiv.org/abs/2201.03545)

## Introduction

In this work, the authors reexamine the design spaces and test the limits of what a pure ConvNet can achieve.
The authors gradually "modernize" a standard ResNet toward the design of a vision Transformer, and discover several key
components that contribute to the performance difference along the way. The outcome of this exploration is a family of
pure ConvNet models dubbed ConvNeXt. Constructed entirely from standard ConvNet modules, ConvNeXts compete favorably
with Transformers in terms of accuracy and scalability, achieving 87.8% ImageNet top-1 accuracy, while maintaining the
simplicity and efficiency of standard ConvNets.[[1](#references)]

<p align="center">
<img src="https://user-images.githubusercontent.com/53842165/223907142-3bf6acfb-080a-49f5-b021-233e003318c3.png" width=250 />
</p>
<p align="center">
<em>Figure 1. Architecture of ConvNeXt [<a href="#references">1</a>] </em>
</p>

## Results

Our reproduced model performance on ImageNet-1K is reported as follows.

<div align="center">

| Model | Context | Top-1 (%) | Top-5 (%) | Params (M) | Recipe | Download |
|----------------|-----------|-----------|-----------|------------|-------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| ConvNeXt_tiny | D910x64-G | 81.91 | 95.79 | 28.59 | [yaml](https://github.com/mindspore-lab/mindcv/blob/main/configs/convnext/convnext_tiny_ascend.yaml) | [weights](https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_tiny-ae5ff8d7.ckpt) |
| ConvNeXt_small | D910x64-G | 83.40 | 96.36 | 50.22 | [yaml](https://github.com/mindspore-lab/mindcv/blob/main/configs/convnext/convnext_small_ascend.yaml) | [weights](https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_small-e23008f3.ckpt) |
| ConvNeXt_base | D910x64-G | 83.32 | 96.24 | 88.59 | [yaml](https://github.com/mindspore-lab/mindcv/blob/main/configs/convnext/convnext_base_ascend.yaml) | [weights](https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_base-ee3544b8.ckpt) |

</div>

#### Notes

- Context: Training context denoted as {device}x{pieces}-{MS mode}, where mindspore mode can be G - graph mode or F - pynative mode with ms function. For example, D910x8-G is for training on 8 pieces of Ascend 910 NPU using graph mode.
- Top-1 and Top-5: Accuracy reported on the validation set of ImageNet-1K.

## Quick Start

### Preparation

#### Installation
Please refer to the [installation instruction](https://github.com/mindspore-ecosystem/mindcv#installation) in MindCV.

#### Dataset Preparation
Please download the [ImageNet-1K](https://www.image-net.org/challenges/LSVRC/2012/index.php) dataset for model training and validation.

### Training

* Distributed Training

It is easy to reproduce the reported results with the pre-defined training recipe. For distributed training on multiple Ascend 910 devices, please run

```shell
# distributed training on multiple GPU/Ascend devices
mpirun -n 8 python train.py --config configs/convnext/convnext_tiny_ascend.yaml --data_dir /path/to/imagenet
```

> If the script is executed by the root user, the `--allow-run-as-root` parameter must be added to `mpirun`.

Similarly, you can train the model on multiple GPU devices with the above `mpirun` command.

For detailed illustration of all hyper-parameters, please refer to [config.py](https://github.com/mindspore-lab/mindcv/blob/main/config.py).

**Note:** As the global batch size (batch_size x num_devices) is an important hyper-parameter, it is recommended to keep the global batch size unchanged for reproduction or adjust the learning rate linearly to a new global batch size.

* Standalone Training

If you want to train or finetune the model on a smaller dataset without distributed training, please run:

```shell
# standalone training on a CPU/GPU/Ascend device
python train.py --config configs/convnext/convnext_tiny_ascend.yaml --data_dir /path/to/dataset --distribute False
```

### Validation

To validate the accuracy of the trained model, you can use `validate.py` and parse the checkpoint path with `--ckpt_path`.

```shell
python validate.py -c configs/convnext/convnext_tiny_ascend.yaml --data_dir /path/to/imagenet --ckpt_path /path/to/ckpt
```

### Deployment

Please refer to the [deployment tutorial](https://github.com/mindspore-lab/mindcv/blob/main/tutorials/deployment.md) in MindCV.

## References

[1] Liu Z, Mao H, Wu C Y, et al. A convnet for the 2020s[C]//Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition. 2022: 11976-11986.
58 changes: 58 additions & 0 deletions configs/convnext/convnext_base_ascend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# system
mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True

# dataset
dataset: 'imagenet'
data_dir: '/path/to/imagenet'
shuffle: True
dataset_download: False
batch_size: 16
drop_remainder: True

# augmentation
image_resize: 224
scale: [0.08, 1.0]
ratio: [0.75, 1.333]
re_value: 'random'
hflip: 0.5
interpolation: 'bicubic'
auto_augment: 'randaug-m9-mstd0.5-inc1'
re_prob: 0.25
crop_pct: 0.95
mixup: 0.8
cutmix: 1.0

# model
model: 'convnext_base'
num_classes: 1000
pretrained: False
ckpt_path: ''
keep_checkpoint_max: 10
ckpt_save_dir: './ckpt'
epoch_size: 450
drop_path_rate: 0.5
dataset_sink_mode: True
amp_level: 'O2'

# loss
loss: 'ce'
label_smoothing: 0.1

# lr scheduler
scheduler: 'cosine_decay'
lr: 0.002
min_lr: 0.0000003
decay_epochs: 430
warmup_factor: 0.0000175
warmup_epochs: 20

# optimizer
opt: 'adamw'
filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale_type: 'auto'
use_nesterov: False
58 changes: 58 additions & 0 deletions configs/convnext/convnext_small_ascend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# system
mode: 0
distribute: True
num_parallel_workers: 8
val_while_train: True

# dataset
dataset: 'imagenet'
data_dir: '/path/to/imagenet'
shuffle: True
dataset_download: False
batch_size: 16
drop_remainder: True

# augmentation
image_resize: 224
scale: [0.08, 1.0]
ratio: [0.75, 1.333]
re_value: 'random'
hflip: 0.5
interpolation: 'bicubic'
auto_augment: 'randaug-m9-mstd0.5-inc1'
re_prob: 0.25
crop_pct: 0.95
mixup: 0.8
cutmix: 1.0

# model
model: 'convnext_small'
num_classes: 1000
pretrained: False
ckpt_path: ''
keep_checkpoint_max: 10
ckpt_save_dir: './ckpt'
epoch_size: 450
drop_path_rate: 0.4
dataset_sink_mode: True
amp_level: 'O2'

# loss
loss: 'ce'
label_smoothing: 0.1

# lr scheduler
scheduler: 'cosine_decay'
lr: 0.002
min_lr: 0.0000003
decay_epochs: 430
warmup_factor: 0.0000175
warmup_epochs: 20

# optimizer
opt: 'adamw'
filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale_type: 'auto'
use_nesterov: False
59 changes: 59 additions & 0 deletions configs/convnext/convnext_tiny_ascend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# system
mode: 0
distribute: True
num_parallel_workers: 16
val_while_train: True

# dataset
dataset: 'imagenet'
data_dir: '/path/to/imagenet'
shuffle: True
dataset_download: False
batch_size: 16
drop_remainder: True

# augmentation
image_resize: 224
scale: [0.08, 1.0]
ratio: [0.75, 1.333]
re_value: 'random'
hflip: 0.5
interpolation: 'bicubic'
auto_augment: 'randaug-m9-mstd0.5-inc1'
re_prob: 0.25
crop_pct: 0.95
mixup: 0.8
cutmix: 1.0

# model
model: 'convnext_tiny'
num_classes: 1000
pretrained: False
ckpt_path: ''
keep_checkpoint_max: 10
ckpt_save_dir: './ckpt'
epoch_size: 450
drop_path_rate: 0.1
dataset_sink_mode: True
amp_level: 'O2'

# loss
loss: 'ce'
label_smoothing: 0.1

# lr scheduler
scheduler: 'cosine_decay'
lr: 0.002
min_lr: 0.0000003
decay_epochs: 430
warmup_factor: 0.0000175
warmup_epochs: 20

# optimizer
opt: 'adamw'
filter_bias_and_bn: True
momentum: 0.9
weight_decay: 0.05
loss_scale_type: 'dynamic'
drop_overflow_update: True
use_nesterov: False
6 changes: 3 additions & 3 deletions mindcv/models/convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def _cfg(url="", **kwargs):


default_cfgs = {
"convnext_tiny": _cfg(url="https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_tiny_224.ckpt"),
"convnext_small": _cfg(url=""),
"convnext_base": _cfg(url=""),
"convnext_tiny": _cfg(url="https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_tiny-ae5ff8d7.ckpt"),
"convnext_small": _cfg(url="https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_small-e23008f3.ckpt"),
"convnext_base": _cfg(url="https://download.mindspore.cn/toolkits/mindcv/convnext/convnext_base-ee3544b8.ckpt"),
"convnext_large": _cfg(url=""),
"convnext_xlarge": _cfg(url=""),
}
Expand Down