Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
yuanAIhan 2135bdf813 | 2 years ago | |
---|---|---|
resnext152_64x4d | 2 years ago | |
README.md | 2 years ago |
ResNeXt是一个简单、高度模块化的图像分类网络架构。ResNeXt的设计为统一的、多分支的架构,该架构仅需设置几个超参数。此策略提供了一个新维度,我们将其称为“基数”(转换集的大小),它是深度和宽度维度之外的一个重要因素。
论文: Xie S, Girshick R, Dollár, Piotr, et al. Aggregated Residual Transformations for Deep Neural Networks. 2016.
ResNeXt整体网络架构如下:
使用的数据集:ImageNet
采用混合精度的训练方法使用支持单精度和半精度数据来提高深度学习神经网络的训练速度,同时保持单精度训练所能达到的网络精度。混合精度训练提高计算速度、减少内存使用的同时,支持在特定硬件上训练更大的模型或实现更大批次的训练。
以FP16算子为例,如果输入数据类型为FP32,MindSpore后台会自动降低精度来处理数据。用户可打开INFO日志,搜索“reduce precision”查看精度降低的算子。
.
└─resnext152
├─README.md
├─scripts
├─run_standalone_train.sh # 启动Ascend单机训练(单卡)
├─run_distribute_train.sh # 启动Ascend分布式训练(8卡)
└─run_eval.sh # 启动评估
├─src
├─backbone
├─_init_.py # 初始化
├─resnet.py # ResNeXt152骨干
├─utils
├─_init_.py # 初始化
├─cunstom_op.py # 网络操作
├─logging.py # 打印日志
├─optimizers_init_.py # 获取参数
├─sampler.py # 分布式采样器
├─var_init_.py # 计算增益值
├─_init_.py # 初始化
├─config.py # 参数配置
├─crossentropy.py # 交叉熵损失函数
├─dataset.py # 数据预处理
├─eval_callback.py # 训练时推理
├─head.py # 常见头
├─image_classification.py # 获取ResNet
├─metric.py # 推理
├─linear_warmup.py # 线性热身学习率
├─warmup_cosine_annealing.py # 每次迭代的学习率
├─warmup_step_lr.py # 热身迭代学习率
├─eval.py # 评估网络
├──train.py # 训练网络
├──mindspore_hub_conf.py # MindSpore Hub接口
在config.py中可以同时配置训练和评估参数。
"image_height": '224,224' # 图像大小
"num_classes": 1000, # 数据集类数
"per_batch_size": 128, # 输入张量的批次大小
"lr": 0.05, # 基础学习率
"lr_scheduler": 'cosine_annealing', # 学习率模式
"lr_epochs": '30,60,90,120', # LR变化轮次
"lr_gamma": 0.1, # 减少LR的exponential lr_scheduler因子
"eta_min": 0, # cosine_annealing调度器中的eta_min
"T_max": 150, # cosine_annealing调度器中的T-max
"max_epoch": 150, # 训练模型的最大轮次数量
"backbone": 'resnext152', # 骨干网络
"warmup_epochs" : 1, # 热身轮次
"weight_decay": 0.0001, # 权重衰减
"momentum": 0.9, # 动量
"is_dynamic_loss_scale": 0, # 动态损失放大
"loss_scale": 1024, # 损失放大
"label_smooth": 1, # 标签平滑
"label_smooth_factor": 0.1, # 标签平滑因子
"ckpt_interval": 2000, # 检查点间隔
"ckpt_path": 'outputs/', # 检查点保存位置
"is_save_on_master": 1,
"rank": 0, # 分布式本地进程序号
"group_size": 1 # 分布式进程总数
您可以通过python脚本开始训练:
python train.py --data_dir ~/imagenet/train/ --platform Ascend --is_distributed 0
或通过shell脚本开始训练:
Ascend:
# 分布式训练示例(8卡)
bash run_distribute_train.sh RANK_TABLE_FILE DATA_PATH
# 单机训练
bash run_standalone_train.sh DEVICE_ID DATA_PATH
# Ascend分布式训练示例(8卡)
bash scripts/run_distribute_train.sh RANK_TABLE_FILE DATA_PATH
# Ascend单机训练示例
bash scripts/run_standalone_train.sh DEVICE_ID DATA_PATH
您可以在日志中找到检查点文件和结果。
您可以通过python脚本开始训练:
python eval.py --data_dir ~/imagenet/val/ --platform Ascend --pretrained resnext.ckpt
或通过shell脚本开始训练:
# 评估
bash run_eval.sh DEVICE_ID DATA_PATH PRETRAINED_CKPT_PATH PLATFORM
PLATFORM is Ascend, default is Ascend.
# 检查点评估
bash scripts/run_eval.sh DEVICE_ID PRETRAINED_CKPT_PATH PLATFORM
#或者直接使用脚本运行
python eval.py --data_dir ~/imagenet/val/ --platform Ascend --pretrained ~/best_acc_0.ckpt
评估结果保存在脚本路径下。您可以在日志中找到类似以下的结果。
acc=80.08%(TOP1)
acc=94.71%(TOP5)
本地导出mindir
python export.py --device_target [PLATFORM] --checkpoint_file_path [CKPT_PATH] --file_format [EXPORT_FORMAT]
checkpoint_file_path
参数为必填项。EXPORT_FORMAT
可选 ["AIR", "ONNX", "MINDIR"].
在执行推理之前,需要通过export.py导出mindir文件。目前仅可处理batch_size为1。
#Ascend310 推理
bash run_infer_310.sh [MINDIR_PATH] [DATA_PATH] [DEVICE_ID]
MINDIR_PATH
为生成的mindir的路径,DATA_PATH
为imagenet的数据集路径,DEVICE_ID
可选,默认值为0。
推理结果保存在当前路径,可在acc.log中看到最终精度结果。
Total data: 50000, top1 accuracy: 0.79174, top5 accuracy: 0.94178.
参数 | ResNeXt152 |
---|---|
资源 | Ascend 910;CPU:2.60GHz,192核;内存:755GB |
上传日期 | 2021-6-30 |
MindSpore版本 | 1.2 |
数据集 | ImageNet |
训练参数 | src/config.py |
优化器 | Momentum |
损失函数 | Softmax交叉熵 |
损失 | 1.2892 |
准确率 | 80.08%(TOP1) |
总时长 | 7.8小时 (8卡) |
调优检查点 | 192 M(.ckpt文件) |
参数 | ||
---|---|---|
资源 | Ascend 910 | Ascend 310 |
上传日期 | 2021-6-20 | 2021-10-27 |
MindSpore版本 | 1.2 | 1.3.0 |
数据集 | ImageNet, 1.2万 | ImageNet, 1.2万 |
batch_size | 1 | 1 |
输出 | 概率 | 概率 |
准确率 | acc=80.08%(TOP1) | acc=79.34%(TOP1) |
dataset.py中设置了“create_dataset”函数内的种子,同时还使用了train.py中的随机种子。
请浏览官网主页。
ResNeXt是一个简单、高度模块化的图像分类网络架构。ResNeXt的设计为统一的、多分支的架构,该架构仅需设置几个超参数。此策略提供了一个新维度,我们将其称为“基数”(转换集的大小),它是深度和宽度维度之外的一个重要因素。传统的要提高模型的准确率,都是加深或加宽网络,但是随着超参数数量的增加(比如channels数,filter size等等),网络设计的难度和计算开销也会增加。模型使用的数据集为ImageNet,其的数据格式为RGB的。ResNeXt是ResNet网络的改进版本。
Python C++ Shell Markdown Text other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》