add resnet34
This commit is contained in:
parent
edd2f113c1
commit
1a0b5f0eb1
|
@ -101,14 +101,14 @@ After installing MindSpore via the official website, you can start training and
|
|||
|
||||
```bash
|
||||
# distributed training
|
||||
Usage: bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
|
||||
Usage: bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
|
||||
|
||||
# standalone training
|
||||
Usage: bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
Usage: bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
[PRETRAINED_CKPT_PATH](optional)
|
||||
|
||||
# run evaluation example
|
||||
Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
Usage: bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
- Running on GPU
|
||||
|
@ -220,6 +220,29 @@ Parameters for both training and evaluation can be set in config.py.
|
|||
"lr_end": 0.0, # minimum learning rate
|
||||
```
|
||||
|
||||
- Config for ResNet34, ImageNet2012 dataset
|
||||
|
||||
```bash
|
||||
"class_num": 1001, # dataset class number
|
||||
"batch_size": 256, # batch size of input tensor
|
||||
"loss_scale": 1024, # loss scale
|
||||
"momentum": 0.9, # momentum optimizer
|
||||
"weight_decay": 1e-4, # weight decay
|
||||
"epoch_size": 90, # only valid for taining, which is always 1 for inference
|
||||
"pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size
|
||||
"save_checkpoint": True, # whether save checkpoint or not
|
||||
"save_checkpoint_epochs": 5, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch
|
||||
"keep_checkpoint_max": 1, # only keep the last keep_checkpoint_max checkpoint
|
||||
"save_checkpoint_path": "./", # path to save checkpoint relative to the executed path
|
||||
"warmup_epochs": 0, # number of warmup epoch
|
||||
"optimizer": 'Momentum', # optimizer
|
||||
"use_label_smooth": True, # label smooth
|
||||
"label_smooth_factor": 0.1, # label smooth factor
|
||||
"lr_init": 0, # initial learning rate
|
||||
"lr_max": 1.0, # maximum learning rate
|
||||
"lr_end": 0.0, # minimum learning rate
|
||||
```
|
||||
|
||||
- Config for ResNet101, ImageNet2012 dataset
|
||||
|
||||
```bash
|
||||
|
@ -273,14 +296,14 @@ Parameters for both training and evaluation can be set in config.py.
|
|||
|
||||
```bash
|
||||
# distributed training
|
||||
Usage: bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
|
||||
Usage: bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
|
||||
|
||||
# standalone training
|
||||
Usage: bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
Usage: bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
[PRETRAINED_CKPT_PATH](optional)
|
||||
|
||||
# run evaluation example
|
||||
Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
Usage: bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
|
||||
```
|
||||
|
||||
|
@ -333,10 +356,10 @@ bash run_parameter_server_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet201
|
|||
|
||||
```bash
|
||||
# evaluation with distributed training Ascend example:
|
||||
bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
||||
# evaluation with standalone training Ascend example:
|
||||
bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
||||
# evaluation with distributed training GPU example:
|
||||
bash run_distribute_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
@ -378,6 +401,17 @@ epoch: 5 step: 625, loss is 3.597817
|
|||
...
|
||||
```
|
||||
|
||||
- Training ResNet34 with ImageNet2012 dataset
|
||||
|
||||
```text
|
||||
# 分布式训练结果(8P)
|
||||
epoch: 2 step: 625, loss is 4.181185
|
||||
epoch: 3 step: 625, loss is 3.8856044
|
||||
epoch: 4 step: 625, loss is 3.423355
|
||||
epoch: 5 step: 625, loss is 3.506971
|
||||
...
|
||||
```
|
||||
|
||||
- Training ResNet50 with CIFAR-10 dataset
|
||||
|
||||
```bash
|
||||
|
@ -446,7 +480,7 @@ epoch: [0/1] step: [100/5004], loss is 6.814013Epoch time: 3437.154 ms, fps: 148
|
|||
|
||||
```bash
|
||||
# evaluation
|
||||
Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
Usage: bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
```bash
|
||||
|
@ -490,6 +524,12 @@ result: {'acc': 0.91446314102564111} ckpt=~/resnet50_cifar10/train_parallel0/res
|
|||
result: {'acc': 0.7671054737516005} ckpt=train_parallel0/resnet-90_5004.ckpt
|
||||
```
|
||||
|
||||
- Evaluating ResNet34 with ImageNet2012 dataset
|
||||
|
||||
```bash
|
||||
result: {'top_1_accuracy': 0.736758814102564} ckpt=train_parallel0/resnet-90_625.ckpt
|
||||
```
|
||||
|
||||
- Evaluating ResNet101 with ImageNet2012 dataset
|
||||
|
||||
```bash
|
||||
|
@ -524,7 +564,7 @@ Current batch_Size can only be set to 1. The precision calculation process needs
|
|||
bash run_infer_310.sh [MINDIR_PATH] [NET_TYPE] [DATASET] [DATA_PATH] [DEVICE_ID]
|
||||
```
|
||||
|
||||
- `NET_TYPE` can choose from [resnet18, se-resnet50, resnet50, resnet101].
|
||||
- `NET_TYPE` can choose from [resnet18, se-resnet50, resnet34, resnet50, resnet101].
|
||||
- `DATASET` can choose from [cifar10, imagenet].
|
||||
- `DEVICE_ID` is optional, default value is 0.
|
||||
|
||||
|
@ -544,6 +584,12 @@ Total data: 10000, top1 accuracy: 0.94.26, top5 accuracy: 0.9987.
|
|||
Total data: 50000, top1 accuracy: 0.70668, top5 accuracy: 0.89698.
|
||||
```
|
||||
|
||||
- Evaluating ResNet34 with ImageNet2012 dataset
|
||||
|
||||
```bash
|
||||
Total data: 50000, top1 accuracy: 0.7342.
|
||||
```
|
||||
|
||||
- Evaluating ResNet50 with CIFAR-10 dataset
|
||||
|
||||
```bash
|
||||
|
@ -654,6 +700,26 @@ Total data: 50000, top1 accuracy: 0.76844, top5 accuracy: 0.93522.
|
|||
| Checkpoint for Fine tuning | 197M (.ckpt file) |197M (.ckpt file) |
|
||||
| Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
|
||||
|
||||
#### ResNet34 on ImageNet2012
|
||||
|
||||
| Parameters | Ascend 910 |
|
||||
| -------------------------- | -------------------------------------- |---------------------------------- |
|
||||
| Model Version | ResNet50-v1.5 |
|
||||
| Resource | Ascend 910; CPU 2.60GHz, 192cores; Memory 755G; OS Euler2.8 |
|
||||
| uploaded Date | 04/01/2020 (month/day/year) ; |
|
||||
| MindSpore Version | 0.1.0-alpha |
|
||||
| Dataset | ImageNet2012 |
|
||||
| Training Parameters | epoch=90, steps per epoch=626, batch_size = 256 |
|
||||
| Optimizer | Momentum |
|
||||
| Loss Function | Softmax Cross Entropy |
|
||||
| outputs | probability |
|
||||
| Loss | 1.9575993 |
|
||||
| Speed | 111ms/step(8pcs) |
|
||||
| Total time | 112 mins |
|
||||
| Parameters (M) | 20.79 |
|
||||
| Checkpoint for Fine tuning | 166M (.ckpt file) |
|
||||
| Scripts | [Link](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
|
||||
|
||||
#### ResNet101 on ImageNet2012
|
||||
|
||||
| Parameters | Ascend 910 | GPU |
|
||||
|
@ -724,6 +790,20 @@ Total data: 50000, top1 accuracy: 0.76844, top5 accuracy: 0.93522.
|
|||
| Accuracy | 70.53% |
|
||||
| Model for inference | 45M (.air file) |
|
||||
|
||||
#### ResNet34 on ImageNet2012
|
||||
|
||||
| Parameters | Ascend |
|
||||
| ------------------- | --------------------------- |
|
||||
| Model Version | ResNet18 |
|
||||
| Resource | Ascend 910; OS Euler2.8 |
|
||||
| Uploaded Date | 02/25/2021 (month/day/year) |
|
||||
| MindSpore Version | 1.1.1-alpha |
|
||||
| Dataset | ImageNet2012 |
|
||||
| batch_size | 256 |
|
||||
| outputs | probability |
|
||||
| Accuracy | 73.67% |
|
||||
| Model for inference | 70M (.air file) |
|
||||
|
||||
#### ResNet50 on CIFAR-10
|
||||
|
||||
| Parameters | Ascend | GPU |
|
||||
|
|
|
@ -104,14 +104,14 @@ ResNet的总体网络架构如下:
|
|||
|
||||
```text
|
||||
# 分布式训练
|
||||
用法:bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](可选)
|
||||
用法:bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](可选)
|
||||
|
||||
# 单机训练
|
||||
用法:bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
用法:bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
[PRETRAINED_CKPT_PATH](可选)
|
||||
|
||||
# 运行评估示例
|
||||
用法:bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
用法:bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
- GPU处理器环境运行
|
||||
|
@ -204,6 +204,29 @@ bash run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH]
|
|||
"lr_end":0.0, # 最小学习率
|
||||
```
|
||||
|
||||
- 配置ResNet34和ImageNet2012数据集。
|
||||
|
||||
```text
|
||||
"class_num":1001, # 数据集类数
|
||||
"batch_size":256, # 输入张量的批次大小
|
||||
"loss_scale":1024, # 损失等级
|
||||
"momentum":0.9, # 动量优化器
|
||||
"weight_decay":1e-4, # 权重衰减
|
||||
"epoch_size":90, # 此值仅适用于训练;应用于推理时固定为1
|
||||
"pretrain_epoch_size":0, # 加载预训练检查点之前已经训练好的模型的周期大小;实际训练周期大小等于epoch_size减去pretrain_epoch_size
|
||||
"save_checkpoint":True, # 是否保存检查点
|
||||
"save_checkpoint_epochs":5, # 两个检查点之间的周期间隔;默认情况下,最后一个检查点将在最后一个周期完成后保存
|
||||
"keep_checkpoint_max":1, # 只保存最后一个keep_checkpoint_max检查点
|
||||
"save_checkpoint_path":"./", # 检查点相对于执行路径的保存路径
|
||||
"warmup_epochs":0, # 热身周期数
|
||||
"optimizer":"Momentum", # 优化器
|
||||
"use_label_smooth":True, # 标签平滑
|
||||
"label_smooth_factor":0.1, # 标签平滑因子
|
||||
"lr_init":0, # 初始学习率
|
||||
"lr_max":1.0, # 最大学习率
|
||||
"lr_end":0.0, # 最小学习率
|
||||
```
|
||||
|
||||
- 配置ResNet101和ImageNet2012数据集。
|
||||
|
||||
```text
|
||||
|
@ -257,14 +280,14 @@ bash run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH]
|
|||
|
||||
```text
|
||||
# 分布式训练
|
||||
用法:bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](可选)
|
||||
用法:bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](可选)
|
||||
|
||||
# 单机训练
|
||||
用法:bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
用法:bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH]
|
||||
[PRETRAINED_CKPT_PATH](可选)
|
||||
|
||||
# 运行评估示例
|
||||
用法:bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
用法:bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
|
||||
```
|
||||
|
||||
|
@ -307,10 +330,10 @@ bash run_parameter_server_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet201
|
|||
|
||||
```bash
|
||||
# Ascend 分布式训练时推理示例:
|
||||
bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
||||
# Ascend 单机训练时推理示例:
|
||||
bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
||||
# GPU 分布式训练时推理示例:
|
||||
bash run_distribute_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)
|
||||
|
@ -351,6 +374,17 @@ epoch: 5 step: 625, loss is 3.597817
|
|||
...
|
||||
```
|
||||
|
||||
- 使用ImageNet2012数据集训练ResNet34
|
||||
|
||||
```text
|
||||
# 分布式训练结果(8P)
|
||||
epoch: 2 step: 625, loss is 4.181185
|
||||
epoch: 3 step: 625, loss is 3.8856044
|
||||
epoch: 4 step: 625, loss is 3.423355
|
||||
epoch: 5 step: 625, loss is 3.506971
|
||||
...
|
||||
```
|
||||
|
||||
- 使用CIFAR-10数据集训练ResNet50
|
||||
|
||||
```text
|
||||
|
@ -412,7 +446,7 @@ epoch:5 step:5004, loss is 3.3501816
|
|||
|
||||
```bash
|
||||
# 评估
|
||||
Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
Usage: bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]
|
||||
```
|
||||
|
||||
```bash
|
||||
|
@ -456,6 +490,12 @@ result:{'acc':0.91446314102564111} ckpt=~/resnet50_cifar10/train_parallel0/resne
|
|||
result:{'acc':0.7671054737516005} ckpt=train_parallel0/resnet-90_5004.ckpt
|
||||
```
|
||||
|
||||
- 使用ImageNet2012数据集评估ResNet34
|
||||
|
||||
```text
|
||||
result: {'top_1_accuracy': 0.736758814102564} ckpt=train_parallel0/resnet-90_625 .ckpt
|
||||
```
|
||||
|
||||
- 使用ImageNet2012数据集评估ResNet101
|
||||
|
||||
```text
|
||||
|
@ -490,7 +530,7 @@ python export.py --ckpt_file [CKPT_PATH] --file_name [FILE_NAME] --file_format [
|
|||
bash run_infer_310.sh [MINDIR_PATH] [NET_TYPE] [DATASET] [DATA_PATH] [DEVICE_ID]
|
||||
```
|
||||
|
||||
- `NET_TYPE` 选择范围:[resnet18, se-resnet50, resnet50, resnet101]。
|
||||
- `NET_TYPE` 选择范围:[resnet18, resnet34, se-resnet50, resnet50, resnet101]。
|
||||
- `DATASET` 选择范围:[cifar10, imagenet]。
|
||||
- `DEVICE_ID` 可选,默认值为0。
|
||||
|
||||
|
@ -519,7 +559,13 @@ Total data: 10000, top1 accuracy: 0.9310, top5 accuracy: 0.9980.
|
|||
- 使用ImageNet2012数据集评估ResNet50
|
||||
|
||||
```text
|
||||
Total data: 50000, top1 accuracy: 0.0.7696, top5 accuracy: 0.93432.
|
||||
Total data: 50000, top1 accuracy: 0.7696, top5 accuracy: 0.93432.
|
||||
```
|
||||
|
||||
- 使用ImageNet2012数据集评估ResNet34
|
||||
|
||||
```text
|
||||
Total data: 50000, top1 accuracy: 0.7367.
|
||||
```
|
||||
|
||||
- 使用ImageNet2012数据集评估ResNet101
|
||||
|
@ -620,6 +666,26 @@ Total data: 50000, top1 accuracy: 0.76844, top5 accuracy: 0.93522.
|
|||
| 微调检查点| 197M(.ckpt文件) | 197M(.ckpt文件) |
|
||||
| 脚本 | [链接](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) | [链接](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
|
||||
|
||||
#### ImageNet2012上的ResNet34
|
||||
|
||||
| 参数 | Ascend 910 |
|
||||
| -------------------------- | -------------------------------------- |
|
||||
| 模型版本 | ResNet34 |
|
||||
| 资源 | Ascend 910;CPU 2.60GHz,192核;内存 755G;系统 Euler2.8 |
|
||||
| 上传日期 | 2021-05-08 ; |
|
||||
| MindSpore版本 | 1.1.1-alpha |
|
||||
| 数据集 | ImageNet2012 |
|
||||
| 训练参数 | epoch=90, steps per epoch=625, batch_size = 256 |
|
||||
| 优化器 | Momentum |
|
||||
| 损失函数 | Softmax交叉熵 |
|
||||
| 输出 | 概率 |
|
||||
| 损失 | 1.9575993 |
|
||||
| 速度 | 111毫秒/步(8卡) |
|
||||
| 总时长 | 112分钟 |
|
||||
| 参数(M) | 20.79 |
|
||||
| 微调检查点| 166M(.ckpt文件) |
|
||||
| 脚本 | [链接](https://gitee.com/mindspore/mindspore/tree/master/model_zoo/official/cv/resnet) |
|
||||
|
||||
#### ImageNet2012上的ResNet101
|
||||
|
||||
| 参数 | Ascend 910 | GPU |
|
||||
|
|
|
@ -23,7 +23,7 @@ from mindspore.train.serialization import load_checkpoint, load_param_into_net
|
|||
from src.CrossEntropySmooth import CrossEntropySmooth
|
||||
|
||||
parser = argparse.ArgumentParser(description='Image classification')
|
||||
parser.add_argument('--net', type=str, default=None, help='Resnet Model, either resnet18, '
|
||||
parser.add_argument('--net', type=str, default=None, help='Resnet Model, either resnet18,resnet34'
|
||||
'resnet50 or resnet101')
|
||||
parser.add_argument('--dataset', type=str, default=None, help='Dataset, either cifar10 or imagenet2012')
|
||||
|
||||
|
@ -46,7 +46,10 @@ if args_opt.net in ("resnet18", "resnet50"):
|
|||
else:
|
||||
from src.config import config2 as config
|
||||
from src.dataset import create_dataset2 as create_dataset
|
||||
|
||||
elif args_opt.net == "resnet34":
|
||||
from src.resnet import resnet34 as resnet
|
||||
from src.config import config_resnet34 as config
|
||||
from src.dataset import create_dataset_resnet34 as create_dataset
|
||||
elif args_opt.net == "resnet101":
|
||||
from src.resnet import resnet101 as resnet
|
||||
from src.config import config3 as config
|
||||
|
|
|
@ -24,6 +24,7 @@ from mindspore import Tensor, load_checkpoint, load_param_into_net, export, cont
|
|||
parser = argparse.ArgumentParser(description='resnet export')
|
||||
parser.add_argument('--network_dataset', type=str, default='resnet50_cifar10', choices=['resnet18_cifar10',
|
||||
'resnet18_imagenet2012',
|
||||
'resnet34_imagenet2012',
|
||||
'resnet50_cifar10',
|
||||
'resnet50_imagenet2012',
|
||||
'resnet101_imagenet2012',
|
||||
|
@ -52,6 +53,9 @@ if __name__ == '__main__':
|
|||
elif args.network_dataset == 'resnet18_imagenet2012':
|
||||
from src.config import config2 as config
|
||||
from src.resnet import resnet18 as resnet
|
||||
elif args.network_dataset == 'resnet34_imagenet2012':
|
||||
from src.config import config2 as config
|
||||
from src.resnet import resnet34 as resnet
|
||||
elif args.network_dataset == 'resnet50_cifar10':
|
||||
from src.config import config1 as config
|
||||
from src.resnet import resnet50 as resnet
|
||||
|
|
|
@ -19,12 +19,12 @@ CURPATH="$(dirname "$0")"
|
|||
|
||||
if [ $# != 4 ] && [ $# != 5 ] && [ $# != 6 ]
|
||||
then
|
||||
echo "Usage: bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
|
||||
echo " bash run_distribute_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)"
|
||||
echo "Usage: bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
|
||||
echo " bash run_distribute_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet34" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
then
|
||||
echo "error: the selected net is neither resnet50 nor resnet101 and se-resnet50"
|
||||
exit 1
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
if [ $# != 4 ]
|
||||
then
|
||||
echo "Usage: bash run_eval.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]"
|
||||
echo "Usage: bash run_eval.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet34" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
then
|
||||
echo "error: the selected net is neither resnet50 nor resnet101 nor se-resnet50"
|
||||
exit 1
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
if [[ $# -lt 4 || $# -gt 5 ]]; then
|
||||
echo "Usage: bash run_infer_310.sh [MINDIR_PATH] [NET_TYPE] [DATASET] [DATA_PATH] [DEVICE_ID]
|
||||
NET_TYPE can choose from [resnet18, se-resnet50, resnet50, resnet101]
|
||||
NET_TYPE can choose from [resnet18, resnet34, se-resnet50, resnet50, resnet101]
|
||||
DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -29,7 +29,7 @@ get_real_path(){
|
|||
fi
|
||||
}
|
||||
model=$(get_real_path $1)
|
||||
if [ $2 == 'resnet18' ] || [ $2 == 'se-resnet50' ] || [ $2 == 'resnet50' ] || [ $2 == 'resnet101' ]; then
|
||||
if [ $2 == 'resnet18' ] || [ $2 == 'resnet34' ] || [ $2 == 'se-resnet50' ] || [ $2 == 'resnet50' ] || [ $2 == 'resnet101' ]; then
|
||||
network=$2
|
||||
else
|
||||
echo "NET_TYPE can choose from [resnet18, se-resnet50]"
|
||||
|
|
|
@ -19,12 +19,12 @@ CURPATH="$(dirname "$0")"
|
|||
|
||||
if [ $# != 3 ] && [ $# != 4 ] && [ $# != 5 ]
|
||||
then
|
||||
echo "Usage: bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
|
||||
echo " bash run_standalone_train.sh [resnet18|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)"
|
||||
echo "Usage: bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
|
||||
echo " bash run_standalone_train.sh [resnet18|resnet34|resnet50|resnet101|se-resnet50] [cifar10|imagenet2012] [DATASET_PATH] [RUN_EVAL](optional) [EVAL_DATASET_PATH](optional)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
if [ $1 != "resnet18" ] && [ $1 != "resnet34" ] && [ $1 != "resnet50" ] && [ $1 != "resnet101" ] && [ $1 != "se-resnet50" ]
|
||||
then
|
||||
echo "error: the selected net is neither resnet50 nor resnet101 and se-resnet50"
|
||||
exit 1
|
||||
|
|
|
@ -153,3 +153,24 @@ config_thor_gpu = ed({
|
|||
"damping_decay": 0.5467,
|
||||
"frequency": 834,
|
||||
})
|
||||
|
||||
# config for resnet34, imagenet2012, Ascend
|
||||
config_resnet34 = ed({
|
||||
"class_num": 1001,
|
||||
"batch_size": 256,
|
||||
"loss_scale": 1024,
|
||||
"momentum": 0.9,
|
||||
"weight_decay": 1e-4,
|
||||
"epoch_size": 90,
|
||||
"pretrain_epoch_size": 0,
|
||||
"save_checkpoint": True,
|
||||
"save_checkpoint_epochs": 5,
|
||||
"keep_checkpoint_max": 1,
|
||||
"save_checkpoint_path": "./",
|
||||
"warmup_epochs": 0,
|
||||
"optimizer": 'Momentum',
|
||||
"use_label_smooth": True,
|
||||
"label_smooth_factor": 0.1,
|
||||
"lr_init": 0.0,
|
||||
"lr_max": 1.0,
|
||||
"lr_end": 0.0})
|
||||
|
|
|
@ -400,6 +400,64 @@ def create_dataset4(dataset_path, do_train, repeat_num=1, batch_size=32, target=
|
|||
|
||||
return data_set
|
||||
|
||||
def create_dataset_resnet34(dataset_path, do_train, repeat_num=1, batch_size=32):
|
||||
"""
|
||||
create a train or eval imagenet2012 dataset for resnet34
|
||||
|
||||
Args:
|
||||
dataset_path(string): the path of dataset.
|
||||
do_train(bool): whether dataset is used for train or eval.
|
||||
repeat_num(int): the repeat times of dataset. Default: 1
|
||||
batch_size(int): the batch size of dataset. Default: 32
|
||||
|
||||
Returns:
|
||||
data_set
|
||||
"""
|
||||
device_id = int(os.getenv('DEVICE_ID'))
|
||||
device_num = int(os.getenv('RANK_SIZE'))
|
||||
|
||||
if device_num == 1:
|
||||
data_set = ds.ImageFolderDataset(dataset_path)
|
||||
else:
|
||||
if do_train:
|
||||
data_set = ds.ImageFolderDataset(dataset_path, shuffle=True,
|
||||
num_shards=device_num, shard_id=device_id)
|
||||
else:
|
||||
data_set = ds.ImageFolderDataset(dataset_path)
|
||||
|
||||
image_size = 224
|
||||
mean = [0.485 * 255, 0.456 * 255, 0.406 * 255]
|
||||
std = [0.229 * 255, 0.224 * 255, 0.225 * 255]
|
||||
|
||||
# define map operations
|
||||
if do_train:
|
||||
trans = [
|
||||
C.RandomCropDecodeResize(image_size, scale=(0.08, 1.0), ratio=(0.75, 1.333)),
|
||||
C.RandomHorizontalFlip(prob=0.5),
|
||||
C.Normalize(mean=mean, std=std),
|
||||
C.HWC2CHW()
|
||||
]
|
||||
else:
|
||||
trans = [
|
||||
C.Decode(),
|
||||
C.Resize(256),
|
||||
C.CenterCrop(image_size),
|
||||
C.Normalize(mean=mean, std=std),
|
||||
C.HWC2CHW()
|
||||
]
|
||||
|
||||
type_cast_op = C2.TypeCast(mstype.int32)
|
||||
|
||||
data_set = data_set.map(operations=trans, input_columns="image", num_parallel_workers=8)
|
||||
data_set = data_set.map(operations=type_cast_op, input_columns="label", num_parallel_workers=8)
|
||||
|
||||
# apply batch operations
|
||||
data_set = data_set.batch(batch_size, drop_remainder=True)
|
||||
|
||||
# apply dataset repeat operation
|
||||
data_set = data_set.repeat(repeat_num)
|
||||
|
||||
return data_set
|
||||
|
||||
def _get_rank_info():
|
||||
"""
|
||||
|
|
|
@ -238,3 +238,20 @@ def get_thor_damping(global_step, damping_init, decay_rate, total_epochs, steps_
|
|||
damping_each_step = np.array(damping_each_step).astype(np.float32)
|
||||
damping_now = damping_each_step[current_step:]
|
||||
return damping_now
|
||||
|
||||
def get_resnet34_lr(lr_init, lr_end, lr_max, warmup_epochs, total_epochs, steps_per_epoch):
|
||||
|
||||
total_steps = steps_per_epoch * total_epochs
|
||||
warmup_steps = steps_per_epoch * warmup_epochs
|
||||
|
||||
lr_each_step = []
|
||||
for i in range(total_steps):
|
||||
if i < warmup_steps:
|
||||
lr = lr_init + (lr_max - lr_init) * i / warmup_steps
|
||||
else:
|
||||
lr = lr_max - (lr_max - lr_end) * (i - warmup_steps) / (total_steps - warmup_steps)
|
||||
lr_each_step.append(lr)
|
||||
|
||||
lr_each_step = np.array(lr_each_step).astype(np.float32)
|
||||
|
||||
return lr_each_step
|
||||
|
|
|
@ -508,6 +508,26 @@ def resnet18(class_num=10):
|
|||
class_num,
|
||||
res_base=True)
|
||||
|
||||
def resnet34(class_num=10):
|
||||
"""
|
||||
Get ResNet34 neural network.
|
||||
|
||||
Args:
|
||||
class_num (int): Class number.
|
||||
|
||||
Returns:
|
||||
Cell, cell instance of ResNet34 neural network.
|
||||
|
||||
Examples:
|
||||
>>> net = resnet18(10)
|
||||
"""
|
||||
return ResNet(ResidualBlockBase,
|
||||
[3, 4, 6, 3],
|
||||
[64, 64, 128, 256],
|
||||
[64, 128, 256, 512],
|
||||
[1, 2, 2, 2],
|
||||
class_num,
|
||||
res_base=True)
|
||||
|
||||
def resnet50(class_num=10):
|
||||
"""
|
||||
|
|
|
@ -32,14 +32,14 @@ from mindspore.parallel import set_algo_parameters
|
|||
import mindspore.nn as nn
|
||||
import mindspore.common.initializer as weight_init
|
||||
import mindspore.log as logger
|
||||
from src.lr_generator import get_lr, warmup_cosine_annealing_lr
|
||||
from src.lr_generator import get_lr, warmup_cosine_annealing_lr, get_resnet34_lr
|
||||
from src.CrossEntropySmooth import CrossEntropySmooth
|
||||
from src.config import cfg
|
||||
from src.eval_callback import EvalCallBack
|
||||
from src.metric import DistAccuracy, ClassifyCorrectCell
|
||||
|
||||
parser = argparse.ArgumentParser(description='Image classification')
|
||||
parser.add_argument('--net', type=str, default=None, help='Resnet Model, resnet18, resnet50 or resnet101')
|
||||
parser.add_argument('--net', type=str, default=None, help='Resnet Model, resnet18, resnet34, resnet50 or resnet101')
|
||||
parser.add_argument('--dataset', type=str, default=None, help='Dataset, either cifar10 or imagenet2012')
|
||||
parser.add_argument('--run_distribute', type=ast.literal_eval, default=False, help='Run distribute')
|
||||
parser.add_argument('--device_num', type=int, default=1, help='Device num.')
|
||||
|
@ -83,7 +83,10 @@ if args_opt.net in ("resnet18", "resnet50"):
|
|||
from src.dataset import create_dataset2 as create_dataset
|
||||
else:
|
||||
from src.dataset import create_dataset_pynative as create_dataset
|
||||
|
||||
elif args_opt.net == "resnet34":
|
||||
from src.resnet import resnet34 as resnet
|
||||
from src.config import config_resnet34 as config
|
||||
from src.dataset import create_dataset_resnet34 as create_dataset
|
||||
elif args_opt.net == "resnet101":
|
||||
from src.resnet import resnet101 as resnet
|
||||
from src.config import config3 as config
|
||||
|
@ -189,13 +192,20 @@ if __name__ == '__main__':
|
|||
from src.lr_generator import get_thor_lr
|
||||
lr = get_thor_lr(0, config.lr_init, config.lr_decay, config.lr_end_epoch, step_size, decay_epochs=39)
|
||||
else:
|
||||
if args_opt.net in ("resnet18", "resnet50", "se-resnet50"):
|
||||
if args_opt.net in ("resnet18", "resnet34", "resnet50", "se-resnet50"):
|
||||
lr = get_lr(lr_init=config.lr_init, lr_end=config.lr_end, lr_max=config.lr_max,
|
||||
warmup_epochs=config.warmup_epochs, total_epochs=config.epoch_size, steps_per_epoch=step_size,
|
||||
lr_decay_mode=config.lr_decay_mode)
|
||||
else:
|
||||
lr = warmup_cosine_annealing_lr(config.lr, step_size, config.warmup_epochs, config.epoch_size,
|
||||
config.pretrain_epoch_size * step_size)
|
||||
if args_opt.net == "resnet34":
|
||||
lr = get_resnet34_lr(lr_init=config.lr_init,
|
||||
lr_end=config.lr_end,
|
||||
lr_max=config.lr_max,
|
||||
warmup_epochs=config.warmup_epochs,
|
||||
total_epochs=config.epoch_size,
|
||||
steps_per_epoch=step_size)
|
||||
lr = Tensor(lr)
|
||||
|
||||
# define opt
|
||||
|
|
Loading…
Reference in New Issue