Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
b621b5b9
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看板
提交
b621b5b9
编写于
10月 09, 2022
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add math and macros
上级
532b6204
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
131 addition
and
4 deletion
+131
-4
speechx/cmake/paddleinference.cmake
speechx/cmake/paddleinference.cmake
+5
-2
speechx/speechx/base/common.h
speechx/speechx/base/common.h
+3
-0
speechx/speechx/base/macros.h
speechx/speechx/base/macros.h
+8
-1
speechx/speechx/decoder/CMakeLists.txt
speechx/speechx/decoder/CMakeLists.txt
+1
-0
speechx/speechx/decoder/param.h
speechx/speechx/decoder/param.h
+4
-1
speechx/speechx/utils/math.cc
speechx/speechx/utils/math.cc
+82
-0
speechx/speechx/utils/math.h
speechx/speechx/utils/math.h
+28
-0
未找到文件。
speechx/cmake/paddleinference.cmake
浏览文件 @
b621b5b9
...
...
@@ -22,6 +22,7 @@ link_directories("${PADDLE_LIB_THIRD_PARTY_PATH}xxhash/lib")
link_directories
(
"
${
PADDLE_LIB_THIRD_PARTY_PATH
}
cryptopp/lib"
)
link_directories
(
"
${
PADDLE_LIB
}
/paddle/lib"
)
link_directories
(
"
${
PADDLE_LIB_THIRD_PARTY_PATH
}
mklml/lib"
)
link_directories
(
"
${
PADDLE_LIB_THIRD_PARTY_PATH
}
mkldnn/lib"
)
##paddle with mkl
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-fopenmp"
)
...
...
@@ -29,14 +30,16 @@ set(MATH_LIB_PATH "${PADDLE_LIB_THIRD_PARTY_PATH}mklml")
include_directories
(
"
${
MATH_LIB_PATH
}
/include"
)
set
(
MATH_LIB
${
MATH_LIB_PATH
}
/lib/libmklml_intel
${
CMAKE_SHARED_LIBRARY_SUFFIX
}
${
MATH_LIB_PATH
}
/lib/libiomp5
${
CMAKE_SHARED_LIBRARY_SUFFIX
}
)
set
(
MKLDNN_PATH
"
${
PADDLE_LIB_THIRD_PARTY_PATH
}
mkldnn"
)
include_directories
(
"
${
MKLDNN_PATH
}
/include"
)
set
(
MKLDNN_LIB
${
MKLDNN_PATH
}
/lib/libmkldnn.so.0
)
set
(
EXTERNAL_LIB
"-lrt -ldl -lpthread"
)
# global vars
set
(
DEPS
${
PADDLE_LIB
}
/paddle/lib/libpaddle_inference
${
CMAKE_SHARED_LIBRARY_SUFFIX
}
CACHE
FORCE
"DEPS
"
)
set
(
DEPS
${
PADDLE_LIB
}
/paddle/lib/libpaddle_inference
${
CMAKE_SHARED_LIBRARY_SUFFIX
}
CACHE
INTERNAL
"deps
"
)
set
(
DEPS
${
DEPS
}
${
MATH_LIB
}
${
MKLDNN_LIB
}
glog gflags protobuf xxhash cryptopp
${
EXTERNAL_LIB
}
CACHE FORCE
"DEPS"
)
${
EXTERNAL_LIB
}
CACHE INTERNAL
"deps"
)
message
(
STATUS
"Deps libraries:
${
DEPS
}
"
)
speechx/speechx/base/common.h
浏览文件 @
b621b5b9
...
...
@@ -38,3 +38,6 @@
#include "base/flags.h"
#include "base/log.h"
#include "base/macros.h"
#include "utils/file_utils.h"
#include "utils/math.h"
\ No newline at end of file
speechx/speechx/base/macros.h
浏览文件 @
b621b5b9
...
...
@@ -14,6 +14,9 @@
#pragma once
#include <limits>
#include <string>
namespace
ppspeech
{
#ifndef DISALLOW_COPY_AND_ASSIGN
...
...
@@ -22,4 +25,8 @@ namespace ppspeech {
void operator=(const TypeName&) = delete
#endif
}
// namespace pp_speech
\ No newline at end of file
constexpr
float
kFloatMax
=
std
::
numeric_limits
<
float
>::
max
();
const
std
::
string
kSpaceSymbol
=
"
\xe2\x96\x81
"
;
}
// namespace ppspeech
speechx/speechx/decoder/CMakeLists.txt
浏览文件 @
b621b5b9
...
...
@@ -18,6 +18,7 @@ set(BINS
tlg_decoder_main
)
message
(
STATUS
"xxxxxxxxxx: "
${
DEPS
}
)
foreach
(
bin_name IN LISTS BINS
)
add_executable
(
${
bin_name
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
bin_name
}
.cc
)
target_include_directories
(
${
bin_name
}
PRIVATE
${
SPEECHX_ROOT
}
${
SPEECHX_ROOT
}
/kaldi
)
...
...
speechx/speechx/decoder/param.h
浏览文件 @
b621b5b9
...
...
@@ -56,7 +56,9 @@ DEFINE_int32(max_active, 7500, "max active");
DEFINE_double
(
beam
,
15.0
,
"decoder beam"
);
DEFINE_double
(
lattice_beam
,
7.5
,
"decoder beam"
);
namespace
ppspeech
{
// todo refactor later
FeaturePipelineOptions
InitFeaturePipelineOptions
()
{
FeaturePipelineOptions
opts
;
...
...
@@ -115,4 +117,5 @@ RecognizerResource InitRecognizerResoure() {
resource
.
tlg_opts
=
InitDecoderOptions
();
return
resource
;
}
}
}
// namespace ppspeech
speechx/speechx/utils/math.cc
0 → 100644
浏览文件 @
b621b5b9
// Copyright (c) 2022 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.
#include "utils/math.h"
#include "base/common.h"
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
namespace
ppspeech
{
// Sum in log scale
float
LogSumExp
(
float
x
,
float
y
)
{
if
(
x
<=
-
kFloatMax
)
return
y
;
if
(
y
<=
-
kFloatMax
)
return
x
;
float
max
=
std
::
max
(
x
,
y
);
return
max
+
std
::
log
(
std
::
exp
(
x
-
max
)
+
std
::
exp
(
y
-
max
));
}
// greater compare for smallest priority_queue
template
<
typename
T
>
struct
ValGreaterComp
{
bool
operator
()(
const
std
::
pair
<
T
,
int32_t
>&
lhs
,
const
std
::
pair
<
T
,
int32_
>&
rhs
)
const
{
return
lhs
.
first
>
rhs
.
first
||
(
lhs
.
first
==
rhs
.
first
&&
lhs
.
second
<
rhs
.
second
);
}
}
template
<
typename
T
>
void
TopK
(
const
std
::
vector
<
T
>&
data
,
int32_t
k
,
std
::
vector
<
T
>*
values
,
std
::
vector
<
int
>*
indices
)
{
int
n
=
data
.
size
();
int
min_k_n
=
std
::
min
(
k
,
n
);
// smallest heap, (val, idx)
std
::
vector
<
std
::
pair
<
T
,
int32_t
>>
smallest_heap
;
for
(
int
i
=
0
;
i
<
min_k_n
;
i
++
){
smallest_heap
.
emplace_back
(
data
[
i
],
i
);
}
// smallest priority_queue
std
::
priority_queue
<
std
::
pair
<
T
,
int32_t
>
,
std
::
vector
<
std
::
pair
<
T
,
int32_t
>>
,
ValGreaterComp
<
T
>>
pq
(
ValGreaterComp
<
T
>
(),
std
::
move
(
smallest_heap
));
// top k
for
(
int
i
=
k
;
i
<
n
;
i
++
){
if
(
pq
.
top
().
first
<
data
[
i
]){
pq
.
pop
();
pq
.
emplace_back
(
data
[
i
],
i
);
}
}
values
->
resize
(
min_k_n
);
indices
->
resize
(
min_k_n
);
// from largest to samllest
int
cur
=
values
->
size
()
-
1
;
while
(
!
pq
.
empty
()){
const
auto
&
item
=
pq
.
top
();
pq
.
pop
();
(
*
values
)[
cur
]
=
item
.
first
;
(
*
indices
)[
cur
]
=
item
.
second
;
cur
--
;
}
}
}
// namespace ppspeech
\ No newline at end of file
speechx/speechx/utils/math.h
0 → 100644
浏览文件 @
b621b5b9
// Copyright (c) 2022 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.
#pragma once
#include <vector>
#include <cstdint>
namespace
ppspeech
{
// Sum in log scale
float
LogSumExp
(
float
x
,
float
y
);
template
<
typename
T
>
void
TopK
(
const
std
::
vector
<
T
>&
data
,
int32_t
k
,
std
::
vector
<
T
>*
values
,
std
::
vector
<
int
>*
indices
);
}
// namespace ppspeech
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录