From b78d47f1efb3d0662fce1b8d45a9eb11b3caef02 Mon Sep 17 00:00:00 2001
From: Lizerui9926 <110582652+Lizerui9926@users.noreply.github.com>
Date: 星期三, 26 四月 2023 17:17:52 +0800
Subject: [PATCH] Merge pull request #427 from alibaba-damo-academy/dev_gflags

---
 funasr/runtime/onnxruntime/src/ct-transformer.cpp |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/funasr/runtime/onnxruntime/src/ct-transformer.cpp b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
index 3d66dcd..ecde636 100644
--- a/funasr/runtime/onnxruntime/src/ct-transformer.cpp
+++ b/funasr/runtime/onnxruntime/src/ct-transformer.cpp
@@ -1,28 +1,28 @@
+/**
+ * Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.
+ * MIT License  (https://opensource.org/licenses/MIT)
+*/
+
 #include "precomp.h"
 
-CTTransformer::CTTransformer(const char* sz_model_dir, int thread_num)
+CTTransformer::CTTransformer()
 :env_(ORT_LOGGING_LEVEL_ERROR, ""),session_options{}
 {
+}
+
+void CTTransformer::InitPunc(const std::string &punc_model, const std::string &punc_config, int thread_num){
     session_options.SetIntraOpNumThreads(thread_num);
     session_options.SetGraphOptimizationLevel(ORT_ENABLE_ALL);
     session_options.DisableCpuMemArena();
 
-	string strModelPath = PathAppend(sz_model_dir, PUNC_MODEL_FILE);
-	string strYamlPath = PathAppend(sz_model_dir, PUNC_YAML_FILE);
-
     try{
-#ifdef _WIN32
-	std::wstring detPath = strToWstr(strModelPath);
-    m_session = std::make_unique<Ort::Session>(env_, detPath.c_str(), session_options);
-#else
-    m_session = std::make_unique<Ort::Session>(env_, strModelPath.c_str(), session_options);
-#endif
+        m_session = std::make_unique<Ort::Session>(env_, punc_model.c_str(), session_options);
     }
-    catch(exception e)
-    {
-        printf(e.what());
+    catch (std::exception const &e) {
+        LOG(ERROR) << "Error when load punc onnx model: " << e.what();
+        exit(0);
     }
-    // read inputnames outputnamess
+    // read inputnames outputnames
     string strName;
     GetInputName(m_session.get(), strName);
     m_strInputNames.push_back(strName.c_str());
@@ -37,7 +37,7 @@
     for (auto& item : m_strOutputNames)
         m_szOutputNames.push_back(item.c_str());
 
-	m_tokenizer.OpenYaml(strYamlPath.c_str());
+	m_tokenizer.OpenYaml(punc_config.c_str());
 }
 
 CTTransformer::~CTTransformer()
@@ -179,10 +179,9 @@
     }
     catch (std::exception const &e)
     {
-        printf(e.what());
+        LOG(ERROR) << "Error when run punc onnx forword: " << (e.what());
+        exit(0);
     }
     return punction;
 }
-
-
 

--
Gitblit v1.9.1