diff --git a/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/README.md b/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/README.md index 5cb5099ea1a81a8a85ea1c90c2b9c0d55af3540a..aefae98b5f0acf58d43922e48d7fad7ef7d85525 100644 --- a/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/README.md +++ b/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/README.md @@ -1,4 +1,9 @@ - +- [基本信息](#基本信息.md) +- [概述](#概述.md) +- [训练环境准备](#训练环境准备.md) +- [快速上手](#快速上手.md) +- [迁移学习指导](#迁移学习指导.md) +- [高级参考](#高级参考.md)

基本信息

**发布者(Publisher):Huawei** @@ -25,140 +30,141 @@

概述

-SSD-VGG是采用单个深度神经网络模型实现目标检测和识别的方法。模型主要特点: -1、多尺度特征映射。将卷积特征层添加到截取的基础网络的末端。大尺度的特征图有较多的信息,可以用来检测小物体。而小尺度的特征图用来检测较大的物体。允许在多个尺度上对检测结果进行预测。 -2、采用卷积层作为预测器。代替了全连接层,直接采用卷积对不同的特征图进行提取检测结果。 +## 简述 + +SSD-VGG是采用单个深度神经网络模型实现目标检测和识别的方法。模型主要特点:多尺度特征映射。将卷积特征层添加到截取的基础网络的末端。大尺度的特征图有较多的信息,可以用来检测小物体。而小尺度的特征图用来检测较大的物体。允许在多个尺度上对检测结果进行预测。采用卷积层作为预测器。代替了全连接层,直接采用卷积对不同的特征图进行提取检测结果。 - 参考论文: - https://arxiv.org/pdf/1512.02325.pdf + [https://arxiv.org/abs/1810.04805](https://gitee.com/link?target=https%3A%2F%2Farxiv.org%2Fabs%2F1810.04805) - 参考实现: - https://github.com/ljanyst/ssd-tensorflow + https://github.com/NVIDIA/DeepLearningExamples/tree/master/TensorFlow2/LanguageModeling/BERT - 适配昇腾 AI 处理器的实现: - - https://gitee.com/ascend/modelzoo/tree/master/built-in/TensorFlow/Research/cv/detection/SSD-VGG_ID1619_for_TensorFlow - - + + https://gitee.com/ascend/ModelZoo-TensorFlow/blob/master/TensorFlow2/built-in/nlp/BERT_ID2478_for_TensorFlow2.X - 通过Git获取对应commit\_id的代码方法如下: + + git clone {repository_url} # 克隆仓库的代码 + cd {repository_name} # 切换到模型的代码仓目录 + git checkout {branch} # 切换到对应分支 + git reset --hard {commit_id} # 代码设置到对应的commit_id + cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换 - ``` - git clone {repository_url} # 克隆仓库的代码 - cd {repository_name} # 切换到模型的代码仓目录 - git checkout {branch} # 切换到对应分支 - git reset --hard {commit_id} # 代码设置到对应的commit_id - cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换 - ``` -

默认配置

- -- 训练数据集预处理(以Pascal VOC训练集为例,仅作为用户参考示例): - - - 图像的输入尺寸为300*300 - - 图像输入格式:pickle - - 随机排序 - - 随机缩放 - - 随机变换亮度 - - 随机变换对比度 - - 随机变换色调 - - 随机变换图像通道 - - 随机变换饱和度 - -- 训练超参 - - - Batch size: 8 - - Momentum: 0.9 - - LR scheduler: cosine - - Learning rate(LR): 0.00075;0.0001;0.0001 - - Optimizer: MomentumOptimizer - - Weight decay: 0.0005 - - Train epoch: 200 - - -

支持特性

- -| 特性列表 | 是否支持 | -|-------|------| -| 分布式训练 | 否 | -| 混合精度 | 是 | -| 并行数据 | 是 | - -- 混合精度训练 + +## 默认配置 + +- 网络结构 + - 24-layer, 1024-hidden, 16-heads, 340M parameters +- 训练超参(单卡): + - Batch size: 8 + - Momentum: 0.9 + - LR scheduler: cosine + - Learning rate(LR): 0.00075;0.0001;0.0001 + - Optimizer: MomentumOptimizer + - Weight decay: 0.0005 + - Train epoch: 200 + + +## 支持特性 + +| 特性列表 | 是否支持 | +| ---------- | -------- | +| 分布式训练 | 是 | +| 混合精度 | 是 | +| 数据并行 | 是 | + + +## 混合精度训练 昇腾910 AI处理器提供自动混合精度功能,可以针对全网中float32数据类型的算子,按照内置的优化策略,自动将部分float32的算子降低精度到float16,从而在精度损失很小的情况下提升系统性能并减少内存使用。 -- 开启混合精度 +## 开启混合精度 -脚本已默认开启混合精度,设置precision_mode参数的命令行参考如下。 +拉起脚本中,传入--precision_mode='allow_mix_precision' - ``` - train_full_1p.sh --precision_mode=allow_fp32_to_fp16 --data_path=./ - ``` +``` + ./train_full_1p.sh --help + +parameter explain: + --precision_mode precision mode(allow_fp32_to_fp16/force_fp16/must_keep_origin_dtype/allow_mix_precision) + --over_dump if or not over detection, default is False + --data_dump_flag data dump flag, default is False + --data_dump_step data dump step, default is 10 + --profiling if or not profiling for performance debug, default is False + --data_path source data of training + -h/--help show help message +``` +相关代码示例: -

训练环境准备

+``` +parser.add_argument('--precision_mode', type=str, default='allow_fp32_to_fp16', + help='precision mode, default is allow_fp32_to_fp16') +``` -1. 硬件环境准备请参见各硬件产品文档"[驱动和固件安装升级指南]( https://support.huawei.com/enterprise/zh/category/ai-computing-platform-pid-1557196528909)"。需要在硬件设备上安装与CANN版本配套的固件与驱动。 -2. 宿主机上需要安装Docker并登录[Ascend Hub中心](https://ascendhub.huawei.com/#/detail?name=ascend-tensorflow-arm)获取镜像。 - - 当前模型支持的镜像列表如[表1](#zh-cn_topic_0000001074498056_table1519011227314)所示。 - - **表 1** 镜像列表 - - - - - - - - - - - - -

镜像名称

-

镜像版本

-

配套CANN版本

-
-

21.0.2

-

5.0.2

-
+

训练环境准备

+- 硬件环境和运行环境准备请参见《[CANN软件安装指南](https://support.huawei.com/enterprise/zh/ascend-computing/cann-pid-251168373?category=installation-update)》 +- 运行以下命令安装依赖。 +``` +pip3 install requirements.txt +``` +说明:依赖配置文件requirements.txt文件位于模型的根目录

快速上手

-- 数据集准备 - 1. 模型训练使用Pascal VOC数据集,数据集请用户自行获取。 - - 2. 数据集训练前需要做预处理操作 +## 数据集准备 +1、用户自行准备好数据集,模型训练使用Pascal VOC数据集,数据集请用户自行获取 + ``` + bash download-data.sh ``` - ./process_dataset.py +2. 数据集训练前需要做预处理操作 ``` + ./process_dataset.py + ``` +3. 数据集处理后,放入模型目录下,在训练脚本中指定数据集路径,可正常使用。 + + + +## 模型训练 + +- 单击“立即下载”,并选择合适的下载方式下载源码包。 +- 开始训练。 + + - 启动训练之前,首先要配置程序运行相关环境变量。 + + 环境变量配置信息参见: - 3. 数据集处理后,放入模型目录下,在训练脚本中指定数据集路径,可正常使用。 - -- 模型训练 + [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819) - 1. 单击“立即下载”,并选择合适的下载方式下载源码包。 + - 单卡训练 - 2. 启动训练之前,首先要配置程序运行相关环境变量。环境变量配置信息参见: - [Ascend 910训练平台环境变量设置](https://gitee.com/ascend/modelzoo/wikis/Ascend%20910%E8%AE%AD%E7%BB%83%E5%B9%B3%E5%8F%B0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F%E8%AE%BE%E7%BD%AE?sort_id=3148819) - 3. 单卡训练 - 以数据集为./data/pascal-voc/train-samples.pkl、./data/pascal-voc/valid-samples.pkl、./data/pascal-voc/training-data.pkl为例,backbone模型为./data/vgg_graph/saved_model.pb、./data/vgg_graph/variables、./data/vgg_graph/vgg为例(vgg参考ssdvgg.py的__download_vgg下载) + 以数据集为./data/pascal-voc/train-samples.pkl、./data/pascal-voc/valid-samples.pkl、./data/pascal-voc/training-data.pkl为例,backbone模型为./data/vgg_graph/saved_model.pb、./data/vgg_graph/variables、./data/vgg_graph/vgg为例(vgg参考ssdvgg.py的__download_vgg下载) ``` cd test; bash train_full_1p.sh --data_path=./data/ ``` + 启动训练。 + + 启动单卡训练 (脚本为MUNIT_ID0953_for_TensorFlow/test/train_full_1p.sh) + + ``` + bash train_full_1p.sh + ``` + + +

高级参考

-- 脚本和示例代码 +## 脚本和示例代码 ``` - . ├── test │   ├── train_full_1p.sh // 执行全量训练脚本 │   └── train_performance_1p.sh @@ -180,10 +186,9 @@ SSD-VGG是采用单个深度神经网络模型实现目标检测和识别的方 ├── train.py ├── training_data.py ├── transforms.py - └── utils.py -``` + └── utils.py -- 脚本参数 +## 脚本参数 ``` --data_path data path,default is the path of train.py @@ -203,3 +208,7 @@ SSD-VGG是采用单个深度神经网络模型实现目标检测和识别的方 --dump_path dump path,default='/home/HwHiAiUser/' ``` + +## 训练过程 + +通过“模型训练”中的训练指令启动单卡或者多卡训练。单卡和多卡通过运行不同脚本,支持单卡,8卡网络训练。模型存储路径为${cur_path}/output/$ASCEND_DEVICE_ID,包括训练的log以及checkpoints文件。以8卡训练为例,loss信息在文件${cur_path}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log中。 \ No newline at end of file diff --git a/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/test/train_full_1p.sh b/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/test/train_full_1p.sh index fe078086b4be5cfdcd83852e6faf6ba96d8d7899..978a4872523113dcf4bf907eef26460fabbddc7b 100644 --- a/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/test/train_full_1p.sh +++ b/TensorFlow/built-in/cv/detection/SSD-VGG_ID1619_for_TensorFlow/test/train_full_1p.sh @@ -91,7 +91,7 @@ echo "Final Train Accuracy : ${train_accuracy}" #训练用例信息,不需要修改 BatchSize=${batch_size} DeviceType=`uname -m` -CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf' +CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc' ##获取性能数据,不需要修改 #吞吐量