Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
sherpaonnx
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Fangjun Kuang
2024-04-16 09:46:15 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-04-16 09:46:15 +0800
Commit
6bf2099781888f1c37ccebba66ceb36a98bd7a79
6bf20997
1 parent
81b7f1d5
Fix code style issues (#774)
隐藏空白字符变更
内嵌
并排对比
正在显示
20 个修改的文件
包含
45 行增加
和
57 行删除
sherpa-onnx/csrc/features.cc
sherpa-onnx/csrc/offline-lm-config.cc
sherpa-onnx/csrc/offline-recognizer-transducer-impl.h
sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h
sherpa-onnx/csrc/offline-websocket-server-impl.cc
sherpa-onnx/csrc/online-lm-config.cc
sherpa-onnx/csrc/online-lm-config.h
sherpa-onnx/csrc/online-model-config.h
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
sherpa-onnx/csrc/online-recognizer.h
sherpa-onnx/csrc/online-rnn-lm.cc
sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc
sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h
sherpa-onnx/csrc/online-transducer-model.h
sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc
sherpa-onnx/csrc/stack-test.cc
sherpa-onnx/python/csrc/features.cc
sherpa-onnx/python/csrc/offline-recognizer.cc
sherpa-onnx/python/csrc/offline-transducer-model-config.cc
sherpa-onnx/python/csrc/online-model-config.cc
sherpa-onnx/csrc/features.cc
查看文件 @
6bf2099
...
...
@@ -26,8 +26,7 @@ void FeatureExtractorConfig::Register(ParseOptions *po) {
po
->
Register
(
"feat-dim"
,
&
feature_dim
,
"Feature dimension. Must match the one expected by the model."
);
po
->
Register
(
"low-freq"
,
&
low_freq
,
"Low cutoff frequency for mel bins"
);
po
->
Register
(
"low-freq"
,
&
low_freq
,
"Low cutoff frequency for mel bins"
);
po
->
Register
(
"high-freq"
,
&
high_freq
,
"High cutoff frequency for mel bins "
...
...
@@ -67,7 +66,7 @@ class FeatureExtractor::Impl {
opts_
.
mel_opts
.
num_bins
=
config
.
feature_dim
;
opts_
.
mel_opts
.
high_freq
=
config
.
high_freq
;
opts_
.
mel_opts
.
low_freq
=
config
.
low_freq
;
opts_
.
mel_opts
.
low_freq
=
config
.
low_freq
;
opts_
.
mel_opts
.
is_librosa
=
config
.
is_librosa
;
...
...
sherpa-onnx/csrc/offline-lm-config.cc
查看文件 @
6bf2099
...
...
@@ -15,7 +15,7 @@ void OfflineLMConfig::Register(ParseOptions *po) {
po
->
Register
(
"lm"
,
&
model
,
"Path to LM model."
);
po
->
Register
(
"lm-scale"
,
&
scale
,
"LM scale."
);
po
->
Register
(
"lm-num-threads"
,
&
lm_num_threads
,
"Number of threads to run the neural network of LM model"
);
"Number of threads to run the neural network of LM model"
);
po
->
Register
(
"lm-provider"
,
&
lm_provider
,
"Specify a provider to LM model use: cpu, cuda, coreml"
);
}
...
...
sherpa-onnx/csrc/offline-recognizer-transducer-impl.h
查看文件 @
6bf2099
...
...
@@ -80,9 +80,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
InitHotwords
();
}
if
(
config_
.
decoding_method
==
"greedy_search"
)
{
decoder_
=
std
::
make_unique
<
OfflineTransducerGreedySearchDecoder
>
(
model_
.
get
(),
config_
.
blank_penalty
);
decoder_
=
std
::
make_unique
<
OfflineTransducerGreedySearchDecoder
>
(
model_
.
get
(),
config_
.
blank_penalty
);
}
else
if
(
config_
.
decoding_method
==
"modified_beam_search"
)
{
if
(
!
config_
.
lm_config
.
model
.
empty
())
{
lm_
=
OfflineLM
::
Create
(
config
.
lm_config
);
...
...
@@ -106,9 +105,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl {
model_
(
std
::
make_unique
<
OfflineTransducerModel
>
(
mgr
,
config_
.
model_config
))
{
if
(
config_
.
decoding_method
==
"greedy_search"
)
{
decoder_
=
std
::
make_unique
<
OfflineTransducerGreedySearchDecoder
>
(
model_
.
get
(),
config_
.
blank_penalty
);
decoder_
=
std
::
make_unique
<
OfflineTransducerGreedySearchDecoder
>
(
model_
.
get
(),
config_
.
blank_penalty
);
}
else
if
(
config_
.
decoding_method
==
"modified_beam_search"
)
{
if
(
!
config_
.
lm_config
.
model
.
empty
())
{
lm_
=
OfflineLM
::
Create
(
mgr
,
config
.
lm_config
);
...
...
sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h
查看文件 @
6bf2099
...
...
@@ -16,8 +16,7 @@ class OfflineTransducerGreedySearchDecoder : public OfflineTransducerDecoder {
public
:
explicit
OfflineTransducerGreedySearchDecoder
(
OfflineTransducerModel
*
model
,
float
blank_penalty
)
:
model_
(
model
),
blank_penalty_
(
blank_penalty
)
{}
:
model_
(
model
),
blank_penalty_
(
blank_penalty
)
{}
std
::
vector
<
OfflineTransducerDecoderResult
>
Decode
(
Ort
::
Value
encoder_out
,
Ort
::
Value
encoder_out_length
,
...
...
sherpa-onnx/csrc/offline-websocket-server-impl.cc
查看文件 @
6bf2099
...
...
@@ -102,9 +102,9 @@ void OfflineWebsocketDecoder::Decode() {
asio
::
post
(
server_
->
GetConnectionContext
(),
[
this
,
hdl
,
result
=
ss
[
i
]
->
GetResult
()]()
{
websocketpp
::
lib
::
error_code
ec
;
server_
->
GetServer
().
send
(
hdl
,
result
.
AsJsonString
(),
websocketpp
::
frame
::
opcode
::
text
,
ec
);
server_
->
GetServer
().
send
(
hdl
,
result
.
AsJsonString
(),
websocketpp
::
frame
::
opcode
::
text
,
ec
);
if
(
ec
)
{
server_
->
GetServer
().
get_alog
().
write
(
websocketpp
::
log
::
alevel
::
app
,
ec
.
message
());
...
...
sherpa-onnx/csrc/online-lm-config.cc
查看文件 @
6bf2099
...
...
@@ -15,7 +15,7 @@ void OnlineLMConfig::Register(ParseOptions *po) {
po
->
Register
(
"lm"
,
&
model
,
"Path to LM model."
);
po
->
Register
(
"lm-scale"
,
&
scale
,
"LM scale."
);
po
->
Register
(
"lm-num-threads"
,
&
lm_num_threads
,
"Number of threads to run the neural network of LM model"
);
"Number of threads to run the neural network of LM model"
);
po
->
Register
(
"lm-provider"
,
&
lm_provider
,
"Specify a provider to LM model use: cpu, cuda, coreml"
);
}
...
...
sherpa-onnx/csrc/online-lm-config.h
查看文件 @
6bf2099
...
...
@@ -22,7 +22,7 @@ struct OnlineLMConfig {
OnlineLMConfig
()
=
default
;
OnlineLMConfig
(
const
std
::
string
&
model
,
float
scale
,
int32_t
lm_num_threads
,
const
std
::
string
&
lm_provider
)
const
std
::
string
&
lm_provider
)
:
model
(
model
),
scale
(
scale
),
lm_num_threads
(
lm_num_threads
),
...
...
sherpa-onnx/csrc/online-model-config.h
查看文件 @
6bf2099
...
...
@@ -40,8 +40,7 @@ struct OnlineModelConfig {
const
OnlineWenetCtcModelConfig
&
wenet_ctc
,
const
OnlineZipformer2CtcModelConfig
&
zipformer2_ctc
,
const
std
::
string
&
tokens
,
int32_t
num_threads
,
int32_t
warm_up
,
bool
debug
,
const
std
::
string
&
provider
,
int32_t
warm_up
,
bool
debug
,
const
std
::
string
&
provider
,
const
std
::
string
&
model_type
)
:
transducer
(
transducer
),
paraformer
(
paraformer
),
...
...
sherpa-onnx/csrc/online-recognizer-transducer-impl.h
查看文件 @
6bf2099
...
...
@@ -30,9 +30,9 @@
#include "sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h"
#include "sherpa-onnx/csrc/online-transducer-model.h"
#include "sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/symbol-table.h"
#include "sherpa-onnx/csrc/utils.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
namespace
sherpa_onnx
{
...
...
@@ -185,7 +185,7 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
}
// Warmping up engine with wp: warm_up count and max-batch-size
void
WarmpUpRecognizer
(
int32_t
warmup
,
int32_t
mbs
)
const
{
void
WarmpUpRecognizer
(
int32_t
warmup
,
int32_t
mbs
)
const
override
{
auto
max_batch_size
=
mbs
;
if
(
warmup
<=
0
||
warmup
>
100
)
{
return
;
...
...
@@ -210,8 +210,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
for
(
int32_t
i
=
0
;
i
!=
warmup
;
++
i
)
{
auto
states
=
model_
->
StackStates
(
states_vec
);
Ort
::
Value
x
=
Ort
::
Value
::
CreateTensor
(
memory_info
,
features_vec
.
data
(),
features_vec
.
size
(),
x_shape
.
data
(),
x_shape
.
size
());
features_vec
.
size
(),
x_shape
.
data
(),
x_shape
.
size
());
auto
x_copy
=
Clone
(
model_
->
Allocator
(),
&
x
);
auto
pair
=
model_
->
RunEncoder
(
std
::
move
(
x
),
std
::
move
(
states
),
std
::
move
(
x_copy
));
...
...
sherpa-onnx/csrc/online-recognizer.h
查看文件 @
6bf2099
...
...
@@ -168,7 +168,7 @@ class OnlineRecognizer {
*
* @param warmup Number of warmups.
* @param mbs : max-batch-size Max batch size for the models
*/
*/
void
WarmpUpRecognizer
(
int32_t
warmup
,
int32_t
mbs
)
const
;
/** Decode multiple streams in parallel
...
...
sherpa-onnx/csrc/online-rnn-lm.cc
查看文件 @
6bf2099
...
...
@@ -12,8 +12,8 @@
#include "onnxruntime_cxx_api.h" // NOLINT
#include "sherpa-onnx/csrc/macros.h"
#include "sherpa-onnx/csrc/onnx-utils.h"
#include "sherpa-onnx/csrc/text-utils.h"
#include "sherpa-onnx/csrc/session.h"
#include "sherpa-onnx/csrc/text-utils.h"
namespace
sherpa_onnx
{
...
...
@@ -42,10 +42,9 @@ class OnlineRnnLM::Impl {
// nn_lm_scores
std
::
array
<
int64_t
,
2
>
x_shape
{
1
,
1
};
Ort
::
Value
x
=
Ort
::
Value
::
CreateTensor
<
int64_t
>
(
allocator_
,
x_shape
.
data
(),
x_shape
.
size
());
x_shape
.
size
());
*
x
.
GetTensorMutableData
<
int64_t
>
()
=
hyp
->
ys
.
back
();
auto
lm_out
=
ScoreToken
(
std
::
move
(
x
),
Convert
(
hyp
->
nn_lm_states
));
auto
lm_out
=
ScoreToken
(
std
::
move
(
x
),
Convert
(
hyp
->
nn_lm_states
));
hyp
->
nn_lm_scores
.
value
=
std
::
move
(
lm_out
.
first
);
hyp
->
nn_lm_states
=
Convert
(
std
::
move
(
lm_out
.
second
));
}
...
...
sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc
查看文件 @
6bf2099
...
...
@@ -71,11 +71,9 @@ void OnlineTransducerGreedySearchDecoder::StripLeadingBlanks(
r
->
tokens
=
std
::
vector
<
int64_t
>
(
start
,
end
);
}
void
OnlineTransducerGreedySearchDecoder
::
Decode
(
Ort
::
Value
encoder_out
,
std
::
vector
<
OnlineTransducerDecoderResult
>
*
result
)
{
std
::
vector
<
int64_t
>
encoder_out_shape
=
encoder_out
.
GetTensorTypeAndShapeInfo
().
GetShape
();
...
...
@@ -106,7 +104,8 @@ void OnlineTransducerGreedySearchDecoder::Decode(
r
.
decoder_out
.
GetTensorTypeAndShapeInfo
().
GetShape
();
decoder_out_shape
[
0
]
=
batch_size
;
decoder_out
=
Ort
::
Value
::
CreateTensor
<
float
>
(
model_
->
Allocator
(),
decoder_out_shape
.
data
(),
decoder_out_shape
.
size
());
decoder_out_shape
.
data
(),
decoder_out_shape
.
size
());
UseCachedDecoderOut
(
*
result
,
&
decoder_out
);
}
else
{
Ort
::
Value
decoder_input
=
model_
->
BuildDecoderInput
(
*
result
);
...
...
@@ -116,8 +115,8 @@ void OnlineTransducerGreedySearchDecoder::Decode(
for
(
int32_t
t
=
0
;
t
!=
num_frames
;
++
t
)
{
Ort
::
Value
cur_encoder_out
=
GetEncoderOutFrame
(
model_
->
Allocator
(),
&
encoder_out
,
t
);
Ort
::
Value
logit
=
model_
->
RunJoiner
(
std
::
move
(
cur_encoder_out
),
View
(
&
decoder_out
));
Ort
::
Value
logit
=
model_
->
RunJoiner
(
std
::
move
(
cur_encoder_out
),
View
(
&
decoder_out
));
float
*
p_logit
=
logit
.
GetTensorMutableData
<
float
>
();
...
...
@@ -145,9 +144,9 @@ void OnlineTransducerGreedySearchDecoder::Decode(
// export the per-token log scores
if
(
y
!=
0
&&
y
!=
unk_id_
)
{
LogSoftmax
(
p_logit
,
vocab_size
);
// renormalize probabilities,
// save time by doing it only for
// emitted symbols
LogSoftmax
(
p_logit
,
vocab_size
);
// renormalize probabilities,
// save time by doing it only for
// emitted symbols
const
float
*
p_logprob
=
p_logit
;
// rename p_logit as p_logprob,
// now it contains normalized
// probability
...
...
sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h
查看文件 @
6bf2099
...
...
@@ -15,8 +15,7 @@ namespace sherpa_onnx {
class
OnlineTransducerGreedySearchDecoder
:
public
OnlineTransducerDecoder
{
public
:
OnlineTransducerGreedySearchDecoder
(
OnlineTransducerModel
*
model
,
int32_t
unk_id
,
float
blank_penalty
)
int32_t
unk_id
,
float
blank_penalty
)
:
model_
(
model
),
unk_id_
(
unk_id
),
blank_penalty_
(
blank_penalty
)
{}
OnlineTransducerDecoderResult
GetEmptyResult
()
const
override
;
...
...
sherpa-onnx/csrc/online-transducer-model.h
查看文件 @
6bf2099
...
...
@@ -69,7 +69,7 @@ class OnlineTransducerModel {
* This has to be called before GetEncoderInitStates(), so the `encoder_embed`
* init state has the correct `embed_dim` of its output.
*/
virtual
void
SetFeatureDim
(
int32_t
feature_dim
)
{
}
virtual
void
SetFeatureDim
(
int32_t
feature_dim
)
{}
/** Run the encoder.
*
...
...
sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc
查看文件 @
6bf2099
...
...
@@ -188,7 +188,7 @@ void OnlineTransducerModifiedBeamSearchDecoder::Decode(
// score of the transducer
// export the per-token log scores
if
(
new_token
!=
0
&&
new_token
!=
unk_id_
)
{
const
Hypothesis
&
prev_i
=
prev
[
hyp_index
];
const
Hypothesis
&
prev_i
=
prev
[
hyp_index
];
// subtract 'prev[i]' path scores, which were added before
// getting topk tokens
float
y_prob
=
p_logprob
[
k
]
-
prev_i
.
log_prob
-
prev_i
.
lm_log_prob
;
...
...
sherpa-onnx/csrc/stack-test.cc
查看文件 @
6bf2099
...
...
@@ -16,10 +16,10 @@ TEST(Stack, Test1DTensors) {
std
::
array
<
int64_t
,
1
>
b_shape
{
3
};
Ort
::
Value
a
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
a_shape
.
data
(),
a_shape
.
size
());
a_shape
.
size
());
Ort
::
Value
b
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
b_shape
.
data
(),
b_shape
.
size
());
b_shape
.
size
());
float
*
pa
=
a
.
GetTensorMutableData
<
float
>
();
float
*
pb
=
b
.
GetTensorMutableData
<
float
>
();
for
(
int32_t
i
=
0
;
i
!=
static_cast
<
int32_t
>
(
a_shape
[
0
]);
++
i
)
{
...
...
@@ -51,11 +51,11 @@ TEST(Stack, Test2DTensorsDim0) {
std
::
array
<
int64_t
,
2
>
a_shape
{
2
,
3
};
std
::
array
<
int64_t
,
2
>
b_shape
{
2
,
3
};
Ort
::
Value
a
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
a_shape
.
data
(),
a_shape
.
size
());
Ort
::
Value
a
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
a_shape
.
data
(),
a_shape
.
size
());
Ort
::
Value
b
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
b_shape
.
data
(),
b_shape
.
size
());
Ort
::
Value
b
=
Ort
::
Value
::
CreateTensor
<
float
>
(
allocator
,
b_shape
.
data
(),
b_shape
.
size
());
float
*
pa
=
a
.
GetTensorMutableData
<
float
>
();
float
*
pb
=
b
.
GetTensorMutableData
<
float
>
();
...
...
sherpa-onnx/python/csrc/features.cc
查看文件 @
6bf2099
...
...
@@ -12,10 +12,8 @@ static void PybindFeatureExtractorConfig(py::module *m) {
using
PyClass
=
FeatureExtractorConfig
;
py
::
class_
<
PyClass
>
(
*
m
,
"FeatureExtractorConfig"
)
.
def
(
py
::
init
<
int32_t
,
int32_t
,
float
,
float
,
float
>
(),
py
::
arg
(
"sampling_rate"
)
=
16000
,
py
::
arg
(
"feature_dim"
)
=
80
,
py
::
arg
(
"low_freq"
)
=
20.0
f
,
py
::
arg
(
"high_freq"
)
=
-
400.0
f
,
py
::
arg
(
"sampling_rate"
)
=
16000
,
py
::
arg
(
"feature_dim"
)
=
80
,
py
::
arg
(
"low_freq"
)
=
20.0
f
,
py
::
arg
(
"high_freq"
)
=
-
400.0
f
,
py
::
arg
(
"dither"
)
=
0.0
f
)
.
def_readwrite
(
"sampling_rate"
,
&
PyClass
::
sampling_rate
)
.
def_readwrite
(
"feature_dim"
,
&
PyClass
::
feature_dim
)
...
...
sherpa-onnx/python/csrc/offline-recognizer.cc
查看文件 @
6bf2099
...
...
@@ -23,8 +23,7 @@ static void PybindOfflineRecognizerConfig(py::module *m) {
py
::
arg
(
"ctc_fst_decoder_config"
)
=
OfflineCtcFstDecoderConfig
(),
py
::
arg
(
"decoding_method"
)
=
"greedy_search"
,
py
::
arg
(
"max_active_paths"
)
=
4
,
py
::
arg
(
"hotwords_file"
)
=
""
,
py
::
arg
(
"hotwords_score"
)
=
1.5
,
py
::
arg
(
"blank_penalty"
)
=
0.0
)
py
::
arg
(
"hotwords_score"
)
=
1.5
,
py
::
arg
(
"blank_penalty"
)
=
0.0
)
.
def_readwrite
(
"feat_config"
,
&
PyClass
::
feat_config
)
.
def_readwrite
(
"model_config"
,
&
PyClass
::
model_config
)
.
def_readwrite
(
"lm_config"
,
&
PyClass
::
lm_config
)
...
...
sherpa-onnx/python/csrc/offline-transducer-model-config.cc
查看文件 @
6bf2099
...
...
@@ -4,7 +4,6 @@
#include "sherpa-onnx/python/csrc/offline-transducer-model-config.h"
#include <string>
#include <vector>
...
...
@@ -16,7 +15,7 @@ void PybindOfflineTransducerModelConfig(py::module *m) {
using
PyClass
=
OfflineTransducerModelConfig
;
py
::
class_
<
PyClass
>
(
*
m
,
"OfflineTransducerModelConfig"
)
.
def
(
py
::
init
<
const
std
::
string
&
,
const
std
::
string
&
,
const
std
::
string
&>
(),
const
std
::
string
&>
(),
py
::
arg
(
"encoder_filename"
),
py
::
arg
(
"decoder_filename"
),
py
::
arg
(
"joiner_filename"
))
.
def_readwrite
(
"encoder_filename"
,
&
PyClass
::
encoder_filename
)
...
...
sherpa-onnx/python/csrc/online-model-config.cc
查看文件 @
6bf2099
...
...
@@ -27,9 +27,9 @@ void PybindOnlineModelConfig(py::module *m) {
.
def
(
py
::
init
<
const
OnlineTransducerModelConfig
&
,
const
OnlineParaformerModelConfig
&
,
const
OnlineWenetCtcModelConfig
&
,
const
OnlineZipformer2CtcModelConfig
&
,
const
std
::
string
&
,
int32_t
,
int32_t
,
bool
,
const
std
::
string
&
,
const
std
::
string
&>
(),
const
OnlineZipformer2CtcModelConfig
&
,
const
std
::
string
&
,
int32_t
,
int32_t
,
bool
,
const
std
::
string
&
,
const
std
::
string
&>
(),
py
::
arg
(
"transducer"
)
=
OnlineTransducerModelConfig
(),
py
::
arg
(
"paraformer"
)
=
OnlineParaformerModelConfig
(),
py
::
arg
(
"wenet_ctc"
)
=
OnlineWenetCtcModelConfig
(),
...
...
请
注册
或
登录
后发表评论