Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
8dc0b2b0
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看板
提交
8dc0b2b0
编写于
8月 23, 2017
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make setup.py to support parallel processing.
上级
2584abd5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
70 addition
and
9 deletion
+70
-9
deploy/README.md
deploy/README.md
+1
-1
deploy/scorer.cpp
deploy/scorer.cpp
+5
-2
deploy/setup.py
deploy/setup.py
+64
-6
未找到文件。
deploy/README.md
浏览文件 @
8dc0b2b0
...
@@ -25,7 +25,7 @@ git clone https://github.com/progschj/ThreadPool.git
...
@@ -25,7 +25,7 @@ git clone https://github.com/progschj/ThreadPool.git
Then run the setup
Then run the setup
```
shell
```
shell
python setup.py
install
python setup.py
install
--num_processes
4
cd
..
cd
..
```
```
...
...
deploy/scorer.cpp
浏览文件 @
8dc0b2b0
#include <iostream>
#include <iostream>
#include <unistd.h>
#include <unistd.h>
#include "lm/config.hh"
#include "lm/state.hh"
#include "lm/model.hh"
#include "scorer.h"
#include "scorer.h"
#include "decoder_utils.h"
#include "decoder_utils.h"
...
@@ -24,7 +27,7 @@ void Scorer::load_LM(const char* filename) {
...
@@ -24,7 +27,7 @@ void Scorer::load_LM(const char* filename) {
exit
(
1
);
exit
(
1
);
}
}
RetriveStrEnumerateVocab
enumerate
;
RetriveStrEnumerateVocab
enumerate
;
Config
config
;
lm
::
ngram
::
Config
config
;
config
.
enumerate_vocab
=
&
enumerate
;
config
.
enumerate_vocab
=
&
enumerate
;
_language_model
=
lm
::
ngram
::
LoadVirtual
(
filename
,
config
);
_language_model
=
lm
::
ngram
::
LoadVirtual
(
filename
,
config
);
_max_order
=
static_cast
<
lm
::
base
::
Model
*>
(
_language_model
)
->
Order
();
_max_order
=
static_cast
<
lm
::
base
::
Model
*>
(
_language_model
)
->
Order
();
...
@@ -43,7 +46,7 @@ void Scorer::load_LM(const char* filename) {
...
@@ -43,7 +46,7 @@ void Scorer::load_LM(const char* filename) {
double
Scorer
::
get_log_cond_prob
(
const
std
::
vector
<
std
::
string
>&
words
)
{
double
Scorer
::
get_log_cond_prob
(
const
std
::
vector
<
std
::
string
>&
words
)
{
lm
::
base
::
Model
*
model
=
static_cast
<
lm
::
base
::
Model
*>
(
_language_model
);
lm
::
base
::
Model
*
model
=
static_cast
<
lm
::
base
::
Model
*>
(
_language_model
);
double
cond_prob
;
double
cond_prob
;
State
state
,
tmp_state
,
out_state
;
lm
::
ngram
::
State
state
,
tmp_state
,
out_state
;
// avoid to inserting <s> in begin
// avoid to inserting <s> in begin
model
->
NullContextWrite
(
&
state
);
model
->
NullContextWrite
(
&
state
);
for
(
size_t
i
=
0
;
i
<
words
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
words
.
size
();
++
i
)
{
...
...
deploy/setup.py
浏览文件 @
8dc0b2b0
from
setuptools
import
setup
,
Extension
"""Script to build and install decoder package."""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
from
setuptools
import
setup
,
Extension
,
distutils
import
glob
import
glob
import
platform
import
platform
import
os
import
os
,
sys
import
multiprocessing.pool
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
parser
.
add_argument
(
"--num_processes"
,
default
=
1
,
type
=
int
,
help
=
"Number of cpu processes to build package. (default: %(default)d)"
)
args
=
parser
.
parse_known_args
()
# reconstruct sys.argv to pass to setup below
sys
.
argv
=
[
sys
.
argv
[
0
]]
+
args
[
1
]
# monkey-patch for parallel compilation
# See: https://stackoverflow.com/a/13176803
def
parallelCCompile
(
self
,
sources
,
output_dir
=
None
,
macros
=
None
,
include_dirs
=
None
,
debug
=
0
,
extra_preargs
=
None
,
extra_postargs
=
None
,
depends
=
None
):
# those lines are copied from distutils.ccompiler.CCompiler directly
macros
,
objects
,
extra_postargs
,
pp_opts
,
build
=
self
.
_setup_compile
(
output_dir
,
macros
,
include_dirs
,
sources
,
depends
,
extra_postargs
)
cc_args
=
self
.
_get_cc_args
(
pp_opts
,
debug
,
extra_preargs
)
# parallel code
def
_single_compile
(
obj
):
try
:
src
,
ext
=
build
[
obj
]
except
KeyError
:
return
self
.
_compile
(
obj
,
src
,
ext
,
cc_args
,
extra_postargs
,
pp_opts
)
# convert to list, imap is evaluated on-demand
thread_pool
=
multiprocessing
.
pool
.
ThreadPool
(
args
[
0
].
num_processes
)
list
(
thread_pool
.
imap
(
_single_compile
,
objects
))
return
objects
def
compile_test
(
header
,
library
):
def
compile_test
(
header
,
library
):
dummy_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"dummy"
)
dummy_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"dummy"
)
command
=
"bash -c
\"
g++ -include "
+
header
+
" -l"
+
library
+
" -x c++ - <<<'int main() {}' -o "
+
dummy_path
+
" >/dev/null 2>/dev/null && rm "
+
dummy_path
+
" 2>/dev/null
\"
"
command
=
"bash -c
\"
g++ -include "
+
header
\
+
" -l"
+
library
+
" -x c++ - <<<'int main() {}' -o "
\
+
dummy_path
+
" >/dev/null 2>/dev/null && rm "
\
+
dummy_path
+
" 2>/dev/null
\"
"
return
os
.
system
(
command
)
==
0
return
os
.
system
(
command
)
==
0
FILES
=
glob
.
glob
(
'kenlm/util/*.cc'
)
+
glob
.
glob
(
'kenlm/lm/*.cc'
)
+
glob
.
glob
(
# hack compile to support parallel compiling
'kenlm/util/double-conversion/*.cc'
)
distutils
.
ccompiler
.
CCompiler
.
compile
=
parallelCCompile
FILES
=
glob
.
glob
(
'kenlm/util/*.cc'
)
\
+
glob
.
glob
(
'kenlm/lm/*.cc'
)
\
+
glob
.
glob
(
'kenlm/util/double-conversion/*.cc'
)
FILES
+=
glob
.
glob
(
'openfst-1.6.3/src/lib/*.cc'
)
FILES
=
[
FILES
=
[
fn
for
fn
in
FILES
if
not
(
fn
.
endswith
(
'main.cc'
)
or
fn
.
endswith
(
'test.cc'
))
fn
for
fn
in
FILES
if
not
(
fn
.
endswith
(
'main.cc'
)
or
fn
.
endswith
(
'test.cc'
))
]
]
...
@@ -40,7 +98,7 @@ decoders_module = [
...
@@ -40,7 +98,7 @@ decoders_module = [
Extension
(
Extension
(
name
=
'_swig_decoders'
,
name
=
'_swig_decoders'
,
sources
=
FILES
+
glob
.
glob
(
'*.cxx'
)
+
glob
.
glob
(
'*.cpp'
),
sources
=
FILES
+
glob
.
glob
(
'*.cxx'
)
+
glob
.
glob
(
'*.cpp'
),
language
=
'
C
++'
,
language
=
'
c
++'
,
include_dirs
=
[
'.'
,
'kenlm'
,
'openfst-1.6.3/src/include'
,
'ThreadPool'
],
include_dirs
=
[
'.'
,
'kenlm'
,
'openfst-1.6.3/src/include'
,
'ThreadPool'
],
libraries
=
LIBS
,
libraries
=
LIBS
,
extra_compile_args
=
ARGS
)
extra_compile_args
=
ARGS
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录