已合并
[西安电子科技大学][高校贡献][Pytorch迁移1.8][Baseline_RawNet2]-初次提交 #1039
AtomGit-Bot创建于 2022年7月6日
[西安电子科技大学][高校贡献][Pytorch迁移1.8][Baseline_RawNet2]-初次提交 #1039
已合并
AtomGit-Bot创建于 2022年7月6日
refs/pull/1039/head合入到master
12 个文件变更+241-146
@@ -1,130 +1,217 @@
1-# RawNet21+# Baseline-Rawnet for PyTorch
2 2 
3-This implements training of RawNet2 on the VoxCeleb1&2 datasets of YouTube.3+- [概述](概述.md)
4+- [准备训练环境](准备训练环境.md)
5+- [开始训练](开始训练.md)
6+- [训练结果](训练结果.md)
7+- [版本说明](版本说明.md)
4 8 
5-- Reference implementation:9+# 概述
6 10 
7-```11+## 简述
8-url=https://github.com/Jungjee/RawNet
9-dir=RawNet-master/python/RawNet2
10-```
11 12 
12-## Baseline-RawNet2 Detail13+最近,使用深度神经网络对原始波形进行直接建模已被广泛研究用于音频领域的许多任务。然而,在说话人验证中,原始波形的利用处于初步阶段,需要进一步研究。在这项研究中,我们探索了输入原始波形以改进各个方面的端到端深度神经网络:前端说话人嵌入提取,包括模型架构、预训练方案、附加目标函数和后端分类。使用预训练方案调整模型架构可以提取说话人嵌入,从而显着提高性能。
13 14 
14-As of the current date, Ascend-Pytorch is still inefficient for contiguous operations. Therefore, RawNet2 is re-implemented using semantics such as custom OP. 15+- 参考实现:
15 16 
16-## Requirements 17+ ```
18+ url=https://github.com/Jungjee/RawNet
19+ commit_id=585ce2c4fb80ae6ab236f79f06911e2f8bef180c
20+ ```
17 21 
18-- Install PyTorch ([pytorch.org](http://pytorch.org))22+- 适配昇腾 AI 处理器的实现:
19-- `pip install -r requirements.txt`
20- Note: pillow recommends installing a newer version. If the corresponding torchvision version cannot be installed directly, you can use the source code to install the corresponding version. The source code reference link: https://github.com/pytorch/vision,
21-Suggestion the pillow is 9.1.0 and the torchvision is 0.6.0
22 23 
23-## DataSet24+ ```
25+ url=https://gitee.com/ascend/ModelZoo-PyTorch.git
26+ code_path=PyTorch/contrib/audio
27+ ```
24 28 
25-```29+- 通过Git获取代码方法如下:
26-url: http://www.robots.ox.ac.uk/~vgg/data/voxceleb/
27-```
28 30 
29-- The training datasets are VoxCeleb2, the evaluation dataset is VoxCeleb1H & VoxCeleb1E. The datasets are large. Please ensure sufficient hard disk space when downloading and decompressing.31+ ```
30-- Besides, the data in the VoxCeleb2 downloaded from the url above is in the format of .m4a. If you do not use the dataset which is converted already, you should firstly run the `m4a2wav.py`.32+ git clone {url} # 克隆仓库的代码
31-- You need to follow directory structure of the `data` as below. If you connect to the prepared data folder, you don't need to build the following directory.33+ cd {code_path} # 切换到模型代码所在路径,若仓库下只有该模型,则无需切换
34+ ```
32 35 
33-```36+- 通过单击“立即下载”,下载源码包。
34-${RawNet}/DB/VoxCeleb1/
35-├── dev_wav
36-│   ├── id10001
37-│   │   ├── 1zcIwhmdeo4
38-│   │   │   ├── 00001.wav
39-│   │   │   ├── 00002.wav
40-│   │   │   └── 00003.wav
41-│   │   ├── 5ssVY9a5X-M
42-│   │   │   ├── 00001.wav
43-│   │   │   ├── 00002.wav
44-│   │   │   ├── 00003.wav
45-│   │   │   └── 00003.wav
46-│   └── ...
47-├── eval_wav
48-│   ├── id10270
49-│   │   ├── 5r0dWxy17C8
50-│   │   │   ├── 00001.wav
51-│   │   │   ├── 00002.wav
52-│   │   │   ├── 00003.wav
53-│   │   │   ├── 00004.wav
54-│   │   │   └── 00005.wav
55-│   └── ...
56-│   ├── _z_BR0ERa9g
57-│   ├── 00001.wav
58-│   ├── 00002.wav
59-│   └── 00003.wav
60-├── val_trial.txt
61-└── veri_test.txt
62 37 
63-${RawNet}/DB/VoxCeleb2/38+# 准备训练环境
64-└── wav
65- ├── id00012
66- │   ├── 21Uxsk56VDQ
67- │   │   ├── 00001.wav
68- │   │   ├── ...
69- │   │   └── 00059.wav
70- │   ├── 00-qODbtozw
71- │   │   ├── ...
72- │   │   ├── 00079.wav
73- │   │   └── 00080.wav
74- ├── ...
75- │   └── zw-4DTjqIA0
76- │   ├── 00108.wav
77- │   └── 00109.wav
78- └── id09272
79- └── u7VNkYraCw0
80- ├── ...
81- └── 00027.wav
82-```
83 39 
84-- You need to follow directory structure of the `output` as below.40+## 准备环境
85 41 
86-```42+- 当前模型支持的固件与驱动、 CANN 以及 PyTorch 如下表所示。
87-${RawNet}/train/train_${device_count}P
88-|-- DNNS/${name}/
89-| |-- models
90-| | |--best_opt_eval.pt ## The best perfomance model is saved here
91-| | |--TA_${epoch}_${eer}.pt ##The other model is saved here
92-| |-- results
93-| |-- log
94-| | |-- eval_epoch${epoch}.txt ## The training log is saved here
95-| |-- prof
96-| |-- eers.txt ##The eers is saved here
97-| |-- f_params.txt ##The params of the model are saved here
98-```
99 43 
100-## Training #44+ **表 1** 版本配套表
101 45 
102-- Note that the `output` folder under the `test` directory will also save the code running log.46+ | 配套 | 版本 |
103-- To run the model, you should cd to the directory of test47+ | ---------- | ------------------------------------------------------------ |
104-- To train a model, run `train_1p.py` or `train_8p.py`: 48+ | 硬件 | [1.0.16](https://www.hiascend.com/hardware/firmware-drivers?tag=commercial) |
49+ | 固件与驱动 | [5.1.RC2](https://www.hiascend.com/hardware/firmware-drivers?tag=commercial) |
50+ | CANN | [5.1.RC2](https://www.hiascend.com/software/cann/commercial?version=5.1.RC2) |
51+ | PyTorch | [1.8.1](https://gitee.com/ascend/pytorch/tree/master/) |
105 52 
106-```bash53+- 环境准备指导。
107-# 1p train perf
108-nohup bash train_performance_1p.sh --data_path=xxx &
109 54 
110-# 8p train perf55+ 请参考《[Pytorch框架训练环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/ptes)》。
111-nohup bash train_performance_8p.sh --data_path=xxx &
112 56 
113-# 1p train full57+- 安装依赖。
114-nohup bash train_full_1p.sh --data_path=xxx &
115 58 
116-# 8p train full59+ ```
117-nohup bash train_full_8p.sh --data_path=xxx &60+ pip install -r requirements.txt
61+ ```
118 62 
119-```63+## 准备数据集
120 64 
121-## RawNet2 training result 65+1. 准备数据集
122 66 
123-| eer(percentage) | FPS(aver) | Npu_nums | Epochs | AMP_Type |67+ 请用户自行准备好数据集,包含训练集和验证集两部分,可选用的数据集包括 [VoxCeleb2,VoxCeleb1](http://www.robots.ox.ac.uk/~vgg/data/voxceleb/) 等。在源码包根目录下建立“DB”/文件夹,将准备好的数据集上传至“DB/”文件夹中并解压。数据集很大。下载和解压缩时,请确保有足够的硬盘空间。
124-| :-------------------------: | :-------: | :------: | :----: | :------: |
125-| 0.14 | 7760 | 1 | 1 | O2 |
126-| 0.038(aver) and 0.035(high) | 8573 | 8 | 20 | O2 |
127 68 
128-### **Testing**69+ 解压后评估数据集和训练数据集分别位于“DB/VoxCeleb1”和“DB/VoxCeleb2”文件夹路径下,该目录下每个文件夹代表一个类别,且同一文件夹下的所有图片都有相同的标签。当前提供的训练脚本中,是以VoxCeleb1和VoxCeleb2数据集为例。在使用其他数据集时,修改数据集路径。
129 70 
130-The testing data in the paper is about the VoxCeleb1H and VoxCeleb1E. And here we use the dataset of the VoxCeleb1H, and the target of the eer in the paper is 0.0489.71+2. 数据预处理
72+ 
73+ 从上面的url下载的VoxCeleb2中的数据格式为.m4a。如果不使用已转换的数据集,则应首先执行数据预处理脚本,将数据格式转为.wav。
74+ 
75+ ```
76+ python m4a2wav.py
77+ ```
78+ 
79+ 数据集目录结构参考:
80+ 
81+ ```
82+ ${RawNet}/DB/VoxCeleb1/
83+ ├── dev_wav
84+ │   ├── id10001
85+ │   │   ├── 1zcIwhmdeo4
86+ │   │   │   ├── 00001.wav
87+ │   │   │   ├── 00002.wav
88+ │   │   │   └── 00003.wav
89+ │   │   ├── 5ssVY9a5X-M
90+ │   │   │   ├── 00001.wav
91+ │   │   │   ├── 00002.wav
92+ │   │   │   ├── 00003.wav
93+ │   │   │   └── 00003.wav
94+ │   └── ...
95+ ├── eval_wav
96+ │   ├── id10270
97+ │   │   ├── 5r0dWxy17C8
98+ │   │   │   ├── 00001.wav
99+ │   │   │   ├── 00002.wav
100+ │   │   │   ├── 00003.wav
101+ │   │   │   ├── 00004.wav
102+ │   │   │   └── 00005.wav
103+ │   └── ...
104+ │   ├── _z_BR0ERa9g
105+ │   ├── 00001.wav
106+ │   ├── 00002.wav
107+ │   └── 00003.wav
108+ ├── val_trial.txt
109+ └── veri_test.txt
110+
111+ ${RawNet}/DB/VoxCeleb2/
112+ └── wav
113+ ├── id00012
114+ │   ├── 21Uxsk56VDQ
115+ │   │   ├── 00001.wav
116+ │   │   ├── ...
117+ │   │   └── 00059.wav
118+ │   ├── 00-qODbtozw
119+ │   │   ├── ...
120+ │   │   ├── 00079.wav
121+ │   │   └── 00080.wav
122+ ├── ...
123+ │   └── zw-4DTjqIA0
124+ │   ├── 00108.wav
125+ │   └── 00109.wav
126+ └── id09272
127+ └── u7VNkYraCw0
128+ ├── ...
129+ └── 00027.wav
130+ ```
131+ 
132+# 开始训练
133+ 
134+1. 进入运行脚本目录下
135+ 
136+ ```
137+ cd /${模型文件夹名称}/test
138+ ```
139+ 
140+2. 运行训练脚本
141+ 
142+ 该模型支持单机单卡训练和单机8卡训练。
143+ 
144+ * 单机单卡训练
145+ 
146+ 启动单卡训练
147+ 
148+ ```
149+ # 1p train perf
150+ bash train_performance_1p.sh --data_path=./DB
151+ # 1p train full
152+ bash train_full_1p.sh --data_path=./DB
153+ ```
154+ 
155+ * 参数说明:
156+ 
157+ * data_path:填写数据集路径
158+ 
159+ * 代码运行日志保存在**test**路径下的**output**文件夹
160+ 
161+ * 单机多卡训练
162+ 
163+ 启动8卡训练
164+ 
165+ ```
166+ # 8p train perf
167+ bash train_performance_8p.sh --data_path=./DB
168+ # 8p train full
169+ bash train_full_8p.sh --data_path=./DB
170+ ```
171+ 
172+ * 参数说明:
173+ 
174+ * data_path:填写数据集路径
175+ 
176+ * 代码运行日志保存在**test**路径下的**output**文件夹
177+ 
178+ 遵循“output”的目录结构如下:
179+ 
180+ ```
181+ ${RawNet}/train/train_${device_count}P
182+ |-- DNNS/${name}/
183+ | |-- models
184+ | | |--best_opt_eval.pt ## The best perfomance model is saved here
185+ | | |--TA_${epoch}_${eer}.pt ##The other model is saved here
186+ | |-- results
187+ | |-- log
188+ | | |-- eval_epoch${epoch}.txt ## The training log is saved here
189+ | |-- prof
190+ | |-- eers.txt ##The eers is saved here
191+ | |-- f_params.txt ##The params of the model are saved here
192+ ```
193+ 
194+# 训练结果展示
195+ 
196+**表 2** 训练结果展示表
197+ 
198+| eer(percentage) | FPS(aver) | Npu_nums | Epochs | AMP_Type | Torch |
199+| :-------------------------: | :-------: | :------: | :----: | :------: | ----- |
200+| 0.14 | 7760 | 1 | 1 | O2 | 1.5 |
201+| - | 7912 | 1 | 1 | O2 | 1.8 |
202+| 0.038(aver) and 0.035(high) | 8573 | 8 | 20 | O2 | 1.5 |
203+| 0.038(aver) and 0.035(high) | 12575 | 8 | 20 | O2 | 1.8 |
204+ 
205+ 
206+ 
207+# 版本说明
208+ 
209+## 变更
210+ 
211+2022.03.18:首次发布
212+ 
213+2022.11.24:更新pytorch1.8版本,重新发布。
214+ 
215+## 已知问题
216+ 
217+无。
@@ -1,19 +1,19 @@
1#!/bin/bash1#!/bin/bash
2+# 配置CANN相关环境变量
2CANN_INSTALL_PATH_CONF='/etc/Ascend/ascend_cann_install.info'3CANN_INSTALL_PATH_CONF='/etc/Ascend/ascend_cann_install.info'
3 4 
4if [ -f $CANN_INSTALL_PATH_CONF ]; then5if [ -f $CANN_INSTALL_PATH_CONF ]; then
5- CANN_INSTALL_PATH=$(cat $CANN_INSTALL_PATH_CONF | grep Install_Path | cut -d "=" -f 2)6+ CANN_INSTALL_PATH=$(cat $CANN_INSTALL_PATH_CONF | grep Install_Path | cut -d "=" -f 2)
6else7else
7- CANN_INSTALL_PATH="/usr/local/Ascend"8+ CANN_INSTALL_PATH="/usr/local/Ascend/"
8fi9fi
9 10 
10-if [ -d ${CANN_INSTALL_PATH}/ascend-toolkit/latest ]; then11+if [ -d ${CANN_INSTALL_PATH}/ascend-toolkit/latest ];then
11- source ${CANN_INSTALL_PATH}/ascend-toolkit/set_env.sh12+ source ${CANN_INSTALL_PATH}/ascend-toolkit/set_env.sh
12else13else
13- source ${CANN_INSTALL_PATH}/nnae/set_env.sh14+ source ${CANN_INSTALL_PATH}/nnae/set_env.sh
14fi15fi
15 16 
16-#设置device侧日志登记为error
17msnpureport -g error -d 017msnpureport -g error -d 0
18msnpureport -g error -d 118msnpureport -g error -d 1
19msnpureport -g error -d 219msnpureport -g error -d 2
@@ -23,8 +23,6 @@ msnpureport -g error -d 5
23msnpureport -g error -d 623msnpureport -g error -d 6
24msnpureport -g error -d 724msnpureport -g error -d 7
25 25 
26-export DUMP_GRAPH_LEVEL=0
27-export DUMP_GE_GRAPH=0
28 26 
29#将Host日志输出到串口,0-关闭/1-开启27#将Host日志输出到串口,0-关闭/1-开启
30export ASCEND_SLOG_PRINT_TO_STDOUT=028export ASCEND_SLOG_PRINT_TO_STDOUT=0
@@ -12,7 +12,7 @@ export RANK_SIZE=1
12data_path=""12data_path=""
13 13 
14# 训练epoch14# 训练epoch
15-train_epochs=8015+train_epochs=20
16# 指定训练所使用的npu device卡id16# 指定训练所使用的npu device卡id
17device_id=117device_id=1
18# 加载数据进程数18# 加载数据进程数
@@ -80,7 +80,7 @@ source test/env_npu.sh
80rm -f nohup.out80rm -f nohup.out
81cd train/train-1P81cd train/train-1P
82 82 
83-nohup python train_RawNet2.py > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &83+nohup python train_RawNet2.py -epoch ${train_epochs} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
84 84 
85wait85wait
86 86 
@@ -93,13 +93,14 @@ e2e_time=$(( $end_time - $start_time ))
93#结果打印,不需要修改93#结果打印,不需要修改
94echo "------------------ Final result ------------------"94echo "------------------ Final result ------------------"
95#输出性能FPS,需要模型审视修改95#输出性能FPS,需要模型审视修改
96-FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'`96+FPS=`grep -a 'INFOFPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'|awk '{sum += $1} END {printf "%3.3f",sum/NR}'`
97#打印,不需要修改97#打印,不需要修改
98echo "Final Performance images/sec : $FPS"98echo "Final Performance images/sec : $FPS"
99 99 
100#输出训练精度,需要模型审视修改100#输出训练精度,需要模型审视修改
101-eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:" '{print $NF}'`101+eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:|/epoch" '{print $2}'|awk 'END{print}'`
102#打印,不需要修改102#打印,不需要修改
103+train_accuracy=${eer}
103echo "Final Train Accuracy : ${eer}"104echo "Final Train Accuracy : ${eer}"
104echo "E2E Training Duration sec : $e2e_time"105echo "E2E Training Duration sec : $e2e_time"
105 106 
@@ -116,10 +117,9 @@ ActualFPS=${FPS}
116TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`117TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`
117 118 
118#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视119#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
119-awk -F "INFOEpoch:" '{print $2}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log >> /opt/npu/Vox_Data/test/output/$ASCEND_DEVICE_ID/train_loss_temp.txt120+cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | grep "INFOEpoch" | awk -F "INFOEpoch:" '{print $2}' | awk -F "loss =" '{print $2}' | awk -F "]" '{print $1}' | sed 's/\s*//g' > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt
120-awk '!/^$/' $ASCEND_DEVICE_ID/output/$ASCEND_DEVICE_ID/train_loss_temp.txt >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
121#最后一个迭代loss值,不需要修改121#最后一个迭代loss值,不需要修改
122-#ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`122+ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
123 123 
124#关键信息打印到${CaseName}.log中,不需要修改124#关键信息打印到${CaseName}.log中,不需要修改
125echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log125echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
@@ -12,7 +12,7 @@ export RANK_SIZE=8
12data_path=""12data_path=""
13 13 
14# 训练epoch14# 训练epoch
15-train_epochs=8015+train_epochs=20
16# 指定训练所使用的npu device卡id16# 指定训练所使用的npu device卡id
17device_id=0,1,2,3,4,5,6,717device_id=0,1,2,3,4,5,6,7
18# 加载数据进程数18# 加载数据进程数
@@ -80,7 +80,7 @@ source test/env_npu.sh
80rm -f nohup.out80rm -f nohup.out
81cd train/train-8P81cd train/train-8P
82 82 
83-nohup python3.7 -m torch.distributed.launch --nproc_per_node=8 train_RawNet2.py > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &83+nohup python3 -m torch.distributed.launch --nproc_per_node=8 train_RawNet2.py -epoch ${train_epochs} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
haiyan8
haiyan8haiyan82022年8月1日

是否python3.7更合适

likedislike
84 84 
85wait85wait
86 86 
@@ -93,14 +93,15 @@ e2e_time=$(( $end_time - $start_time ))
93#结果打印,不需要修改93#结果打印,不需要修改
94echo "------------------ Final result ------------------"94echo "------------------ Final result ------------------"
95#输出性能FPS,需要模型审视修改95#输出性能FPS,需要模型审视修改
96-FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'`96+FPS=`grep -a 'INFOFPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'|awk '{sum += $1} END {printf "%3.3f",sum/NR}'`
97#打印,不需要修改97#打印,不需要修改
98echo "Final Performance images/sec : $FPS"98echo "Final Performance images/sec : $FPS"
99 99 
100#输出训练精度,需要模型审视修改100#输出训练精度,需要模型审视修改
101-eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:" '{print $NF}'`101+eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:|/epoch" '{print $2}'|awk 'END{print}'`
102train_accuracy=${eer}102train_accuracy=${eer}
103#打印,不需要修改103#打印,不需要修改
104+train_accuracy=${eer}
104echo "Final Train Accuracy : ${eer}"105echo "Final Train Accuracy : ${eer}"
105echo "E2E Training Duration sec : $e2e_time"106echo "E2E Training Duration sec : $e2e_time"
106 107 
@@ -117,11 +118,9 @@ ActualFPS=${FPS}
117TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`118TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`
118 119 
119#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视120#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
120-awk -F "INFOEpoch:" '{print $2}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_temp.txt121+cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | grep "INFOEpoch" | awk -F "INFOEpoch:" '{print $2}' | awk -F "loss =" '{print $2}' | awk -F "]" '{print $1}' | sed 's/\s*//g' > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt
121-awk '!/^$/' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss_temp.txt >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
122- 
123#最后一个迭代loss值,不需要修改122#最后一个迭代loss值,不需要修改
124-#ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`123+ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
125 124 
126#关键信息打印到${CaseName}.log中,不需要修改125#关键信息打印到${CaseName}.log中,不需要修改
127echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log126echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
@@ -12,7 +12,8 @@ export RANK_SIZE=1
12data_path=""12data_path=""
13 13 
14# 训练epoch14# 训练epoch
15-train_epochs=8015+ 
16+train_epochs=1
16# 指定训练所使用的npu device卡id17# 指定训练所使用的npu device卡id
17device_id=118device_id=1
18# 加载数据进程数19# 加载数据进程数
@@ -80,7 +81,7 @@ source test/env_npu.sh
80rm -f nohup.out81rm -f nohup.out
81cd train/train-1P82cd train/train-1P
82 83 
haiyan8
haiyan8haiyan82022年8月1日

是否python3.7更合适

likedislike
83-nohup python3.7 train_RawNet2.py > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &84+nohup python3 train_RawNet2.py -epoch ${train_epochs} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
84 85 
85wait86wait
86 87 
@@ -93,13 +94,14 @@ e2e_time=$(( $end_time - $start_time ))
93#结果打印,不需要修改94#结果打印,不需要修改
94echo "------------------ Final result ------------------"95echo "------------------ Final result ------------------"
95#输出性能FPS,需要模型审视修改96#输出性能FPS,需要模型审视修改
96-FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'`97+FPS=`grep -a 'INFOFPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'|awk '{sum += $1} END {printf "%3.3f",sum/NR}'`
97#打印,不需要修改98#打印,不需要修改
98echo "Final Performance images/sec : $FPS"99echo "Final Performance images/sec : $FPS"
99 100 
100#输出训练精度,需要模型审视修改101#输出训练精度,需要模型审视修改
101-eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:" '{print $NF}'`102+eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:|/epoch" '{print $2}'|awk 'END{print}'`
102#打印,不需要修改103#打印,不需要修改
104+train_accuracy=${eer}
103echo "Final Train Accuracy : ${eer}"105echo "Final Train Accuracy : ${eer}"
104echo "E2E Training Duration sec : $e2e_time"106echo "E2E Training Duration sec : $e2e_time"
105 107 
@@ -107,7 +109,7 @@ echo "E2E Training Duration sec : $e2e_time"
107#训练用例信息,不需要修改109#训练用例信息,不需要修改
108BatchSize=${batch_size}110BatchSize=${batch_size}
109DeviceType=`uname -m`111DeviceType=`uname -m`
110-CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'112+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
111 113 
112##获取性能数据,不需要修改114##获取性能数据,不需要修改
113#吞吐量115#吞吐量
@@ -116,10 +118,9 @@ ActualFPS=${FPS}
116TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`118TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`
117 119 
118#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视120#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
119-awk -F "INFOEpoch:" '{print $2}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log >> /opt/npu/Vox_Data/test/output/$ASCEND_DEVICE_ID/train_loss_temp.txt121+cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | grep "INFOEpoch" | awk -F "INFOEpoch:" '{print $2}' | awk -F "loss =" '{print $2}' | awk -F "]" '{print $1}' | sed 's/\s*//g' > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt
120-awk '!/^$/' $ASCEND_DEVICE_ID/output/$ASCEND_DEVICE_ID/train_loss_temp.txt >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
121#最后一个迭代loss值,不需要修改122#最后一个迭代loss值,不需要修改
122-#ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`123+ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
123 124 
124#关键信息打印到${CaseName}.log中,不需要修改125#关键信息打印到${CaseName}.log中,不需要修改
125echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log126echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
@@ -12,7 +12,7 @@ export RANK_SIZE=8
12data_path=""12data_path=""
13 13 
14# 训练epoch14# 训练epoch
15-train_epochs=8015+train_epochs=1
16# 指定训练所使用的npu device卡id16# 指定训练所使用的npu device卡id
17device_id=0,1,2,3,4,5,6,717device_id=0,1,2,3,4,5,6,7
18# 加载数据进程数18# 加载数据进程数
@@ -80,7 +80,7 @@ source test/env_npu.sh
80rm -f nohup.out80rm -f nohup.out
81cd train/train-8P81cd train/train-8P
82 82 
83-nohup python3.7 train_RawNet2.py ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &83+nohup python3 -m torch.distributed.launch --nproc_per_node=8 train_RawNet2.py -epoch ${train_epochs} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
84 84 
85wait85wait
86 86 
@@ -92,13 +92,14 @@ e2e_time=$(( $end_time - $start_time ))
92#结果打印,不需要修改92#结果打印,不需要修改
93echo "------------------ Final result ------------------"93echo "------------------ Final result ------------------"
94#输出性能FPS,需要模型审视修改94#输出性能FPS,需要模型审视修改
95-FPS=`grep -a 'FPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'`95+FPS=`grep -a 'INFOFPS' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F 'INFOFPS:|/epoch' '{print $2}'|awk '{sum += $1} END {printf "%3.3f",sum/NR}'`
96#打印,不需要修改96#打印,不需要修改
97echo "Final Performance images/sec : $FPS"97echo "Final Performance images/sec : $FPS"
98 98 
99#输出训练精度,需要模型审视修改99#输出训练精度,需要模型审视修改
100-eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:" '{print $NF}'`100+eer=`grep -a 'eer' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|awk -F "eer:|/epoch" '{print $2}'|awk 'END{print}'`
101#打印,不需要修改101#打印,不需要修改
102+train_accuracy=${eer}
102echo "Final Train Accuracy : ${eer}"103echo "Final Train Accuracy : ${eer}"
103echo "E2E Training Duration sec : $e2e_time"104echo "E2E Training Duration sec : $e2e_time"
104 105 
@@ -106,7 +107,7 @@ echo "E2E Training Duration sec : $e2e_time"
106#训练用例信息,不需要修改107#训练用例信息,不需要修改
107BatchSize=${batch_size}108BatchSize=${batch_size}
108DeviceType=`uname -m`109DeviceType=`uname -m`
109-CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'110+CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'perf'
110 111 
111##获取性能数据,不需要修改112##获取性能数据,不需要修改
112#吞吐量113#吞吐量
@@ -115,10 +116,9 @@ ActualFPS=${FPS}
115TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`116TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`
116 117 
117#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视118#从train_$ASCEND_DEVICE_ID.log提取Loss到train_${CaseName}_loss.txt中,需要根据模型审视
118-awk -F "INFOEpoch:" '{print $2}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log >> /opt/npu/Vox_Data/test/output/$ASCEND_DEVICE_ID/train_loss_temp.txt119+cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log | grep "INFOEpoch" | awk -F "INFOEpoch:" '{print $2}' | awk -F "loss =" '{print $2}' | awk -F "]" '{print $1}' | sed 's/\s*//g' > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${CaseName}_loss.txt
119-awk '!/^$/' $ASCEND_DEVICE_ID/output/$ASCEND_DEVICE_ID/train_loss_temp.txt >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
120#最后一个迭代loss值,不需要修改120#最后一个迭代loss值,不需要修改
121-#ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`121+ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
122 122 
123#关键信息打印到${CaseName}.log中,不需要修改123#关键信息打印到${CaseName}.log中,不需要修改
124echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log124echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
@@ -54,7 +54,7 @@ def get_args():
54 #hyper-params54 #hyper-params
55 parser.add_argument('-frame', type = int, default = 135395880960) # the number of frames of all the .wav file55 parser.add_argument('-frame', type = int, default = 135395880960) # the number of frames of all the .wav file
56 parser.add_argument('-bs', type = int, default = 128)56 parser.add_argument('-bs', type = int, default = 128)
57- parser.add_argument('-lr', type = float, default = 0.001)57+ parser.add_argument('-lr', type = float, default = 0.0015)
58 parser.add_argument('-nb_samp', type = int, default = 59049)58 parser.add_argument('-nb_samp', type = int, default = 59049)
59 parser.add_argument('-window_size', type = int, default = 11810)59 parser.add_argument('-window_size', type = int, default = 11810)
60 60
@@ -28,6 +28,8 @@ import json
28import numpy as np28import numpy as np
29 29 
30import torch30import torch
31+if torch.__version__ >="1.8":
32+ import torch_npu
31import torch.nn as nn33import torch.nn as nn
32import torch.distributed as dist34import torch.distributed as dist
33from torch.nn.parallel import DistributedDataParallel as DDP35from torch.nn.parallel import DistributedDataParallel as DDP
@@ -121,6 +121,9 @@ def train_model(model, db_gen, optimizer, epoch, args, device, lr_scheduler, cri
121 121
122 122 
123def time_augmented_evaluate_model(mode, model, db_gen, l_utt, save_dir, epoch, l_trial, args, device):123def time_augmented_evaluate_model(mode, model, db_gen, l_utt, save_dir, epoch, l_trial, args, device):
124+ with open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), mode = 'w') as ff:
125+ logger = get_logger(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch))
126+
124 f_log = open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), 'a', buffering = 1)127 f_log = open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), 'a', buffering = 1)
125 args = get_args()128 args = get_args()
126 if mode not in ['val','eval']: raise ValueError('mode should be either "val" or "eval"')129 if mode not in ['val','eval']: raise ValueError('mode should be either "val" or "eval"')
@@ -54,7 +54,7 @@ def get_args():
54 #hyper-params54 #hyper-params
55 parser.add_argument('-frame', type = int, default = 135395880960) # the number of frames of all the .wav file55 parser.add_argument('-frame', type = int, default = 135395880960) # the number of frames of all the .wav file
56 parser.add_argument('-bs', type = int, default = 1024)56 parser.add_argument('-bs', type = int, default = 1024)
57- parser.add_argument('-lr', type = float, default = 0.001)57+ parser.add_argument('-lr', type = float, default = 0.0015)
58 parser.add_argument('-nb_samp', type = int, default = 59049)58 parser.add_argument('-nb_samp', type = int, default = 59049)
59 parser.add_argument('-window_size', type = int, default = 11810)59 parser.add_argument('-window_size', type = int, default = 11810)
60 60
@@ -28,6 +28,8 @@ import json
28import numpy as np28import numpy as np
29 29 
30import torch30import torch
31+if torch.__version__ >="1.8":
32+ import torch_npu
31import torch.nn as nn33import torch.nn as nn
32import torch.distributed as dist34import torch.distributed as dist
33from torch.nn.parallel import DistributedDataParallel as DDP35from torch.nn.parallel import DistributedDataParallel as DDP
@@ -106,6 +106,9 @@ def train_model(model, db_gen, optimizer, epoch, args, device, lr_scheduler, cri
106 106
107 107 
108def time_augmented_evaluate_model(mode, model, db_gen, l_utt, save_dir, epoch, l_trial, args, device):108def time_augmented_evaluate_model(mode, model, db_gen, l_utt, save_dir, epoch, l_trial, args, device):
109+ with open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), mode = 'w') as ff:
110+ logger = get_logger(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch))
111+
109 f_log = open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), 'a', buffering = 1)112 f_log = open(args.save_dir + args.name + '/' + args.save_log + 'TA_{}.log'.format(epoch), 'a', buffering = 1)
110 args = get_args()113 args = get_args()
111 if mode not in ['val','eval']: raise ValueError('mode should be either "val" or "eval"')114 if mode not in ['val','eval']: raise ValueError('mode should be either "val" or "eval"')