Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
156ccb94
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 2 年 前同步成功
通知
210
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
156ccb94
编写于
4月 16, 2021
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix board logger
上级
fa6e3334
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
222 addition
and
46 deletion
+222
-46
.notebook/python_test.ipynb
.notebook/python_test.ipynb
+121
-39
deepspeech/exps/u2/model.py
deepspeech/exps/u2/model.py
+5
-7
utils/avg_model.py
utils/avg_model.py
+96
-0
未找到文件。
.notebook/python_test.ipynb
浏览文件 @
156ccb94
...
@@ -637,7 +637,7 @@
...
@@ -637,7 +637,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 59,
"execution_count": 59,
"id": "
norwegian-cleveland
",
"id": "
engaged-offense
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -660,7 +660,7 @@
...
@@ -660,7 +660,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 35,
"execution_count": 35,
"id": "
endless-kidne
y",
"id": "
level-fair
y",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -705,7 +705,7 @@
...
@@ -705,7 +705,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 3,
"execution_count": 3,
"id": "
later-louisiana
",
"id": "
beautiful-geometry
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -728,7 +728,7 @@
...
@@ -728,7 +728,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 4,
"execution_count": 4,
"id": "
funded-nudist
",
"id": "
african-trustee
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -748,7 +748,7 @@
...
@@ -748,7 +748,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 5,
"execution_count": 5,
"id": "
contrary-affiliation
",
"id": "
ready-wages
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -758,7 +758,7 @@
...
@@ -758,7 +758,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 6,
"execution_count": 6,
"id": "
friendly-interpretation
",
"id": "
distinguished-printer
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -776,7 +776,7 @@
...
@@ -776,7 +776,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 7,
"execution_count": 7,
"id": "
bottom-wilderness
",
"id": "
precious-limit
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -809,7 +809,7 @@
...
@@ -809,7 +809,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 17,
"execution_count": 17,
"id": "
acquired-jacksonvill
e",
"id": "
chemical-convenienc
e",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -839,7 +839,7 @@
...
@@ -839,7 +839,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 18,
"execution_count": 18,
"id": "
entertaining-capture
",
"id": "
round-remark
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -871,7 +871,7 @@
...
@@ -871,7 +871,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 19,
"execution_count": 19,
"id": "
amber-grade
",
"id": "
smaller-shower
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -903,7 +903,7 @@
...
@@ -903,7 +903,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 31,
"execution_count": 31,
"id": "
hidden-playba
ck",
"id": "
integrated-blo
ck",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -935,7 +935,7 @@
...
@@ -935,7 +935,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 32,
"execution_count": 32,
"id": "
twelve-university
",
"id": "
favorite-failure
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -966,7 +966,7 @@
...
@@ -966,7 +966,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 20,
"execution_count": 20,
"id": "
minor-endorseme
nt",
"id": "
boolean-sai
nt",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -977,7 +977,7 @@
...
@@ -977,7 +977,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 46,
"execution_count": 46,
"id": "
upper-majority
",
"id": "
senior-hospital
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -997,7 +997,7 @@
...
@@ -997,7 +997,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 30,
"execution_count": 30,
"id": "
supreme-coverage
",
"id": "
consolidated-incident
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1007,7 +1007,7 @@
...
@@ -1007,7 +1007,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 31,
"execution_count": 31,
"id": "
tough-domain
",
"id": "
pursuant-paragraph
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1017,7 +1017,7 @@
...
@@ -1017,7 +1017,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 47,
"execution_count": 47,
"id": "
indian-empire
",
"id": "
mexican-apollo
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1038,7 +1038,7 @@
...
@@ -1038,7 +1038,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1,
"execution_count": 1,
"id": "
horizontal-paragraph
",
"id": "
encouraging-integration
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1049,7 +1049,7 @@
...
@@ -1049,7 +1049,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 56,
"execution_count": 56,
"id": "
homeless-zoning
",
"id": "
trying-auckland
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1059,7 +1059,7 @@
...
@@ -1059,7 +1059,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 58,
"execution_count": 58,
"id": "
floating-atmosphere
",
"id": "
national-edward
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1069,7 +1069,7 @@
...
@@ -1069,7 +1069,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 60,
"execution_count": 60,
"id": "
stupid-reducing
",
"id": "
aerial-campaign
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1079,7 +1079,7 @@
...
@@ -1079,7 +1079,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 66,
"execution_count": 66,
"id": "
practical-airlin
e",
"id": "
instant-violenc
e",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1089,7 +1089,7 @@
...
@@ -1089,7 +1089,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 95,
"execution_count": 95,
"id": "
apart-comfort
",
"id": "
medical-globe
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1110,7 +1110,7 @@
...
@@ -1110,7 +1110,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 81,
"execution_count": 81,
"id": "
underlying-brand
",
"id": "
three-contrast
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1131,7 +1131,7 @@
...
@@ -1131,7 +1131,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 11,
"execution_count": 11,
"id": "
german-thing
s",
"id": "
cross-atla
s",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1161,7 +1161,7 @@
...
@@ -1161,7 +1161,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 12,
"execution_count": 12,
"id": "
third-regression
",
"id": "
empirical-defense
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1172,7 +1172,7 @@
...
@@ -1172,7 +1172,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 14,
"execution_count": 14,
"id": "
thick-korea
",
"id": "
rocky-listening
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1201,7 +1201,7 @@
...
@@ -1201,7 +1201,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 13,
"execution_count": 13,
"id": "
institutional-hands
",
"id": "
surrounded-absolute
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1230,7 +1230,7 @@
...
@@ -1230,7 +1230,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 15,
"execution_count": 15,
"id": "
brave-native
",
"id": "
differential-surgery
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1260,7 +1260,7 @@
...
@@ -1260,7 +1260,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 29,
"execution_count": 29,
"id": "
turkish-ticket
",
"id": "
durable-powell
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1290,7 +1290,7 @@
...
@@ -1290,7 +1290,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 30,
"execution_count": 30,
"id": "
executed-excerpt
",
"id": "
young-continuity
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1308,7 +1308,7 @@
...
@@ -1308,7 +1308,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 22,
"execution_count": 22,
"id": "
continental-boring
",
"id": "
geological-sarah
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1343,7 +1343,7 @@
...
@@ -1343,7 +1343,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 23,
"execution_count": 23,
"id": "
linear-assembly
",
"id": "
possible-angle
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1376,7 +1376,7 @@
...
@@ -1376,7 +1376,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 33,
"execution_count": 33,
"id": "
applied-louis
",
"id": "
novel-sucking
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1386,7 +1386,7 @@
...
@@ -1386,7 +1386,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 34,
"execution_count": 34,
"id": "
historic-struggle
",
"id": "
fixed-wallet
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1428,7 +1428,7 @@
...
@@ -1428,7 +1428,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 35,
"execution_count": 35,
"id": "
monthly-roads
",
"id": "
north-seattle
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
...
@@ -1438,7 +1438,7 @@
...
@@ -1438,7 +1438,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 38,
"execution_count": 38,
"id": "
boxed-peoples
",
"id": "
above-western
",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
...
@@ -1471,17 +1471,99 @@
...
@@ -1471,17 +1471,99 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 41,
"execution_count": 41,
"id": "
fresh-tender
",
"id": "
choice-diabetes
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"!ls"
"!ls"
]
]
},
},
{
"cell_type": "code",
"execution_count": 3,
"id": "white-vessel",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(2, 2)\n",
"[ 1 20]\n"
]
}
],
"source": [
"import numpy as np\n",
"l = [(1, 20), (2, 30)]\n",
"scores = np.array(l)\n",
"print(scores.shape)\n",
"print(scores[0])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "treated-freedom",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0 1]\n"
]
}
],
"source": [
"sort_idx = np.argsort(scores[:, -1])\n",
"print(sort_idx)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "convinced-safety",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1 20]\n",
" [ 2 30]]\n"
]
}
],
"source": [
"sorted_val_scores = scores[sort_idx][::1]\n",
"print(sorted_val_scores)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "blond-bunny",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1 20]\n",
" [ 2 30]]\n"
]
}
],
"source": [
"sorted_val_scores = scores[sort_idx]\n",
"print(sorted_val_scores)"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"id": "
religious-peripheral
",
"id": "
utility-monroe
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
"source": []
deepspeech/exps/u2/model.py
浏览文件 @
156ccb94
...
@@ -89,9 +89,8 @@ class U2Trainer(Trainer):
...
@@ -89,9 +89,8 @@ class U2Trainer(Trainer):
if
(
batch_index
+
1
)
%
train_conf
.
accum_grad
==
0
:
if
(
batch_index
+
1
)
%
train_conf
.
accum_grad
==
0
:
if
dist
.
get_rank
()
==
0
and
self
.
visualizer
:
if
dist
.
get_rank
()
==
0
and
self
.
visualizer
:
for
k
,
v
in
losses_np
.
items
():
losses_np
.
update
({
"lr"
:
self
.
lr_scheduler
()})
self
.
visualizer
.
add_scalar
(
"train/{}"
.
format
(
k
),
v
,
self
.
visualizer
.
add_scalars
(
"step"
,
losses_np
,
self
.
iteration
)
self
.
iteration
)
self
.
optimizer
.
step
()
self
.
optimizer
.
step
()
self
.
optimizer
.
clear_grad
()
self
.
optimizer
.
clear_grad
()
self
.
lr_scheduler
.
step
()
self
.
lr_scheduler
.
step
()
...
@@ -144,7 +143,7 @@ class U2Trainer(Trainer):
...
@@ -144,7 +143,7 @@ class U2Trainer(Trainer):
raise
e
raise
e
valid_losses
=
self
.
valid
()
valid_losses
=
self
.
valid
()
self
.
save
(
infos
=
valid_losses
)
self
.
save
(
tag
=
self
.
epoch
,
infos
=
valid_losses
)
self
.
new_epoch
()
self
.
new_epoch
()
@
mp_tools
.
rank_zero_only
@
mp_tools
.
rank_zero_only
...
@@ -172,9 +171,8 @@ class U2Trainer(Trainer):
...
@@ -172,9 +171,8 @@ class U2Trainer(Trainer):
logger
.
info
(
msg
)
logger
.
info
(
msg
)
if
self
.
visualizer
:
if
self
.
visualizer
:
for
k
,
v
in
valid_losses
.
items
():
valid_losses
.
update
({
"lr"
:
self
.
lr_scheduler
()})
self
.
visualizer
.
add_scalar
(
"valid/{}"
.
format
(
k
),
v
,
self
.
visualizer
.
add_scalars
(
'epoch'
,
valid_losses
,
self
.
epoch
)
self
.
iteration
)
return
valid_losses
return
valid_losses
def
setup_dataloader
(
self
):
def
setup_dataloader
(
self
):
...
...
utils/avg_model.py
0 → 100644
浏览文件 @
156ccb94
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# 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.
import
argparse
import
glob
import
json
import
os
import
numpy
as
np
import
paddle
def
main
(
args
):
checkpoints
=
[]
val_scores
=
[]
if
args
.
val_best
:
jsons
=
glob
.
glob
(
f
'
{
args
.
ckpt_dir
}
/[!train]*.json'
)
for
y
in
jsons
:
dic_json
=
json
.
load
(
y
)
loss
=
dic_json
[
'valid_loss'
]
epoch
=
dic_json
[
'epoch'
]
if
epoch
>=
args
.
min_epoch
and
epoch
<=
args
.
max_epoch
:
val_scores
.
append
((
epoch
,
loss
))
val_scores
=
np
.
array
(
val_scores
)
sort_idx
=
np
.
argsort
(
val_scores
[:,
1
])
sorted_val_scores
=
val_scores
[
sort_idx
]
path_list
=
[
args
.
ckpt_dir
+
'/{}.pdparams'
.
format
(
int
(
epoch
))
for
epoch
in
sorted_val_scores
[:
args
.
num
,
0
]
]
print
(
"best val scores = "
+
str
(
sorted_val_scores
[:
args
.
num
,
1
]))
print
(
"selected epochs = "
+
str
(
sorted_val_scores
[:
args
.
num
,
0
].
astype
(
np
.
int64
)))
else
:
path_list
=
glob
.
glob
(
f
'
{
args
.
ckpt_dir
}
/[!avg][!final]*.pdparams'
)
path_list
=
sorted
(
path_list
,
key
=
os
.
path
.
getmtime
)
path_list
=
path_list
[
-
args
.
num
:]
print
(
path_list
)
avg
=
None
num
=
args
.
num
assert
num
==
len
(
path_list
)
for
path
in
path_list
:
print
(
f
'Processing
{
path
}
'
)
states
=
paddle
.
load
(
path
)
if
avg
is
None
:
avg
=
states
else
:
for
k
in
avg
.
keys
():
avg
[
k
]
+=
states
[
k
]
# average
for
k
in
avg
.
keys
():
if
avg
[
k
]
is
not
None
:
avg
[
k
]
=
paddle
.
divide
(
avg
[
k
],
num
)
paddle
.
save
(
avg
,
args
.
dst_model
)
print
(
f
'Saving to
{
args
.
dst_model
}
'
)
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
(
description
=
'average model'
)
parser
.
add_argument
(
'--dst_model'
,
required
=
True
,
help
=
'averaged model'
)
parser
.
add_argument
(
'--ckpt_dir'
,
required
=
True
,
help
=
'ckpt model dir for average'
)
parser
.
add_argument
(
'--val_best'
,
action
=
"store_true"
,
help
=
'averaged model'
)
parser
.
add_argument
(
'--num'
,
default
=
5
,
type
=
int
,
help
=
'nums for averaged model'
)
parser
.
add_argument
(
'--min_epoch'
,
default
=
0
,
type
=
int
,
help
=
'min epoch used for averaging model'
)
parser
.
add_argument
(
'--max_epoch'
,
default
=
65536
,
# Big enough
type
=
int
,
help
=
'max epoch used for averaging model'
)
args
=
parser
.
parse_args
()
print
(
args
)
main
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录