mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
add GetInputNames GetOutputNames
This commit is contained in:
parent
bef2d3a391
commit
1480dcf5d5
@ -65,6 +65,19 @@ inline void GetInputName(Ort::Session* session, string& inputName,int nIndex=0)
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetInputNames(Ort::Session* session, std::vector<std::string> &m_strInputNames,
|
||||
std::vector<const char *> &m_szInputNames) {
|
||||
Ort::AllocatorWithDefaultOptions allocator;
|
||||
size_t numNodes = session->GetInputCount();
|
||||
m_strInputNames.resize(numNodes);
|
||||
m_szInputNames.resize(numNodes);
|
||||
for (size_t i = 0; i != numNodes; ++i) {
|
||||
auto t = session->GetInputNameAllocated(i, allocator);
|
||||
m_strInputNames[i] = t.get();
|
||||
m_szInputNames[i] = m_strInputNames[i].c_str();
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetOutputName(Ort::Session* session, string& outputName, int nIndex = 0) {
|
||||
size_t numOutputNodes = session->GetOutputCount();
|
||||
if (numOutputNodes > 0) {
|
||||
@ -76,6 +89,19 @@ inline void GetOutputName(Ort::Session* session, string& outputName, int nIndex
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetOutputNames(Ort::Session* session, std::vector<std::string> &m_strOutputNames,
|
||||
std::vector<const char *> &m_szOutputNames) {
|
||||
Ort::AllocatorWithDefaultOptions allocator;
|
||||
size_t numNodes = session->GetOutputCount();
|
||||
m_strOutputNames.resize(numNodes);
|
||||
m_szOutputNames.resize(numNodes);
|
||||
for (size_t i = 0; i != numNodes; ++i) {
|
||||
auto t = session->GetOutputNameAllocated(i, allocator);
|
||||
m_strOutputNames[i] = t.get();
|
||||
m_szOutputNames[i] = m_strOutputNames[i].c_str();
|
||||
}
|
||||
}
|
||||
|
||||
template <class ForwardIterator>
|
||||
inline static size_t Argmax(ForwardIterator first, ForwardIterator last) {
|
||||
return std::distance(first, std::max_element(first, last));
|
||||
|
||||
@ -25,23 +25,8 @@ void CTTransformerOnline::InitPunc(const std::string &punc_model, const std::str
|
||||
exit(-1);
|
||||
}
|
||||
// read inputnames outputnames
|
||||
string strName;
|
||||
GetInputName(m_session.get(), strName);
|
||||
m_strInputNames.push_back(strName.c_str());
|
||||
GetInputName(m_session.get(), strName, 1);
|
||||
m_strInputNames.push_back(strName);
|
||||
GetInputName(m_session.get(), strName, 2);
|
||||
m_strInputNames.push_back(strName);
|
||||
GetInputName(m_session.get(), strName, 3);
|
||||
m_strInputNames.push_back(strName);
|
||||
|
||||
GetOutputName(m_session.get(), strName);
|
||||
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());
|
||||
GetInputNames(m_session.get(), m_strInputNames, m_szInputNames);
|
||||
GetOutputNames(m_session.get(), m_strOutputNames, m_szOutputNames);
|
||||
|
||||
m_tokenizer.OpenYaml(punc_config.c_str(), token_file.c_str());
|
||||
}
|
||||
|
||||
@ -25,20 +25,9 @@ void CTTransformer::InitPunc(const std::string &punc_model, const std::string &p
|
||||
exit(-1);
|
||||
}
|
||||
// read inputnames outputnames
|
||||
string strName;
|
||||
GetInputName(m_session.get(), strName);
|
||||
m_strInputNames.push_back(strName.c_str());
|
||||
GetInputName(m_session.get(), strName, 1);
|
||||
m_strInputNames.push_back(strName);
|
||||
GetInputNames(m_session.get(), m_strInputNames, m_szInputNames);
|
||||
GetOutputNames(m_session.get(), m_strOutputNames, m_szOutputNames);
|
||||
|
||||
GetOutputName(m_session.get(), strName);
|
||||
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());
|
||||
|
||||
m_tokenizer.OpenYaml(punc_config.c_str(), token_file.c_str());
|
||||
m_tokenizer.JiebaInit(punc_config);
|
||||
}
|
||||
|
||||
@ -60,30 +60,10 @@ void FsmnVad::ReadModel(const char* vad_model) {
|
||||
LOG(ERROR) << "Error when load vad onnx model: " << e.what();
|
||||
exit(-1);
|
||||
}
|
||||
GetInputOutputInfo(vad_session_, &vad_in_names_, &vad_out_names_);
|
||||
GetInputNames(vad_session_.get(), m_strInputNames, vad_in_names_);
|
||||
GetOutputNames(vad_session_.get(), m_strOutputNames, vad_out_names_);
|
||||
}
|
||||
|
||||
void FsmnVad::GetInputOutputInfo(
|
||||
const std::shared_ptr<Ort::Session> &session,
|
||||
std::vector<const char *> *in_names, std::vector<const char *> *out_names) {
|
||||
Ort::AllocatorWithDefaultOptions allocator;
|
||||
// Input info
|
||||
int num_nodes = session->GetInputCount();
|
||||
in_names->resize(num_nodes);
|
||||
for (int i = 0; i < num_nodes; ++i) {
|
||||
std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetInputNameAllocated(i, allocator);
|
||||
(*in_names)[i] = name.get();
|
||||
}
|
||||
// Output info
|
||||
num_nodes = session->GetOutputCount();
|
||||
out_names->resize(num_nodes);
|
||||
for (int i = 0; i < num_nodes; ++i) {
|
||||
std::unique_ptr<char, Ort::detail::AllocatedFree> name = session->GetOutputNameAllocated(i, allocator);
|
||||
(*out_names)[i] = name.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FsmnVad::Forward(
|
||||
const std::vector<std::vector<float>> &chunk_feats,
|
||||
std::vector<std::vector<float>> *out_prob,
|
||||
|
||||
@ -34,6 +34,7 @@ public:
|
||||
std::shared_ptr<Ort::Session> vad_session_ = nullptr;
|
||||
Ort::Env env_;
|
||||
Ort::SessionOptions session_options_;
|
||||
vector<string> m_strInputNames, m_strOutputNames;
|
||||
std::vector<const char *> vad_in_names_;
|
||||
std::vector<const char *> vad_out_names_;
|
||||
std::vector<std::vector<float>> in_cache_;
|
||||
@ -54,10 +55,6 @@ private:
|
||||
void ReadModel(const char* vad_model);
|
||||
void LoadConfigFromYaml(const char* filename);
|
||||
|
||||
static void GetInputOutputInfo(
|
||||
const std::shared_ptr<Ort::Session> &session,
|
||||
std::vector<const char *> *in_names, std::vector<const char *> *out_names);
|
||||
|
||||
void FbankKaldi(float sample_rate, std::vector<std::vector<float>> &vad_feats,
|
||||
std::vector<float> &waves);
|
||||
|
||||
|
||||
@ -45,26 +45,8 @@ void Paraformer::InitAsr(const std::string &am_model, const std::string &am_cmvn
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
string strName;
|
||||
GetInputName(m_session_.get(), strName);
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
GetInputNames(m_session_.get(), m_strInputNames, m_szInputNames);
|
||||
GetOutputNames(m_session_.get(), m_strOutputNames, m_szOutputNames);
|
||||
vocab = new Vocab(token_file.c_str());
|
||||
phone_set_ = new PhoneSet(token_file.c_str());
|
||||
LoadCmvn(am_cmvn.c_str());
|
||||
@ -162,28 +144,30 @@ void Paraformer::InitAsr(const std::string &am_model, const std::string &en_mode
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
string strName;
|
||||
GetInputName(m_session_.get(), strName);
|
||||
m_strInputNames.push_back(strName.c_str());
|
||||
GetInputName(m_session_.get(), strName,1);
|
||||
m_strInputNames.push_back(strName);
|
||||
// string strName;
|
||||
// GetInputName(m_session_.get(), strName);
|
||||
// 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);
|
||||
}
|
||||
// if (use_hotword) {
|
||||
// GetInputName(m_session_.get(), strName, 2);
|
||||
// m_strInputNames.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);
|
||||
}
|
||||
// // 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());
|
||||
// for (auto& item : m_strInputNames)
|
||||
// m_szInputNames.push_back(item.c_str());
|
||||
// for (auto& item : m_strOutputNames)
|
||||
// m_szOutputNames.push_back(item.c_str());
|
||||
GetInputNames(m_session_.get(), m_strInputNames, m_szInputNames);
|
||||
GetOutputNames(m_session_.get(), m_strOutputNames, m_szOutputNames);
|
||||
}
|
||||
|
||||
void Paraformer::InitLm(const std::string &lm_file,
|
||||
|
||||
@ -42,26 +42,8 @@ void SenseVoiceSmall::InitAsr(const std::string &am_model, const std::string &am
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
string strName;
|
||||
GetInputName(m_session_.get(), strName);
|
||||
m_strInputNames.push_back(strName.c_str());
|
||||
GetInputName(m_session_.get(), strName,1);
|
||||
m_strInputNames.push_back(strName);
|
||||
GetInputName(m_session_.get(), strName,2);
|
||||
m_strInputNames.push_back(strName);
|
||||
GetInputName(m_session_.get(), strName,3);
|
||||
m_strInputNames.push_back(strName);
|
||||
|
||||
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());
|
||||
GetInputNames(m_session_.get(), m_strInputNames, m_szInputNames);
|
||||
GetOutputNames(m_session_.get(), m_strOutputNames, m_szOutputNames);
|
||||
vocab = new Vocab(token_file.c_str());
|
||||
LoadCmvn(am_cmvn.c_str());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user