Merge branch 'main' of github.com:alibaba-damo-academy/FunASR
merge
| | |
| | | } |
| | | } |
| | | |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | |
| | | 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)); |
| | |
| | | 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()); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | 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); |
| | | Ort::TypeInfo type_info = session->GetInputTypeInfo(i); |
| | | auto tensor_info = type_info.GetTensorTypeAndShapeInfo(); |
| | | ONNXTensorElementDataType type = tensor_info.GetElementType(); |
| | | std::vector<int64_t> node_dims = tensor_info.GetShape(); |
| | | std::stringstream shape; |
| | | for (auto j: node_dims) { |
| | | shape << j; |
| | | shape << " "; |
| | | } |
| | | // LOG(INFO) << "\tInput " << i << " : name=" << name.get() << " type=" << type |
| | | // << " dims=" << shape.str(); |
| | | (*in_names)[i] = name.get(); |
| | | name.release(); |
| | | } |
| | | // 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); |
| | | Ort::TypeInfo type_info = session->GetOutputTypeInfo(i); |
| | | auto tensor_info = type_info.GetTensorTypeAndShapeInfo(); |
| | | ONNXTensorElementDataType type = tensor_info.GetElementType(); |
| | | std::vector<int64_t> node_dims = tensor_info.GetShape(); |
| | | std::stringstream shape; |
| | | for (auto j: node_dims) { |
| | | shape << j; |
| | | shape << " "; |
| | | } |
| | | // LOG(INFO) << "\tOutput " << i << " : name=" << name.get() << " type=" << type |
| | | // << " dims=" << shape.str(); |
| | | (*out_names)[i] = name.get(); |
| | | name.release(); |
| | | } |
| | | } |
| | | |
| | | |
| | | void FsmnVad::Forward( |
| | | const std::vector<std::vector<float>> &chunk_feats, |
| | |
| | | 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_; |
| | |
| | | |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | 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, |
| | |
| | | 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()); |
| | | } |