From cc5cf4c2efbca3297b8826237a4215178dc90f07 Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Mon, 29 Aug 2022 21:31:09 +0800 Subject: [PATCH] Move uie to fd (#166) * Move uie to fd * Add using namespace * remove fastdeploy::text:: Co-authored-by: Jason --- csrc/fastdeploy/text.h | 2 +- .../fastdeploy/text/uie/model.cc | 8 +++++++- .../uie.h => csrc/fastdeploy/text/uie/model.h | 18 +++++++++++++----- examples/CMakeLists.txt | 7 ++++--- examples/text/uie/cpp/CMakeLists.txt | 2 +- examples/text/uie/cpp/infer.cc | 12 ++++++------ 6 files changed, 32 insertions(+), 17 deletions(-) rename examples/text/uie/cpp/uie.cc => csrc/fastdeploy/text/uie/model.cc (99%) rename examples/text/uie/cpp/uie.h => csrc/fastdeploy/text/uie/model.h (94%) diff --git a/csrc/fastdeploy/text.h b/csrc/fastdeploy/text.h index 184f0f4f9..85563a658 100644 --- a/csrc/fastdeploy/text.h +++ b/csrc/fastdeploy/text.h @@ -15,5 +15,5 @@ #include "fastdeploy/core/config.h" #ifdef ENABLE_TEXT -#include "fastdeploy/text/text_model.h" +#include "fastdeploy/text/uie/model.h" #endif diff --git a/examples/text/uie/cpp/uie.cc b/csrc/fastdeploy/text/uie/model.cc similarity index 99% rename from examples/text/uie/cpp/uie.cc rename to csrc/fastdeploy/text/uie/model.cc index e9f124ba5..36140fd75 100644 --- a/examples/text/uie/cpp/uie.cc +++ b/csrc/fastdeploy/text/uie/model.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "uie.h" +#include "fastdeploy/text/uie/model.h" #include #include #include @@ -22,6 +22,9 @@ #include "faster_tokenizer/pretokenizers/pretokenizer.h" #include "faster_tokenizer/utils/utf8.h" +namespace fastdeploy { +namespace text { + static std::string DBC2SBC(const std::string& content) { std::string result; size_t content_utf8_len = 0; @@ -644,3 +647,6 @@ void UIEModel::Predict( } } } + +} // namespace text +} // namespace fastdeploy \ No newline at end of file diff --git a/examples/text/uie/cpp/uie.h b/csrc/fastdeploy/text/uie/model.h similarity index 94% rename from examples/text/uie/cpp/uie.h rename to csrc/fastdeploy/text/uie/model.h index 5894ae1d6..cfdd099fd 100644 --- a/examples/text/uie/cpp/uie.h +++ b/csrc/fastdeploy/text/uie/model.h @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + #pragma once #include @@ -24,7 +25,10 @@ using namespace paddlenlp; -struct UIEResult { +namespace fastdeploy { +namespace text { + +struct FASTDEPLOY_DECL UIEResult { size_t start_; size_t end_; double probability_; @@ -35,13 +39,14 @@ struct UIEResult { : start_(start), end_(end), probability_(probability), text_(text) {} }; -std::ostream& operator<<(std::ostream& os, const UIEResult& result); -std::ostream& operator<<( +FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& os, + const UIEResult& result); +FASTDEPLOY_DECL std::ostream& operator<<( std::ostream& os, const std::vector>>& results); -struct SchemaNode { +struct FASTDEPLOY_DECL SchemaNode { std::string name_; std::vector> prefix_; std::vector> relations_; @@ -82,7 +87,7 @@ struct Schema { friend class UIEModel; }; -struct UIEModel { +struct FASTDEPLOY_DECL UIEModel { public: UIEModel( const std::string& model_file, const std::string& params_file, @@ -154,3 +159,6 @@ struct UIEModel { float position_prob_; faster_tokenizer::tokenizers_impl::ErnieFasterTokenizer tokenizer_; }; + +} // namespace text +} // namespace fastdeploy diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 01775e76c..160cb5751 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -69,9 +69,10 @@ if(BUILD_EXAMPLES AND ENABLE_TEXT) if(EXISTS ${PROJECT_SOURCE_DIR}/examples/text) message(STATUS "") message(STATUS "*************FastDeploy Text Examples Summary**********") - # TODO(zhoushunjie): will use add_fastdeploy_executable later - add_executable(uie_infer_demo ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/infer.cc ${PROJECT_SOURCE_DIR}/examples/text/uie/cpp/uie.cc) - target_link_libraries(uie_infer_demo PUBLIC fastdeploy) + file(GLOB_RECURSE ALL_TEXT_EXAMPLE_SRCS ${PROJECT_SOURCE_DIR}/examples/text/*.cc) + foreach(_CC_FILE ${ALL_TEXT_EXAMPLE_SRCS}) + add_fastdeploy_executable(text ${_CC_FILE}) + endforeach() message(STATUS " [FastDeploy Executable Path] : ${EXECUTABLE_OUTPUT_PATH}") endif() endif() diff --git a/examples/text/uie/cpp/CMakeLists.txt b/examples/text/uie/cpp/CMakeLists.txt index 80731eda4..829bde994 100644 --- a/examples/text/uie/cpp/CMakeLists.txt +++ b/examples/text/uie/cpp/CMakeLists.txt @@ -21,5 +21,5 @@ include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake) include_directories(${FASTDEPLOY_INCS}) -add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc ${PROJECT_SOURCE_DIR}/uie.cc) +add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc) target_link_libraries(infer_demo ${FASTDEPLOY_LIBS}) diff --git a/examples/text/uie/cpp/infer.cc b/examples/text/uie/cpp/infer.cc index fd81b88bc..9963ad644 100644 --- a/examples/text/uie/cpp/infer.cc +++ b/examples/text/uie/cpp/infer.cc @@ -13,12 +13,9 @@ // limitations under the License. #include #include +#include -#include "fastdeploy/function/reduce.h" -#include "fastdeploy/function/softmax.h" #include "fastdeploy/text.h" -#include "faster_tokenizer/tokenizers/ernie_faster_tokenizer.h" -#include "uie.h" using namespace paddlenlp; @@ -48,9 +45,12 @@ int main(int argc, char* argv[]) { std::string model_path = model_dir + sep + "inference.pdmodel"; std::string param_path = model_dir + sep + "inference.pdiparams"; std::string vocab_path = model_dir + sep + "vocab.txt"; + using fastdeploy::text::SchemaNode; + using fastdeploy::text::UIEResult; - auto predictor = UIEModel(model_path, param_path, vocab_path, 0.5, 128, - {"时间", "选手", "赛事名称"}, option); + auto predictor = + fastdeploy::text::UIEModel(model_path, param_path, vocab_path, 0.5, 128, + {"时间", "选手", "赛事名称"}, option); fastdeploy::FDINFO << "After init predictor" << std::endl; std::vector>> results; // Named Entity Recognition