Skip to content
Snippets Groups Projects
Unverified Commit 86024548 authored by i-robot's avatar i-robot Committed by Gitee
Browse files

!2236 ghostnet for D-chips

Merge pull request !2236 from Sifan.Sun/ssf_ghost
parents a2c696a7 8a8eb0ea
No related branches found
No related tags found
No related merge requests found
# Contents
- [Contents](#contents)
- [Algorithm Introduction](#algorithm-introduction)
- [Algorithm Principles](#algorithm-principles)
- [Configuring the training process](#configuring-the-training-process)
- [Dataset](#dataset)
- [Requirements](#requirements)
- [Hardware (Ascend)](#hardware-ascend)
- [Framework](#framework)
- [For more information, please check the resources below](#for-more-information-please-check-the-resources-below)
- [Script Description](#script-description)
- [Scripts and Sample Code](#scripts-and-sample-code)
- [Script Parameter](#script-parameter)
- [Training Process](#training-process)
- [For training](#for-training)
- [Evaluation](#evaluation)
- [Evaluation Process](#evaluation-process)
- [Evaluation Result](#evaluation-result)
- [ModeZoo Homepage](#modelzoo-homepage)
## Algorithm Introduction
GhostNeXt is an efficient network architecture, which can obtain high performance on GPUs in terms of both accuracy and latency. Current networks usually use depth-wise convolution to reduce latency, but a GPU-efficient network architecture should not contain too much trivial computation in a building stage. Therefore, we present to utilize the stage-wise feature redundancy to formulate GhostX stage structure. The new GhostX stage can be well embedded into any mainstream CNN architectures.
### Paper
[GhostNets on Heterogeneous Devices via Cheap Operations](https://arxiv.org/pdf/2201.03297.pdf)
## Algorithm Principles
The features will be split into two parts where the first part is processed using the original block with fewer output channels for generating intrinsic features, and the other are generated using cheap operations by exploiting stage-wise redundancy. To further enhance their representation capacity, we embed the information of intermediate intrinsic features into the cheap operation for compensation. The following figure shows the proposed GhostX stage:
![G1](image/ghostnetD_1.png)
To complement the lacked information, we propose to utilize the intermediate features in the complicated path to enhance the representation capacity of the cheap operations. Mix operation for aggregating the intermediate information into the ghost features.
![G2](image/ghostnetD_2.png)
We apply a global average pooling to obtain the aggregated feature, then transform the aggregated feature into the same domain as the origin output.
For Davincit chips, the slicing operation will introduce a larger latency so we apply 1x1 convolution to replace it. In this work, we apply the proposed GhostX stage on ResNets to obtain GhostNets_D.
### Configuring the training process
For details, see the configuration file src/ghostnet_d.yml in the sample code.
```yaml
general:
backend: mindspore
parallel_fully_train: True
pipeline: [fully_train]
fully_train:
pipe_step:
type: TrainPipeStep
model:
model_desc:
type: ./src/ghostnet_d.ghostnet101
trainer:
type: Trainer
epochs: 120
mixup: True
optimizer:
type: SGD
params:
lr: 0.001
momentum: 0.9
weight_decay: 0.0001
lr_scheduler:
type: CosineAnnealingLR
by_epoch: True
params:
T_max: 120
loss:
type: CrossEntropyLoss
params:
sparse: True
```
## Dataset
The benchmark datasets can be downloaded as follows:
[ImageNet2012](https://image-net.org/challenges/LSVRC/2012/).
After downloaded the correspond dataset to the target place, You can configure and use the dataset separately for train and test.
Dataset configuration parameters in src/ghostnext_d.yml:
```yaml
type: Imagenet
common:
data_path: "/cache/datasets/ILSVRC/Data/CLS-LOC"
batch_size: 128
n_class: 1000
```
## Requirements
### Hardware (Ascend)
> Prepare hardware environment with Ascend.
### Framework
> [MindSpore](https://www.mindspore.cn/install/en)
### For more information, please check the resources below
[MindSpore Tutorials](https://www.mindspore.cn/tutorials/en/r1.6/index.html)
[MindSpore Python API](https://www.mindspore.cn/docs/api/en/r1.6/index.html)
## Script Description
### Scripts and Sample Code
```bash
ghostnet_d
├── eval.py # inference entry
├── train.py # pre-training entry
├── README.md # Readme
├── scripts
│ ├── run_standalone.sh # shell script for standalone train on ascend
│ ├── run_distributed.sh # shell script for distributed train on ascend
└── src
├── eval.yml # options/hyper-parameters of eval
└── ghostnet_d.yml # options/hyper-parameters of ghostnet_d
```
### Script Parameter
> For details about hyperparameters, see src/ghostnet_d.yml.
## Training Process
### For training
- Standalone Ascend Training:
```bash
bash scripts/run_standalone.sh
```
- Distributed Ascend Training:
```bash
bash scripts/run_distributed.sh [RANK_TABLE_FILE]
```
For distributed training, a hccl configuration file with JSON format needs to be created in advance.
Please follow the instructions in the link below:
<https://gitee.com/mindspore/models/tree/master/utils/hccl_tools>.
`$RANK_TABLE_FILE` is needed when you are running a distribute task on ascend.
> Or one can run following script for all tasks.
```bash
python3 train.py
```
## Evaluation
### Evaluation Process
> Inference example:
Modify src/eval.yml:
```text
models_folder: [CHECKPOINT_PATH]
```
```text
python3 eval.py
```
### Evaluation Result
The result are evaluated by the value of accuracy and parameters.
```text
INFO Best values: [{'worker_id': '0', 'performance': {'accuracy_top1': 0.7735977564102564,'flops': 0.0, 'params': 38216.872}}]
```
## ModelZoo Homepage
Please check the official [homepage](https://gitee.com/mindspore/models).
\ No newline at end of file
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""eval script"""
import vega
if __name__ == '__main__':
vega.run('./src/eval.yml')
research/cv/ghostnet_d/image/ghostnetD_1.png

224 KiB

research/cv/ghostnet_d/image/ghostnetD_2.png

44.8 KiB

noah-vega==1.8.1
\ No newline at end of file
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
ulimit -u unlimited
export DEVICE_NUM=8
export RANK_SIZE=8
if [ $# != 1 ]
then
echo "Usage: bash run_distribution.sh [RANK_TABLE_FILE]"
exit 1
fi
if [ ! -f $1 ]
then
echo "error: RANK_TABLE_FILE=$1 is not a file"
exit 1
fi
RANK_TABLE_FILE=$(realpath $1)
export RANK_TABLE_FILE
python3 -m vega.tools.run_pipeline ../src/ghostnet_d.yml -b m -d NPU \
> train.log 2>&1 &
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
ulimit -u unlimited
export DEVICE_NUM=1
export RANK_SIZE=1
if [ $# != 0 ]
then
echo "Usage: bash run_standalone.sh"
exit 1
fi
python3 -m vega.tools.run_pipeline ../src/ghostnet_d.yml -b m -d NPU \
> train.log 2>&1 &
general:
backend: mindspore
pipeline: [eval]
eval:
pipe_step:
type: TrainPipeStep
models_folder: ~
dataset:
type: Imagenet
common:
data_path: "/cache/datasets/ILSVRC/Data/CLS-LOC"
batch_size: 128
trainer:
with_train: False
type: Trainer
epochs: 120
optimizer:
type: SGD
params:
lr: 0.001
momentum: 0.9
weight_decay: 0.0001
lr_scheduler:
type: CosineAnnealingLR
by_epoch: True
params:
T_max: 120
loss:
type: CrossEntropyLoss
params:
sparse: True
general:
backend: mindspore
device_category: NPU
parallel_fully_train: True
pipeline: [fully_train]
fully_train:
pipe_step:
type: TrainPipeStep
model:
model_desc:
type: ghostnet_d.ghostnet101
trainer:
type: Trainer
epochs: 120
mixup: True
optimizer:
type: SGD
params:
lr: 0.001
momentum: 0.9
weight_decay: 0.0001
lr_scheduler:
type: CosineAnnealingLR
by_epoch: True
params:
T_max: 120
loss:
type: CrossEntropyLoss
params:
sparse: True
dataset:
type: Imagenet
common:
data_path: "/cache/datasets/ILSVRC/Data/CLS-LOC"
batch_size: 128
n_class: 1000
\ No newline at end of file
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""train"""
import vega
if __name__ == '__main__':
vega.run('./src/ghostnet_d.yml')
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment