From b9bcf1f093c3053fdc4e2cf4a1d38e27bbf429fb Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期四, 19 十月 2023 14:03:48 +0800
Subject: [PATCH] docs
---
funasr/runtime/onnxruntime/src/paraformer.cpp | 62 ++++++++++++++++++++-----------
1 files changed, 40 insertions(+), 22 deletions(-)
diff --git a/funasr/runtime/onnxruntime/src/paraformer.cpp b/funasr/runtime/onnxruntime/src/paraformer.cpp
index 887a463..5bbaeef 100644
--- a/funasr/runtime/onnxruntime/src/paraformer.cpp
+++ b/funasr/runtime/onnxruntime/src/paraformer.cpp
@@ -37,7 +37,7 @@
session_options_.DisableCpuMemArena();
try {
- m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_);
+ m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_);
LOG(INFO) << "Successfully load model from " << am_model;
} catch (std::exception const &e) {
LOG(ERROR) << "Error when load am onnx model: " << e.what();
@@ -65,6 +65,7 @@
for (auto& item : m_strOutputNames)
m_szOutputNames.push_back(item.c_str());
vocab = new Vocab(am_config.c_str());
+ LoadConfigFromYaml(am_config.c_str());
LoadCmvn(am_cmvn.c_str());
}
@@ -89,7 +90,7 @@
session_options_.DisableCpuMemArena();
try {
- encoder_session_ = std::make_unique<Ort::Session>(env_, en_model.c_str(), session_options_);
+ encoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(en_model).c_str(), session_options_);
LOG(INFO) << "Successfully load model from " << en_model;
} catch (std::exception const &e) {
LOG(ERROR) << "Error when load am encoder model: " << e.what();
@@ -97,7 +98,7 @@
}
try {
- decoder_session_ = std::make_unique<Ort::Session>(env_, de_model.c_str(), session_options_);
+ decoder_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(de_model).c_str(), session_options_);
LOG(INFO) << "Successfully load model from " << de_model;
} catch (std::exception const &e) {
LOG(ERROR) << "Error when load am decoder model: " << e.what();
@@ -152,7 +153,7 @@
// offline
try {
- m_session_ = std::make_unique<Ort::Session>(env_, am_model.c_str(), session_options_);
+ m_session_ = std::make_unique<Ort::Session>(env_, ORTSTRING(am_model).c_str(), session_options_);
LOG(INFO) << "Successfully load model from " << am_model;
} catch (std::exception const &e) {
LOG(ERROR) << "Error when load am onnx model: " << e.what();
@@ -164,16 +165,44 @@
m_strInputNames.push_back(strName.c_str());
GetInputName(m_session_.get(), strName,1);
m_strInputNames.push_back(strName);
+
+ if (use_hotword) {
+ GetInputName(m_session_.get(), strName, 2);
+ m_strInputNames.push_back(strName);
+ }
- GetOutputName(m_session_.get(), strName);
- m_strOutputNames.push_back(strName);
- GetOutputName(m_session_.get(), strName,1);
- m_strOutputNames.push_back(strName);
+ // support time stamp
+ size_t numOutputNodes = m_session_->GetOutputCount();
+ for(int index=0; index<numOutputNodes; index++){
+ GetOutputName(m_session_.get(), strName, index);
+ m_strOutputNames.push_back(strName);
+ }
for (auto& item : m_strInputNames)
m_szInputNames.push_back(item.c_str());
for (auto& item : m_strOutputNames)
m_szOutputNames.push_back(item.c_str());
+}
+
+void Paraformer::LoadConfigFromYaml(const char* filename){
+
+ YAML::Node config;
+ try{
+ config = YAML::LoadFile(filename);
+ }catch(exception const &e){
+ LOG(ERROR) << "Error loading file, yaml file error or not exist.";
+ exit(-1);
+ }
+
+ try{
+ YAML::Node lang_conf = config["lang"];
+ if (lang_conf.IsDefined()){
+ language = lang_conf.as<string>();
+ }
+ }catch(exception const &e){
+ LOG(ERROR) << "Error when load argument from vad config YAML.";
+ exit(-1);
+ }
}
void Paraformer::LoadOnlineConfigFromYaml(const char* filename){
@@ -221,7 +250,7 @@
hw_session_options.DisableCpuMemArena();
try {
- hw_m_session = std::make_unique<Ort::Session>(hw_env_, hw_model.c_str(), hw_session_options);
+ hw_m_session = std::make_unique<Ort::Session>(hw_env_, ORTSTRING(hw_model).c_str(), hw_session_options);
LOG(INFO) << "Successfully load model from " << hw_model;
} catch (std::exception const &e) {
LOG(ERROR) << "Error when load hw compiler onnx model: " << e.what();
@@ -335,7 +364,7 @@
hyps.push_back(max_idx);
}
if(!is_stamp){
- return vocab->Vector2StringV2(hyps);
+ return vocab->Vector2StringV2(hyps, language);
}else{
std::vector<string> char_list;
std::vector<std::vector<float>> timestamp_list;
@@ -655,7 +684,7 @@
return "";
}
//PrintMat(hw_emb, "input_clas_emb");
- const int64_t hotword_shape[3] = {1, hw_emb.size(), hw_emb[0].size()};
+ const int64_t hotword_shape[3] = {1, static_cast<int64_t>(hw_emb.size()), static_cast<int64_t>(hw_emb[0].size())};
embedding.reserve(hw_emb.size() * hw_emb[0].size());
for (auto item : hw_emb) {
embedding.insert(embedding.end(), item.begin(), item.end());
@@ -700,17 +729,6 @@
}else{
result = GreedySearch(floatData, *encoder_out_lens, outputShape[2]);
}
-// int pos = 0;
-// std::vector<std::vector<float>> logits;
-// for (int j = 0; j < outputShape[1]; j++)
-// {
-// std::vector<float> vec_token;
-// vec_token.insert(vec_token.begin(), floatData + pos, floatData + pos + outputShape[2]);
-// logits.push_back(vec_token);
-// pos += outputShape[2];
-// }
-// //PrintMat(logits, "logits_out");
-// result = GreedySearch(floatData, *encoder_out_lens, outputShape[2]);
}
catch (std::exception const &e)
{
--
Gitblit v1.9.1