diff --git a/.clang-format b/.clang-format
index c91ec19fb1e..4ea70510d26 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,180 +1,180 @@
-# ---
-# Language: Cpp
-# # BasedOnStyle: LLVM
-# AccessModifierOffset: -1
-# AlignAfterOpenBracket: Align
-# AlignArrayOfStructures: None
-# AlignConsecutiveMacros: None
-# AlignConsecutiveAssignments: None
-# AlignConsecutiveBitFields: None
-# AlignConsecutiveDeclarations: None
-# AlignEscapedNewlines: Right
-# AlignOperands: Align
-# AlignTrailingComments: true
-# AllowAllArgumentsOnNextLine: true
-# AllowAllConstructorInitializersOnNextLine: true
-# AllowAllParametersOfDeclarationOnNextLine: true
-# AllowShortEnumsOnASingleLine: true
-# AllowShortBlocksOnASingleLine: Never
-# AllowShortCaseLabelsOnASingleLine: false
-# AllowShortFunctionsOnASingleLine: All
-# AllowShortLambdasOnASingleLine: All
-# AllowShortIfStatementsOnASingleLine: Never
-# AllowShortLoopsOnASingleLine: false
-# AlwaysBreakAfterDefinitionReturnType: None
-# AlwaysBreakAfterReturnType: None
-# AlwaysBreakBeforeMultilineStrings: false
-# AlwaysBreakTemplateDeclarations: MultiLine
-# AttributeMacros:
-# - __capability
-# BinPackArguments: true
-# BinPackParameters: true
-# BraceWrapping:
-# AfterCaseLabel: false
-# AfterClass: false
-# AfterControlStatement: Never
-# AfterEnum: false
-# AfterFunction: false
-# AfterNamespace: false
-# AfterObjCDeclaration: false
-# AfterStruct: false
-# AfterUnion: false
-# AfterExternBlock: false
-# BeforeCatch: false
-# BeforeElse: false
-# BeforeLambdaBody: false
-# BeforeWhile: false
-# IndentBraces: false
-# SplitEmptyFunction: true
-# SplitEmptyRecord: true
-# SplitEmptyNamespace: true
-# BreakBeforeBinaryOperators: None
-# BreakBeforeConceptDeclarations: true
-# BreakBeforeBraces: Attach
-# BreakBeforeInheritanceComma: false
-# BreakInheritanceList: BeforeColon
-# BreakBeforeTernaryOperators: true
-# BreakConstructorInitializersBeforeComma: false
-# BreakConstructorInitializers: BeforeColon
-# BreakAfterJavaFieldAnnotations: false
-# BreakStringLiterals: true
-# ColumnLimit: 80
-# # CommentPragmas: '^ IWYU pragma:'
-# # CommentPragmas: '^[^ ]'
-# CommentPragmas: '^\\.+'
-# CompactNamespaces: false
-# ConstructorInitializerAllOnOneLineOrOnePerLine: false
-# ConstructorInitializerIndentWidth: 4
-# ContinuationIndentWidth: 4
-# Cpp11BracedListStyle: true
-# DeriveLineEnding: true
-# DerivePointerAlignment: false
-# DisableFormat: false
-# EmptyLineAfterAccessModifier: Never
-# EmptyLineBeforeAccessModifier: LogicalBlock
-# ExperimentalAutoDetectBinPacking: false
-# FixNamespaceComments: true
-# ForEachMacros:
-# - foreach
-# - Q_FOREACH
-# - BOOST_FOREACH
-# IfMacros:
-# - KJ_IF_MAYBE
-# IncludeBlocks: Preserve
-# IncludeCategories:
-# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
-# Priority: 2
-# SortPriority: 0
-# CaseSensitive: false
-# - Regex: '^(<|"(gtest|gmock|isl|json)/)'
-# Priority: 3
-# SortPriority: 0
-# CaseSensitive: false
-# - Regex: '.*'
-# Priority: 1
-# SortPriority: 0
-# CaseSensitive: false
-# IncludeIsMainRegex: '(Test)?$'
-# IncludeIsMainSourceRegex: ''
-# IndentAccessModifiers: false
-# IndentCaseLabels: false
-# IndentCaseBlocks: false
-# IndentGotoLabels: true
-# IndentPPDirectives: None
-# IndentExternBlock: AfterExternBlock
-# IndentRequires: false
-# IndentWidth: 2
-# IndentWrappedFunctionNames: false
-# InsertTrailingCommas: None
-# JavaScriptQuotes: Leave
-# JavaScriptWrapImports: true
-# KeepEmptyLinesAtTheStartOfBlocks: true
-# LambdaBodyIndentation: Signature
-# MacroBlockBegin: ''
-# MacroBlockEnd: ''
-# MaxEmptyLinesToKeep: 1
-# NamespaceIndentation: None
-# ObjCBinPackProtocolList: Auto
-# ObjCBlockIndentWidth: 2
-# ObjCBreakBeforeNestedBlockParam: true
-# ObjCSpaceAfterProperty: false
-# ObjCSpaceBeforeProtocolList: true
-# PenaltyBreakAssignment: 2
-# PenaltyBreakBeforeFirstCallParameter: 19
-# PenaltyBreakComment: 300
-# PenaltyBreakFirstLessLess: 120
-# PenaltyBreakString: 1000
-# PenaltyBreakTemplateDeclaration: 10
-# PenaltyExcessCharacter: 1000000
-# PenaltyReturnTypeOnItsOwnLine: 60
-# PenaltyIndentedWhitespace: 0
-# PointerAlignment: Left
-# PPIndentWidth: -1
-# ReferenceAlignment: Pointer
-# ReflowComments: false
-# ShortNamespaceLines: 1
-# SortIncludes: CaseSensitive
-# SortJavaStaticImport: Before
-# SortUsingDeclarations: true
-# SpaceAfterCStyleCast: false
-# SpaceAfterLogicalNot: false
-# SpaceAfterTemplateKeyword: true
-# SpaceBeforeAssignmentOperators: true
-# SpaceBeforeCaseColon: false
-# SpaceBeforeCpp11BracedList: false
-# SpaceBeforeCtorInitializerColon: true
-# SpaceBeforeInheritanceColon: true
-# SpaceBeforeParens: ControlStatements
-# SpaceAroundPointerQualifiers: Default
-# SpaceBeforeRangeBasedForLoopColon: true
-# SpaceInEmptyBlock: false
-# SpaceInEmptyParentheses: false
-# SpacesBeforeTrailingComments: 2
-# SpacesInAngles: Never
-# SpacesInConditionalStatement: false
-# SpacesInContainerLiterals: true
-# SpacesInCStyleCastParentheses: false
-# SpacesInLineCommentPrefix:
-# Minimum: 1
-# Maximum: -1
-# SpacesInParentheses: false
-# SpacesInSquareBrackets: false
-# SpaceBeforeSquareBrackets: false
-# BitFieldColonSpacing: Both
-# Standard: Latest
-# StatementAttributeLikeMacros:
-# - Q_EMIT
-# StatementMacros:
-# - Q_UNUSED
-# - QT_REQUIRE_VERSION
-# TabWidth: 8
-# UseCRLF: false
-# UseTab: Never
-# WhitespaceSensitiveMacros:
-# - STRINGIZE
-# - PP_STRINGIZE
-# - BOOST_PP_STRINGIZE
-# - NS_SWIFT_NAME
-# - CF_SWIFT_NAME
-# ...
-#
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -1
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveMacros: None
+AlignConsecutiveAssignments: None
+AlignConsecutiveBitFields: None
+AlignConsecutiveDeclarations: None
+AlignEscapedNewlines: Right
+AlignOperands: Align
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: true
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortEnumsOnASingleLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: All
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: MultiLine
+AttributeMacros:
+ - __capability
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterControlStatement: Never
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ BeforeLambdaBody: false
+ BeforeWhile: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: true
+BreakBeforeBraces: Attach
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 80
+# CommentPragmas: '^ IWYU pragma:'
+# CommentPragmas: '^[^ ]'
+CommentPragmas: '^\\.+'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat: false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IfMacros:
+ - KJ_IF_MAYBE
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ SortPriority: 0
+ CaseSensitive: false
+ - Regex: '.*'
+ Priority: 1
+ SortPriority: 0
+ CaseSensitive: false
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: false
+IndentCaseBlocks: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentExternBlock: AfterExternBlock
+IndentRequires: false
+IndentWidth: 2
+IndentWrappedFunctionNames: false
+InsertTrailingCommas: None
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+LambdaBodyIndentation: Signature
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PenaltyIndentedWhitespace: 0
+PointerAlignment: Left
+PPIndentWidth: -1
+ReferenceAlignment: Pointer
+ReflowComments: false
+ShortNamespaceLines: 1
+SortIncludes: CaseSensitive
+SortJavaStaticImport: Before
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+ Minimum: 1
+ Maximum: -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+BitFieldColonSpacing: Both
+Standard: Latest
+StatementAttributeLikeMacros:
+ - Q_EMIT
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 8
+UseCRLF: false
+UseTab: Never
+WhitespaceSensitiveMacros:
+ - STRINGIZE
+ - PP_STRINGIZE
+ - BOOST_PP_STRINGIZE
+ - NS_SWIFT_NAME
+ - CF_SWIFT_NAME
+...
+
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0a9168eea21..3e60016ef96 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -24,14 +24,14 @@ repos:
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$
exclude: (?!.*third_party)^.*$
-# - repo: local
-# hooks:
-# - id: clang-format-with-version-check
-# name: clang-format
-# description: Format files with ClangFormat.
-# entry: bash .clang_format.hook -i
-# language: system
-# files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto)$
+- repo: local
+ hooks:
+ - id: clang-format-with-version-check
+ name: clang-format
+ description: Format files with ClangFormat.
+ entry: bash .clang_format.hook -i
+ language: system
+ files: \.(c|cc|cxx|cpp|cu|hxx|proto)$
- repo: local
hooks:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 549d7b708d6..42bc600bb89 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@
PROJECT(fastdeploy C CXX)
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
option(CSRCS_DIR_NAME "Name of source code directory")
option(LIBRARY_NAME "Name of build library name")
option(PY_LIBRARY_NAME "Name of build python library name")
@@ -60,10 +61,12 @@ option(ENABLE_PADDLE_BACKEND "Whether to enable paddle backend." OFF)
option(ENABLE_POROS_BACKEND "Whether to enable poros backend." OFF)
option(ENABLE_OPENVINO_BACKEND "Whether to enable openvino backend." OFF)
option(ENABLE_RKNPU2_BACKEND "Whether to enable RKNPU2 backend." OFF)
+option(ENABLE_SOPHGO_BACKEND "Whether to enable SOPHON backend." OFF)
option(ENABLE_LITE_BACKEND "Whether to enable paddle lite backend." OFF)
option(ENABLE_VISION "Whether to enable vision models usage." OFF)
option(ENABLE_TEXT "Whether to enable text models usage." OFF)
option(ENABLE_FLYCV "Whether to enable flycv to boost image preprocess." OFF)
+option(ENABLE_ENCRYPTION "Whether to enable ENCRYPTION." OFF)
option(WITH_ASCEND "Whether to compile for Huawei Ascend deploy." OFF)
option(WITH_TIMVX "Whether to compile for TIMVX deploy." OFF)
option(WITH_KUNLUNXIN "Whether to compile for KunlunXin XPU deploy." OFF)
@@ -193,13 +196,15 @@ file(GLOB_RECURSE DEPLOY_POROS_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fast
file(GLOB_RECURSE DEPLOY_TRT_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/*.cc ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/*.cpp)
file(GLOB_RECURSE DEPLOY_OPENVINO_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/openvino/*.cc)
file(GLOB_RECURSE DEPLOY_RKNPU2_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/rknpu/rknpu2/*.cc)
+file(GLOB_RECURSE DEPLOY_SOPHGO_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/sophgo/*.cc)
file(GLOB_RECURSE DEPLOY_LITE_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/lite/*.cc)
file(GLOB_RECURSE DEPLOY_VISION_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/vision/*.cc)
+file(GLOB_RECURSE DEPLOY_ENCRYPTION_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/encryption/*.cc)
file(GLOB_RECURSE DEPLOY_PIPELINE_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/pipeline/*.cc)
file(GLOB_RECURSE DEPLOY_VISION_CUDA_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/vision/*.cu)
file(GLOB_RECURSE DEPLOY_TEXT_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/text/*.cc)
file(GLOB_RECURSE DEPLOY_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/pybind/*.cc ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/*_pybind.cc)
-list(REMOVE_ITEM ALL_DEPLOY_SRCS ${DEPLOY_ORT_SRCS} ${DEPLOY_PADDLE_SRCS} ${DEPLOY_POROS_SRCS} ${DEPLOY_TRT_SRCS} ${DEPLOY_OPENVINO_SRCS} ${DEPLOY_LITE_SRCS} ${DEPLOY_VISION_SRCS} ${DEPLOY_TEXT_SRCS} ${DEPLOY_PIPELINE_SRCS} ${DEPLOY_RKNPU2_SRCS})
+list(REMOVE_ITEM ALL_DEPLOY_SRCS ${DEPLOY_ORT_SRCS} ${DEPLOY_PADDLE_SRCS} ${DEPLOY_POROS_SRCS} ${DEPLOY_TRT_SRCS} ${DEPLOY_OPENVINO_SRCS} ${DEPLOY_LITE_SRCS} ${DEPLOY_VISION_SRCS} ${DEPLOY_TEXT_SRCS} ${DEPLOY_PIPELINE_SRCS} ${DEPLOY_RKNPU2_SRCS} ${DEPLOY_SOPHGO_SRCS} ${DEPLOY_ENCRYPTION_SRCS})
set(DEPEND_LIBS "")
@@ -240,12 +245,12 @@ if(ENABLE_PADDLE_BACKEND)
add_definitions(-DENABLE_PADDLE_BACKEND)
list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_PADDLE_SRCS})
include(${PROJECT_SOURCE_DIR}/cmake/paddle_inference.cmake)
- if(NOT APPLE)
- list(APPEND DEPEND_LIBS external_paddle_inference external_dnnl external_omp)
- else()
- # no third parties libs(mkldnn and omp) need to
- # link into paddle_inference on MacOS OSX.
- list(APPEND DEPEND_LIBS external_paddle_inference)
+ list(APPEND DEPEND_LIBS external_paddle_inference)
+ if(external_dnnl_FOUND)
+ list(APPEND DEPEND_LIBS external_dnnl external_omp)
+ endif()
+ if(external_ort_FOUND)
+ list(APPEND DEPEND_LIBS external_p2o external_ort)
endif()
endif()
@@ -263,6 +268,13 @@ if(ENABLE_RKNPU2_BACKEND)
list(APPEND DEPEND_LIBS ${RKNN_RT_LIB})
endif()
+if(ENABLE_SOPHGO_BACKEND)
+ add_definitions(-DENABLE_SOPHGO_BACKEND)
+ list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_SOPHGO_SRCS})
+ include(${PROJECT_SOURCE_DIR}/cmake/sophgo.cmake)
+ list(APPEND DEPEND_LIBS ${SOPHGO_RT_LIB})
+endif()
+
if(ENABLE_POROS_BACKEND)
set(CMAKE_CXX_STANDARD 14)
add_definitions(-DENABLE_POROS_BACKEND)
@@ -387,9 +399,9 @@ if(ENABLE_TRT_BACKEND)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Copying ${TRT_DIRECTORY}/lib to ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib ...")
execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/copy_directory.py ${TRT_DIRECTORY}/lib ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib)
- file(GLOB_RECURSE TRT_STAIC_LIBS ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib/*.a)
+ file(GLOB_RECURSE TRT_STATIC_LIBS ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib/*.a)
if(TRT_STATIC_LIBS)
- file(REMOVE ${TRT_STAIC_LIBS})
+ file(REMOVE ${TRT_STATIC_LIBS})
endif()
if(UNIX AND (NOT APPLE) AND (NOT ANDROID))
execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib
@@ -441,6 +453,14 @@ if(ENABLE_TEXT)
include(${PROJECT_SOURCE_DIR}/cmake/fast_tokenizer.cmake)
endif()
+if(ENABLE_ENCRYPTION)
+ add_definitions(-DENABLE_ENCRYPTION)
+ list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_ENCRYPTION_SRCS})
+ include(${PROJECT_SOURCE_DIR}/cmake/gflags.cmake)
+ include(${PROJECT_SOURCE_DIR}/cmake/openssl.cmake)
+ list(APPEND DEPEND_LIBS ${OPENSSL_LIBRARIES})
+endif()
+
if(ENABLE_PADDLE_FRONTEND)
add_definitions(-DENABLE_PADDLE_FRONTEND)
include(${PROJECT_SOURCE_DIR}/cmake/paddle2onnx.cmake)
@@ -653,6 +673,11 @@ if(BUILD_FASTDEPLOY_PYTHON)
list(REMOVE_ITEM DEPLOY_PYBIND_SRCS ${VISION_PYBIND_SRCS} ${PIPELINE_PYBIND_SRCS})
endif()
+ if(NOT ENABLE_ENCRYPTION)
+ file(GLOB_RECURSE ENCRYPTION_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/encryption/*_pybind.cc)
+ list(REMOVE_ITEM DEPLOY_PYBIND_SRCS ${ENCRYPTION_PYBIND_SRCS})
+ endif()
+
if (NOT ENABLE_TEXT)
file(GLOB_RECURSE TEXT_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/text/*_pybind.cc)
list(REMOVE_ITEM DEPLOY_PYBIND_SRCS ${TEXT_PYBIND_SRCS})
diff --git a/FastDeploy.cmake.in b/FastDeploy.cmake.in
index 456a4d3217f..6ba0b430781 100755
--- a/FastDeploy.cmake.in
+++ b/FastDeploy.cmake.in
@@ -3,6 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
set(WITH_GPU @WITH_GPU@)
set(ENABLE_ORT_BACKEND @ENABLE_ORT_BACKEND@)
set(ENABLE_RKNPU2_BACKEND @ENABLE_RKNPU2_BACKEND@)
+set(ENABLE_SOPHGO_BACKEND @ENABLE_SOPHGO_BACKEND@)
set(ENABLE_LITE_BACKEND @ENABLE_LITE_BACKEND@)
set(ENABLE_PADDLE_BACKEND @ENABLE_PADDLE_BACKEND@)
set(ENABLE_OPENVINO_BACKEND @ENABLE_OPENVINO_BACKEND@)
@@ -13,6 +14,7 @@ set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
set(ENABLE_VISION @ENABLE_VISION@)
set(ENABLE_FLYCV @ENABLE_FLYCV@)
set(ENABLE_TEXT @ENABLE_TEXT@)
+set(ENABLE_ENCRYPTION @ENABLE_ENCRYPTION@)
set(BUILD_ON_JETSON @BUILD_ON_JETSON@)
set(PADDLEINFERENCE_VERSION @PADDLEINFERENCE_VERSION@)
set(OPENVINO_VERSION @OPENVINO_VERSION@)
@@ -74,10 +76,9 @@ if(ENABLE_PADDLE_BACKEND)
set(DNNL_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mkldnn/lib/libmkldnn.so.0")
set(IOMP_LIB "${CMAKE_CURRENT_LIST_DIR}/third_libs/install/paddle_inference/third_party/install/mklml/lib/libiomp5.so")
endif()
- if(NOT APPLE)
- list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB} ${DNNL_LIB} ${IOMP_LIB})
- else()
- list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB})
+ list(APPEND FASTDEPLOY_LIBS ${PADDLE_LIB})
+ if(EXISTS "${DNNL_LIB}")
+ list(APPEND FASTDEPLOY_LIBS ${DNNL_LIB} ${IOMP_LIB})
endif()
endif()
@@ -271,6 +272,7 @@ message(STATUS " CXX flags : ${CMAKE_CXX_FLAGS}")
message(STATUS " WITH_GPU : ${WITH_GPU}")
message(STATUS " ENABLE_ORT_BACKEND : ${ENABLE_ORT_BACKEND}")
message(STATUS " ENABLE_RKNPU2_BACKEND : ${ENABLE_RKNPU2_BACKEND}")
+message(STATUS " ENABLE_SOPHGO_BACKEND : ${ENABLE_SOPHGO_BACKEND}")
message(STATUS " ENABLE_PADDLE_BACKEND : ${ENABLE_PADDLE_BACKEND}")
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
message(STATUS " ENABLE_OPENVINO_BACKEND : ${ENABLE_OPENVINO_BACKEND}")
@@ -288,6 +290,7 @@ endif()
message(STATUS " ENABLE_TRT_BACKEND : ${ENABLE_TRT_BACKEND}")
message(STATUS " ENABLE_VISION : ${ENABLE_VISION}")
message(STATUS " ENABLE_TEXT : ${ENABLE_TEXT}")
+message(STATUS " ENABLE_ENCRYPTION : ${ENABLE_ENCRYPTION}")
if(WITH_GPU)
message(STATUS " CUDA_DIRECTORY : ${CUDA_DIRECTORY}")
endif()
diff --git a/README.md b/README.md
index e8f014f6ffd..b1dd06cd5cb 120000
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-README_CN.md
+README_EN.md
diff --git a/README_CN.md b/README_CN.md
index 886118c2ee3..251f019a6ab 100755
--- a/README_CN.md
+++ b/README_CN.md
@@ -274,7 +274,7 @@ int main(int argc, char* argv[]) {
| 任务场景 | 模型 | 大小(MB) | Linux | Android | Linux | Linux | Linux | Linux | Linux | 更新中... |
|:------------------:|:-----------------------------------------------------------------------------------------:|:--------:|:-------:|:-------:|:-------:|:-----------------------:|:------------------------------:|:---------------------------:|:--------------------------------:|:-------:|
-| --- | --- | --- | ARM CPU | [ARM CPU](./java/android) | [瑞芯微NPU
RK3568/RK3588](./docs/cn/build_and_install/rknpu2.md) | [瑞芯微NPU
RV1109/RV1126/RK1808](./docs/cn/build_and_install/rv1126.md) | [晶晨NPU
A311D/S905D/C308X](./docs/cn/build_and_install/a311d.md) | 恩智浦NPU
i.MX 8M Plus | 更新中...| |
+| --- | --- | --- | ARM CPU | [ARM CPU](./java/android) | [瑞芯微NPU
RK3588/RK3568/RK3566](./docs/cn/build_and_install/rknpu2.md) | [瑞芯微NPU
RV1109/RV1126/RK1808](./docs/cn/build_and_install/rv1126.md) | [晶晨NPU
A311D/S905D/C308X](./docs/cn/build_and_install/a311d.md) | 恩智浦NPU
i.MX 8M Plus | 更新中...| |
| Classification | [PaddleClas/ResNet50](examples/vision/classification/paddleclas) | 98 | ✅ | ✅ | [✅](./examples/vision/classification/paddleclas/rknpu2) | ✅ | | | |
| Classification | [PaddleClas/PP-LCNet](examples/vision/classification/paddleclas) | 11.9 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- |
| Classification | [PaddleClas/PP-LCNetv2](examples/vision/classification/paddleclas) | 26.6 | ✅ | ✅ | ❔ | ✅ | -- | -- | -- |
diff --git a/benchmark/benchmark_uie.py b/benchmark/benchmark_uie.py
new file mode 100644
index 00000000000..44c562d7e66
--- /dev/null
+++ b/benchmark/benchmark_uie.py
@@ -0,0 +1,321 @@
+import numpy as np
+import os
+import time
+import distutils.util
+import sys
+import json
+
+import fastdeploy as fd
+from fastdeploy.text import UIEModel, SchemaLanguage
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="The directory of model and tokenizer.")
+ parser.add_argument(
+ "--data_path", required=True, help="The path of uie data.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ choices=['gpu', 'cpu'],
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--backend",
+ type=str,
+ default='paddle',
+ choices=['ort', 'paddle', 'trt', 'paddle_trt', 'ov'],
+ help="The inference runtime backend.")
+ parser.add_argument(
+ "--device_id", type=int, default=0, help="device(gpu) id")
+ parser.add_argument(
+ "--batch_size", type=int, default=1, help="The batch size of data.")
+ parser.add_argument(
+ "--max_length",
+ type=int,
+ default=128,
+ help="The max length of sequence.")
+ parser.add_argument(
+ "--cpu_num_threads",
+ type=int,
+ default=8,
+ help="The number of threads when inferring on cpu.")
+ parser.add_argument(
+ "--enable_trt_fp16",
+ type=distutils.util.strtobool,
+ default=False,
+ help="whether enable fp16 in trt backend")
+ parser.add_argument(
+ "--epoch", type=int, default=1, help="The epoch of test")
+ parser.add_argument(
+ "--enable_collect_memory_info",
+ type=ast.literal_eval,
+ default=False,
+ help="whether enable collect memory info")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device == 'cpu':
+ option.use_cpu()
+ option.set_cpu_thread_num(args.cpu_num_threads)
+ else:
+ option.use_gpu(args.device_id)
+ if args.backend == 'paddle':
+ option.use_paddle_backend()
+ elif args.backend == 'ort':
+ option.use_ort_backend()
+ elif args.backend == 'ov':
+ option.use_openvino_backend()
+ else:
+ option.use_trt_backend()
+ if args.backend == 'paddle_trt':
+ option.enable_paddle_to_trt()
+ option.enable_paddle_trt_collect_shape()
+ trt_file = os.path.join(args.model_dir, "infer.trt")
+ option.set_trt_input_shape(
+ 'input_ids',
+ min_shape=[1, 1],
+ opt_shape=[args.batch_size, args.max_length // 2],
+ max_shape=[args.batch_size, args.max_length])
+ option.set_trt_input_shape(
+ 'token_type_ids',
+ min_shape=[1, 1],
+ opt_shape=[args.batch_size, args.max_length // 2],
+ max_shape=[args.batch_size, args.max_length])
+ option.set_trt_input_shape(
+ 'pos_ids',
+ min_shape=[1, 1],
+ opt_shape=[args.batch_size, args.max_length // 2],
+ max_shape=[args.batch_size, args.max_length])
+ option.set_trt_input_shape(
+ 'att_mask',
+ min_shape=[1, 1],
+ opt_shape=[args.batch_size, args.max_length // 2],
+ max_shape=[args.batch_size, args.max_length])
+ if args.enable_trt_fp16:
+ option.enable_trt_fp16()
+ trt_file = trt_file + ".fp16"
+ option.set_trt_cache_file(trt_file)
+ return option
+
+
+class StatBase(object):
+ """StatBase"""
+ nvidia_smi_path = "nvidia-smi"
+ gpu_keys = ('index', 'uuid', 'name', 'timestamp', 'memory.total',
+ 'memory.free', 'memory.used', 'utilization.gpu',
+ 'utilization.memory')
+ nu_opt = ',nounits'
+ cpu_keys = ('cpu.util', 'memory.util', 'memory.used')
+
+
+class Monitor(StatBase):
+ """Monitor"""
+
+ def __init__(self, use_gpu=False, gpu_id=0, interval=0.1):
+ self.result = {}
+ self.gpu_id = gpu_id
+ self.use_gpu = use_gpu
+ self.interval = interval
+ self.cpu_stat_q = multiprocessing.Queue()
+
+ def start(self):
+ cmd = '%s --id=%s --query-gpu=%s --format=csv,noheader%s -lms 50' % (
+ StatBase.nvidia_smi_path, self.gpu_id, ','.join(StatBase.gpu_keys),
+ StatBase.nu_opt)
+ if self.use_gpu:
+ self.gpu_stat_worker = subprocess.Popen(
+ cmd,
+ stderr=subprocess.STDOUT,
+ stdout=subprocess.PIPE,
+ shell=True,
+ close_fds=True,
+ preexec_fn=os.setsid)
+ # cpu stat
+ pid = os.getpid()
+ self.cpu_stat_worker = multiprocessing.Process(
+ target=self.cpu_stat_func,
+ args=(self.cpu_stat_q, pid, self.interval))
+ self.cpu_stat_worker.start()
+
+ def stop(self):
+ try:
+ if self.use_gpu:
+ os.killpg(self.gpu_stat_worker.pid, signal.SIGUSR1)
+ # os.killpg(p.pid, signal.SIGTERM)
+ self.cpu_stat_worker.terminate()
+ self.cpu_stat_worker.join(timeout=0.01)
+ except Exception as e:
+ print(e)
+ return
+
+ # gpu
+ if self.use_gpu:
+ lines = self.gpu_stat_worker.stdout.readlines()
+ lines = [
+ line.strip().decode("utf-8") for line in lines
+ if line.strip() != ''
+ ]
+ gpu_info_list = [{
+ k: v
+ for k, v in zip(StatBase.gpu_keys, line.split(', '))
+ } for line in lines]
+ if len(gpu_info_list) == 0:
+ return
+ result = gpu_info_list[0]
+ for item in gpu_info_list:
+ for k in item.keys():
+ if k not in ["name", "uuid", "timestamp"]:
+ result[k] = max(int(result[k]), int(item[k]))
+ else:
+ result[k] = max(result[k], item[k])
+ self.result['gpu'] = result
+
+ # cpu
+ cpu_result = {}
+ if self.cpu_stat_q.qsize() > 0:
+ cpu_result = {
+ k: v
+ for k, v in zip(StatBase.cpu_keys, self.cpu_stat_q.get())
+ }
+ while not self.cpu_stat_q.empty():
+ item = {
+ k: v
+ for k, v in zip(StatBase.cpu_keys, self.cpu_stat_q.get())
+ }
+ for k in StatBase.cpu_keys:
+ cpu_result[k] = max(cpu_result[k], item[k])
+ cpu_result['name'] = cpuinfo.get_cpu_info()['brand_raw']
+ self.result['cpu'] = cpu_result
+
+ def output(self):
+ return self.result
+
+ def cpu_stat_func(self, q, pid, interval=0.0):
+ """cpu stat function"""
+ stat_info = psutil.Process(pid)
+ while True:
+ # pid = os.getpid()
+ cpu_util, mem_util, mem_use = stat_info.cpu_percent(
+ ), stat_info.memory_percent(), round(stat_info.memory_info().rss /
+ 1024.0 / 1024.0, 4)
+ q.put([cpu_util, mem_util, mem_use])
+ time.sleep(interval)
+ return
+
+
+def get_dataset(data_path, max_seq_len=512):
+ json_lines = []
+ with open(data_path, 'r', encoding='utf-8') as f:
+ for line in f:
+ json_line = json.loads(line)
+ content = json_line['content'].strip()
+ prompt = json_line['prompt']
+ # Model Input is aslike: [CLS] Prompt [SEP] Content [SEP]
+ # It include three summary tokens.
+ if max_seq_len <= len(prompt) + 3:
+ raise ValueError(
+ "The value of max_seq_len is too small, please set a larger value"
+ )
+ json_lines.append(json_line)
+
+ return json_lines
+
+
+if __name__ == '__main__':
+ args = parse_arguments()
+ runtime_option = build_option(args)
+ model_path = os.path.join(args.model_dir, "inference.pdmodel")
+ param_path = os.path.join(args.model_dir, "inference.pdiparams")
+ vocab_path = os.path.join(args.model_dir, "vocab.txt")
+
+ gpu_id = args.device_id
+ enable_collect_memory_info = args.enable_collect_memory_info
+ dump_result = dict()
+ end2end_statis = list()
+ cpu_mem = list()
+ gpu_mem = list()
+ gpu_util = list()
+ if args.device == "cpu":
+ file_path = args.model_dir + "_model_" + args.backend + "_" + \
+ args.device + "_" + str(args.cpu_num_threads) + ".txt"
+ else:
+ if args.enable_trt_fp16:
+ file_path = args.model_dir + "_model_" + \
+ args.backend + "_fp16_" + args.device + ".txt"
+ else:
+ file_path = args.model_dir + "_model_" + args.backend + "_" + args.device + ".txt"
+ f = open(file_path, "w")
+ f.writelines("===={}====: \n".format(os.path.split(file_path)[-1][:-4]))
+
+ ds = get_dataset(args.data_path)
+ schema = ["时间"]
+ uie = UIEModel(
+ model_path,
+ param_path,
+ vocab_path,
+ position_prob=0.5,
+ max_length=args.max_length,
+ batch_size=args.batch_size,
+ schema=schema,
+ runtime_option=runtime_option,
+ schema_language=SchemaLanguage.ZH)
+
+ try:
+ if enable_collect_memory_info:
+ import multiprocessing
+ import subprocess
+ import psutil
+ import signal
+ import cpuinfo
+ enable_gpu = args.device == "gpu"
+ monitor = Monitor(enable_gpu, gpu_id)
+ monitor.start()
+ uie.enable_record_time_of_runtime()
+
+ for ep in range(args.epoch):
+ for i, sample in enumerate(ds):
+ curr_start = time.time()
+ uie.set_schema([sample['prompt']])
+ result = uie.predict([sample['content']])
+ end2end_statis.append(time.time() - curr_start)
+ runtime_statis = uie.print_statis_info_of_runtime()
+
+ warmup_iter = args.epoch * len(ds) // 5
+
+ end2end_statis_repeat = end2end_statis[warmup_iter:]
+ if enable_collect_memory_info:
+ monitor.stop()
+ mem_info = monitor.output()
+ dump_result["cpu_rss_mb"] = mem_info['cpu'][
+ 'memory.used'] if 'cpu' in mem_info else 0
+ dump_result["gpu_rss_mb"] = mem_info['gpu'][
+ 'memory.used'] if 'gpu' in mem_info else 0
+ dump_result["gpu_util"] = mem_info['gpu'][
+ 'utilization.gpu'] if 'gpu' in mem_info else 0
+
+ dump_result["runtime"] = runtime_statis["avg_time"] * 1000
+ dump_result["end2end"] = np.mean(end2end_statis_repeat) * 1000
+
+ time_cost_str = f"Runtime(ms): {dump_result['runtime']}\n" \
+ f"End2End(ms): {dump_result['end2end']}\n"
+ f.writelines(time_cost_str)
+ print(time_cost_str)
+
+ if enable_collect_memory_info:
+ mem_info_str = f"cpu_rss_mb: {dump_result['cpu_rss_mb']}\n" \
+ f"gpu_rss_mb: {dump_result['gpu_rss_mb']}\n" \
+ f"gpu_util: {dump_result['gpu_util']}\n"
+ f.writelines(mem_info_str)
+ print(mem_info_str)
+ except:
+ f.writelines("!!!!!Infer Failed\n")
+
+ f.close()
diff --git a/benchmark/run_benchmark_uie.sh b/benchmark/run_benchmark_uie.sh
new file mode 100644
index 00000000000..51eb5d97328
--- /dev/null
+++ b/benchmark/run_benchmark_uie.sh
@@ -0,0 +1,27 @@
+# wget https://bj.bcebos.com/fastdeploy/benchmark/uie/reimbursement_form_data.txt
+# wget https://bj.bcebos.com/fastdeploy/models/uie/uie-base.tgz
+# tar xvfz uie-base.tgz
+
+DEVICE_ID=0
+
+echo "[FastDeploy] Running UIE benchmark..."
+
+# GPU
+echo "-------------------------------GPU Benchmark---------------------------------------"
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend paddle --device_id $DEVICE_ID --device gpu --enable_collect_memory_info True
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend ort --device_id $DEVICE_ID --device gpu --enable_collect_memory_info True
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend paddle_trt --device_id $DEVICE_ID --device gpu --enable_trt_fp16 False --enable_collect_memory_info True
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend trt --device_id $DEVICE_ID --device gpu --enable_trt_fp16 False --enable_collect_memory_info True
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend paddle_trt --device_id $DEVICE_ID --device gpu --enable_trt_fp16 True --enable_collect_memory_info True
+python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend trt --device_id $DEVICE_ID --device gpu --enable_trt_fp16 True --enable_collect_memory_info True
+echo "-----------------------------------------------------------------------------------"
+
+# CPU
+echo "-------------------------------CPU Benchmark---------------------------------------"
+for cpu_num_threads in 1 8;
+do
+ python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend paddle --device cpu --cpu_num_threads ${cpu_num_threads} --enable_collect_memory_info True
+ python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend ort --device cpu --cpu_num_threads ${cpu_num_threads} --enable_collect_memory_info True
+ python benchmark_uie.py --epoch 5 --model_dir uie-base --data_path reimbursement_form_data.txt --backend ov --device cpu --cpu_num_threads ${cpu_num_threads} --enable_collect_memory_info True
+done
+echo "-----------------------------------------------------------------------------------"
diff --git a/cmake/ascend.cmake b/cmake/ascend.cmake
index 01582d4186e..ed5aa5d933c 100644
--- a/cmake/ascend.cmake
+++ b/cmake/ascend.cmake
@@ -16,13 +16,4 @@ else ()
if(NOT PADDLELITE_URL)
set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/test/lite-linux_arm64_huawei_ascend_npu_python_1207.tgz")
endif()
- execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib
- COMMAND sh -c "xargs ${PATCHELF_EXE} --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/paddlelite/lib
- RESULT_VARIABLE result
- OUTPUT_VARIABLE curr_out
- ERROR_VARIABLE curr_out)
- if(ret EQUAL "1")
- message(FATAL_ERROR "Failed to patchelf Paddle Lite libraries when using Ascend.")
- endif()
- message(STATUS "result:${result} out:${curr_out}")
endif()
diff --git a/cmake/openssl.cmake b/cmake/openssl.cmake
new file mode 100755
index 00000000000..2d7eb4402c0
--- /dev/null
+++ b/cmake/openssl.cmake
@@ -0,0 +1,50 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
+SET(OPENSSL_URL_PREFIX "https://bj.bcebos.com/paddlex/tools")
+IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(OPENSSL_FILENAME "windows_openssl-1.1.0k")
+ set(COMPRESSED_SUFFIX ".zip")
+ add_definitions(-DWIN32)
+ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(OPENSSL_FILENAME "openssl-1.1.0k")
+ set(COMPRESSED_SUFFIX ".tar.gz")
+ add_definitions(-DLINUX)
+ENDIF()
+set(OPENSSL_URL ${OPENSSL_URL_PREFIX}/${OPENSSL_FILENAME}${COMPRESSED_SUFFIX})
+if(THIRD_PARTY_PATH)
+ SET(OPENSSL_INSTALL_DIR ${THIRD_PARTY_PATH})
+ SET(OPENSSL_ROOT_DIR ${THIRD_PARTY_PATH}/openssl-1.1.0k/install-${CMAKE_SYSTEM_PROCESSOR})
+else()
+ SET(OPENSSL_INSTALL_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake)
+ SET(OPENSSL_ROOT_DIR ${FASTDEPLOY_INSTALL_DIR}/installed_fastdeploy/cmake/openssl-1.1.0k/install-${CMAKE_SYSTEM_PROCESSOR})
+endif()
+download_and_decompress(${OPENSSL_URL} ${CMAKE_CURRENT_BINARY_DIR}/${OPENSSL_FILENAME}${COMPRESSED_SUFFIX} ${OPENSSL_INSTALL_DIR})
+SET(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include" CACHE PATH "openssl include directory." FORCE)
+include_directories(${OPENSSL_INCLUDE_DIR})
+IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
+ set(OPENSSL_LIBRARIES
+ "${OPENSSL_ROOT_DIR}/lib/libssl_static.lib"
+ "${OPENSSL_ROOT_DIR}/lib/libcrypto_static.lib"
+ ${GFLAGS_LIBRARIES}
+ shlwapi
+ CACHE FILEPATH "OPENSSL_LIBRARIES" FORCE)
+ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
+ set(OPENSSL_LIBRARIES
+ "${OPENSSL_ROOT_DIR}/lib/libssl.a"
+ "${OPENSSL_ROOT_DIR}/lib/libcrypto.a"
+ ${GFLAGS_LIBRARIES}
+ -ldl -lpthread
+ CACHE FILEPATH "OPENSSL_LIBRARIES" FORCE)
+ENDIF()
\ No newline at end of file
diff --git a/cmake/paddle_inference.cmake b/cmake/paddle_inference.cmake
index 3ab45454a51..6d5c8f0c134 100644
--- a/cmake/paddle_inference.cmake
+++ b/cmake/paddle_inference.cmake
@@ -40,16 +40,24 @@ if(WIN32)
CACHE FILEPATH "paddle_inference compile library." FORCE)
set(DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mkldnn/lib/mkldnn.lib")
set(OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mklml/lib/libiomp5md.lib")
+ set(P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/paddle2onnx/lib/paddle2onnx.lib")
+ set(ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/onnxruntime/lib/onnxruntime.lib")
elseif(APPLE)
set(PADDLEINFERENCE_COMPILE_LIB
"${PADDLEINFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.dylib"
CACHE FILEPATH "paddle_inference compile library." FORCE)
+ set(DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mkldnn/lib/libdnnl.so.2")
+ set(OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mklml/lib/libiomp5.so")
+ set(P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/paddle2onnx/lib/libpaddle2onnx.dylib")
+ set(ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/onnxruntime/lib/libonnxruntime.dylib")
else()
set(PADDLEINFERENCE_COMPILE_LIB
"${PADDLEINFERENCE_INSTALL_DIR}/paddle/lib/libpaddle_inference.so"
CACHE FILEPATH "paddle_inference compile library." FORCE)
set(DNNL_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mkldnn/lib/libdnnl.so.2")
set(OMP_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/mklml/lib/libiomp5.so")
+ set(P2O_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/paddle2onnx/lib/libpaddle2onnx.so")
+ set(ORT_LIB "${PADDLEINFERENCE_INSTALL_DIR}/third_party/install/onnxruntime/lib/libonnxruntime.so")
endif(WIN32)
@@ -59,10 +67,16 @@ if(PADDLEINFERENCE_DIRECTORY)
endif()
find_package(Python COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Copying ${PADDLEINFERENCE_DIRECTORY} to ${THIRD_PARTY_PATH}/install/paddle_inference ...")
- execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/copy_directory.py ${PADDLEINFERENCE_DIRECTORY} ${THIRD_PARTY_PATH}/install/paddle_inference)
+ if(WIN32)
+ message(FATAL_ERROR "Define PADDLEINFERENCE_DIRECTORY is not supported on Windows platform.")
+ else()
+ execute_process(COMMAND mkdir -p ${THIRD_PARTY_PATH}/install)
+ execute_process(COMMAND cp -r ${PADDLEINFERENCE_DIRECTORY} ${THIRD_PARTY_PATH}/install/paddle_inference)
+ execute_process(COMMAND rm -rf ${THIRD_PARTY_PATH}/install/paddle_inference/paddle/lib/*.a)
+ endif()
else()
set(PADDLEINFERENCE_URL_BASE "https://bj.bcebos.com/fastdeploy/third_libs/")
- set(PADDLEINFERENCE_VERSION "2.4-dev3")
+ set(PADDLEINFERENCE_VERSION "2.4-dev4")
if(WIN32)
if (WITH_GPU)
set(PADDLEINFERENCE_FILE "paddle_inference-win-x64-gpu-trt-${PADDLEINFERENCE_VERSION}.zip")
@@ -116,16 +130,23 @@ set_property(TARGET external_paddle_inference PROPERTY IMPORTED_LOCATION
${PADDLEINFERENCE_COMPILE_LIB})
add_dependencies(external_paddle_inference ${PADDLEINFERENCE_PROJECT})
-if (NOT APPLE)
- # no third parties libs(mkldnn and omp) need to
- # link into paddle_inference on MacOS OSX.
- add_library(external_dnnl STATIC IMPORTED GLOBAL)
- set_property(TARGET external_dnnl PROPERTY IMPORTED_LOCATION
- ${DNNL_LIB})
- add_dependencies(external_dnnl ${PADDLEINFERENCE_PROJECT})
- add_library(external_omp STATIC IMPORTED GLOBAL)
- set_property(TARGET external_omp PROPERTY IMPORTED_LOCATION
- ${OMP_LIB})
- add_dependencies(external_omp ${PADDLEINFERENCE_PROJECT})
-endif()
+add_library(external_p2o STATIC IMPORTED GLOBAL)
+set_property(TARGET external_p2o PROPERTY IMPORTED_LOCATION
+ ${P2O_LIB})
+add_dependencies(external_p2o ${PADDLEINFERENCE_PROJECT})
+
+add_library(external_ort STATIC IMPORTED GLOBAL)
+set_property(TARGET external_ort PROPERTY IMPORTED_LOCATION
+ ${ORT_LIB})
+add_dependencies(external_ort ${PADDLEINFERENCE_PROJECT})
+
+add_library(external_dnnl STATIC IMPORTED GLOBAL)
+set_property(TARGET external_dnnl PROPERTY IMPORTED_LOCATION
+ ${DNNL_LIB})
+add_dependencies(external_dnnl ${PADDLEINFERENCE_PROJECT})
+
+add_library(external_omp STATIC IMPORTED GLOBAL)
+set_property(TARGET external_omp PROPERTY IMPORTED_LOCATION
+ ${OMP_LIB})
+add_dependencies(external_omp ${PADDLEINFERENCE_PROJECT})
diff --git a/cmake/paddlelite.cmake b/cmake/paddlelite.cmake
index 74525b7a9d3..d546cbf38f8 100755
--- a/cmake/paddlelite.cmake
+++ b/cmake/paddlelite.cmake
@@ -114,6 +114,10 @@ else()
BUILD_BYPRODUCTS ${PADDLELITE_LIB})
endif()
+if(UNIX AND (NOT APPLE) AND (NOT ANDROID) AND BUILD_FASTDEPLOY_PYTHON)
+ add_custom_target(patchelf_paddle_lite ALL COMMAND bash -c "PATCHELF_EXE=${PATCHELF_EXE} python ${PROJECT_SOURCE_DIR}/scripts/patch_paddle_lite.py ${PADDLELITE_INSTALL_DIR}/lib/" DEPENDS ${LIBRARY_NAME})
+endif()
+
add_library(external_paddle_lite STATIC IMPORTED GLOBAL)
set_property(TARGET external_paddle_lite PROPERTY IMPORTED_LOCATION ${PADDLELITE_LIB})
add_dependencies(external_paddle_lite ${PADDLELITE_PROJECT})
diff --git a/cmake/sophgo.cmake b/cmake/sophgo.cmake
new file mode 100644
index 00000000000..d51d61368bd
--- /dev/null
+++ b/cmake/sophgo.cmake
@@ -0,0 +1,7 @@
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+find_package(libsophon REQUIRED)
+message(${LIBSOPHON_LIB_DIRS})
+include_directories(${LIBSOPHON_INCLUDE_DIRS})
+message(${LIBSOPHON_LIB_DIRS})
+set(SOPHGO_RT_LIB ${LIBSOPHON_LIB_DIRS}/libbmrt.so)
\ No newline at end of file
diff --git a/cmake/summary.cmake b/cmake/summary.cmake
index 85c829e04c7..9c3b1981cbd 100755
--- a/cmake/summary.cmake
+++ b/cmake/summary.cmake
@@ -32,6 +32,7 @@ function(fastdeploy_summary)
message(STATUS " Paddle2ONNX version : ${PADDLE2ONNX_VERSION}")
message(STATUS " ENABLE_ORT_BACKEND : ${ENABLE_ORT_BACKEND}")
message(STATUS " ENABLE_RKNPU2_BACKEND : ${ENABLE_RKNPU2_BACKEND}")
+ message(STATUS " ENABLE_SOPHGO_BACKEND : ${ENABLE_SOPHGO_BACKEND}")
message(STATUS " ENABLE_PADDLE_BACKEND : ${ENABLE_PADDLE_BACKEND}")
message(STATUS " ENABLE_LITE_BACKEND : ${ENABLE_LITE_BACKEND}")
message(STATUS " ENABLE_POROS_BACKEND : ${ENABLE_POROS_BACKEND}")
@@ -60,6 +61,7 @@ function(fastdeploy_summary)
endif()
message(STATUS " ENABLE_VISION : ${ENABLE_VISION}")
message(STATUS " ENABLE_TEXT : ${ENABLE_TEXT}")
+ message(STATUS " ENABLE_ENCRYPTION : ${ENABLE_ENCRYPTION}")
message(STATUS " ENABLE_DEBUG : ${ENABLE_DEBUG}")
message(STATUS " ENABLE_VISION_VISUALIZE : ${ENABLE_VISION_VISUALIZE}")
if(ANDROID)
diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake
index 4b3485748b7..85bd057981b 100755
--- a/cmake/toolchain.cmake
+++ b/cmake/toolchain.cmake
@@ -10,7 +10,7 @@ if (DEFINED TARGET_ABI)
set(OPENCV_URL "https://bj.bcebos.com/fastdeploy/third_libs/opencv-linux-armv7hf-4.6.0.tgz")
set(OPENCV_FILENAME "opencv-linux-armv7hf-4.6.0")
if(WITH_TIMVX)
- set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-1130.tgz")
+ set(PADDLELITE_URL "https://bj.bcebos.com/fastdeploy/third_libs/lite-linux-armhf-timvx-20221229.tgz")
else()
message(STATUS "PADDLELITE_URL will be configured if WITH_TIMVX=ON.")
endif()
diff --git a/docs/cn/build_and_install/README.md b/docs/cn/build_and_install/README.md
index 0ca92592ad7..5175f50d947 100755
--- a/docs/cn/build_and_install/README.md
+++ b/docs/cn/build_and_install/README.md
@@ -6,10 +6,10 @@
- [FastDeploy预编译库下载安装](download_prebuilt_libraries.md)
## 自行编译安装
-- [GPU部署环境](gpu.md)
+- [NVIDIA GPU部署环境](gpu.md)
- [CPU部署环境](cpu.md)
- [IPU部署环境](ipu.md)
-- [Jetson部署环境](jetson.md)
+- [Nvidia Jetson部署环境](jetson.md)
- [Android平台部署环境](android.md)
- [瑞芯微RV1126部署环境](rv1126.md)
- [瑞芯微RK3588部署环境](rknpu2.md)
@@ -26,6 +26,7 @@
| ENABLE_PADDLE_BACKEND | 默认OFF,是否编译集成Paddle Inference后端(CPU/GPU上推荐打开) |
| ENABLE_LITE_BACKEND | 默认OFF,是否编译集成Paddle Lite后端(编译Android库时需要设置为ON) |
| ENABLE_RKNPU2_BACKEND | 默认OFF,是否编译集成RKNPU2后端(RK3588/RK3568/RK3566上推荐打开) |
+| ENABLE_SOPHGO_BACKEND | 默认OFF,是否编译集成SOPHGO后端, 当在SOPHGO TPU上部署时,需要设置为ON |
| WITH_ASCEND | 默认OFF,当在华为昇腾NPU上部署时, 需要设置为ON |
| WITH_KUNLUNXIN | 默认OFF,当在昆仑芯XPU上部署时,需设置为ON |
| WITH_TIMVX | 默认OFF,需要在RV1126/RV1109/A311D上部署时,需设置为ON |
diff --git a/docs/cn/build_and_install/download_prebuilt_libraries.md b/docs/cn/build_and_install/download_prebuilt_libraries.md
index c3c733467da..30ad094f977 100755
--- a/docs/cn/build_and_install/download_prebuilt_libraries.md
+++ b/docs/cn/build_and_install/download_prebuilt_libraries.md
@@ -22,7 +22,7 @@ FastDeploy提供各平台预编译库,供开发者直接下载安装使用。
### Python安装
-Release版本(当前最新1.0.1)安装
+Release版本(当前最新1.0.2)安装
```bash
pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
```
@@ -43,8 +43,8 @@ Release版本
| 平台 | 文件 | 说明 |
| :--- | :--- | :---- |
-| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.1.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2编译产出 |
-| Windows x64 | [fastdeploy-win-x64-gpu-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.1.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2编译产出 |
+| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.2.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2编译产出 |
+| Windows x64 | [fastdeploy-win-x64-gpu-1.0.2.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.2.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2编译产出 |
Develop版本(Nightly build)
@@ -65,7 +65,7 @@ Develop版本(Nightly build)
### Python安装
-Release版本(当前最新1.0.1)安装
+Release版本(当前最新1.0.2)安装
```bash
pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
```
@@ -81,11 +81,11 @@ Release版本
| 平台 | 文件 | 说明 |
| :--- | :--- | :---- |
-| Linux x64 | [fastdeploy-linux-x64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.1.tgz) | g++ 8.2编译产出 |
-| Windows x64 | [fastdeploy-win-x64-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.1.zip) | Visual Studio 16 2019编译产出 |
-| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.1.tgz) | clang++ 10.0.0编译产出|
-| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.1.tgz) | clang++ 13.0.0编译产出 |
-| Linux aarch64 | [fastdeploy-linux-aarch64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.1.tgz) | gcc 6.3编译产出 |
+| Linux x64 | [fastdeploy-linux-x64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.2.tgz) | g++ 8.2编译产出 |
+| Windows x64 | [fastdeploy-win-x64-1.0.2.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.2.zip) | Visual Studio 16 2019编译产出 |
+| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.2.tgz) | clang++ 10.0.0编译产出|
+| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.2.tgz) | clang++ 13.0.0编译产出 |
+| Linux aarch64 | [fastdeploy-linux-aarch64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.2.tgz) | gcc 6.3编译产出 |
| Android armv7&v8 | [fastdeploy-android-1.0.0-shared.tgz](https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-1.0.0-shared.tgz) | NDK 25及clang++编译产出, 支持arm64-v8a及armeabi-v7a |
## Java SDK安装
diff --git a/docs/cn/build_and_install/huawei_ascend.md b/docs/cn/build_and_install/huawei_ascend.md
index b2a6b2ea402..ce0c8021155 100644
--- a/docs/cn/build_and_install/huawei_ascend.md
+++ b/docs/cn/build_and_install/huawei_ascend.md
@@ -94,6 +94,12 @@ python setup.py bdist_wheel
#编译完成后,请用户自行安装当前目录的dist文件夹内的whl包.
```
+## 五.昇腾部署时开启FlyCV
+[FlyCV](https://github.com/PaddlePaddle/FlyCV) 是一款高性能计算机图像处理库, 针对ARM架构做了很多优化, 相比其他图像处理库性能更为出色.
+FastDeploy现在已经集成FlyCV, 用户可以在支持的硬件平台上使用FlyCV, 实现模型端到端推理性能的加速.
+模型端到端推理中, 预处理和后处理阶段为CPU计算, 当用户使用ARM CPU + 昇腾的硬件平台时, 我们推荐用户使用FlyCV, 可以实现端到端的推理性能加速, 详见[FLyCV使用文档](./boost_cv_by_flycv.md).
-- 华为昇腾NPU 上使用C++部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU C++ 部署示例](../../../examples/vision/classification/paddleclas/ascend/cpp/README.md)
-- 华为昇腾NPU 上使用Python部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU Python 部署示例](../../../examples/vision/classification/paddleclas/ascend/python/README.md)
+
+## 六.昇腾部署Demo参考
+- 华为昇腾NPU 上使用C++部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU C++ 部署示例](../../../examples/vision/classification/paddleclas/cpp/README.md)
+- 华为昇腾NPU 上使用Python部署 PaddleClas 分类模型请参考:[PaddleClas 华为升腾NPU Python 部署示例](../../../examples/vision/classification/paddleclas/python/README.md)
diff --git a/docs/cn/build_and_install/sophgo.md b/docs/cn/build_and_install/sophgo.md
new file mode 100644
index 00000000000..f27432e71dc
--- /dev/null
+++ b/docs/cn/build_and_install/sophgo.md
@@ -0,0 +1,78 @@
+# SOPHGO 部署库编译
+
+## SOPHGO 环境准备
+SOPHGO支持linux下进行编译,系统为Debian/Ubuntu
+安装包由三个文件构成
+- [sophon-driver\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/KWqbmEcKp)
+- [sophon-libsophon\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/PlvlBXhWY)
+- [sophon-libsophon-dev\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/zTErLlpS7)
+
+其中“$arch”为当前机器的硬件架构,使用以下命令可以获取当前的服务器arch:
+```shell
+uname -m
+```
+通常x86_64 机器对应的硬件架构为amd64,arm64 机器对应的硬件架构为 arm64:
+```text
+- sophon-driver_0.4.2_$arch.deb
+- sophon-libsophon_0.4.2_$arch.deb
+- sophon-libsophon-dev_0.4.2_$arch.deb
+```
+
+其中:sophon-driver 包含了 PCIe 加速卡驱动;sophon-libsophon 包含了运行时环境(库文
+件、工具等);sophon-libsophon-dev 包含了开发环境(头文件等)。如果只是在部署环境上安
+装,则不需要安装 sophon-libsophon-dev。
+可以通过如下步骤安装:
+```shell
+#安装依赖库,只需要执行一次:
+sudo apt install dkms libncurses5
+#安装 libsophon:
+sudo dpkg -i sophon-*.deb
+#在终端执行如下命令,或者登出再登入当前用户后即可使用 bm-smi 等命令:
+source /etc/profile
+```
+安装位置为:
+```text
+/opt/sophon/
+├── driver-0.4.2
+├── libsophon-0.4.2
+| ├──bin
+| ├──data
+| ├──include
+| └──lib
+└── libsophon-current->/opt/sophon/libsophon-0.4.2
+```
+
+## C++ SDK编译安装
+搭建好编译环境之后,编译命令如下:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with Ascend
+cmake -DENABLE_SOPHGO_BACKEND=ON \
+ -DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-sophgo \
+ -DENABLE_VISION=ON \
+ ..
+
+# Build FastDeploy Ascend C++ SDK
+make -j8
+make install
+```
+编译完成之后,会在当前的build目录下生成 fastdeploy-sophgo 目录,编译完成。
+
+## Python FastDeploy 库编译
+搭建好编译环境之后,编译命令如下:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export ENABLE_SOPHGO_BACKEND=ON
+export ENABLE_VISION=ON
+
+python setup.py build
+python setup.py bdist_wheel
+
+#编译完成后,请用户自行安装当前目录的dist文件夹内的whl包.
+```
diff --git a/docs/cn/faq/boost_cv_by_flycv.md b/docs/cn/faq/boost_cv_by_flycv.md
new file mode 100644
index 00000000000..591a5fa0a73
--- /dev/null
+++ b/docs/cn/faq/boost_cv_by_flycv.md
@@ -0,0 +1,68 @@
+[English](../../en/faq/boost_cv_by_flycv.md) | 中文
+
+
+# 使用FlyCV加速端到端推理性能
+
+[FlyCV](https://github.com/PaddlePaddle/FlyCV) 是一款高性能计算机图像处理库, 针对ARM架构做了很多优化, 相比其他图像处理库性能更为出色.
+FastDeploy现在已经集成FlyCV, 用户可以在支持的硬件平台上使用FlyCV, 实现模型端到端推理性能的加速.
+
+## 已支持的系统与硬件架构
+
+| 系统 | 硬件架构 |
+| :-----------| :-------- |
+| Android | armeabi-v7a, arm64-v8a |
+| Linux | aarch64, armhf, x86_64|
+
+
+## 使用方式
+使用FlyCV,首先需要在编译时开启FlyCV编译选项,之后在部署时新增一行代码即可开启.
+本文以Linux系统为例,说明如何开启FlyCV编译选项, 之后在部署时, 新增一行代码使用FlyCV.
+
+用户可以按照如下方式,在编译预测库时,开启FlyCV编译选项.
+```bash
+# 编译C++预测库时, 开启FlyCV编译选项.
+-DENABLE_VISION=ON \
+
+# 在编译Python预测库时, 开启FlyCV编译选项
+export ENABLE_FLYCV=ON
+```
+
+用户可以按照如下方式,在部署代码中新增一行代码启用FlyCV.
+```bash
+# C++部署代码.
+# 新增一行代码启用FlyCV
+fastdeploy::vision::EnableFlyCV();
+# 其他部署代码...(以昇腾部署为例)
+fastdeploy::RuntimeOption option;
+option.UseAscend();
+...
+
+
+# Python部署代码
+# 新增一行代码启用FlyCV
+fastdeploy.vision.enable_flycv()
+# 其他部署代码...(以昇腾部署为例)
+runtime_option = build_option()
+option.use_ascend()
+...
+```
+
+## 部分平台FlyCV 端到端性能数据
+
+鲲鹏920 CPU + Atlas 300I Pro 推理卡.
+| 模型 | OpenCV 端到端性能(ms) | FlyCV 端到端性能(ms) |
+| :-----------| :-------- | :-------- |
+| ResNet50 | 2.78 | 1.63 |
+| PP-LCNetV2 | 2.50 | 1.39 |
+| YOLOv7 | 27.00 | 21.36 |
+| PP_HumanSegV2_Lite | 2.76 | 2.10 |
+
+
+瑞芯微RV1126.
+
+| 模型 | OpenCV 端到端性能(ms) | FlyCV 端到端性能(ms) |
+| :-----------| :-------- | :-------- |
+| ResNet50 | 9.23 | 6.01 |
+| mobilenetv1_ssld_量化模型 | 9.23 | 6.01 |
+| yolov5s_量化模型 | 28.33 | 14.25 |
+| PP_LiteSeg_量化模型 | 132.25 | 60.31 |
diff --git a/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md b/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md
new file mode 100755
index 00000000000..7ff5f91aa92
--- /dev/null
+++ b/docs/cn/faq/heterogeneous_computing_on_timvx_npu.md
@@ -0,0 +1,36 @@
+[English](../../en/faq/heterogeneous_computing_on_timvx_npu.md) | 中文
+
+# 在芯原系列 NPU 上实现异构计算
+在芯原系列 NPU 上,例如 RV1126 或者 A311D 上部署全量化模型时,有可能会有精度下降的问题,那么就需要在 NPU 和 ARM CPU 上进行异构计算,FastDeploy 中的异构计算是通过 subgraph.txt 配置文件来完成的,如果在更换全量化模型后,发现精度有较大的下降,可以参考本文档来定义异构配置文件。
+
+异构配置文件的更新步骤:
+1. 确定模型量化后在 ARM CPU 上的精度。
+- 如果在 ARM CPU 上,精度都无法满足,那量化本身就是失败的,此时可以考虑修改训练集或者更改量化方法。
+- 只需要修改 demo 中的代码,将 NPU 推理的部分改为使用 ARM CPU int8 推理,便可实现使用ARM CPU进行计算
+ ```
+ # 如下接口表示使用 NPU 进行推理
+ fastdeploy::RuntimeOption option;
+ option.UseTimVX(); # 开启 TIMVX 进行 NPU 推理
+ option.SetLiteSubgraphPartitionPath(subgraph_file); # 加载异构计算配置文件
+
+ # 如下接口表示使用 ARM CPU int8 推理
+ fastdeploy::RuntimeOption option;
+ option.UseLiteBackend();
+ option.EnableLiteInt8();
+ ```
+ 如果 ARM CPU 计算结果精度达标,则继续下面的步骤。
+
+2. 获取整网拓扑信息。
+- 回退第一步中的修改,使用 NPU 进行推理的 API 接口,加载异构计算配置文件的开关保持关闭。
+- 将所有的日志信息写入到 log.txt中,在 log.txt 中搜索关键字 "subgraph operators" 随后的一段便是整个模型的拓扑信息
+- 它的格式如下:
+ - 每行记录由 ”算子类型:输入张量名列表:输出张量名列表“ 组成(即以分号分隔算子类型、输入和输出张量名列表),以逗号分隔输入、输出张量名列表中的每个张量名;
+ - 示例说明:
+ ```
+ op_type0:var_name0,var_name1:var_name2 # 表示将算子类型为 op_type0、输入张量为var_name0 和 var_name1、输出张量为 var_name2 的节点强制运行在 ARM CPU 上
+ ```
+
+3. 修改异构配置文件
+- 将所有的 Subgraph operators 写到在 subgraph.txt 中,并打开加载异构计算配置文件的接口
+- 逐行删除、成片删除、二分法,发挥开发人员的耐心,找到引入 NPU 精度异常的 layer,将其留在 subgraph.txt 中
+- 在 txt 中的结点都是需要异构到 ARM CPU 上的 layer,不用特别担心性能问题,Paddle Lite 的 ARM kernel 性能也是非常卓越的
diff --git a/docs/cn/faq/rknpu2/rknpu2.md b/docs/cn/faq/rknpu2/rknpu2.md
index e0384e05136..fcd3e7c35c2 100644
--- a/docs/cn/faq/rknpu2/rknpu2.md
+++ b/docs/cn/faq/rknpu2/rknpu2.md
@@ -23,4 +23,4 @@ ONNX模型不能直接调用RK芯片中的NPU进行运算,需要把ONNX模型
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | portrait(int8) | 133/43 |
| Segmentation | [PP-HumanSegV2Lite](../../../../examples/vision/segmentation/paddleseg/rknpu2/README.md) | human(int8) | 133/43 |
| Face Detection | [SCRFD](../../../../examples/vision/facedet/scrfd/rknpu2/README.md) | SCRFD-2.5G-kps-640(int8) | 108/42 |
-| Classification | [ResNet](../../../../examples/vision/classification/paddleclas/rknpu2/README.md) | ResNet50_vd | -/92 |
+| Classification | [ResNet](../../../../examples/vision/classification/paddleclas/rknpu2/README.md) | ResNet50_vd | -/33 |
diff --git a/docs/cn/faq/use_sdk_on_ascend.md b/docs/cn/faq/use_sdk_on_ascend.md
index 8f87d5a229d..fc0ccc45e37 100644
--- a/docs/cn/faq/use_sdk_on_ascend.md
+++ b/docs/cn/faq/use_sdk_on_ascend.md
@@ -1,4 +1,4 @@
-[English](../../en/faq/use_sdk_on_linux.md) | 中文
+[English](../../en/faq/use_sdk_on_ascend.md) | 中文
# Linux上使用C++在华为昇腾部署
diff --git a/docs/cn/faq/use_sdk_on_linux.md b/docs/cn/faq/use_sdk_on_linux.md
index 0ceb5ca0c52..ccf46f5e041 100644
--- a/docs/cn/faq/use_sdk_on_linux.md
+++ b/docs/cn/faq/use_sdk_on_linux.md
@@ -3,7 +3,8 @@
# Linux上C++部署
-1. 编译完成运行,提示找不到.so文件
+1. 编译完成运行,提示找不到.so文件 "cannot open shared object file: No such file or directory"
+
在执行二进制文件时,需要能够在环境变量中找到FastDeploy相关的库文件。FastDeploy提供了辅助脚本来帮助完成。
diff --git a/docs/en/build_and_install/download_prebuilt_libraries.md b/docs/en/build_and_install/download_prebuilt_libraries.md
index 19da3ae1018..b8e40035f37 100644
--- a/docs/en/build_and_install/download_prebuilt_libraries.md
+++ b/docs/en/build_and_install/download_prebuilt_libraries.md
@@ -4,7 +4,7 @@ English | [中文](../../cn/build_and_install/download_prebuilt_libraries.md)
FastDeploy provides pre-built libraries for developers to download and install directly. Meanwhile, FastDeploy also offers easy access to compile so that developers can compile FastDeploy according to their own needs.
-This article is divided into two parts:
+This document is divided into two parts:
- [1.GPU Deployment Environment](#1)
- [2.CPU Deployment Environment](#2)
@@ -23,7 +23,7 @@ FastDeploy supports Computer Vision, Text and NLP model deployment on CPU and Nv
### Python SDK
-Install the released version(the newest 1.0.1 for now)
+Install the released version(the newest 1.0.2 for now)
```
pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
@@ -43,12 +43,12 @@ conda config --add channels conda-forge && conda install cudatoolkit=11.2 cudnn=
### C++ SDK
-Install the released version(Latest 1.0.1)
+Install the released version(Latest 1.0.2)
| Platform | File | Description |
|:----------- |:--------------------------------------------------------------------------------------------------------------------- |:--------------------------------------------------------- |
-| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.1.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2 |
-| Windows x64 | [fastdeploy-win-x64-gpu-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.1.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 |
+| Linux x64 | [fastdeploy-linux-x64-gpu-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.2.tgz) | g++ 8.2, CUDA 11.2, cuDNN 8.2 |
+| Windows x64 | [fastdeploy-win-x64-gpu-1.0.2.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-1.0.2.zip) | Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 |
Install the Develop version(Nightly build)
@@ -70,7 +70,7 @@ FastDeploy supports computer vision, text and NLP model deployment on CPU with P
### Python SDK
-Install the released version(Latest 1.0.1 for now)
+Install the released version(Latest 1.0.2 for now)
```
pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
@@ -84,15 +84,15 @@ pip install fastdeploy-python==0.0.0 -f https://www.paddlepaddle.org.cn/whl/fast
### C++ SDK
-Install the released version(Latest 1.0.1 for now, Android is 1.0.1)
+Install the released version(Latest 1.0.2 for now, Android is 1.0.0)
| Platform | File | Description |
|:------------- |:--------------------------------------------------------------------------------------------------------------------- |:------------------------------ |
-| Linux x64 | [fastdeploy-linux-x64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.1.tgz) | g++ 8.2 |
-| Windows x64 | [fastdeploy-win-x64-1.0.1.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.1.zip) | Visual Studio 16 2019 |
-| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.1.tgz) | clang++ 10.0.0|
-| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.1.tgz) | clang++ 13.0.0 |
-| Linux aarch64 | [fastdeploy-osx-arm64-1.0.1.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.1.tgz) | gcc 6.3 |
+| Linux x64 | [fastdeploy-linux-x64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-1.0.2.tgz) | g++ 8.2 |
+| Windows x64 | [fastdeploy-win-x64-1.0.2.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-1.0.2.zip) | Visual Studio 16 2019 |
+| Mac OSX x64 | [fastdeploy-osx-x86_64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-x86_64-1.0.2.tgz) | clang++ 10.0.0|
+| Mac OSX arm64 | [fastdeploy-osx-arm64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-osx-arm64-1.0.2.tgz) | clang++ 13.0.0 |
+| Linux aarch64 | [fastdeploy-osx-arm64-1.0.2.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-aarch64-1.0.2.tgz) | gcc 6.3 |
| Android armv7&v8 | [fastdeploy-android-1.0.0-shared.tgz](https://bj.bcebos.com/fastdeploy/release/android/fastdeploy-android-1.0.0-shared.tgz)| NDK 25, clang++, support arm64-v8a and armeabi-v7a |
## Java SDK
diff --git a/docs/en/build_and_install/huawei_ascend.md b/docs/en/build_and_install/huawei_ascend.md
index 3a0bd8911fe..48653939d5d 100644
--- a/docs/en/build_and_install/huawei_ascend.md
+++ b/docs/en/build_and_install/huawei_ascend.md
@@ -93,6 +93,14 @@ python setup.py bdist_wheel
#After the compilation is complete, please install the whl package in the dist folder of the current directory.
```
-Deploying PaddleClas Classification Model on Huawei Ascend NPU using C++ please refer to: [PaddleClas Huawei Ascend NPU C++ Deployment Example](../../../examples/vision/classification/paddleclas/ascend/cpp/README.md)
+## Enable FlyCV for Ascend deployment
-Deploying PaddleClas classification model on Huawei Ascend NPU using Python please refer to: [PaddleClas Huawei Ascend NPU Python Deployment Example](../../../examples/vision/classification/paddleclas/ascend/python/README.md)
+[FlyCV](https://github.com/PaddlePaddle/FlyCV) is a high performance computer image processing library, providing better performance than other image processing libraries, especially in the ARM architecture.
+FastDeploy is now integrated with FlyCV, allowing users to use FlyCV on supported hardware platforms to accelerate model end-to-end inference performance.
+In end-to-end model inference, the pre-processing and post-processing phases are CPU computation, we recommend using FlyCV for end-to-end inference performance acceleration when you are using ARM CPU + Ascend hardware platform. See [Enable FlyCV](./boost_cv_by_flycv.md) documentation for details.
+
+
+## Deployment demo reference
+- Deploying PaddleClas Classification Model on Huawei Ascend NPU using C++ please refer to: [PaddleClas Huawei Ascend NPU C++ Deployment Example](../../../examples/vision/classification/paddleclas/cpp/README.md)
+
+- Deploying PaddleClas classification model on Huawei Ascend NPU using Python please refer to: [PaddleClas Huawei Ascend NPU Python Deployment Example](../../../examples/vision/classification/paddleclas/python/README.md)
diff --git a/docs/en/build_and_install/sophgo.md b/docs/en/build_and_install/sophgo.md
new file mode 100644
index 00000000000..08d18122c0f
--- /dev/null
+++ b/docs/en/build_and_install/sophgo.md
@@ -0,0 +1,77 @@
+
+# How to Build SOPHGO Deployment Environment
+
+## SOPHGO Environment Preparation
+SOPHGO supports compilation on linux, using Debian/Ubuntu as an example
+The installation package consists of three files
+- [sophon-driver\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/KWqbmEcKp)
+- [sophon-libsophon\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/PlvlBXhWY)
+- [sophon-libsophon-dev\_0.4.2\_$arch.deb](http://219.142.246.77:65000/sharing/zTErLlpS7)
+
+$arch indicates the hardware architecture of the current machine. Run the following command to obtain the current server arch:
+```shell
+uname -m
+```
+Generally, the hardware architecture of x86_64 machines is amd64, so the hardware architecture is arm64:
+```text
+- sophon-driver_0.4.2_$arch.deb
+- sophon-libsophon_0.4.2_$arch.deb
+- sophon-libsophon-dev_0.4.2_$arch.deb
+```
+
+sophon-driver contains PCIe acceleration card drivers; sophon-libsophon contains the runtime environment (librarys, tools, etc); sophon-libsophon-dev contains the development environment (header files, etc.). If you install packages only on a deployment environment, you do not need to install sophon-libsophon-dev.
+You can perform the following steps to install:
+```shell
+#To install a dependency library, you only need to do this once:
+sudo apt install dkms libncurses5
+#install libsophon:
+sudo dpkg -i sophon-*.deb
+#Run the following command on the terminal, log out and then log in the current user to use commands such as bm-smi:
+source /etc/profile
+```
+The position of installation::
+```text
+/opt/sophon/
+├── driver-0.4.2
+├── libsophon-0.4.2
+| ├──bin
+| ├──data
+| ├──include
+| └──lib
+└── libsophon-current->/opt/sophon/libsophon-0.4.2
+```
+
+## How to Build and Install C++ SDK
+After setting up the compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy
+mkdir build && cd build
+
+# CMake configuration with Ascend
+cmake -DENABLE_SOPHGO_BACKEND=ON \
+ -DCMAKE_INSTALL_PREFIX=${PWD}/fastdeploy-sophgo \
+ -DENABLE_VISION=ON \
+ ..
+
+# Build FastDeploy Ascend C++ SDK
+make -j8
+make install
+```
+When the compilation is complete, the fastdeploy-sophgo directory is created in the current build directory, indicating that the FastDeploy library has been compiled.
+
+## Compiling Python FastDeploy Libraries
+After setting up the compilation environment, the compilation command is as follows:
+```bash
+# Download the latest source code
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/python
+export ENABLE_SOPHGO_BACKEND=ON
+export ENABLE_VISION=ON
+
+python setup.py build
+python setup.py bdist_wheel
+
+#After the compilation is complete, please install the whl package in the dist folder of the current directory.
+```
diff --git a/docs/en/faq/boost_cv_by_flycv.md b/docs/en/faq/boost_cv_by_flycv.md
new file mode 100644
index 00000000000..2a06a362933
--- /dev/null
+++ b/docs/en/faq/boost_cv_by_flycv.md
@@ -0,0 +1,66 @@
+[简体中文](../../cn/faq/boost_cv_by_flycv.md) | English
+
+
+# Accelerate end-to-end inference performance using FlyCV
+
+[FlyCV](https://github.com/PaddlePaddle/FlyCV) is a high performance computer image processing library, providing better performance than other image processing libraries, especially in the ARM architecture.
+FastDeploy is now integrated with FlyCV, allowing users to use FlyCV on supported hardware platforms to accelerate model end-to-end inference performance.
+
+## Supported OS and Architectures
+
+| OS | Architectures |
+| :-----------| :-------- |
+| Android | armeabi-v7a, arm64-v8a |
+| Linux | aarch64, armhf, x86_64|
+
+
+## Usage
+To use FlyCV, you first need to turn on the FlyCV compile option at compile time, and then add a new line of code to turn it on.
+This article uses Linux as an example to show how to enable the FlyCV compile option, and then add a new line of code to use FlyCV during deployment.
+
+You can turn on the FlyCV compile option when compiling the FastDeploy library as follows.
+```bash
+# When compiling C++ libraries
+-DENABLE_VISION=ON
+
+# When compiling Python libraries
+export ENABLE_FLYCV=ON
+```
+
+You can enable FlyCV by adding a new line of code to the deployment code as follows.
+```bash
+# C++ code
+fastdeploy::vision::EnableFlyCV();
+# Other..(e.g. With Huawei Ascend)
+fastdeploy::RuntimeOption option;
+option.UseAscend();
+...
+
+
+# Python code
+fastdeploy.vision.enable_flycv()
+# Other..(e.g. With Huawei Ascend)
+runtime_option = build_option()
+option.use_ascend()
+...
+```
+
+## Some Platforms FlyCV End-to-End Inference Performance
+
+KunPeng 920 CPU + Atlas 300I Pro.
+| Model | OpenCV E2E Performance(ms) | FlyCV E2E Performance(ms) |
+| :-----------| :-------- | :-------- |
+| ResNet50 | 2.78 | 1.63 |
+| PP-LCNetV2 | 2.50 | 1.39 |
+| YOLOv7 | 27.00 | 21.36 |
+| PP_HumanSegV2_Lite | 2.76 | 2.10 |
+
+
+Rockchip RV1126.
+
+| Model | OpenCV E2E Performance(ms) | FlyCV E2E Performance(ms) |
+| :-----------| :-------- | :-------- |
+| ResNet50 | 9.23 | 6.01 |
+| mobilenetv1_ssld_量化模型 | 9.23 | 6.01 |
+| yolov5s_量化模型 | 28.33 | 14.25 |
+| PP_LiteSeg_量化模型 | 132.25 | 60.31 |
diff --git a/docs/en/faq/heterogeneous_computing_on_timvx_npu.md b/docs/en/faq/heterogeneous_computing_on_timvx_npu.md
new file mode 100755
index 00000000000..467fd45fae2
--- /dev/null
+++ b/docs/en/faq/heterogeneous_computing_on_timvx_npu.md
@@ -0,0 +1,36 @@
+English | [中文](../../cn/faq/heterogeneous_computing_on_timvx_npu.md)
+
+# Heterogeneous Computing on VeriSilicon Series NPUs
+When deploying a quantized model on a VeriSilicon series NPU, such as RV1126 or A311D, there may be a problem of decreased accuracy, so heterogeneous computing needs to be performed on the NPU and ARM CPU. The heterogeneous computing in FastDeploy is implemented by loading subgraph.txt configuration files. If you find that the accuracy has dropped significantly after replacing the quantized model, you can refer to this document to define the heterogeneous configuration file.
+
+Update steps for heterogeneous configuration files:
+1. Determine the accuracy of the quantized model on an ARM CPU.
+- If the accuracy cannot be satisfied on the ARM CPU, then there is a problem with the quantized model. At this time, you can consider modifying the dataset or changing the quantization method.
+- Only need to modify a few lines of code in the demo, change the part of NPU inference to use ARM CPU int8.
+ ```
+ # The following interface represents the use of NPU for inference
+ fastdeploy::RuntimeOption option;
+ option.UseTimVX(); # Turn on TIMVX for NPU inference
+ option.SetLiteSubgraphPartitionPath(subgraph_file); # Load heterogeneous computing configuration files
+
+ # The following interface indicates the use of ARM CPU int8 inference
+ fastdeploy::RuntimeOption option;
+ option.UseLiteBackend();
+ option.EnableLiteInt8();
+ ```
+ If the ARM CPU accuracy is up to standard, continue with the next steps.
+
+2. Obtain the topology information of the entire network.
+- Roll back the modification in the first step, use the API interface of NPU for inference, and keep the switch of loading heterogeneous computing configuration files off.
+- Write all the log information to log.txt, search for the keyword "subgraph operators" in log.txt and the following paragraph is the topology information of the entire model.
+- It has the following format:
+ - Each line of records consists of "operator type: list of input tensor names: list of output tensor names" (that is, the operator type, list of input and output tensor names are separated by semicolons), and the input and output tensor names are separated by commas each tensor name in the list;
+ - Example:
+ ```
+ op_type0:var_name0,var_name1:var_name2 # Indicates that the node whose operator type is op_type0, input tensors are var_name0 and var_name1, and output tensor is var_name2 is forced to run on the ARM CPU
+ ```
+
+3. Modify heterogeneous configuration files
+- Write all Subgraph operators in subgraph.txt, and open the interface for loading heterogeneous computing configuration files
+- Delete line by line, delete in pieces, dichotomy, use the patience of developers, find the layer that introduces NPU precision exception, and leave it in subgraph.txt
+- The nodes in txt all need to be heterogeneous to the layer on the ARM CPU, so don’t worry about performance issues. The ARM kernel performance of Paddle Lite is also very good.
diff --git a/docs/en/faq/use_sdk_on_ascend.md b/docs/en/faq/use_sdk_on_ascend.md
index e3cd55b40c6..c1ac864b85b 100644
--- a/docs/en/faq/use_sdk_on_ascend.md
+++ b/docs/en/faq/use_sdk_on_ascend.md
@@ -1,4 +1,4 @@
-[简体中文](../../cn/faq/use_sdk_on_linux.md) | English
+[简体中文](../../cn/faq/use_sdk_on_ascend.md) | English
# # Linux deployment with C++ on Huawei Ascend
diff --git a/examples/text/uie/serving/models/uie/1/model.py b/examples/text/uie/serving/models/uie/1/model.py
index 5bb1c816417..b839ae0657e 100644
--- a/examples/text/uie/serving/models/uie/1/model.py
+++ b/examples/text/uie/serving/models/uie/1/model.py
@@ -141,7 +141,7 @@ def execute(self, requests):
self.uie_model_.set_schema(schema)
results = self.uie_model_.predict(texts, return_dict=True)
- results = np.array(results, dtype=np.object)
+ results = np.array(results, dtype=np.object_)
out_tensor = pb_utils.Tensor(self.output_names[0], results)
inference_response = pb_utils.InferenceResponse(
output_tensors=[out_tensor, ])
diff --git a/examples/vision/classification/paddleclas/a311d/cpp/README.md b/examples/vision/classification/paddleclas/a311d/cpp/README.md
index 11279ccb000..c7f6afa1e45 100755
--- a/examples/vision/classification/paddleclas/a311d/cpp/README.md
+++ b/examples/vision/classification/paddleclas/a311d/cpp/README.md
@@ -3,12 +3,13 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
### 量化模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 A311D 上部署量化后的 ResNet50_Vd 分类模型
请按照以下步骤完成在 A311D 上部署 ResNet50_Vd 量化模型:
diff --git a/examples/vision/classification/paddleclas/rknpu2/README.md b/examples/vision/classification/paddleclas/rknpu2/README.md
index bd4305dc0a5..d61e6c57064 100644
--- a/examples/vision/classification/paddleclas/rknpu2/README.md
+++ b/examples/vision/classification/paddleclas/rknpu2/README.md
@@ -3,6 +3,7 @@
## 转换模型
下面以 ResNet50_vd为例子,教大家如何转换分类模型到RKNN模型。
+### 导出ONNX模型
```bash
# 安装 paddle2onnx
pip install paddle2onnx
@@ -17,34 +18,59 @@ paddle2onnx --model_dir ResNet50_vd_infer \
--params_filename inference.pdiparams \
--save_file ResNet50_vd_infer/ResNet50_vd_infer.onnx \
--enable_dev_version True \
- --opset_version 12 \
+ --opset_version 10 \
--enable_onnx_checker True
# 固定shape,注意这里的inputs得对应netron.app展示的 inputs 的 name,有可能是image 或者 x
python -m paddle2onnx.optimize --input_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \
--output_model ResNet50_vd_infer/ResNet50_vd_infer.onnx \
--input_shape_dict "{'inputs':[1,3,224,224]}"
-```
+```
- ### 编写模型导出配置文件
-以转化RK3588的RKNN模型为例子,我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml,来转换ONNX模型到RKNN模型。
+### 编写模型导出配置文件
+以转化RK3588的RKNN模型为例子,我们需要编辑tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml,来转换ONNX模型到RKNN模型。
-默认的 mean=0, std=1是在内存做normalize,如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如:
+如果你需要在NPU上执行normalize操作,请根据你的模型配置normalize参数,例如:
```yaml
-model_path: ./ResNet50_vd_infer.onnx
-output_folder: ./
-target_platform: RK3588
-normalize:
- mean: [[0.485,0.456,0.406]]
- std: [[0.229,0.224,0.225]]
-outputs: []
-outputs_nodes: []
+model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx
+output_folder: ./ResNet50_vd_infer
+mean:
+ -
+ - 123.675
+ - 116.28
+ - 103.53
+std:
+ -
+ - 58.395
+ - 57.12
+ - 57.375
+outputs_nodes:
do_quantization: False
-dataset:
+dataset: "./ResNet50_vd_infer/dataset.txt"
```
+**在CPU上做normalize**可以参考以下yaml:
+```yaml
+model_path: ./ResNet50_vd_infer/ResNet50_vd_infer.onnx
+output_folder: ./ResNet50_vd_infer
+mean:
+ -
+ - 0
+ - 0
+ - 0
+std:
+ -
+ - 1
+ - 1
+ - 1
+outputs_nodes:
+do_quantization: False
+dataset: "./ResNet50_vd_infer/dataset.txt"
+```
+这里我们选择在NPU上执行normalize操作.
+
-# ONNX模型转RKNN模型
+### ONNX模型转RKNN模型
```shell
python tools/rknpu2/export.py \
--config_path tools/rknpu2/config/ResNet50_vd_infer_rknn.yaml \
@@ -54,4 +80,4 @@ python tools/rknpu2/export.py \
## 其他链接
- [Cpp部署](./cpp)
- [Python部署](./python)
-- [视觉模型预测结果](../../../../../docs/api/vision_results/)
\ No newline at end of file
+- [视觉模型预测结果](../../../../../docs/api/vision_results/)
diff --git a/examples/vision/classification/paddleclas/rknpu2/cpp/README.md b/examples/vision/classification/paddleclas/rknpu2/cpp/README.md
index 1e1883486d1..c21d1d77b37 100644
--- a/examples/vision/classification/paddleclas/rknpu2/cpp/README.md
+++ b/examples/vision/classification/paddleclas/rknpu2/cpp/README.md
@@ -64,8 +64,8 @@ cd ./build/install
## 运行结果展示
ClassifyResult(
-label_ids: 153,
-scores: 0.684570,
+label_ids: 153,
+scores: 0.684570,
)
## 注意事项
@@ -75,4 +75,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
## 其它文档
- [ResNet50_vd Python 部署](../python)
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
-- [转换ResNet50_vd RKNN模型文档](../README.md)
\ No newline at end of file
+- [转换ResNet50_vd RKNN模型文档](../README.md)
diff --git a/examples/vision/classification/paddleclas/rknpu2/python/README.md b/examples/vision/classification/paddleclas/rknpu2/python/README.md
index b85bb81f70a..f1f0994d857 100644
--- a/examples/vision/classification/paddleclas/rknpu2/python/README.md
+++ b/examples/vision/classification/paddleclas/rknpu2/python/README.md
@@ -19,8 +19,8 @@ python3 infer.py --model_file ./ResNet50_vd_infer/ResNet50_vd_infer_rk3588.rknn
# 运行完成后返回结果如下所示
ClassifyResult(
-label_ids: 153,
-scores: 0.684570,
+label_ids: 153,
+scores: 0.684570,
)
```
@@ -32,4 +32,4 @@ DisablePermute(C++)或`disable_permute(Python),在预处理阶段禁用数据
## 其它文档
- [ResNet50_vd C++部署](../cpp)
- [模型预测结果说明](../../../../../../docs/api/vision_results/)
-- [转换ResNet50_vd RKNN模型文档](../README.md)
\ No newline at end of file
+- [转换ResNet50_vd RKNN模型文档](../README.md)
diff --git a/examples/vision/classification/paddleclas/rv1126/cpp/README.md b/examples/vision/classification/paddleclas/rv1126/cpp/README.md
index b0e4623a704..b621ff72003 100755
--- a/examples/vision/classification/paddleclas/rv1126/cpp/README.md
+++ b/examples/vision/classification/paddleclas/rv1126/cpp/README.md
@@ -3,12 +3,13 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
### 量化模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的inference_cls.yaml文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从 FP32 模型文件夹下复制此 yaml 文件到量化后的模型文件夹内即可.)
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 RV1126 上部署量化后的 ResNet50_Vd 分类模型
请按照以下步骤完成在 RV1126 上部署 ResNet50_Vd 量化模型:
diff --git a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
index 0ab7dcdc4ae..de000f6eee8 100755
--- a/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
+++ b/examples/vision/classification/paddleclas/serving/models/postprocess/1/model.py
@@ -92,7 +92,7 @@ def execute(self, requests):
results = self.postprocess_.run([infer_outputs, ])
r_str = fd.vision.utils.fd_result_to_json(results)
- r_np = np.array(r_str, dtype=np.object)
+ r_np = np.array(r_str, dtype=np.object_)
out_tensor = pb_utils.Tensor(self.output_names[0], r_np)
inference_response = pb_utils.InferenceResponse(
output_tensors=[out_tensor, ])
diff --git a/examples/vision/classification/paddleclas/sophgo/README.md b/examples/vision/classification/paddleclas/sophgo/README.md
new file mode 100644
index 00000000000..32bb3bfbf19
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/README.md
@@ -0,0 +1,84 @@
+# PaddleDetection SOPHGO部署示例
+
+## 支持模型列表
+
+目前FastDeploy支持的如下模型的部署[ResNet系列模型](https://github.com/PaddlePaddle/PaddleClas/blob/release/2.4/docs/zh_CN/models/ResNet_and_vd.md)
+
+## 准备ResNet部署模型以及转换模型
+
+SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下:
+- Paddle动态图模型转换为ONNX模型,请参考[Paddle2ONNX模型转换](https://github.com/PaddlePaddle/Paddle2ONNX/tree/develop/model_zoo/classification)
+- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir)。
+
+## 模型转换example
+
+下面以[ResNet50_vd](https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz)为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型。
+
+## 导出ONNX模型
+
+### 下载Paddle ResNet50_vd静态图模型并解压
+```shell
+wget https://bj.bcebos.com/paddlehub/fastdeploy/ResNet50_vd_infer.tgz
+tar xvf ResNet50_vd_infer.tgz
+```
+
+### 静态图转ONNX模型,注意,这里的save_file请和压缩包名对齐
+```shell
+paddle2onnx --model_dir ResNet50_vd_infer \
+ --model_filename inference.pdmodel \
+ --params_filename inference.pdiparams \
+ --save_file ResNet50_vd_infer.onnx \
+ --enable_dev_version True
+```
+### 导出bmodel模型
+
+以转化BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+### 1. 安装
+``` shell
+docker pull sophgo/tpuc_dev:latest
+
+# myname1234是一个示例,也可以设置其他名字
+docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest
+
+source ./envsetup.sh
+./build.sh
+```
+
+### 2. ONNX模型转换为bmodel模型
+``` shell
+mkdir ResNet50_vd_infer && cd ResNet50_vd_infer
+
+# 在该文件中放入测试图片,同时将上一步转换好的ResNet50_vd_infer.onnx放入该文件夹中
+cp -rf ${REGRESSION_PATH}/dataset/COCO2017 .
+cp -rf ${REGRESSION_PATH}/image .
+# 放入onnx模型文件ResNet50_vd_infer.onnx
+
+mkdir workspace && cd workspace
+
+# 将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看
+model_transform.py \
+ --model_name ResNet50_vd_infer \
+ --model_def ../ResNet50_vd_infer.onnx \
+ --input_shapes [[1,3,224,224]] \
+ --mean 0.0,0.0,0.0 \
+ --scale 0.0039216,0.0039216,0.0039216 \
+ --keep_aspect_ratio \
+ --pixel_format rgb \
+ --output_names save_infer_model/scale_0.tmp_1 \
+ --test_input ../image/dog.jpg \
+ --test_result ResNet50_vd_infer_top_outputs.npz \
+ --mlir ResNet50_vd_infer.mlir
+
+# 将mlir模型转换为BM1684x的F32 bmodel模型
+model_deploy.py \
+ --mlir ResNet50_vd_infer.mlir \
+ --quantize F32 \
+ --chip bm1684x \
+ --test_input ResNet50_vd_infer_in_f32.npz \
+ --test_reference ResNet50_vd_infer_top_outputs.npz \
+ --model ResNet50_vd_infer_1684x_f32.bmodel
+```
+最终获得可以在BM1684x上能够运行的bmodel模型ResNet50_vd_infer_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+
+## 其他链接
+- [Cpp部署](./cpp)
diff --git a/examples/vision/classification/paddleclas/sophgo/cpp/CMakeLists.txt b/examples/vision/classification/paddleclas/sophgo/cpp/CMakeLists.txt
new file mode 100644
index 00000000000..53837058969
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/cpp/CMakeLists.txt
@@ -0,0 +1,17 @@
+PROJECT(infer_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+# 指定下载解压后的fastdeploy库路径
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+
+set(ENABLE_LITE_BACKEND OFF)
+#set(FDLIB ${FASTDEPLOY_INSTALL_DIR})
+
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+
+# 添加FastDeploy依赖头文件
+include_directories(${FASTDEPLOY_INCS})
+include_directories(${FastDeploy_INCLUDE_DIRS})
+
+add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/classification/paddleclas/sophgo/cpp/README.md b/examples/vision/classification/paddleclas/sophgo/cpp/README.md
new file mode 100644
index 00000000000..7edfd2c94b6
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/cpp/README.md
@@ -0,0 +1,61 @@
+# PaddleClas C++部署示例
+
+本目录下提供`infer.cc`快速完成ResNet50_vd模型在SOPHGO BM1684x板子上加速部署的示例。
+
+在部署前,需确认以下两个步骤:
+
+1. 软硬件环境满足要求
+2. 根据开发环境,从头编译FastDeploy仓库
+
+以上步骤请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)实现
+
+## 生成基本目录文件
+
+该例程由以下几个部分组成
+```text
+.
+├── CMakeLists.txt
+├── build # 编译文件夹
+├── image # 存放图片的文件夹
+├── infer.cc
+├── preprocess_config.yaml #示例前处理配置文件
+└── model # 存放模型文件的文件夹
+```
+
+## 编译
+
+### 编译并拷贝SDK到thirdpartys文件夹
+
+请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录.
+
+### 拷贝模型文件,以及配置文件至model文件夹
+将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md)
+将转换后的SOPHGO bmodel模型文件拷贝至model中
+将前处理配置文件也拷贝到model中
+```bash
+cp preprocess_config.yaml ./model
+```
+
+### 准备测试图片至image文件夹
+```bash
+wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
+cp ILSVRC2012_val_00000010.jpeg ./images
+```
+
+### 编译example
+
+```bash
+cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3
+make
+```
+
+## 运行例程
+
+```bash
+./infer_demo model images/ILSVRC2012_val_00000010.jpeg
+```
+
+
+- [模型介绍](../../)
+- [模型转换](../)
diff --git a/examples/vision/classification/paddleclas/sophgo/cpp/infer.cc b/examples/vision/classification/paddleclas/sophgo/cpp/infer.cc
new file mode 100644
index 00000000000..b9281ffb0c1
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/cpp/infer.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+#include
+#include "fastdeploy/vision.h"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void InitAndInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "resnet50_1684x_f32.bmodel";
+ auto params_file = model_dir + sep + "";
+ auto config_file = model_dir + sep + "preprocess_config.yaml";
+
+ fastdeploy::RuntimeOption option;
+ option.UseSophgo();
+ auto model_format = fastdeploy::ModelFormat::SOPHGO;
+ auto model = fastdeploy::vision::classification::PaddleClasModel(
+ model_file, params_file, config_file, option, model_format);
+
+ assert(model.Initialized());
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::ClassifyResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 3) {
+ std::cout << "Usage: infer_demo path/to/model "
+ "path/to/image "
+ "run_option, "
+ "e.g ./infer_demo ./bmodel ./test.jpeg"
+ << std::endl;
+ return -1;
+ }
+
+ std::string model_dir = argv[1];
+ std::string test_image = argv[2];
+ InitAndInfer(model_dir, test_image);
+ return 0;
+}
diff --git a/examples/vision/classification/paddleclas/sophgo/python/README.md b/examples/vision/classification/paddleclas/sophgo/python/README.md
new file mode 100644
index 00000000000..f495e583095
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/python/README.md
@@ -0,0 +1,29 @@
+# PaddleClas Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md)
+
+本目录下提供`infer.py`快速完成 ResNet50_vd 在SOPHGO TPU上部署的示例。执行如下脚本即可完成
+
+```bash
+# 下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/examples/vision/classification/paddleclas/sophgo/python
+
+# 下载图片
+wget https://gitee.com/paddlepaddle/PaddleClas/raw/release/2.4/deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg
+
+# 推理
+python3 infer.py --model_file ./bmodel/resnet50_1684x_f32.bmodel --config_file ResNet50_vd_infer/inference_cls.yaml --image ILSVRC2012_val_00000010.jpeg
+
+# 运行完成后返回结果如下所示
+ClassifyResult(
+label_ids: 153,
+scores: 0.684570,
+)
+```
+
+## 其它文档
+- [ResNet50_vd C++部署](../cpp)
+- [转换ResNet50_vd SOPHGO模型文档](../README.md)
diff --git a/examples/vision/classification/paddleclas/sophgo/python/infer.py b/examples/vision/classification/paddleclas/sophgo/python/infer.py
new file mode 100644
index 00000000000..5bc84789ec7
--- /dev/null
+++ b/examples/vision/classification/paddleclas/sophgo/python/infer.py
@@ -0,0 +1,41 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--model", required=True, help="Path of model.")
+ parser.add_argument(
+ "--config_file", required=True, help="Path of config file.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--topk", type=int, default=1, help="Return topk results.")
+
+ return parser.parse_args()
+
+
+args = parse_arguments()
+
+# 配置runtime,加载模型
+runtime_option = fd.RuntimeOption()
+runtime_option.use_sophgo()
+
+model_file = args.model
+params_file = ""
+config_file = args.config_file
+
+model = fd.vision.classification.PaddleClasModel(
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=runtime_option,
+ model_format=fd.ModelFormat.SOPHGO)
+
+# 预测图片分类结果
+im = cv2.imread(args.image)
+result = model.predict(im, args.topk)
+print(result)
diff --git a/examples/vision/detection/nanodet_plus/python/README.md b/examples/vision/detection/nanodet_plus/python/README.md
index b5085662ce2..a89e15d1b17 100644
--- a/examples/vision/detection/nanodet_plus/python/README.md
+++ b/examples/vision/detection/nanodet_plus/python/README.md
@@ -69,7 +69,7 @@ NanoDetPlus模型加载和初始化,其中model_file为导出的ONNX模型格
> > * **padding_value**(list[float]): 通过此参数可以修改图片在resize时候做填充(padding)的值, 包含三个浮点型元素, 分别表示三个通道的值, 默认值为[0, 0, 0]
> > * **keep_ratio**(bool): 通过此参数指定resize时是否保持宽高比例不变,默认是fasle.
> > * **reg_max**(int): GFL回归中的reg_max参数,默认是7.
-> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含三个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64]
+> > * **downsample_strides**(list[int]): 通过此参数可以修改生成anchor的特征图的下采样倍数, 包含四个整型元素, 分别表示默认的生成anchor的下采样倍数, 默认值为[8, 16, 32, 64]
diff --git a/examples/vision/detection/paddledetection/README.md b/examples/vision/detection/paddledetection/README.md
index ae4ba494c4b..11b616ba90d 100644
--- a/examples/vision/detection/paddledetection/README.md
+++ b/examples/vision/detection/paddledetection/README.md
@@ -20,6 +20,15 @@
- [YOLOv6系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov6)
- [YOLOv7系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/yolov7)
- [RTMDet系列模型](https://github.com/PaddlePaddle/PaddleYOLO/tree/release/2.5/configs/rtmdet)
+- [CascadeRCNN系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/cascade_rcnn)
+- [PSSDet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/rcnn_enhance)
+- [RetinaNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/retinanet)
+- [PPYOLOESOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/develop/configs/smalldet)
+- [FCOS系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/fcos)
+- [TTFNet系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/ttfnet)
+- [TOOD系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/tood)
+- [GFL系列模型](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/gfl)
+
## 导出部署模型
@@ -59,6 +68,16 @@
| [yolov6_s_400e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6_s_400e_coco.tgz) | 68M | Box AP 43.4%| |
| [yolov7_l_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_l_300e_coco.tgz) | 145M | Box AP 51.0%| |
| [yolov7_x_300e_coco](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7_x_300e_coco.tgz) | 277M | Box AP 53.0%| |
+| [cascade_rcnn_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_fpn_1x_coco.tgz) | 271M | Box AP 41.1%| 暂不支持TensorRT、ORT |
+| [cascade_rcnn_r50_vd_fpn_ssld_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/cascade_rcnn_r50_vd_fpn_ssld_2x_coco.tgz) | 271M | Box AP 45.0%| 暂不支持TensorRT、ORT |
+| [faster_rcnn_enhance_3x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/faster_rcnn_enhance_3x_coco.tgz) | 119M | Box AP 41.5%| 暂不支持TensorRT、ORT |
+| [fcos_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/fcos_r50_fpn_1x_coco.tgz) | 129M | Box AP 39.6%| 暂不支持TensorRT |
+| [gfl_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/gfl_r50_fpn_1x_coco.tgz) | 128M | Box AP 41.0%| 暂不支持TensorRT |
+| [ppyoloe_crn_l_80e_sliced_visdrone_640_025](https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_80e_sliced_visdrone_640_025.tgz) | 200M | Box AP 31.9%| |
+| [retinanet_r101_fpn_2x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r101_fpn_2x_coco.tgz) | 210M | Box AP 40.6%| 暂不支持TensorRT、ORT |
+| [retinanet_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/retinanet_r50_fpn_1x_coco.tgz) | 136M | Box AP 37.5%| 暂不支持TensorRT、ORT |
+| [tood_r50_fpn_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/tood_r50_fpn_1x_coco.tgz) | 130M | Box AP 42.5%| 暂不支持TensorRT、ORT |
+| [ttfnet_darknet53_1x_coco](https://bj.bcebos.com/paddlehub/fastdeploy/ttfnet_darknet53_1x_coco.tgz) | 178M | Box AP 33.5%| 暂不支持TensorRT、ORT |
## 详细部署文档
diff --git a/examples/vision/detection/paddledetection/a311d/cpp/README.md b/examples/vision/detection/paddledetection/a311d/cpp/README.md
index 41e4ab3d287..baf2016f4a2 100755
--- a/examples/vision/detection/paddledetection/a311d/cpp/README.md
+++ b/examples/vision/detection/paddledetection/a311d/cpp/README.md
@@ -4,13 +4,15 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
### 模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe)
-- 3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe)
+3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。)
+4. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 A311D 上部署量化后的 PP-YOLOE 检测模型
请按照以下步骤完成在 A311D 上部署 PP-YOLOE 量化模型:
diff --git a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
index 9382931a146..6dcbb7cc884 100644
--- a/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
+++ b/examples/vision/detection/paddledetection/cpp/CMakeLists.txt
@@ -44,3 +44,27 @@ target_link_libraries(infer_yolov7_demo ${FASTDEPLOY_LIBS})
add_executable(infer_rtmdet_demo ${PROJECT_SOURCE_DIR}/infer_rtmdet.cc)
target_link_libraries(infer_rtmdet_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_cascadercnn_demo ${PROJECT_SOURCE_DIR}/infer_cascadercnn.cc)
+target_link_libraries(infer_cascadercnn_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_pssdet_demo ${PROJECT_SOURCE_DIR}/infer_pssdet.cc)
+target_link_libraries(infer_pssdet_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_retinanet_demo ${PROJECT_SOURCE_DIR}/infer_retinanet.cc)
+target_link_libraries(infer_retinanet_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_ppyoloesod_demo ${PROJECT_SOURCE_DIR}/infer_ppyoloesod.cc)
+target_link_libraries(infer_ppyoloesod_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_fcos_demo ${PROJECT_SOURCE_DIR}/infer_fcos.cc)
+target_link_libraries(infer_fcos_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_ttfnet_demo ${PROJECT_SOURCE_DIR}/infer_ttfnet.cc)
+target_link_libraries(infer_ttfnet_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_tood_demo ${PROJECT_SOURCE_DIR}/infer_tood.cc)
+target_link_libraries(infer_tood_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_gfl_demo ${PROJECT_SOURCE_DIR}/infer_gfl.cc)
+target_link_libraries(infer_gfl_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/paddledetection/cpp/README.md b/examples/vision/detection/paddledetection/cpp/README.md
index 5dbee5bf2df..0e944a465aa 100755
--- a/examples/vision/detection/paddledetection/cpp/README.md
+++ b/examples/vision/detection/paddledetection/cpp/README.md
@@ -1,6 +1,6 @@
# PaddleDetection C++部署示例
-本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
+本目录下提供`infer_xxx.cc`快速完成PaddleDetection模型包括PPYOLOE/PicoDet/YOLOX/YOLOv3/PPYOLO/FasterRCNN/YOLOv5/YOLOv6/YOLOv7/RTMDet/CascadeRCNN/PSSDet/RetinaNet/PPYOLOESOD/FCOS/TTFNet/TOOD/GFL在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。
在部署前,需确认以下两个步骤
@@ -34,16 +34,21 @@ tar xvf ppyoloe_crn_l_300e_coco.tgz
./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 2
# 昆仑芯XPU推理
./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 3
+# 华为昇腾推理
+./infer_ppyoloe_demo ./ppyoloe_crn_l_300e_coco 000000014439.jpg 4
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
## PaddleDetection C++接口
### 模型类
-PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API
+PaddleDetection目前支持6种模型系列,类名分别为`PPYOLOE`, `PicoDet`, `PaddleYOLOX`, `PPYOLO`, `FasterRCNN`,`SSD`,`PaddleYOLOv5`,`PaddleYOLOv6`,`PaddleYOLOv7`,`RTMDet`,`CascadeRCNN`,`PSSDet`,`RetinaNet`,`PPYOLOESOD`,`FCOS`,`TTFNet`,`TOOD`,`GFL`所有类名的构造函数和预测函数在参数上完全一致,本文档以PPYOLOE为例讲解API
```c++
fastdeploy::vision::detection::PPYOLOE(
const string& model_file,
diff --git a/examples/vision/detection/paddledetection/cpp/infer_cascadercnn.cc b/examples/vision/detection/paddledetection/cpp/infer_cascadercnn.cc
new file mode 100644
index 00000000000..35043aa35c1
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_cascadercnn.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::CascadeRCNN(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::CascadeRCNN(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_fcos.cc b/examples/vision/detection/paddledetection/cpp/infer_fcos.cc
new file mode 100644
index 00000000000..9c9bd18cb6b
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_fcos.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::FCOS(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::FCOS(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_gfl.cc b/examples/vision/detection/paddledetection/cpp/infer_gfl.cc
new file mode 100644
index 00000000000..ae772f63a30
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_gfl.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::GFL(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::GFL(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_ppyolo.cc b/examples/vision/detection/paddledetection/cpp/infer_ppyolo.cc
index 088e984027f..6db82aaca77 100755
--- a/examples/vision/detection/paddledetection/cpp/infer_ppyolo.cc
+++ b/examples/vision/detection/paddledetection/cpp/infer_ppyolo.cc
@@ -102,6 +102,33 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::PPYOLO(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout
@@ -120,6 +147,8 @@ int main(int argc, char* argv[]) {
GpuInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 2) {
KunlunXinInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 3) {
+ AscendInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_ppyoloe.cc b/examples/vision/detection/paddledetection/cpp/infer_ppyoloe.cc
index 99922e22a94..c7efaa7c5ba 100755
--- a/examples/vision/detection/paddledetection/cpp/infer_ppyoloe.cc
+++ b/examples/vision/detection/paddledetection/cpp/infer_ppyoloe.cc
@@ -131,6 +131,33 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout
@@ -151,6 +178,8 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
KunlunXinInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 4) {
+ AscendInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_ppyoloesod.cc b/examples/vision/detection/paddledetection/cpp/infer_ppyoloesod.cc
new file mode 100644
index 00000000000..2ef3d0d1bff
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_ppyoloesod.cc
@@ -0,0 +1,127 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::PPYOLOESOD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::PPYOLOESOD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void TrtInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ option.UseTrtBackend();
+ auto model = fastdeploy::vision::detection::PPYOLOESOD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 2) {
+ TrtInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_pssdet.cc b/examples/vision/detection/paddledetection/cpp/infer_pssdet.cc
new file mode 100644
index 00000000000..5d282d86104
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_pssdet.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::PSSDet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::PSSDet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_retinanet.cc b/examples/vision/detection/paddledetection/cpp/infer_retinanet.cc
new file mode 100644
index 00000000000..4accb51c88a
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_retinanet.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::RetinaNet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::RetinaNet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_ssd.cc b/examples/vision/detection/paddledetection/cpp/infer_ssd.cc
index b71bf266cf1..6c050da7f69 100755
--- a/examples/vision/detection/paddledetection/cpp/infer_ssd.cc
+++ b/examples/vision/detection/paddledetection/cpp/infer_ssd.cc
@@ -104,6 +104,33 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::SSD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout
@@ -122,6 +149,8 @@ int main(int argc, char* argv[]) {
GpuInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 2) {
KunlunXinInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 3) {
+ AscendInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_tood.cc b/examples/vision/detection/paddledetection/cpp/infer_tood.cc
new file mode 100644
index 00000000000..fb0fd778b71
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_tood.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::TOOD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::TOOD(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_ttfnet.cc b/examples/vision/detection/paddledetection/cpp/infer_ttfnet.cc
new file mode 100644
index 00000000000..144486f159e
--- /dev/null
+++ b/examples/vision/detection/paddledetection/cpp/infer_ttfnet.cc
@@ -0,0 +1,96 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void CpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseCpu();
+ auto model = fastdeploy::vision::detection::TTFNet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+void GpuInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+
+ auto option = fastdeploy::RuntimeOption();
+ option.UseGpu();
+ auto model = fastdeploy::vision::detection::TTFNet(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 4) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./ppyoloe_model_dir ./test.jpeg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with gpu; 2: run with gpu and use tensorrt backend."
+ << std::endl;
+ return -1;
+ }
+
+ if (std::atoi(argv[3]) == 0) {
+ CpuInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 1) {
+ GpuInfer(argv[1], argv[2]);
+ }
+ return 0;
+}
diff --git a/examples/vision/detection/paddledetection/cpp/infer_yolov3.cc b/examples/vision/detection/paddledetection/cpp/infer_yolov3.cc
index 3ec4410146d..2f866bf5e51 100755
--- a/examples/vision/detection/paddledetection/cpp/infer_yolov3.cc
+++ b/examples/vision/detection/paddledetection/cpp/infer_yolov3.cc
@@ -102,6 +102,34 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "infer_cfg.yml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::YOLOv3(model_file, params_file,
+ config_file, option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisDetection(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout
@@ -120,6 +148,8 @@ int main(int argc, char* argv[]) {
GpuInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 2) {
KunlunXinInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 3) {
+ AscendInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/detection/paddledetection/python/README.md b/examples/vision/detection/paddledetection/python/README.md
index b926dd9eea5..856629a5686 100755
--- a/examples/vision/detection/paddledetection/python/README.md
+++ b/examples/vision/detection/paddledetection/python/README.md
@@ -25,6 +25,8 @@ python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device gpu --use_trt True
# 昆仑芯XPU推理
python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device kunlunxin
+# 华为昇腾推理
+python infer_ppyoloe.py --model_dir ppyoloe_crn_l_300e_coco --image 000000014439.jpg --device ascend
```
运行完成可视化结果如下图所示
@@ -47,6 +49,14 @@ fastdeploy.vision.detection.PaddleYOLOv5(model_file, params_file, config_file, r
fastdeploy.vision.detection.PaddleYOLOv6(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
fastdeploy.vision.detection.PaddleYOLOv7(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
fastdeploy.vision.detection.RTMDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.CascadeRCNN(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.PSSDet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.RetinaNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.PPYOLOESOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.FCOS(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.TTFNet(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.TOOD(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+fastdeploy.vision.detection.GFL(model_file, params_file, config_file, runtime_option=None, model_format=ModelFormat.PADDLE)
```
PaddleDetection模型加载和初始化,其中model_file, params_file为导出的Paddle部署模型格式, config_file为PaddleDetection同时导出的部署配置yaml文件
diff --git a/examples/vision/detection/paddledetection/python/infer_cascadercnn.py b/examples/vision/detection/paddledetection/python/infer_cascadercnn.py
new file mode 100644
index 00000000000..26541a8a7a6
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_cascadercnn.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.CascadeRCNN(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_fcos.py b/examples/vision/detection/paddledetection/python/infer_fcos.py
new file mode 100644
index 00000000000..f8ff6ffa333
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_fcos.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.FCOS(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_gfl.py b/examples/vision/detection/paddledetection/python/infer_gfl.py
new file mode 100644
index 00000000000..36194ea630b
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_gfl.py
@@ -0,0 +1,51 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.GFL(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_ppyolo.py b/examples/vision/detection/paddledetection/python/infer_ppyolo.py
index 279c5bb9fc1..77feb8072f4 100755
--- a/examples/vision/detection/paddledetection/python/infer_ppyolo.py
+++ b/examples/vision/detection/paddledetection/python/infer_ppyolo.py
@@ -32,6 +32,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.device.lower() == "gpu":
option.use_gpu()
diff --git a/examples/vision/detection/paddledetection/python/infer_ppyoloe.py b/examples/vision/detection/paddledetection/python/infer_ppyoloe.py
index 2b0971f1289..9f3f6283263 100755
--- a/examples/vision/detection/paddledetection/python/infer_ppyoloe.py
+++ b/examples/vision/detection/paddledetection/python/infer_ppyoloe.py
@@ -33,6 +33,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.device.lower() == "gpu":
option.use_gpu()
diff --git a/examples/vision/detection/paddledetection/python/infer_ppyoloesod.py b/examples/vision/detection/paddledetection/python/infer_ppyoloesod.py
new file mode 100644
index 00000000000..6dece21387f
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_ppyoloesod.py
@@ -0,0 +1,59 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ parser.add_argument(
+ "--use_trt",
+ type=ast.literal_eval,
+ default=False,
+ help="Wether to use tensorrt.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+
+ if args.use_trt:
+ option.use_trt_backend()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.PPYOLOESOD(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im.copy())
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_pssdet.py b/examples/vision/detection/paddledetection/python/infer_pssdet.py
new file mode 100644
index 00000000000..00ab7fb73b3
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_pssdet.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.PSSDet(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_retinanet.py b/examples/vision/detection/paddledetection/python/infer_retinanet.py
new file mode 100644
index 00000000000..65edc78c57f
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_retinanet.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.RetinaNet(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_ssd.py b/examples/vision/detection/paddledetection/python/infer_ssd.py
index 536bf59447e..410f469dd7d 100755
--- a/examples/vision/detection/paddledetection/python/infer_ssd.py
+++ b/examples/vision/detection/paddledetection/python/infer_ssd.py
@@ -26,6 +26,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.device.lower() == "gpu":
option.use_gpu()
return option
diff --git a/examples/vision/detection/paddledetection/python/infer_tood.py b/examples/vision/detection/paddledetection/python/infer_tood.py
new file mode 100644
index 00000000000..dc5d2253218
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_tood.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.TOOD(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_ttfnet.py b/examples/vision/detection/paddledetection/python/infer_ttfnet.py
new file mode 100644
index 00000000000..c3ec8a7f57c
--- /dev/null
+++ b/examples/vision/detection/paddledetection/python/infer_ttfnet.py
@@ -0,0 +1,50 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--model_dir",
+ required=True,
+ help="Path of PaddleDetection model directory")
+ parser.add_argument(
+ "--image", required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ return option
+
+
+args = parse_arguments()
+
+model_file = os.path.join(args.model_dir, "model.pdmodel")
+params_file = os.path.join(args.model_dir, "model.pdiparams")
+config_file = os.path.join(args.model_dir, "infer_cfg.yml")
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+model = fd.vision.detection.TTFNet(
+ model_file, params_file, config_file, runtime_option=runtime_option)
+
+# 预测图片检测结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result, score_threshold=0.5)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/detection/paddledetection/python/infer_yolov3.py b/examples/vision/detection/paddledetection/python/infer_yolov3.py
index 8f6b509f98a..26c12f7f2fc 100755
--- a/examples/vision/detection/paddledetection/python/infer_yolov3.py
+++ b/examples/vision/detection/paddledetection/python/infer_yolov3.py
@@ -32,6 +32,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.device.lower() == "gpu":
option.use_gpu()
diff --git a/examples/vision/detection/paddledetection/rv1126/cpp/README.md b/examples/vision/detection/paddledetection/rv1126/cpp/README.md
index de47ec8bfb8..c662ecb4409 100755
--- a/examples/vision/detection/paddledetection/rv1126/cpp/README.md
+++ b/examples/vision/detection/paddledetection/rv1126/cpp/README.md
@@ -4,13 +4,15 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
### 模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe)
-- 3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以先使用 PaddleDetection 自行导出 Float32 模型,注意导出模型模型时设置参数:use_shared_conv=False,更多细节请参考:[PP-YOLOE](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/configs/ppyoloe)
+3. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。(注意: 推理量化后的检测模型仍然需要FP32模型文件夹下的 infer_cfg.yml 文件,自行量化的模型文件夹内不包含此 yaml 文件,用户从 FP32 模型文件夹下复制此yaml文件到量化后的模型文件夹内即可。)
+4. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 RV1126 上部署量化后的 PP-YOLOE 检测模型
请按照以下步骤完成在 RV1126 上部署 PP-YOLOE 量化模型:
diff --git a/examples/vision/detection/paddledetection/serving/models/postprocess/1/model.py b/examples/vision/detection/paddledetection/serving/models/postprocess/1/model.py
index 4872b0dee2c..35054e51657 100644
--- a/examples/vision/detection/paddledetection/serving/models/postprocess/1/model.py
+++ b/examples/vision/detection/paddledetection/serving/models/postprocess/1/model.py
@@ -95,7 +95,7 @@ def execute(self, requests):
results = self.postprocess_.run(infer_outputs)
r_str = fd.vision.utils.fd_result_to_json(results)
- r_np = np.array(r_str, dtype=np.object)
+ r_np = np.array(r_str, dtype=np.object_)
out_tensor = pb_utils.Tensor(self.output_names[0], r_np)
inference_response = pb_utils.InferenceResponse(
output_tensors=[out_tensor, ])
diff --git a/examples/vision/detection/paddledetection/serving/models/runtime/ppyoloe_runtime_config.pbtxt b/examples/vision/detection/paddledetection/serving/models/runtime/ppyoloe_runtime_config.pbtxt
index 39b2c6045f5..dc8d15845ce 100644
--- a/examples/vision/detection/paddledetection/serving/models/runtime/ppyoloe_runtime_config.pbtxt
+++ b/examples/vision/detection/paddledetection/serving/models/runtime/ppyoloe_runtime_config.pbtxt
@@ -1,5 +1,5 @@
# optional, If name is specified it must match the name of the model repository directory containing the model.
-name: "ppyoloe_runtime"
+name: "runtime"
backend: "fastdeploy"
# Input configuration of the model
diff --git a/examples/vision/detection/scaledyolov4/README.md b/examples/vision/detection/scaledyolov4/README.md
index 36ec1af0ce0..df3799282ef 100644
--- a/examples/vision/detection/scaledyolov4/README.md
+++ b/examples/vision/detection/scaledyolov4/README.md
@@ -23,19 +23,18 @@
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了ScaledYOLOv4导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [ScaledYOLOv4-P5-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5-896.onnx) | 271MB | 51.2% |
-| [ScaledYOLOv4-P5+BoF-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_-896.onnx) | 271MB | 51.7% |
-| [ScaledYOLOv4-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6-1280.onnx) | 487MB | 53.9% |
-| [ScaledYOLOv4-P6+BoF-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_-1280.onnx) | 487MB | 54.4% |
-| [ScaledYOLOv4-P7-1536](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7-1536.onnx) | 1.1GB | 55.0% |
-| [ScaledYOLOv4-P5](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx) | 271MB | - |
-| [ScaledYOLOv4-P5+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_.onnx) | 271MB | -|
-| [ScaledYOLOv4-P6](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6.onnx) | 487MB | - |
-| [ScaledYOLOv4-P6+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_.onnx) | 487MB | - |
-| [ScaledYOLOv4-P7](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7.onnx) | 1.1GB | - |
-
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [ScaledYOLOv4-P5-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5-896.onnx) | 271MB | 51.2% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P5+BoF-896](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_-896.onnx) | 271MB | 51.7% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6-1280.onnx) | 487MB | 53.9% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P6+BoF-1280](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_-1280.onnx) | 487MB | 54.4% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P7-1536](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7-1536.onnx) | 1.1GB | 55.0% | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P5](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5.onnx) | 271MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P5+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p5_.onnx) | 271MB | -| 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P6](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P6+BoF](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p6_.onnx) | 487MB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
+| [ScaledYOLOv4-P7](https://bj.bcebos.com/paddlehub/fastdeploy/scaled_yolov4-p7.onnx) | 1.1GB | - | 此模型文件来源于[ScaledYOLOv4](https://github.com/WongKinYiu/ScaledYOLOv4),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolor/README.md b/examples/vision/detection/yolor/README.md
index ffe29f39f5b..c9749a0886f 100644
--- a/examples/vision/detection/yolor/README.md
+++ b/examples/vision/detection/yolor/README.md
@@ -22,19 +22,18 @@
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOR导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOR-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-1280-1280.onnx) | 143MB | 54.1% |
-| [YOLOR-W6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-1280-1280.onnx) | 305MB | 55.5% |
-| [YOLOR-E6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-1280-1280.onnx ) | 443MB | 56.4% |
-| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-1280-1280.onnx) | 580MB | 57.0% |
-| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-1280-1280.onnx) | 580MB | 57.3% |
-| [YOLOR-P6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx) | 143MB | - |
-| [YOLOR-W6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-640-640.onnx) | 305MB | - |
-| [YOLOR-E6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-640-640.onnx ) | 443MB | - |
-| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-640-640.onnx) | 580MB | - |
-| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-640-640.onnx) | 580MB | - |
-
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [YOLOR-P6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-1280-1280.onnx) | 143MB | 54.1% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-W6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-1280-1280.onnx) | 305MB | 55.5% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-E6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-1280-1280.onnx ) | 443MB | 56.4% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-1280-1280.onnx) | 580MB | 57.0% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-D6-1280](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-1280-1280.onnx) | 580MB | 57.3% | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-P6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-p6-paper-541-640-640.onnx) | 143MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-W6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-w6-paper-555-640-640.onnx) | 305MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-E6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-e6-paper-564-640-640.onnx ) | 443MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-570-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
+| [YOLOR-D6](https://bj.bcebos.com/paddlehub/fastdeploy/yolor-d6-paper-573-640-640.onnx) | 580MB | - | 此模型文件来源于[YOLOR](https://github.com/WongKinYiu/yolor),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov5/README.md b/examples/vision/detection/yolov5/README.md
index 095c8071d00..5ffe3f046a2 100644
--- a/examples/vision/detection/yolov5/README.md
+++ b/examples/vision/detection/yolov5/README.md
@@ -8,13 +8,13 @@
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv5导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% |
-| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% |
-| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% |
-| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% |
-| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% |
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:---- |
+| [YOLOv5n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5n.onnx) | 7.6MB | 28.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License |
+| [YOLOv5s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx) | 28MB | 37.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License |
+| [YOLOv5m](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5m.onnx) | 82MB | 45.4% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License |
+| [YOLOv5l](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5l.onnx) | 178MB | 49.0% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License |
+| [YOLOv5x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov5x.onnx) | 332MB | 50.7% | 此模型文件来源于[YOLOv5](https://github.com/ultralytics/yolov5),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov5/a311d/README.md b/examples/vision/detection/yolov5/a311d/README.md
index fc2ddd40f0e..2f8451c60e7 100755
--- a/examples/vision/detection/yolov5/a311d/README.md
+++ b/examples/vision/detection/yolov5/a311d/README.md
@@ -1,8 +1,5 @@
# YOLOv5 量化模型在 A311D 上的部署
-目前 FastDeploy 已经支持基于 Paddle Lite 部署 YOLOv5 量化模型到 A311D 上。
-
-模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md)
-
+目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 A311D 上。
## 详细部署文档
diff --git a/examples/vision/detection/yolov5/a311d/cpp/README.md b/examples/vision/detection/yolov5/a311d/cpp/README.md
index 0fad86f485b..2271af43500 100755
--- a/examples/vision/detection/yolov5/a311d/cpp/README.md
+++ b/examples/vision/detection/yolov5/a311d/cpp/README.md
@@ -4,12 +4,31 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
### 量化模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+可以直接使用由 FastDeploy 提供的量化模型进行部署,也可以按照如下步骤准备量化模型:
+1. 按照 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 官方导出方式导出 ONNX 模型,或者直接使用如下命令下载
+```bash
+wget https://paddle-slim-models.bj.bcebos.com/act/yolov5s.onnx
+```
+2. 准备 300 张左右量化用的图片,也可以使用如下命令下载我们准备好的数据。
+```bash
+wget https://bj.bcebos.com/fastdeploy/models/COCO_val_320.tar.gz
+tar -xf COCO_val_320.tar.gz
+```
+3. 使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。
+```bash
+fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model_new/'
+```
+4. YOLOv5 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了 YOLOv5 模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+```bash
+# 先下载我们提供的模型,解压后将其中的 subgraph.txt 文件拷贝到新量化的模型目录中
+wget https://bj.bcebos.com/fastdeploy/models/yolov5s_ptq_model.tar.gz
+tar -xvf yolov5s_ptq_model.tar.gz
+```
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 A311D 上部署量化后的 YOLOv5 检测模型
请按照以下步骤完成在 A311D 上部署 YOLOv5 量化模型:
diff --git a/examples/vision/detection/yolov5/cpp/README.md b/examples/vision/detection/yolov5/cpp/README.md
index 8f03a39ad03..c70d0d11885 100755
--- a/examples/vision/detection/yolov5/cpp/README.md
+++ b/examples/vision/detection/yolov5/cpp/README.md
@@ -31,6 +31,8 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
./infer_paddle_demo yolov5s_infer 000000014439.jpg 2
# 昆仑芯XPU推理
./infer_paddle_demo yolov5s_infer 000000014439.jpg 3
+# 华为昇腾推理
+./infer_paddle_demo yolov5s_infer 000000014439.jpg 4
```
上述的模型为 Paddle 模型的推理,如果想要做 ONNX 模型的推理,可以按照如下步骤:
@@ -53,6 +55,9 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
## YOLOv5 C++接口
### YOLOv5类
diff --git a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
index e4c02af8ade..e5302eca20c 100755
--- a/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
+++ b/examples/vision/detection/yolov5/cpp/infer_paddle_model.cc
@@ -130,6 +130,35 @@ void KunlunXinInfer(const std::string& model_dir, const std::string& image_file)
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+ std::cout << res.Str() << std::endl;
+
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
+
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout << "Usage: infer_demo path/to/model path/to/image run_option, "
@@ -149,6 +178,8 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
KunlunXinInfer(argv[1], argv[2]);
- }
+ } else if (std::atoi(argv[3]) == 4) {
+ AscendInfer(argv[1], argv[2]);
+ }
return 0;
}
diff --git a/examples/vision/detection/yolov5/python/README.md b/examples/vision/detection/yolov5/python/README.md
index 77f9027d584..de93ef0ecb9 100755
--- a/examples/vision/detection/yolov5/python/README.md
+++ b/examples/vision/detection/yolov5/python/README.md
@@ -25,6 +25,8 @@ python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu
python infer.py --model yolov5s_infer --image 000000014439.jpg --device gpu --use_trt True
# 昆仑芯XPU推理
python infer.py --model yolov5s_infer --image 000000014439.jpg --device kunlunxin
+# 华为昇腾推理
+python infer.py --model yolov5s_infer --image 000000014439.jpg --device ascend
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/detection/yolov5/python/infer.py b/examples/vision/detection/yolov5/python/infer.py
index 7f0823d8abe..74fd96e6c99 100755
--- a/examples/vision/detection/yolov5/python/infer.py
+++ b/examples/vision/detection/yolov5/python/infer.py
@@ -31,6 +31,9 @@ def build_option(args):
if args.device.lower() == "gpu":
option.use_gpu()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.use_trt:
option.use_trt_backend()
option.set_trt_input_shape("images", [1, 3, 640, 640])
diff --git a/examples/vision/detection/yolov5/rv1126/README.md b/examples/vision/detection/yolov5/rv1126/README.md
index b92c9903b63..5bac651e207 100755
--- a/examples/vision/detection/yolov5/rv1126/README.md
+++ b/examples/vision/detection/yolov5/rv1126/README.md
@@ -1,8 +1,5 @@
# YOLOv5 量化模型在 RV1126 上的部署
-目前 FastDeploy 已经支持基于 Paddle Lite 部署 YOLOv5 量化模型到 RV1126 上。
-
-模型的量化和量化模型的下载请参考:[模型量化](../quantize/README.md)
-
+目前 FastDeploy 已经支持基于 Paddle Lite 部署 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 量化模型到 RV1126 上。
## 详细部署文档
diff --git a/examples/vision/detection/yolov5/rv1126/cpp/README.md b/examples/vision/detection/yolov5/rv1126/cpp/README.md
index 437c4c0b968..469bb6060b6 100755
--- a/examples/vision/detection/yolov5/rv1126/cpp/README.md
+++ b/examples/vision/detection/yolov5/rv1126/cpp/README.md
@@ -4,12 +4,31 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
### 量化模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+可以直接使用由 FastDeploy 提供的量化模型进行部署,也可以按照如下步骤准备量化模型:
+1. 按照 [YOLOv5](https://github.com/ultralytics/yolov5/releases/tag/v6.1) 官方导出方式导出 ONNX 模型,或者直接使用如下命令下载
+```bash
+wget https://paddle-slim-models.bj.bcebos.com/act/yolov5s.onnx
+```
+2. 准备 300 张左右量化用的图片,也可以使用如下命令下载我们准备好的数据。
+```bash
+wget https://bj.bcebos.com/fastdeploy/models/COCO_val_320.tar.gz
+tar -xf COCO_val_320.tar.gz
+```
+3. 使用 FastDeploy 提供的[一键模型自动化压缩工具](../../../../../../tools/common_tools/auto_compression/),自行进行模型量化, 并使用产出的量化模型进行部署。
+```bash
+fastdeploy compress --config_path=./configs/detection/yolov5s_quant.yaml --method='PTQ' --save_dir='./yolov5s_ptq_model_new/'
+```
+4. YOLOv5 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了 YOLOv5 模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+```bash
+# 先下载我们提供的模型,解压后将其中的 subgraph.txt 文件拷贝到新量化的模型目录中
+wget https://bj.bcebos.com/fastdeploy/models/yolov5s_ptq_model.tar.gz
+tar -xvf yolov5s_ptq_model.tar.gz
+```
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 RV1126 上部署量化后的 YOLOv5 检测模型
请按照以下步骤完成在 RV1126 上部署 YOLOv5 量化模型:
diff --git a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
index 7c608db4372..1204446c438 100644
--- a/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
+++ b/examples/vision/detection/yolov5/serving/models/postprocess/1/model.py
@@ -96,7 +96,7 @@ def execute(self, requests):
results = self.postprocessor_.run([infer_outputs], im_infos)
r_str = fd.vision.utils.fd_result_to_json(results)
- r_np = np.array(r_str, dtype=np.object)
+ r_np = np.array(r_str, dtype=np.object_)
out_tensor = pb_utils.Tensor(self.output_names[0], r_np)
inference_response = pb_utils.InferenceResponse(
diff --git a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
index cf4f7e8e8b3..d60de6541bc 100644
--- a/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
+++ b/examples/vision/detection/yolov5/serving/models/preprocess/1/model.py
@@ -95,7 +95,7 @@ def execute(self, requests):
dlpack_tensor)
output_tensor_1 = pb_utils.Tensor(
self.output_names[1], np.array(
- im_infos, dtype=np.object))
+ im_infos, dtype=np.object_))
inference_response = pb_utils.InferenceResponse(
output_tensors=[output_tensor_0, output_tensor_1])
responses.append(inference_response)
diff --git a/examples/vision/detection/yolov5/sophgo/README.md b/examples/vision/detection/yolov5/sophgo/README.md
new file mode 100644
index 00000000000..d4fa4f7a8b0
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/README.md
@@ -0,0 +1,75 @@
+# YOLOv5 SOPHGO部署示例
+
+## 支持模型列表
+
+YOLOv5 v6.0部署模型实现来自[YOLOv5](https://github.com/ultralytics/yolov5/tree/v6.0),和[基于COCO的预训练模型](https://github.com/ultralytics/yolov5/releases/tag/v6.0)
+
+## 准备YOLOv5部署模型以及转换模型
+
+SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下:
+- 下载预训练ONNX模型,请参考[YOLOv5准备部署模型](https://github.com/PaddlePaddle/FastDeploy/tree/develop/examples/vision/detection/yolov5)
+- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir)
+
+## 模型转换example
+
+下面以YOLOv5s为例子,教大家如何转换ONNX模型到SOPHGO-TPU模型
+
+## 下载YOLOv5s模型
+
+### 下载ONNX YOLOv5s静态图模型
+```shell
+wget https://bj.bcebos.com/paddlehub/fastdeploy/yolov5s.onnx
+
+```
+### 导出bmodel模型
+
+以转化BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+### 1. 安装
+``` shell
+docker pull sophgo/tpuc_dev:latest
+
+# myname1234是一个示例,也可以设置其他名字
+docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest
+
+source ./envsetup.sh
+./build.sh
+```
+
+### 2. ONNX模型转换为bmodel模型
+``` shell
+mkdir YOLOv5s && cd YOLOv5s
+
+# 在该文件中放入测试图片,同时将上一步下载的yolov5s.onnx放入该文件夹中
+cp -rf ${REGRESSION_PATH}/dataset/COCO2017 .
+cp -rf ${REGRESSION_PATH}/image .
+# 放入onnx模型文件yolov5s.onnx
+
+mkdir workspace && cd workspace
+
+# 将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看
+model_transform.py \
+ --model_name yolov5s \
+ --model_def ../yolov5s.onnx \
+ --input_shapes [[1,3,640,640]] \
+ --mean 0.0,0.0,0.0 \
+ --scale 0.0039216,0.0039216,0.0039216 \
+ --keep_aspect_ratio \
+ --pixel_format rgb \
+ --output_names output,350,498,646 \
+ --test_input ../image/dog.jpg \
+ --test_result yolov5s_top_outputs.npz \
+ --mlir yolov5s.mlir
+
+# 将mlir模型转换为BM1684x的F32 bmodel模型
+model_deploy.py \
+ --mlir yolov5s.mlir \
+ --quantize F32 \
+ --chip bm1684x \
+ --test_input yolov5s_in_f32.npz \
+ --test_reference yolov5s_top_outputs.npz \
+ --model yolov5s_1684x_f32.bmodel
+```
+最终获得可以在BM1684x上能够运行的bmodel模型yolov5s_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+
+## 其他链接
+- [Cpp部署](./cpp)
diff --git a/examples/vision/detection/yolov5/sophgo/cpp/CMakeLists.txt b/examples/vision/detection/yolov5/sophgo/cpp/CMakeLists.txt
new file mode 100644
index 00000000000..53837058969
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/cpp/CMakeLists.txt
@@ -0,0 +1,17 @@
+PROJECT(infer_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+# 指定下载解压后的fastdeploy库路径
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+
+set(ENABLE_LITE_BACKEND OFF)
+#set(FDLIB ${FASTDEPLOY_INSTALL_DIR})
+
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+
+# 添加FastDeploy依赖头文件
+include_directories(${FASTDEPLOY_INCS})
+include_directories(${FastDeploy_INCLUDE_DIRS})
+
+add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/detection/yolov5/sophgo/cpp/README.md b/examples/vision/detection/yolov5/sophgo/cpp/README.md
new file mode 100644
index 00000000000..e313da85559
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/cpp/README.md
@@ -0,0 +1,56 @@
+# YOLOv5 C++部署示例
+
+本目录下提供`infer.cc`快速完成yolov5s模型在SOPHGO BM1684x板子上加速部署的示例。
+
+在部署前,需确认以下两个步骤:
+
+1. 软硬件环境满足要求
+2. 根据开发环境,从头编译FastDeploy仓库
+
+以上步骤请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)实现
+
+## 生成基本目录文件
+
+该例程由以下几个部分组成
+```text
+.
+├── CMakeLists.txt
+├── build # 编译文件夹
+├── image # 存放图片的文件夹
+├── infer.cc
+└── model # 存放模型文件的文件夹
+```
+
+## 编译
+
+### 编译并拷贝SDK到thirdpartys文件夹
+
+请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录.
+
+### 拷贝模型文件,以及配置文件至model文件夹
+将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md)
+将转换后的SOPHGO bmodel模型文件拷贝至model中
+
+### 准备测试图片至image文件夹
+```bash
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+cp 000000014439.jpg ./images
+```
+
+### 编译example
+
+```bash
+cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3
+make
+```
+
+## 运行例程
+
+```bash
+./infer_demo model images/000000014439.jpg
+```
+
+
+- [模型介绍](../../)
+- [模型转换](../)
diff --git a/examples/vision/detection/yolov5/sophgo/cpp/infer.cc b/examples/vision/detection/yolov5/sophgo/cpp/infer.cc
new file mode 100644
index 00000000000..f1f63bcdc40
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/cpp/infer.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+#include
+#include "fastdeploy/vision.h"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void InitAndInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "yolov5s_1684x_f32.bmodel";
+ auto params_file = model_dir + sep + "";
+
+ fastdeploy::RuntimeOption option;
+ option.UseSophgo();
+ auto model_format = fastdeploy::ModelFormat::SOPHGO;
+
+ auto model = fastdeploy::vision::detection::YOLOv5(
+ model_file, params_file, option, model_format);
+
+ assert(model.Initialized());
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 3) {
+ std::cout << "Usage: infer_demo path/to/model "
+ "path/to/image "
+ "run_option, "
+ "e.g ./infer_demo ./model ./test.jpeg"
+ << std::endl;
+ return -1;
+ }
+
+ std::string model_dir = argv[1];
+ std::string test_image = argv[2];
+ InitAndInfer(model_dir, test_image);
+ return 0;
+}
diff --git a/examples/vision/detection/yolov5/sophgo/python/README.md b/examples/vision/detection/yolov5/sophgo/python/README.md
new file mode 100644
index 00000000000..ccf8ed7e872
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/python/README.md
@@ -0,0 +1,46 @@
+# YOLOv5 Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md)
+
+本目录下提供`infer.py`快速完成 YOLOv5 在SOPHGO TPU上部署的示例。执行如下脚本即可完成
+
+```bash
+# 下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/examples/vision/detection/yolov5/sophgo/python
+
+# 下载图片
+wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/000000014439.jpg
+
+# 推理
+python3 infer.py --model_file ./bmodel/yolov5s_1684x_f32.bmodel --image 000000014439.jpg
+
+# 运行完成后返回结果如下所示
+DetectionResult: [xmin, ymin, xmax, ymax, score, label_id]
+268.480255,81.053055, 298.694794, 169.439026, 0.896569, 0
+104.731163,45.661972, 127.583824, 93.449387, 0.869531, 0
+378.909363,39.750137, 395.608643, 84.243454, 0.868430, 0
+158.552979,80.361511, 199.185760, 168.181915, 0.842988, 0
+414.375305,90.948090, 506.321899, 280.405182, 0.835842, 0
+364.003448,56.608932, 381.978607, 115.968216, 0.815136, 0
+351.725128,42.635330, 366.910309, 98.048386, 0.808936, 0
+505.888306,114.366791, 593.124878, 275.995270, 0.801361, 0
+327.708618,38.363693, 346.849915, 80.893021, 0.794725, 0
+583.493408,114.532883, 612.354614, 175.873535, 0.760649, 0
+186.470657,44.941360, 199.664505, 61.037643, 0.632591, 0
+169.615891,48.014603, 178.141556, 60.888596, 0.613938, 0
+25.810200,117.199692, 59.888783, 152.850128, 0.590614, 0
+352.145294,46.712723, 381.946075, 106.752151, 0.505329, 0
+1.875000,150.734375, 37.968750, 173.781250, 0.404573, 24
+464.657288,15.901413, 472.512939, 34.116409, 0.346033, 0
+64.625000,135.171875, 84.500000, 154.406250, 0.332831, 24
+57.812500,151.234375, 103.000000, 174.156250, 0.332566, 24
+165.906250,88.609375, 527.906250, 339.953125, 0.259424, 33
+101.406250,152.562500, 118.890625, 169.140625, 0.253891, 24
+```
+
+## 其它文档
+- [YOLOv5 C++部署](../cpp)
+- [转换YOLOv5 SOPHGO模型文档](../README.md)
diff --git a/examples/vision/detection/yolov5/sophgo/python/infer.py b/examples/vision/detection/yolov5/sophgo/python/infer.py
new file mode 100644
index 00000000000..d1ea190c586
--- /dev/null
+++ b/examples/vision/detection/yolov5/sophgo/python/infer.py
@@ -0,0 +1,40 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--model", required=True, help="Path of model.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+
+ return parser.parse_args()
+
+
+args = parse_arguments()
+
+# 配置runtime,加载模型
+runtime_option = fd.RuntimeOption()
+runtime_option.use_sophgo()
+
+model_file = args.model
+params_file = ""
+
+model = fd.vision.detection.YOLOv5(
+ model_file,
+ params_file,
+ runtime_option=runtime_option,
+ model_format=fd.ModelFormat.SOPHGO)
+
+# 预测图片分类结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_detection(im, result)
+cv2.imwrite("sophgo_result.jpg", vis_im)
+print("Visualized result save in ./sophgo_result.jpg")
diff --git a/examples/vision/detection/yolov5lite/README.md b/examples/vision/detection/yolov5lite/README.md
index e8f72099bd8..0429758b844 100644
--- a/examples/vision/detection/yolov5lite/README.md
+++ b/examples/vision/detection/yolov5lite/README.md
@@ -52,12 +52,12 @@
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv5Lite导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOv5Lite-e](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-e-sim-320.onnx) | 3.1MB | 35.1% |
-| [YOLOv5Lite-s](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-s-sim-416.onnx) | 6.3MB | 42.0% |
-| [YOLOv5Lite-c](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-c-sim-512.onnx) | 18MB | 50.9% |
-| [YOLOv5Lite-g](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx) | 21MB | 57.6% |
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [YOLOv5Lite-e](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-e-sim-320.onnx) | 3.1MB | 35.1% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License |
+| [YOLOv5Lite-s](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-s-sim-416.onnx) | 6.3MB | 42.0% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License |
+| [YOLOv5Lite-c](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-c-sim-512.onnx) | 18MB | 50.9% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License |
+| [YOLOv5Lite-g](https://bj.bcebos.com/paddlehub/fastdeploy/v5Lite-g-sim-640.onnx) | 21MB | 57.6% | 此模型文件来源于[YOLOv5-Lite](https://github.com/ppogg/YOLOv5-Lite),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov6/README.md b/examples/vision/detection/yolov6/README.md
index 6c0ca042218..d31622a8b35 100644
--- a/examples/vision/detection/yolov6/README.md
+++ b/examples/vision/detection/yolov6/README.md
@@ -11,13 +11,12 @@
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv6导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx) | 66MB | 43.1% |
-| [YOLOv6s_640](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s-640x640.onnx) | 66MB | 43.1% |
-| [YOLOv6t](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6t.onnx) | 58MB | 41.3% |
-| [YOLOv6n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6n.onnx) | 17MB | 35.0% |
-
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [YOLOv6s](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License |
+| [YOLOv6s_640](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6s-640x640.onnx) | 66MB | 43.1% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License |
+| [YOLOv6t](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6t.onnx) | 58MB | 41.3% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License |
+| [YOLOv6n](https://bj.bcebos.com/paddlehub/fastdeploy/yolov6n.onnx) | 17MB | 35.0% | 此模型文件来源于[YOLOv6](https://github.com/meituan/YOLOv6),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov6/cpp/README.md b/examples/vision/detection/yolov6/cpp/README.md
index 973b6a54693..eceb5bc46f3 100755
--- a/examples/vision/detection/yolov6/cpp/README.md
+++ b/examples/vision/detection/yolov6/cpp/README.md
@@ -29,8 +29,14 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
./infer_paddle_demo yolov6s_infer 000000014439.jpg 1
# 昆仑芯XPU推理
./infer_paddle_demo yolov6s_infer 000000014439.jpg 2
+# 华为昇腾推理
+./infer_paddle_demo yolov6s_infer 000000014439.jpg 3
```
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
+
如果想要验证ONNX模型的推理,可以参考如下命令:
```bash
#下载官方转换好的YOLOv6 ONNX模型文件和测试图片
diff --git a/examples/vision/detection/yolov6/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov6/cpp/infer_paddle_model.cc
index fc43ee0ae63..bd5d0b0a6b7 100755
--- a/examples/vision/detection/yolov6/cpp/infer_paddle_model.cc
+++ b/examples/vision/detection/yolov6/cpp/infer_paddle_model.cc
@@ -96,6 +96,32 @@ void GpuInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ fastdeploy::RuntimeOption option;
+ option.UseAscend();
+ auto model = fastdeploy::vision::detection::YOLOv6(
+ model_file, params_file, option, fastdeploy::ModelFormat::PADDLE);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::DetectionResult res;
+ if (!model.Predict(&im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+ std::cout << res.Str() << std::endl;
+
+ auto vis_im = fastdeploy::vision::VisDetection(im, res);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
int main(int argc, char* argv[]) {
if (argc < 4) {
@@ -114,6 +140,8 @@ int main(int argc, char* argv[]) {
GpuInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 2) {
KunlunXinInfer(argv[1], argv[2]);
- }
+ } else if (std::atoi(argv[3]) == 3) {
+ AscendInfer(argv[1], argv[2]);
+ }
return 0;
}
diff --git a/examples/vision/detection/yolov6/python/README.md b/examples/vision/detection/yolov6/python/README.md
index a12bb902084..37a06fd5cec 100755
--- a/examples/vision/detection/yolov6/python/README.md
+++ b/examples/vision/detection/yolov6/python/README.md
@@ -22,6 +22,8 @@ python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --d
python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device gpu
# 昆仑芯XPU推理
python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device kunlunxin
+# 华为昇腾推理
+python infer_paddle_model.py --model yolov6s_infer --image 000000014439.jpg --device ascend
```
如果想要验证ONNX模型的推理,可以参考如下命令:
```bash
diff --git a/examples/vision/detection/yolov6/python/infer_paddle_model.py b/examples/vision/detection/yolov6/python/infer_paddle_model.py
index 25048620117..9fd1c382631 100755
--- a/examples/vision/detection/yolov6/python/infer_paddle_model.py
+++ b/examples/vision/detection/yolov6/python/infer_paddle_model.py
@@ -28,6 +28,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
return option
diff --git a/examples/vision/detection/yolov7/README.md b/examples/vision/detection/yolov7/README.md
index 925c26100cf..d07350fbc5d 100644
--- a/examples/vision/detection/yolov7/README.md
+++ b/examples/vision/detection/yolov7/README.md
@@ -27,16 +27,14 @@ python models/export.py --grid --dynamic --end2end --weights PATH/TO/yolov7.pt
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv7导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% |
-| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% |
-| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% |
-| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% |
-| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% |
-| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% |
-
-
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- | :----- |
+| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov7/README_EN.md b/examples/vision/detection/yolov7/README_EN.md
index 83394f52cc9..04001beb7b3 100644
--- a/examples/vision/detection/yolov7/README_EN.md
+++ b/examples/vision/detection/yolov7/README_EN.md
@@ -24,14 +24,14 @@ python models/export.py --grid --dynamic --end2end --weights PATH/TO/yolov7.pt
To facilitate testing for developers, we provide below the models exported by YOLOv7, which developers can download and use directly. (The accuracy of the models in the table is sourced from the official library)
-| Model | Size | Accuracy |
-| ------------------------------------------------------------------------ | ----- | -------- |
-| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% |
-| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% |
-| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% |
-| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% |
-| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% |
-| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% |
+| Model | Size | Accuracy | Note |
+| ------------------------------------------------------------------------ | ----- | -------- | -------- |
+| [YOLOv7](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7.onnx) | 141MB | 51.4% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
+| [YOLOv7x](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x.onnx) | 273MB | 53.1% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
+| [YOLOv7-w6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6.onnx) | 269MB | 54.9% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
+| [YOLOv7-e6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6.onnx) | 372MB | 56.0% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
+| [YOLOv7-d6](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6.onnx) | 511MB | 56.6% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
+| [YOLOv7-e6e](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e.onnx) | 579MB | 56.8% | This model file comes from [YOLOv7](https://github.com/WongKinYiu/yolov7), GPL-3.0 License |
## Detailed Deployment Tutorials
diff --git a/examples/vision/detection/yolov7/cpp/README.md b/examples/vision/detection/yolov7/cpp/README.md
index 8fc7928a8d6..5308f7ddbe7 100755
--- a/examples/vision/detection/yolov7/cpp/README.md
+++ b/examples/vision/detection/yolov7/cpp/README.md
@@ -28,7 +28,13 @@ wget https://gitee.com/paddlepaddle/PaddleDetection/raw/release/2.4/demo/0000000
./infer_paddle_model_demo yolov7_infer 000000014439.jpg 1
# 昆仑芯XPU推理
./infer_paddle_model_demo yolov7_infer 000000014439.jpg 2
+# 华为昇腾推理
+./infer_paddle_model_demo yolov7_infer 000000014439.jpg 3
```
+
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
如果想要验证ONNX模型的推理,可以参考如下命令:
```bash
#下载官方转换好的yolov7 ONNX模型文件和测试图片
diff --git a/examples/vision/detection/yolov7/cpp/infer_paddle_model.cc b/examples/vision/detection/yolov7/cpp/infer_paddle_model.cc
index f88f0d3a0f4..baed4acce41 100755
--- a/examples/vision/detection/yolov7/cpp/infer_paddle_model.cc
+++ b/examples/vision/detection/yolov7/cpp/infer_paddle_model.cc
@@ -31,7 +31,7 @@ void InitAndInfer(const std::string& model_dir, const std::string& image_file,
auto im = cv::imread(image_file);
fastdeploy::vision::DetectionResult res;
- if (!model.Predict(&im, &res)) {
+ if (!model.Predict(im, &res)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
@@ -68,7 +68,9 @@ int main(int argc, char* argv[]) {
option.UseTrtBackend();
} else if (flag == 2) {
option.UseKunlunXin();
- }
+ } else if (flag == 3) {
+ option.UseAscend();
+ }
std::string model_dir = argv[1];
std::string test_image = argv[2];
diff --git a/examples/vision/detection/yolov7/python/README.md b/examples/vision/detection/yolov7/python/README.md
index c0aa78337a2..a925e78efa0 100755
--- a/examples/vision/detection/yolov7/python/README.md
+++ b/examples/vision/detection/yolov7/python/README.md
@@ -24,6 +24,8 @@ python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --dev
python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device gpu
# 昆仑芯XPU推理
python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device kunlunxin
+# 华为昇腾推理
+python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device ascend
```
如果想要验证ONNX模型的推理,可以参考如下命令:
```bash
diff --git a/examples/vision/detection/yolov7/python/README_EN.md b/examples/vision/detection/yolov7/python/README_EN.md
index 64b6fcc98d3..ee7b486b3ce 100755
--- a/examples/vision/detection/yolov7/python/README_EN.md
+++ b/examples/vision/detection/yolov7/python/README_EN.md
@@ -24,6 +24,8 @@ python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --dev
python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device gpu
# KunlunXin XPU
python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device kunlunxin
+# Huawei Ascend
+python infer_paddle_model.py --model yolov7_infer --image 000000014439.jpg --device ascend
```
If you want to test ONNX model:
```bash
diff --git a/examples/vision/detection/yolov7/python/infer_paddle_model.py b/examples/vision/detection/yolov7/python/infer_paddle_model.py
index 2a3351e595e..28f1b747a4d 100755
--- a/examples/vision/detection/yolov7/python/infer_paddle_model.py
+++ b/examples/vision/detection/yolov7/python/infer_paddle_model.py
@@ -28,6 +28,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
return option
diff --git a/examples/vision/detection/yolov7end2end_ort/README.md b/examples/vision/detection/yolov7end2end_ort/README.md
index fdfd0801936..8b733bd25f4 100644
--- a/examples/vision/detection/yolov7end2end_ort/README.md
+++ b/examples/vision/detection/yolov7end2end_ort/README.md
@@ -20,14 +20,14 @@ python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv7End2EndORT导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% |
-| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% |
-| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% |
-| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% |
-| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% |
-| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% |
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [yolov7-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-ort-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7x-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-ort-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-w6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-ort-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-e6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-ort-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-d6-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-ort-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-e6e-end2end-ort-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-ort-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/detection/yolov7end2end_trt/README.md b/examples/vision/detection/yolov7end2end_trt/README.md
index 9e6d30cdf08..04be6f5687a 100644
--- a/examples/vision/detection/yolov7end2end_trt/README.md
+++ b/examples/vision/detection/yolov7end2end_trt/README.md
@@ -22,14 +22,14 @@ python export.py --weights yolov7.pt --grid --end2end --simplify --topk-all 100
## 下载预训练ONNX模型
为了方便开发者的测试,下面提供了YOLOv7End2EndTRT 导出的各系列模型,开发者可直接下载使用。(下表中模型的精度来源于源官方库)
-| 模型 | 大小 | 精度 |
-|:---------------------------------------------------------------- |:----- |:----- |
-| [yolov7-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx) | 141MB | 51.4% |
-| [yolov7x-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-trt-nms.onnx) | 273MB | 53.1% |
-| [yolov7-w6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-trt-nms.onnx) | 269MB | 54.9% |
-| [yolov7-e6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-trt-nms.onnx) | 372MB | 56.0% |
-| [yolov7-d6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-trt-nms.onnx) | 511MB | 56.6% |
-| [yolov7-e6e-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-trt-nms.onnx) | 579MB | 56.8% |
+| 模型 | 大小 | 精度 | 备注 |
+|:---------------------------------------------------------------- |:----- |:----- |:----- |
+| [yolov7-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-end2end-trt-nms.onnx) | 141MB | 51.4% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7x-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7x-end2end-trt-nms.onnx) | 273MB | 53.1% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-w6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-w6-end2end-trt-nms.onnx) | 269MB | 54.9% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-e6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6-end2end-trt-nms.onnx) | 372MB | 56.0% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-d6-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-d6-end2end-trt-nms.onnx) | 511MB | 56.6% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
+| [yolov7-e6e-end2end-trt-nms](https://bj.bcebos.com/paddlehub/fastdeploy/yolov7-e6e-end2end-trt-nms.onnx) | 579MB | 56.8% | 此模型文件来源于[YOLOv7](https://github.com/WongKinYiu/yolov7),GPL-3.0 License |
## 详细部署文档
diff --git a/examples/vision/generation/anemigan/README.md b/examples/vision/generation/anemigan/README.md
new file mode 100644
index 00000000000..721ed5644b4
--- /dev/null
+++ b/examples/vision/generation/anemigan/README.md
@@ -0,0 +1,36 @@
+# 图像生成模型
+
+FastDeploy目前支持PaddleHub预训练模型库中如下风格迁移模型的部署
+
+| 模型 | 说明 | 模型格式 |
+| :--- | :--- | :------- |
+|[animegan_v1_hayao_60](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v1_hayao_60&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V1官方开源项目|paddle|
+|[animegan_v2_paprika_97](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_97&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_hayao_64](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_64&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_shinkai_53](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_53&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_shinkai_33](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_shinkai_33&en_category=GANs)|可将输入的图像转换成新海诚动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_paprika_54](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_54&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_hayao_99](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_hayao_99&en_category=GANs)|可将输入的图像转换成宫崎骏动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_paprika_74](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_74&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+|[animegan_v2_paprika_98](https://www.paddlepaddle.org.cn/hubdetail?name=animegan_v2_paprika_98&en_category=GANs)|可将输入的图像转换成今敏红辣椒动漫风格,模型权重转换自AnimeGAN V2官方开源项目|paddle|
+
+## FastDeploy paddle backend部署和hub速度对比(ips, 越高越好)
+| Device | FastDeploy | Hub |
+| :--- | :--- | :------- |
+| CPU | 0.075 | 0.069|
+| GPU | 8.33 | 8.26 |
+
+
+
+## 下载预训练模型
+使用fastdeploy.download_model即可以下载模型, 例如下载animegan_v1_hayao_60
+```python
+import fastdeploy as fd
+fd.download_model(name='animegan_v1_hayao_60', path='./', format='paddle')
+```
+将会在当前目录获得animegan_v1_hayao_60的预训练模型。
+
+## 详细部署文档
+
+- [Python部署](python)
+- [C++部署](cpp)
diff --git a/examples/vision/generation/anemigan/cpp/CMakeLists.txt b/examples/vision/generation/anemigan/cpp/CMakeLists.txt
new file mode 100755
index 00000000000..7d1bd2ee11a
--- /dev/null
+++ b/examples/vision/generation/anemigan/cpp/CMakeLists.txt
@@ -0,0 +1,13 @@
+PROJECT(infer_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+
+# 指定下载解压后的fastdeploy库路径
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+include(${FASTDEPLOY_INSTALL_DIR}/utils/gflags.cmake)
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+
+# 添加FastDeploy依赖头文件
+include_directories(${FASTDEPLOY_INCS})
+
+add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
+target_link_libraries(infer_demo ${FASTDEPLOY_LIBS} ${GFLAGS_LIBRARIES})
diff --git a/examples/vision/generation/anemigan/cpp/README.md b/examples/vision/generation/anemigan/cpp/README.md
new file mode 100755
index 00000000000..9d58c6ad3f0
--- /dev/null
+++ b/examples/vision/generation/anemigan/cpp/README.md
@@ -0,0 +1,84 @@
+# AnimeGAN C++部署示例
+
+本目录下提供`infer.cc`快速完成AnimeGAN在CPU/GPU部署的示例。
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. 根据开发环境,下载预编译部署库和samples代码,参考[FastDeploy预编译库](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+以Linux上AnimeGAN推理为例,在本目录执行如下命令即可完成编译测试,支持此模型需保证FastDeploy版本1.0.2以上(x.x.x>=1.0.2)
+
+```bash
+mkdir build
+cd build
+# 下载FastDeploy预编译库,用户可在上文提到的`FastDeploy预编译库`中自行选择合适的版本使用
+wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-x.x.x.tgz
+tar xvf fastdeploy-linux-x64-x.x.x.tgz
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-linux-x64-x.x.x
+make -j
+
+# 下载准备好的模型文件和测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg
+wget https://bj.bcebos.com/paddlehub/fastdeploy/animegan_v1_hayao_60_v1.0.0.tgz
+tar xvfz animegan_v1_hayao_60_v1.0.0.tgz
+
+# CPU推理
+./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu
+# GPU推理
+./infer_demo --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu
+```
+
+以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
+- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+
+## AnimeGAN C++接口
+
+### AnimeGAN类
+
+```c++
+fastdeploy::vision::generation::AnimeGAN(
+ const string& model_file,
+ const string& params_file = "",
+ const RuntimeOption& runtime_option = RuntimeOption(),
+ const ModelFormat& model_format = ModelFormat::PADDLE)
+```
+
+AnimeGAN模型加载和初始化,其中model_file为导出的Paddle模型结构文件,params_file为模型参数文件。
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
+
+#### Predict函数
+
+> ```c++
+> bool AnimeGAN::Predict(cv::Mat& image, cv::Mat* result)
+> ```
+>
+> 模型预测入口,输入图像输出风格迁移后的结果。
+>
+> **参数**
+>
+> > * **image**: 输入数据,注意需为HWC,BGR格式
+> > * **result**: 风格转换后的图像,BGR格式
+
+#### BatchPredict函数
+
+> ```c++
+> bool AnimeGAN::BatchPredict(const std::vector& images, std::vector* results);
+> ```
+>
+> 模型预测入口,输入一组图像并输出风格迁移后的结果。
+>
+> **参数**
+>
+> > * **images**: 输入数据,一组图像数据,注意需为HWC,BGR格式
+> > * **results**: 风格转换后的一组图像,BGR格式
+
+- [模型介绍](../../)
+- [Python部署](../python)
+- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
diff --git a/examples/vision/generation/anemigan/cpp/infer.cc b/examples/vision/generation/anemigan/cpp/infer.cc
new file mode 100644
index 00000000000..ad10797e973
--- /dev/null
+++ b/examples/vision/generation/anemigan/cpp/infer.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+#include "gflags/gflags.h"
+
+DEFINE_string(model, "", "Directory of the inference model.");
+DEFINE_string(image, "", "Path of the image file.");
+DEFINE_string(device, "cpu",
+ "Type of inference device, support 'cpu' or 'gpu'.");
+
+void PrintUsage() {
+ std::cout << "Usage: infer_demo --model model_path --image img_path --device [cpu|gpu]"
+ << std::endl;
+ std::cout << "Default value of device: cpu" << std::endl;
+}
+
+bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) {
+ if (FLAGS_device == "gpu") {
+ option->UseGpu();
+ }
+ else if (FLAGS_device == "cpu") {
+ option->SetPaddleMKLDNN(false);
+ return true;
+ } else {
+ std::cerr << "Only support device CPU/GPU now, " << FLAGS_device << " is not supported." << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char* argv[]) {
+ google::ParseCommandLineFlags(&argc, &argv, true);
+ auto option = fastdeploy::RuntimeOption();
+ if (!CreateRuntimeOption(&option)) {
+ PrintUsage();
+ return -1;
+ }
+
+ auto model = fastdeploy::vision::generation::AnimeGAN(FLAGS_model+"/model.pdmodel", FLAGS_model+"/model.pdiparams", option);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return -1;
+ }
+
+ auto im = cv::imread(FLAGS_image);
+ cv::Mat res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return -1;
+ }
+
+ cv::imwrite("style_transfer_result.png", res);
+ std::cout << "Visualized result saved in ./style_transfer_result.png" << std::endl;
+
+ return 0;
+}
diff --git a/examples/vision/generation/anemigan/python/README.md b/examples/vision/generation/anemigan/python/README.md
new file mode 100644
index 00000000000..9c4562402db
--- /dev/null
+++ b/examples/vision/generation/anemigan/python/README.md
@@ -0,0 +1,70 @@
+# AnimeGAN Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+- 2. FastDeploy Python whl包安装,参考[FastDeploy Python安装](../../../../../docs/cn/build_and_install/download_prebuilt_libraries.md)
+
+本目录下提供`infer.py`快速完成AnimeGAN在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成
+
+```bash
+# 下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/examples/vision/generation/anemigan/python
+# 下载准备好的测试图片
+wget https://bj.bcebos.com/paddlehub/fastdeploy/style_transfer_testimg.jpg
+
+# CPU推理
+python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device cpu
+# GPU推理
+python infer.py --model animegan_v1_hayao_60 --image style_transfer_testimg.jpg --device gpu
+```
+
+## AnimeGAN Python接口
+
+```python
+fd.vision.generation.AnimeGAN(model_file, params_file, runtime_option=None, model_format=ModelFormat.PADDLE)
+```
+
+AnimeGAN模型加载和初始化,其中model_file和params_file为用于Paddle inference的模型结构文件和参数文件。
+
+**参数**
+
+> * **model_file**(str): 模型文件路径
+> * **params_file**(str): 参数文件路径
+> * **runtime_option**(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
+> * **model_format**(ModelFormat): 模型格式,默认为Paddle格式
+
+
+### predict函数
+
+> ```python
+> AnimeGAN.predict(input_image)
+> ```
+>
+> 模型预测入口,输入图像输出风格迁移后的结果。
+>
+> **参数**
+>
+> > * **input_image**(np.ndarray): 输入数据,注意需为HWC,BGR格式
+
+> **返回** np.ndarray, 风格转换后的图像,BGR格式
+
+### batch_predict函数
+> ```python
+> AnimeGAN.batch_predict函数(input_images)
+> ```
+>
+> 模型预测入口,输入一组图像并输出风格迁移后的结果。
+>
+> **参数**
+>
+> > * **input_images**(list(np.ndarray)): 输入数据,一组图像数据,注意需为HWC,BGR格式
+
+> **返回** list(np.ndarray), 风格转换后的一组图像,BGR格式
+
+## 其它文档
+
+- [风格迁移 模型介绍](..)
+- [C++部署](../cpp)
+- [如何切换模型推理后端引擎](../../../../../docs/cn/faq/how_to_change_backend.md)
diff --git a/examples/vision/generation/anemigan/python/infer.py b/examples/vision/generation/anemigan/python/infer.py
new file mode 100644
index 00000000000..69f610eda14
--- /dev/null
+++ b/examples/vision/generation/anemigan/python/infer.py
@@ -0,0 +1,43 @@
+import cv2
+import os
+import fastdeploy as fd
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--model", required=True, help="Name of the model.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu' or 'gpu'.")
+ return parser.parse_args()
+
+
+def build_option(args):
+ option = fd.RuntimeOption()
+ if args.device.lower() == "gpu":
+ option.use_gpu()
+ else:
+ option.set_paddle_mkldnn(False)
+ return option
+
+
+args = parse_arguments()
+
+# 配置runtime,加载模型
+runtime_option = build_option(args)
+fd.download_model(name=args.model, path='./', format='paddle')
+model_file = os.path.join(args.model, "model.pdmodel")
+params_file = os.path.join(args.model, "model.pdiparams")
+model = fd.vision.generation.AnimeGAN(
+ model_file, params_file, runtime_option=runtime_option)
+
+# 预测图片并保存结果
+im = cv2.imread(args.image)
+result = model.predict(im)
+cv2.imwrite('style_transfer_result.png', result)
diff --git a/examples/vision/matting/rvm/README.md b/examples/vision/matting/rvm/README.md
index 16f33aae44f..56d371c5c90 100755
--- a/examples/vision/matting/rvm/README.md
+++ b/examples/vision/matting/rvm/README.md
@@ -16,10 +16,10 @@
| 模型 | 参数大小 | 精度 | 备注 |
|:---------------------------------------------------------------- |:----- |:----- | :------ |
-| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB | - |
-| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | - |
-| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | - |
-| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | - |
+| [rvm_mobilenetv3_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_fp32.onnx) | 15MB ||exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License |
+| [rvm_resnet50_fp32.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_fp32.onnx) | 103MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License |
+| [rvm_mobilenetv3_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_mobilenetv3_trt.onnx) | 15MB | |exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License |
+| [rvm_resnet50_trt.onnx](https://bj.bcebos.com/paddlehub/fastdeploy/rvm_resnet50_trt.onnx) | 103MB | | exported from [RobustVideoMatting](https://github.com/PeterL1n/RobustVideoMatting/commit/81a1093),GPL-3.0 License |
**Note**:
- 如果要使用 TensorRT 进行推理,需要下载后缀为 trt 的 onnx 模型文件
diff --git a/examples/vision/ocr/PP-OCRv2/cpp/CMakeLists.txt b/examples/vision/ocr/PP-OCRv2/cpp/CMakeLists.txt
index 93540a7e83e..8b2f7aa6100 100644
--- a/examples/vision/ocr/PP-OCRv2/cpp/CMakeLists.txt
+++ b/examples/vision/ocr/PP-OCRv2/cpp/CMakeLists.txt
@@ -12,3 +12,7 @@ include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_static_shape_demo ${PROJECT_SOURCE_DIR}/infer_static_shape.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_static_shape_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/ocr/PP-OCRv2/cpp/README.md b/examples/vision/ocr/PP-OCRv2/cpp/README.md
index fbde53fffce..9052dd80ec6 100755
--- a/examples/vision/ocr/PP-OCRv2/cpp/README.md
+++ b/examples/vision/ocr/PP-OCRv2/cpp/README.md
@@ -43,11 +43,16 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_
./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3
# 昆仑芯XPU推理
./infer_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4
+# 华为昇腾推理, 需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸
+./infer_static_shape_demo ./ch_PP-OCRv2_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
运行完成可视化结果如下图所示
diff --git a/examples/vision/ocr/PP-OCRv2/cpp/infer.cc b/examples/vision/ocr/PP-OCRv2/cpp/infer.cc
index 3406246aaef..72a7fcf7ea9 100755
--- a/examples/vision/ocr/PP-OCRv2/cpp/infer.cc
+++ b/examples/vision/ocr/PP-OCRv2/cpp/infer.cc
@@ -65,9 +65,9 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model
// Set inference batch size for cls model and rec model, the value could be -1 and 1 to positive infinity.
// When inference batch size is set to -1, it means that the inference batch size
- // of the cls and rec models will be the same as the number of boxes detected by the det model.
+ // of the cls and rec models will be the same as the number of boxes detected by the det model.
ppocr_v2.SetClsBatchSize(cls_batch_size);
- ppocr_v2.SetRecBatchSize(rec_batch_size);
+ ppocr_v2.SetRecBatchSize(rec_batch_size);
if(!ppocr_v2.Initialized()){
std::cerr << "Failed to initialize PP-OCR." << std::endl;
diff --git a/examples/vision/ocr/PP-OCRv2/cpp/infer_static_shape.cc b/examples/vision/ocr/PP-OCRv2/cpp/infer_static_shape.cc
new file mode 100755
index 00000000000..ba5527a2e90
--- /dev/null
+++ b/examples/vision/ocr/PP-OCRv2/cpp/infer_static_shape.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model_dir, const std::string& rec_model_dir, const std::string& rec_label_file, const std::string& image_file, const fastdeploy::RuntimeOption& option) {
+ auto det_model_file = det_model_dir + sep + "inference.pdmodel";
+ auto det_params_file = det_model_dir + sep + "inference.pdiparams";
+
+ auto cls_model_file = cls_model_dir + sep + "inference.pdmodel";
+ auto cls_params_file = cls_model_dir + sep + "inference.pdiparams";
+
+ auto rec_model_file = rec_model_dir + sep + "inference.pdmodel";
+ auto rec_params_file = rec_model_dir + sep + "inference.pdiparams";
+
+ auto det_option = option;
+ auto cls_option = option;
+ auto rec_option = option;
+
+ auto det_model = fastdeploy::vision::ocr::DBDetector(det_model_file, det_params_file, det_option);
+ auto cls_model = fastdeploy::vision::ocr::Classifier(cls_model_file, cls_params_file, cls_option);
+ auto rec_model = fastdeploy::vision::ocr::Recognizer(rec_model_file, rec_params_file, rec_label_file, rec_option);
+
+ // Users could enable static shape infer for rec model when deploy PP-OCR on hardware
+ // which can not support dynamic shape infer well, like Huawei Ascend series.
+ rec_model.GetPreprocessor().SetStaticShapeInfer(true);
+
+ assert(det_model.Initialized());
+ assert(cls_model.Initialized());
+ assert(rec_model.Initialized());
+
+ // The classification model is optional, so the PP-OCR can also be connected in series as follows
+ // auto ppocr_v2 = fastdeploy::pipeline::PPOCRv2(&det_model, &rec_model);
+ auto ppocr_v2 = fastdeploy::pipeline::PPOCRv2(&det_model, &cls_model, &rec_model);
+
+ // When users enable static shape infer for rec model, the batch size of cls and rec model must to be set to 1.
+ ppocr_v2.SetClsBatchSize(1);
+ ppocr_v2.SetRecBatchSize(1);
+
+ if(!ppocr_v2.Initialized()){
+ std::cerr << "Failed to initialize PP-OCR." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::OCRResult result;
+ if (!ppocr_v2.Predict(im, &result)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << result.Str() << std::endl;
+
+ auto vis_im = fastdeploy::vision::VisOcr(im, result);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 7) {
+ std::cout << "Usage: infer_demo path/to/det_model path/to/cls_model "
+ "path/to/rec_model path/to/rec_label_file path/to/image "
+ "run_option, "
+ "e.g ./infer_demo ./ch_PP-OCRv2_det_infer "
+ "./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv2_rec_infer "
+ "./ppocr_keys_v1.txt ./12.jpg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with ascend."
+ << std::endl;
+ return -1;
+ }
+
+ fastdeploy::RuntimeOption option;
+ int flag = std::atoi(argv[6]);
+
+ if (flag == 0) {
+ option.UseCpu();
+ } else if (flag == 1) {
+ option.UseAscend();
+ }
+
+ std::string det_model_dir = argv[1];
+ std::string cls_model_dir = argv[2];
+ std::string rec_model_dir = argv[3];
+ std::string rec_label_file = argv[4];
+ std::string test_image = argv[5];
+ InitAndInfer(det_model_dir, cls_model_dir, rec_model_dir, rec_label_file, test_image, option);
+ return 0;
+}
diff --git a/examples/vision/ocr/PP-OCRv2/python/README.md b/examples/vision/ocr/PP-OCRv2/python/README.md
index 66bba9e5bfd..1ea95695f3a 100755
--- a/examples/vision/ocr/PP-OCRv2/python/README.md
+++ b/examples/vision/ocr/PP-OCRv2/python/README.md
@@ -36,6 +36,8 @@ python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2
python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt
# 昆仑芯XPU推理
python infer.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin
+# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸
+python infer_static_shape.py --det_model ch_PP-OCRv2_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv2_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/ocr/PP-OCRv2/python/infer.py b/examples/vision/ocr/PP-OCRv2/python/infer.py
index b8c731ef364..6e8fe62b157 100755
--- a/examples/vision/ocr/PP-OCRv2/python/infer.py
+++ b/examples/vision/ocr/PP-OCRv2/python/infer.py
@@ -58,39 +58,113 @@ def parse_arguments():
type=int,
default=9,
help="Number of threads while inference on CPU.")
+ parser.add_argument(
+ "--cls_bs",
+ type=int,
+ default=1,
+ help="Classification model inference batch size.")
+ parser.add_argument(
+ "--rec_bs",
+ type=int,
+ default=6,
+ help="Recognition model inference batch size")
return parser.parse_args()
def build_option(args):
- option = fd.RuntimeOption()
- if args.device.lower() == "gpu":
- option.use_gpu(0)
- option.set_cpu_thread_num(args.cpu_thread_num)
+ det_option = fd.RuntimeOption()
+ cls_option = fd.RuntimeOption()
+ rec_option = fd.RuntimeOption()
+
+ det_option.set_cpu_thread_num(args.cpu_thread_num)
+ cls_option.set_cpu_thread_num(args.cpu_thread_num)
+ rec_option.set_cpu_thread_num(args.cpu_thread_num)
+
+ if args.device.lower() == "gpu":
+ det_option.use_gpu(args.device_id)
+ cls_option.use_gpu(args.device_id)
+ rec_option.use_gpu(args.device_id)
if args.device.lower() == "kunlunxin":
- option.use_kunlunxin()
- return option
+ det_option.use_kunlunxin()
+ cls_option.use_kunlunxin()
+ rec_option.use_kunlunxin()
+
+ return det_option, cls_option, rec_option
if args.backend.lower() == "trt":
assert args.device.lower(
) == "gpu", "TensorRT backend require inference on device GPU."
- option.use_trt_backend()
+ det_option.use_trt_backend()
+ cls_option.use_trt_backend()
+ rec_option.use_trt_backend()
+
+ # 设置trt input shape
+ # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
+ det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
+ [1, 3, 960, 960])
+ cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.cls_bs, 3, 48, 320],
+ [args.cls_bs, 3, 48, 1024])
+ rec_option.set_trt_input_shape("x", [1, 3, 32, 10],
+ [args.rec_bs, 3, 32, 320],
+ [args.rec_bs, 3, 32, 2304])
+
+ # 用户可以把TRT引擎文件保存至本地
+ det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
+ cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
+ rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
+
elif args.backend.lower() == "pptrt":
assert args.device.lower(
) == "gpu", "Paddle-TensorRT backend require inference on device GPU."
- option.use_trt_backend()
- option.enable_paddle_trt_collect_shape()
- option.enable_paddle_to_trt()
+ det_option.use_trt_backend()
+ det_option.enable_paddle_trt_collect_shape()
+ det_option.enable_paddle_to_trt()
+
+ cls_option.use_trt_backend()
+ cls_option.enable_paddle_trt_collect_shape()
+ cls_option.enable_paddle_to_trt()
+
+ rec_option.use_trt_backend()
+ rec_option.enable_paddle_trt_collect_shape()
+ rec_option.enable_paddle_to_trt()
+
+ # 设置trt input shape
+ # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
+ det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
+ [1, 3, 960, 960])
+ cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.cls_bs, 3, 48, 320],
+ [args.cls_bs, 3, 48, 1024])
+ rec_option.set_trt_input_shape("x", [1, 3, 32, 10],
+ [args.rec_bs, 3, 32, 320],
+ [args.rec_bs, 3, 32, 2304])
+
+ # 用户可以把TRT引擎文件保存至本地
+ det_option.set_trt_cache_file(args.det_model)
+ cls_option.set_trt_cache_file(args.cls_model)
+ rec_option.set_trt_cache_file(args.rec_model)
+
elif args.backend.lower() == "ort":
- option.use_ort_backend()
+ det_option.use_ort_backend()
+ cls_option.use_ort_backend()
+ rec_option.use_ort_backend()
+
elif args.backend.lower() == "paddle":
- option.use_paddle_infer_backend()
+ det_option.use_paddle_infer_backend()
+ cls_option.use_paddle_infer_backend()
+ rec_option.use_paddle_infer_backend()
+
elif args.backend.lower() == "openvino":
assert args.device.lower(
) == "cpu", "OpenVINO backend require inference on device CPU."
- option.use_openvino_backend()
- return option
+ det_option.use_openvino_backend()
+ cls_option.use_openvino_backend()
+ rec_option.use_openvino_backend()
+
+ return det_option, cls_option, rec_option
args = parse_arguments()
@@ -107,40 +181,15 @@ def build_option(args):
rec_label_file = args.rec_label_file
# 对于三个模型,均采用同样的部署配置
-# 用户也可根据自行需求分别配置
-runtime_option = build_option(args)
-
-# PPOCR的cls和rec模型现在已经支持推理一个Batch的数据
-# 定义下面两个变量后, 可用于设置trt输入shape, 并在PPOCR模型初始化后, 完成Batch推理设置
-cls_batch_size = 1
-rec_batch_size = 6
-
-# 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建.
-# 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理.
-# 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
-det_option = runtime_option
-det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
- [1, 3, 960, 960])
-# 用户可以把TRT引擎文件保存至本地
-# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
+# 用户也可根据自己的需求,个性化配置
+det_option, cls_option, rec_option = build_option(args)
+
det_model = fd.vision.ocr.DBDetector(
det_model_file, det_params_file, runtime_option=det_option)
-cls_option = runtime_option
-cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
- [cls_batch_size, 3, 48, 320],
- [cls_batch_size, 3, 48, 1024])
-# 用户可以把TRT引擎文件保存至本地
-# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
cls_model = fd.vision.ocr.Classifier(
cls_model_file, cls_params_file, runtime_option=cls_option)
-rec_option = runtime_option
-rec_option.set_trt_input_shape("x", [1, 3, 32, 10],
- [rec_batch_size, 3, 32, 320],
- [rec_batch_size, 3, 32, 2304])
-# 用户可以把TRT引擎文件保存至本地
-# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
rec_model = fd.vision.ocr.Recognizer(
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
@@ -151,8 +200,8 @@ def build_option(args):
# 给cls和rec模型设置推理时的batch size
# 此值能为-1, 和1到正无穷
# 当此值为-1时, cls和rec模型的batch size将默认和det模型检测出的框的数量相同
-ppocr_v2.cls_batch_size = cls_batch_size
-ppocr_v2.rec_batch_size = rec_batch_size
+ppocr_v2.cls_batch_size = args.cls_bs
+ppocr_v2.rec_batch_size = args.rec_bs
# 预测图片准备
im = cv2.imread(args.image)
diff --git a/examples/vision/ocr/PP-OCRv2/python/infer_static_shape.py b/examples/vision/ocr/PP-OCRv2/python/infer_static_shape.py
new file mode 100755
index 00000000000..29055fdaae4
--- /dev/null
+++ b/examples/vision/ocr/PP-OCRv2/python/infer_static_shape.py
@@ -0,0 +1,114 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--det_model", required=True, help="Path of Detection model of PPOCR.")
+ parser.add_argument(
+ "--cls_model",
+ required=True,
+ help="Path of Classification model of PPOCR.")
+ parser.add_argument(
+ "--rec_model",
+ required=True,
+ help="Path of Recognization model of PPOCR.")
+ parser.add_argument(
+ "--rec_label_file",
+ required=True,
+ help="Path of Recognization model of PPOCR.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu', 'kunlunxin' or 'gpu'.")
+ parser.add_argument(
+ "--cpu_thread_num",
+ type=int,
+ default=9,
+ help="Number of threads while inference on CPU.")
+ return parser.parse_args()
+
+
+def build_option(args):
+
+ det_option = fd.RuntimeOption()
+ cls_option = fd.RuntimeOption()
+ rec_option = fd.RuntimeOption()
+
+ # 当前需要对PP-OCR启用静态shape推理的硬件只有昇腾.
+ if args.device.lower() == "ascend":
+ det_option.use_ascend()
+ cls_option.use_ascend()
+ rec_option.use_ascend()
+
+ return det_option, cls_option, rec_option
+
+
+args = parse_arguments()
+
+# Detection模型, 检测文字框
+det_model_file = os.path.join(args.det_model, "inference.pdmodel")
+det_params_file = os.path.join(args.det_model, "inference.pdiparams")
+# Classification模型,方向分类,可选
+cls_model_file = os.path.join(args.cls_model, "inference.pdmodel")
+cls_params_file = os.path.join(args.cls_model, "inference.pdiparams")
+# Recognition模型,文字识别模型
+rec_model_file = os.path.join(args.rec_model, "inference.pdmodel")
+rec_params_file = os.path.join(args.rec_model, "inference.pdiparams")
+rec_label_file = args.rec_label_file
+
+det_option, cls_option, rec_option = build_option(args)
+
+det_model = fd.vision.ocr.DBDetector(
+ det_model_file, det_params_file, runtime_option=det_option)
+
+cls_model = fd.vision.ocr.Classifier(
+ cls_model_file, cls_params_file, runtime_option=cls_option)
+
+rec_model = fd.vision.ocr.Recognizer(
+ rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
+
+# Rec模型启用静态shape推理
+rec_model.preprocessor.static_shape_infer = True
+
+# 创建PP-OCR,串联3个模型,其中cls_model可选,如无需求,可设置为None
+ppocr_v2 = fd.vision.ocr.PPOCRv2(
+ det_model=det_model, cls_model=cls_model, rec_model=rec_model)
+
+# Cls模型和Rec模型的batch size 必须设置为1, 开启静态shape推理
+ppocr_v2.cls_batch_size = 1
+ppocr_v2.rec_batch_size = 1
+
+# 预测图片准备
+im = cv2.imread(args.image)
+
+#预测并打印结果
+result = ppocr_v2.predict(im)
+
+print(result)
+
+# 可视化结果
+vis_im = fd.vision.vis_ppocr(im, result)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/ocr/PP-OCRv3/cpp/CMakeLists.txt b/examples/vision/ocr/PP-OCRv3/cpp/CMakeLists.txt
index 93540a7e83e..8b2f7aa6100 100644
--- a/examples/vision/ocr/PP-OCRv3/cpp/CMakeLists.txt
+++ b/examples/vision/ocr/PP-OCRv3/cpp/CMakeLists.txt
@@ -12,3 +12,7 @@ include_directories(${FASTDEPLOY_INCS})
add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
# 添加FastDeploy库依赖
target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
+
+add_executable(infer_static_shape_demo ${PROJECT_SOURCE_DIR}/infer_static_shape.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_static_shape_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/ocr/PP-OCRv3/cpp/README.md b/examples/vision/ocr/PP-OCRv3/cpp/README.md
index 9c5eff4ef57..7f557a213b7 100755
--- a/examples/vision/ocr/PP-OCRv3/cpp/README.md
+++ b/examples/vision/ocr/PP-OCRv3/cpp/README.md
@@ -43,11 +43,16 @@ wget https://gitee.com/paddlepaddle/PaddleOCR/raw/release/2.6/ppocr/utils/ppocr_
./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 3
# 昆仑芯XPU推理
./infer_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 4
+# 华为昇腾推理,需要使用静态shape的demo, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸
+./infer_static_shape_demo ./ch_PP-OCRv3_det_infer ./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer ./ppocr_keys_v1.txt ./12.jpg 1
```
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
运行完成可视化结果如下图所示
diff --git a/examples/vision/ocr/PP-OCRv3/cpp/infer.cc b/examples/vision/ocr/PP-OCRv3/cpp/infer.cc
index fd25eca7e09..3b35c1d44eb 100755
--- a/examples/vision/ocr/PP-OCRv3/cpp/infer.cc
+++ b/examples/vision/ocr/PP-OCRv3/cpp/infer.cc
@@ -34,7 +34,7 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model
auto rec_option = option;
// The cls and rec model can inference a batch of images now.
- // User could initialize the inference batch size and set them after create PPOCR model.
+ // User could initialize the inference batch size and set them after create PP-OCR model.
int cls_batch_size = 1;
int rec_batch_size = 6;
@@ -66,9 +66,9 @@ void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model
// Set inference batch size for cls model and rec model, the value could be -1 and 1 to positive infinity.
// When inference batch size is set to -1, it means that the inference batch size
- // of the cls and rec models will be the same as the number of boxes detected by the det model.
+ // of the cls and rec models will be the same as the number of boxes detected by the det model.
ppocr_v3.SetClsBatchSize(cls_batch_size);
- ppocr_v3.SetRecBatchSize(rec_batch_size);
+ ppocr_v3.SetRecBatchSize(rec_batch_size);
if(!ppocr_v3.Initialized()){
std::cerr << "Failed to initialize PP-OCR." << std::endl;
diff --git a/examples/vision/ocr/PP-OCRv3/cpp/infer_static_shape.cc b/examples/vision/ocr/PP-OCRv3/cpp/infer_static_shape.cc
new file mode 100755
index 00000000000..aea3f5699ca
--- /dev/null
+++ b/examples/vision/ocr/PP-OCRv3/cpp/infer_static_shape.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+
+#include "fastdeploy/vision.h"
+#ifdef WIN32
+const char sep = '\\';
+#else
+const char sep = '/';
+#endif
+
+void InitAndInfer(const std::string& det_model_dir, const std::string& cls_model_dir, const std::string& rec_model_dir, const std::string& rec_label_file, const std::string& image_file, const fastdeploy::RuntimeOption& option) {
+ auto det_model_file = det_model_dir + sep + "inference.pdmodel";
+ auto det_params_file = det_model_dir + sep + "inference.pdiparams";
+
+ auto cls_model_file = cls_model_dir + sep + "inference.pdmodel";
+ auto cls_params_file = cls_model_dir + sep + "inference.pdiparams";
+
+ auto rec_model_file = rec_model_dir + sep + "inference.pdmodel";
+ auto rec_params_file = rec_model_dir + sep + "inference.pdiparams";
+
+ auto det_option = option;
+ auto cls_option = option;
+ auto rec_option = option;
+
+ auto det_model = fastdeploy::vision::ocr::DBDetector(det_model_file, det_params_file, det_option);
+ auto cls_model = fastdeploy::vision::ocr::Classifier(cls_model_file, cls_params_file, cls_option);
+ auto rec_model = fastdeploy::vision::ocr::Recognizer(rec_model_file, rec_params_file, rec_label_file, rec_option);
+
+ // Users could enable static shape infer for rec model when deploy PP-OCR on hardware
+ // which can not support dynamic shape infer well, like Huawei Ascend series.
+ rec_model.GetPreprocessor().SetStaticShapeInfer(true);
+
+ assert(det_model.Initialized());
+ assert(cls_model.Initialized());
+ assert(rec_model.Initialized());
+
+ // The classification model is optional, so the PP-OCR can also be connected in series as follows
+ // auto ppocr_v3 = fastdeploy::pipeline::PPOCRv3(&det_model, &rec_model);
+ auto ppocr_v3 = fastdeploy::pipeline::PPOCRv3(&det_model, &cls_model, &rec_model);
+
+ // When users enable static shape infer for rec model, the batch size of cls and rec model must to be set to 1.
+ ppocr_v3.SetClsBatchSize(1);
+ ppocr_v3.SetRecBatchSize(1);
+
+ if(!ppocr_v3.Initialized()){
+ std::cerr << "Failed to initialize PP-OCR." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::OCRResult result;
+ if (!ppocr_v3.Predict(im, &result)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << result.Str() << std::endl;
+
+ auto vis_im = fastdeploy::vision::VisOcr(im, result);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 7) {
+ std::cout << "Usage: infer_demo path/to/det_model path/to/cls_model "
+ "path/to/rec_model path/to/rec_label_file path/to/image "
+ "run_option, "
+ "e.g ./infer_demo ./ch_PP-OCRv3_det_infer "
+ "./ch_ppocr_mobile_v2.0_cls_infer ./ch_PP-OCRv3_rec_infer "
+ "./ppocr_keys_v1.txt ./12.jpg 0"
+ << std::endl;
+ std::cout << "The data type of run_option is int, 0: run with cpu; 1: run "
+ "with ascend."
+ << std::endl;
+ return -1;
+ }
+
+ fastdeploy::RuntimeOption option;
+ int flag = std::atoi(argv[6]);
+
+ if (flag == 0) {
+ option.UseCpu();
+ } else if (flag == 1) {
+ option.UseAscend();
+ }
+
+ std::string det_model_dir = argv[1];
+ std::string cls_model_dir = argv[2];
+ std::string rec_model_dir = argv[3];
+ std::string rec_label_file = argv[4];
+ std::string test_image = argv[5];
+ InitAndInfer(det_model_dir, cls_model_dir, rec_model_dir, rec_label_file, test_image, option);
+ return 0;
+}
diff --git a/examples/vision/ocr/PP-OCRv3/python/README.md b/examples/vision/ocr/PP-OCRv3/python/README.md
index e87729353d6..3fcf372e05d 100755
--- a/examples/vision/ocr/PP-OCRv3/python/README.md
+++ b/examples/vision/ocr/PP-OCRv3/python/README.md
@@ -35,6 +35,8 @@ python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device gpu --backend trt
# 昆仑芯XPU推理
python infer.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device kunlunxin
+# 华为昇腾推理,需要使用静态shape脚本, 若用户需要连续地预测图片, 输入图片尺寸需要准备为统一尺寸
+python infer_static_shape.py --det_model ch_PP-OCRv3_det_infer --cls_model ch_ppocr_mobile_v2.0_cls_infer --rec_model ch_PP-OCRv3_rec_infer --rec_label_file ppocr_keys_v1.txt --image 12.jpg --device ascend
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/ocr/PP-OCRv3/python/infer.py b/examples/vision/ocr/PP-OCRv3/python/infer.py
index 97ee1d07030..6dabce80ee9 100755
--- a/examples/vision/ocr/PP-OCRv3/python/infer.py
+++ b/examples/vision/ocr/PP-OCRv3/python/infer.py
@@ -58,39 +58,113 @@ def parse_arguments():
type=int,
default=9,
help="Number of threads while inference on CPU.")
+ parser.add_argument(
+ "--cls_bs",
+ type=int,
+ default=1,
+ help="Classification model inference batch size.")
+ parser.add_argument(
+ "--rec_bs",
+ type=int,
+ default=6,
+ help="Recognition model inference batch size")
return parser.parse_args()
def build_option(args):
- option = fd.RuntimeOption()
- if args.device.lower() == "gpu":
- option.use_gpu(0)
- option.set_cpu_thread_num(args.cpu_thread_num)
+ det_option = fd.RuntimeOption()
+ cls_option = fd.RuntimeOption()
+ rec_option = fd.RuntimeOption()
+
+ det_option.set_cpu_thread_num(args.cpu_thread_num)
+ cls_option.set_cpu_thread_num(args.cpu_thread_num)
+ rec_option.set_cpu_thread_num(args.cpu_thread_num)
+
+ if args.device.lower() == "gpu":
+ det_option.use_gpu(args.device_id)
+ cls_option.use_gpu(args.device_id)
+ rec_option.use_gpu(args.device_id)
if args.device.lower() == "kunlunxin":
- option.use_kunlunxin()
- return option
+ det_option.use_kunlunxin()
+ cls_option.use_kunlunxin()
+ rec_option.use_kunlunxin()
+
+ return det_option, cls_option, rec_option
if args.backend.lower() == "trt":
assert args.device.lower(
) == "gpu", "TensorRT backend require inference on device GPU."
- option.use_trt_backend()
+ det_option.use_trt_backend()
+ cls_option.use_trt_backend()
+ rec_option.use_trt_backend()
+
+ # 设置trt input shape
+ # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
+ det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
+ [1, 3, 960, 960])
+ cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.cls_bs, 3, 48, 320],
+ [args.cls_bs, 3, 48, 1024])
+ rec_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.rec_bs, 3, 48, 320],
+ [args.rec_bs, 3, 48, 2304])
+
+ # 用户可以把TRT引擎文件保存至本地
+ det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
+ cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
+ rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
+
elif args.backend.lower() == "pptrt":
assert args.device.lower(
) == "gpu", "Paddle-TensorRT backend require inference on device GPU."
- option.use_trt_backend()
- option.enable_paddle_trt_collect_shape()
- option.enable_paddle_to_trt()
+ det_option.use_trt_backend()
+ det_option.enable_paddle_trt_collect_shape()
+ det_option.enable_paddle_to_trt()
+
+ cls_option.use_trt_backend()
+ cls_option.enable_paddle_trt_collect_shape()
+ cls_option.enable_paddle_to_trt()
+
+ rec_option.use_trt_backend()
+ rec_option.enable_paddle_trt_collect_shape()
+ rec_option.enable_paddle_to_trt()
+
+ # 设置trt input shape
+ # 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
+ det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
+ [1, 3, 960, 960])
+ cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.cls_bs, 3, 48, 320],
+ [args.cls_bs, 3, 48, 1024])
+ rec_option.set_trt_input_shape("x", [1, 3, 48, 10],
+ [args.rec_bs, 3, 48, 320],
+ [args.rec_bs, 3, 48, 2304])
+
+ # 用户可以把TRT引擎文件保存至本地
+ det_option.set_trt_cache_file(args.det_model)
+ cls_option.set_trt_cache_file(args.cls_model)
+ rec_option.set_trt_cache_file(args.rec_model)
+
elif args.backend.lower() == "ort":
- option.use_ort_backend()
+ det_option.use_ort_backend()
+ cls_option.use_ort_backend()
+ rec_option.use_ort_backend()
+
elif args.backend.lower() == "paddle":
- option.use_paddle_infer_backend()
+ det_option.use_paddle_infer_backend()
+ cls_option.use_paddle_infer_backend()
+ rec_option.use_paddle_infer_backend()
+
elif args.backend.lower() == "openvino":
assert args.device.lower(
) == "cpu", "OpenVINO backend require inference on device CPU."
- option.use_openvino_backend()
- return option
+ det_option.use_openvino_backend()
+ cls_option.use_openvino_backend()
+ rec_option.use_openvino_backend()
+
+ return det_option, cls_option, rec_option
args = parse_arguments()
@@ -107,40 +181,15 @@ def build_option(args):
rec_label_file = args.rec_label_file
# 对于三个模型,均采用同样的部署配置
-# 用户也可根据自行需求分别配置
-runtime_option = build_option(args)
-
-# PPOCR的cls和rec模型现在已经支持推理一个Batch的数据
-# 定义下面两个变量后, 可用于设置trt输入shape, 并在PPOCR模型初始化后, 完成Batch推理设置
-cls_batch_size = 1
-rec_batch_size = 6
-
-# 当使用TRT时,分别给三个模型的runtime设置动态shape,并完成模型的创建.
-# 注意: 需要在检测模型创建完成后,再设置分类模型的动态输入并创建分类模型, 识别模型同理.
-# 如果用户想要自己改动检测模型的输入shape, 我们建议用户把检测模型的长和高设置为32的倍数.
-det_option = runtime_option
-det_option.set_trt_input_shape("x", [1, 3, 64, 64], [1, 3, 640, 640],
- [1, 3, 960, 960])
-# 用户可以把TRT引擎文件保存至本地
-# det_option.set_trt_cache_file(args.det_model + "/det_trt_cache.trt")
+# 用户也可根据自己的需求,个性化配置
+det_option, cls_option, rec_option = build_option(args)
+
det_model = fd.vision.ocr.DBDetector(
det_model_file, det_params_file, runtime_option=det_option)
-cls_option = runtime_option
-cls_option.set_trt_input_shape("x", [1, 3, 48, 10],
- [cls_batch_size, 3, 48, 320],
- [cls_batch_size, 3, 48, 1024])
-# 用户可以把TRT引擎文件保存至本地
-# cls_option.set_trt_cache_file(args.cls_model + "/cls_trt_cache.trt")
cls_model = fd.vision.ocr.Classifier(
cls_model_file, cls_params_file, runtime_option=cls_option)
-rec_option = runtime_option
-rec_option.set_trt_input_shape("x", [1, 3, 48, 10],
- [rec_batch_size, 3, 48, 320],
- [rec_batch_size, 3, 48, 2304])
-# 用户可以把TRT引擎文件保存至本地
-# rec_option.set_trt_cache_file(args.rec_model + "/rec_trt_cache.trt")
rec_model = fd.vision.ocr.Recognizer(
rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
@@ -151,8 +200,8 @@ def build_option(args):
# 给cls和rec模型设置推理时的batch size
# 此值能为-1, 和1到正无穷
# 当此值为-1时, cls和rec模型的batch size将默认和det模型检测出的框的数量相同
-ppocr_v3.cls_batch_size = cls_batch_size
-ppocr_v3.rec_batch_size = rec_batch_size
+ppocr_v3.cls_batch_size = args.cls_bs
+ppocr_v3.rec_batch_size = args.rec_bs
# 预测图片准备
im = cv2.imread(args.image)
diff --git a/examples/vision/ocr/PP-OCRv3/python/infer_static_shape.py b/examples/vision/ocr/PP-OCRv3/python/infer_static_shape.py
new file mode 100755
index 00000000000..e707d378c38
--- /dev/null
+++ b/examples/vision/ocr/PP-OCRv3/python/infer_static_shape.py
@@ -0,0 +1,114 @@
+# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "--det_model", required=True, help="Path of Detection model of PPOCR.")
+ parser.add_argument(
+ "--cls_model",
+ required=True,
+ help="Path of Classification model of PPOCR.")
+ parser.add_argument(
+ "--rec_model",
+ required=True,
+ help="Path of Recognization model of PPOCR.")
+ parser.add_argument(
+ "--rec_label_file",
+ required=True,
+ help="Path of Recognization model of PPOCR.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+ parser.add_argument(
+ "--device",
+ type=str,
+ default='cpu',
+ help="Type of inference device, support 'cpu', 'kunlunxin' or 'gpu'.")
+ parser.add_argument(
+ "--cpu_thread_num",
+ type=int,
+ default=9,
+ help="Number of threads while inference on CPU.")
+ return parser.parse_args()
+
+
+def build_option(args):
+
+ det_option = fd.RuntimeOption()
+ cls_option = fd.RuntimeOption()
+ rec_option = fd.RuntimeOption()
+
+ # 当前需要对PP-OCR启用静态shape推理的硬件只有昇腾.
+ if args.device.lower() == "ascend":
+ det_option.use_ascend()
+ cls_option.use_ascend()
+ rec_option.use_ascend()
+
+ return det_option, cls_option, rec_option
+
+
+args = parse_arguments()
+
+# Detection模型, 检测文字框
+det_model_file = os.path.join(args.det_model, "inference.pdmodel")
+det_params_file = os.path.join(args.det_model, "inference.pdiparams")
+# Classification模型,方向分类,可选
+cls_model_file = os.path.join(args.cls_model, "inference.pdmodel")
+cls_params_file = os.path.join(args.cls_model, "inference.pdiparams")
+# Recognition模型,文字识别模型
+rec_model_file = os.path.join(args.rec_model, "inference.pdmodel")
+rec_params_file = os.path.join(args.rec_model, "inference.pdiparams")
+rec_label_file = args.rec_label_file
+
+det_option, cls_option, rec_option = build_option(args)
+
+det_model = fd.vision.ocr.DBDetector(
+ det_model_file, det_params_file, runtime_option=det_option)
+
+cls_model = fd.vision.ocr.Classifier(
+ cls_model_file, cls_params_file, runtime_option=cls_option)
+
+rec_model = fd.vision.ocr.Recognizer(
+ rec_model_file, rec_params_file, rec_label_file, runtime_option=rec_option)
+
+# Rec模型启用静态shape推理
+rec_model.preprocessor.static_shape_infer = True
+
+# 创建PP-OCR,串联3个模型,其中cls_model可选,如无需求,可设置为None
+ppocr_v3 = fd.vision.ocr.PPOCRv3(
+ det_model=det_model, cls_model=cls_model, rec_model=rec_model)
+
+# Cls模型和Rec模型的batch size 必须设置为1, 开启静态shape推理
+ppocr_v3.cls_batch_size = 1
+ppocr_v3.rec_batch_size = 1
+
+# 预测图片准备
+im = cv2.imread(args.image)
+
+#预测并打印结果
+result = ppocr_v3.predict(im)
+
+print(result)
+
+# 可视化结果
+vis_im = fd.vision.vis_ppocr(im, result)
+cv2.imwrite("visualized_result.jpg", vis_im)
+print("Visualized result save in ./visualized_result.jpg")
diff --git a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py
index faaca906737..9cfe2583e02 100644
--- a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py
+++ b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py
@@ -217,7 +217,7 @@ def execute(self, requests):
out_tensor_0 = pb_utils.Tensor(
self.output_names[0],
np.array(
- batch_rec_texts, dtype=np.object))
+ batch_rec_texts, dtype=np.object_))
out_tensor_1 = pb_utils.Tensor(self.output_names[1],
np.array(batch_rec_scores))
inference_response = pb_utils.InferenceResponse(
diff --git a/examples/vision/ocr/PP-OCRv3/serving/models/rec_postprocess/1/model.py b/examples/vision/ocr/PP-OCRv3/serving/models/rec_postprocess/1/model.py
index fe66e8c3f3c..c046cd929b7 100755
--- a/examples/vision/ocr/PP-OCRv3/serving/models/rec_postprocess/1/model.py
+++ b/examples/vision/ocr/PP-OCRv3/serving/models/rec_postprocess/1/model.py
@@ -96,7 +96,7 @@ def execute(self, requests):
results = self.postprocessor.run([infer_outputs])
out_tensor_0 = pb_utils.Tensor(
self.output_names[0], np.array(
- results[0], dtype=np.object))
+ results[0], dtype=np.object_))
out_tensor_1 = pb_utils.Tensor(self.output_names[1],
np.array(results[1]))
inference_response = pb_utils.InferenceResponse(
diff --git a/examples/vision/segmentation/paddleseg/a311d/cpp/README.md b/examples/vision/segmentation/paddleseg/a311d/cpp/README.md
index c4eabf471d4..8bd94e6468e 100755
--- a/examples/vision/segmentation/paddleseg/a311d/cpp/README.md
+++ b/examples/vision/segmentation/paddleseg/a311d/cpp/README.md
@@ -4,12 +4,14 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/a311d.md#交叉编译环境搭建)
### 模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
+3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 A311D 上部署量化后的 PP-LiteSeg 分割模型
请按照以下步骤完成在 A311D 上部署 PP-LiteSeg 量化模型:
diff --git a/examples/vision/segmentation/paddleseg/cpp/README.md b/examples/vision/segmentation/paddleseg/cpp/README.md
index 35d288ba498..07f9f4c62dc 100755
--- a/examples/vision/segmentation/paddleseg/cpp/README.md
+++ b/examples/vision/segmentation/paddleseg/cpp/README.md
@@ -34,6 +34,8 @@ wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 2
# 昆仑芯XPU推理
./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 3
+# 华为昇腾推理
+./infer_demo Unet_cityscapes_without_argmax_infer cityscapes_demo.png 4
```
运行完成可视化结果如下图所示
@@ -44,6 +46,9 @@ wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
以上命令只适用于Linux或MacOS, Windows下SDK的使用方式请参考:
- [如何在Windows中使用FastDeploy C++ SDK](../../../../../docs/cn/faq/use_sdk_on_windows.md)
+如果用户使用华为昇腾NPU部署, 请参考以下方式在部署前初始化部署环境:
+- [如何使用华为昇腾NPU部署](../../../../../docs/cn/faq/use_sdk_on_ascend.md)
+
## PaddleSeg C++接口
### PaddleSeg类
diff --git a/examples/vision/segmentation/paddleseg/cpp/infer.cc b/examples/vision/segmentation/paddleseg/cpp/infer.cc
index 389699a5129..ae97c0406ed 100755
--- a/examples/vision/segmentation/paddleseg/cpp/infer.cc
+++ b/examples/vision/segmentation/paddleseg/cpp/infer.cc
@@ -135,6 +135,34 @@ void TrtInfer(const std::string& model_dir, const std::string& image_file) {
std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}
+void AscendInfer(const std::string& model_dir, const std::string& image_file) {
+ auto model_file = model_dir + sep + "model.pdmodel";
+ auto params_file = model_dir + sep + "model.pdiparams";
+ auto config_file = model_dir + sep + "deploy.yaml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseAscend();
+ auto model = fastdeploy::vision::segmentation::PaddleSegModel(
+ model_file, params_file, config_file, option);
+
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+
+ auto im = cv::imread(image_file);
+
+ fastdeploy::vision::SegmentationResult res;
+ if (!model.Predict(im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+
+ std::cout << res.Str() << std::endl;
+ auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5);
+ cv::imwrite("vis_result.jpg", vis_im);
+ std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
+}
+
int main(int argc, char* argv[]) {
if (argc < 4) {
std::cout
@@ -155,6 +183,8 @@ int main(int argc, char* argv[]) {
TrtInfer(argv[1], argv[2]);
} else if (std::atoi(argv[3]) == 3) {
KunlunXinInfer(argv[1], argv[2]);
+ } else if (std::atoi(argv[3]) == 4) {
+ AscendInfer(argv[1], argv[2]);
}
return 0;
}
diff --git a/examples/vision/segmentation/paddleseg/python/README.md b/examples/vision/segmentation/paddleseg/python/README.md
index 9b5163bdfe0..02b2e6ab5f5 100755
--- a/examples/vision/segmentation/paddleseg/python/README.md
+++ b/examples/vision/segmentation/paddleseg/python/README.md
@@ -27,6 +27,8 @@ python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_
python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True
# 昆仑芯XPU推理
python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device kunlunxin
+# 华为昇腾推理
+python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device ascend
```
运行完成可视化结果如下图所示
diff --git a/examples/vision/segmentation/paddleseg/python/infer.py b/examples/vision/segmentation/paddleseg/python/infer.py
index 0b19fedc2f8..6862330ed63 100755
--- a/examples/vision/segmentation/paddleseg/python/infer.py
+++ b/examples/vision/segmentation/paddleseg/python/infer.py
@@ -33,6 +33,9 @@ def build_option(args):
if args.device.lower() == "kunlunxin":
option.use_kunlunxin()
+ if args.device.lower() == "ascend":
+ option.use_ascend()
+
if args.use_trt:
option.use_trt_backend()
option.set_trt_input_shape("x", [1, 3, 256, 256], [1, 3, 1024, 1024],
diff --git a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc b/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc
index 834b2ccb3fc..f80d3fc8f5e 100644
--- a/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc
+++ b/examples/vision/segmentation/paddleseg/rknpu2/cpp/infer.cc
@@ -62,7 +62,8 @@ void RKNPU2Infer(const std::string& model_dir, const std::string& image_file) {
std::cerr << "Failed to initialize." << std::endl;
return;
}
- model.GetPreprocessor().DisableNormalizeAndPermute();
+ model.GetPreprocessor().DisablePermute();
+ model.GetPreprocessor().DisableNormalize();
fastdeploy::TimeCounter tc;
tc.Start();
diff --git a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py b/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py
index 4168d591df8..193a6dfb9b3 100644
--- a/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py
+++ b/examples/vision/segmentation/paddleseg/rknpu2/python/infer.py
@@ -49,7 +49,8 @@ def build_option(args):
runtime_option=runtime_option,
model_format=fd.ModelFormat.RKNN)
-model.preprocessor.disable_normalize_and_permute()
+model.preprocessor.disable_normalize()
+model.preprocessor.disable_permute()
# 预测图片分割结果
im = cv2.imread(args.image)
diff --git a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md b/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md
index 5975ac3f670..a15dd0a6473 100755
--- a/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md
+++ b/examples/vision/segmentation/paddleseg/rv1126/cpp/README.md
@@ -4,12 +4,14 @@
## 部署准备
### FastDeploy 交叉编译环境准备
-- 1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
+1. 软硬件环境满足要求,以及交叉编译环境的准备,请参考:[FastDeploy 交叉编译环境准备](../../../../../../docs/cn/build_and_install/rv1126.md#交叉编译环境搭建)
### 模型准备
-- 1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
-- 2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
-- 更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
+1. 用户可以直接使用由 FastDeploy 提供的量化模型进行部署。
+2. 用户可以使用 FastDeploy 提供的一键模型自动化压缩工具,自行进行模型量化, 并使用产出的量化模型进行部署.(注意: 推理量化后的分类模型仍然需要FP32模型文件夹下的 deploy.yaml 文件, 自行量化的模型文件夹内不包含此 yaml 文件, 用户从FP32模型文件夹下复制此yaml文件到量化后的模型文件夹内即可.)
+3. 模型需要异构计算,异构计算文件可以参考:[异构计算](./../../../../../../docs/cn/faq/heterogeneous_computing_on_timvx_npu.md),由于 FastDeploy 已经提供了模型,可以先测试我们提供的异构文件,验证精度是否符合要求。
+
+更多量化相关相关信息可查阅[模型量化](../../quantize/README.md)
## 在 RV1126 上部署量化后的 PP-LiteSeg 分割模型
请按照以下步骤完成在 RV1126 上部署 PP-LiteSeg 量化模型:
diff --git a/examples/vision/segmentation/paddleseg/sophgo/README.md b/examples/vision/segmentation/paddleseg/sophgo/README.md
new file mode 100644
index 00000000000..afebe34519a
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/README.md
@@ -0,0 +1,89 @@
+# PaddleSeg C++部署示例
+
+## 支持模型列表
+
+- PP-LiteSeg部署模型实现来自[PaddleSeg PP-LiteSeg系列模型](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.6/configs/pp_liteseg/README.md)
+
+## 准备PP-LiteSeg部署模型以及转换模型
+
+SOPHGO-TPU部署模型前需要将Paddle模型转换成bmodel模型,具体步骤如下:
+- 下载Paddle模型[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)
+- Pddle模型转换为ONNX模型,请参考[Paddle2ONNX](https://github.com/PaddlePaddle/Paddle2ONNX)
+- ONNX模型转换bmodel模型的过程,请参考[TPU-MLIR](https://github.com/sophgo/tpu-mlir)
+
+## 模型转换example
+
+下面以[PP-LiteSeg-B(STDC2)-cityscapes-without-argmax](https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz)为例子,教大家如何转换Paddle模型到SOPHGO-TPU模型
+
+### 下载PP-LiteSeg-B(STDC2)-cityscapes-without-argmax模型,并转换为ONNX模型
+```shell
+https://bj.bcebos.com/paddlehub/fastdeploy/PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz
+tar xvf PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer.tgz
+
+# 修改PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer模型的输入shape,由动态输入变成固定输入
+python paddle_infer_shape.py --model_dir PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer \
+ --model_filename model.pdmodel \
+ --params_filename model.pdiparams \
+ --save_dir pp_liteseg_fix \
+ --input_shape_dict="{'x':[1,3,512,512]}"
+
+#将固定输入的Paddle模型转换成ONNX模型
+paddle2onnx --model_dir pp_liteseg_fix \
+ --model_filename model.pdmodel \
+ --params_filename model.pdiparams \
+ --save_file pp_liteseg.onnx \
+ --enable_dev_version True
+```
+
+### 导出bmodel模型
+
+以转换BM1684x的bmodel模型为例子,我们需要下载[TPU-MLIR](https://github.com/sophgo/tpu-mlir)工程,安装过程具体参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+### 1. 安装
+``` shell
+docker pull sophgo/tpuc_dev:latest
+
+# myname1234是一个示例,也可以设置其他名字
+docker run --privileged --name myname1234 -v $PWD:/workspace -it sophgo/tpuc_dev:latest
+
+source ./envsetup.sh
+./build.sh
+```
+
+### 2. ONNX模型转换为bmodel模型
+``` shell
+mkdir pp_liteseg && cd pp_liteseg
+
+#在该文件中放入测试图片,同时将上一步转换的pp_liteseg.onnx放入该文件夹中
+cp -rf ${REGRESSION_PATH}/dataset/COCO2017 .
+cp -rf ${REGRESSION_PATH}/image .
+#放入onnx模型文件pp_liteseg.onnx
+
+mkdir workspace && cd workspace
+
+#将ONNX模型转换为mlir模型,其中参数--output_names可以通过NETRON查看
+model_transform.py \
+ --model_name pp_liteseg \
+ --model_def ../pp_liteseg.onnx \
+ --input_shapes [[1,3,512,512]] \
+ --mean 0.0,0.0,0.0 \
+ --scale 0.0039216,0.0039216,0.0039216 \
+ --keep_aspect_ratio \
+ --pixel_format rgb \
+ --output_names bilinear_interp_v2_6.tmp_0 \
+ --test_input ../image/dog.jpg \
+ --test_result pp_liteseg_top_outputs.npz \
+ --mlir pp_liteseg.mlir
+
+#将mlir模型转换为BM1684x的F32 bmodel模型
+model_deploy.py \
+ --mlir pp_liteseg.mlir \
+ --quantize F32 \
+ --chip bm1684x \
+ --test_input pp_liteseg_in_f32.npz \
+ --test_reference pp_liteseg_top_outputs.npz \
+ --model pp_liteseg_1684x_f32.bmodel
+```
+最终获得可以在BM1684x上能够运行的bmodel模型pp_liteseg_1684x_f32.bmodel。如果需要进一步对模型进行加速,可以将ONNX模型转换为INT8 bmodel,具体步骤参见[TPU-MLIR文档](https://github.com/sophgo/tpu-mlir/blob/master/README.md)。
+
+## 其他链接
+- [Cpp部署](./cpp)
diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/CMakeLists.txt b/examples/vision/segmentation/paddleseg/sophgo/cpp/CMakeLists.txt
new file mode 100644
index 00000000000..53837058969
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/CMakeLists.txt
@@ -0,0 +1,17 @@
+PROJECT(infer_demo C CXX)
+CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
+# 指定下载解压后的fastdeploy库路径
+option(FASTDEPLOY_INSTALL_DIR "Path of downloaded fastdeploy sdk.")
+
+set(ENABLE_LITE_BACKEND OFF)
+#set(FDLIB ${FASTDEPLOY_INSTALL_DIR})
+
+include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
+
+# 添加FastDeploy依赖头文件
+include_directories(${FASTDEPLOY_INCS})
+include_directories(${FastDeploy_INCLUDE_DIRS})
+
+add_executable(infer_demo ${PROJECT_SOURCE_DIR}/infer.cc)
+# 添加FastDeploy库依赖
+target_link_libraries(infer_demo ${FASTDEPLOY_LIBS})
diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md
new file mode 100644
index 00000000000..dac3ed565dd
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/README.md
@@ -0,0 +1,56 @@
+# PaddleSeg C++部署示例
+
+本目录下提供`infer.cc`快速完成pp_liteseg模型在SOPHGO BM1684x板子上加速部署的示例。
+
+在部署前,需确认以下两个步骤:
+
+1. 软硬件环境满足要求
+2. 根据开发环境,从头编译FastDeploy仓库
+
+以上步骤请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)实现
+
+## 生成基本目录文件
+
+该例程由以下几个部分组成
+```text
+.
+├── CMakeLists.txt
+├── build # 编译文件夹
+├── image # 存放图片的文件夹
+├── infer.cc
+└── model # 存放模型文件的文件夹
+```
+
+## 编译
+
+### 编译并拷贝SDK到thirdpartys文件夹
+
+请参考[SOPHGO部署库编译](../../../../../../docs/cn/build_and_install/sophgo.md)仓库编译SDK,编译完成后,将在build目录下生成fastdeploy-0.0.3目录.
+
+### 拷贝模型文件,以及配置文件至model文件夹
+将Paddle模型转换为SOPHGO bmodel模型,转换步骤参考[文档](../README.md)
+将转换后的SOPHGO bmodel模型文件拷贝至model中
+
+### 准备测试图片至image文件夹
+```bash
+wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
+cp cityscapes_demo.png ./images
+```
+
+### 编译example
+
+```bash
+cd build
+cmake .. -DFASTDEPLOY_INSTALL_DIR=${PWD}/fastdeploy-0.0.3
+make
+```
+
+## 运行例程
+
+```bash
+./infer_demo model images/cityscapes_demo.png
+```
+
+
+- [模型介绍](../../)
+- [模型转换](../)
diff --git a/examples/vision/segmentation/paddleseg/sophgo/cpp/infer.cc b/examples/vision/segmentation/paddleseg/sophgo/cpp/infer.cc
new file mode 100644
index 00000000000..934ab648c97
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/cpp/infer.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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.
+#include
+#include
+#include "fastdeploy/vision.h"
+
+void SophgoInfer(const std::string& model_dir, const std::string& image_file) {
+ std::string model_file = model_dir + "/pp_liteseg_1684x_f32.bmodel";
+ std::string params_file;
+ std::string config_file = model_dir + "/deploy.yaml";
+ auto option = fastdeploy::RuntimeOption();
+ option.UseSophgo();
+ auto model_format = fastdeploy::ModelFormat::SOPHGO;
+
+ auto model = fastdeploy::vision::segmentation::PaddleSegModel(
+ model_file, params_file, config_file, option, model_format);
+ if (!model.Initialized()) {
+ std::cerr << "Failed to initialize." << std::endl;
+ return;
+ }
+ //model.GetPreprocessor().DisableNormalizeAndPermute();
+
+ fastdeploy::TimeCounter tc;
+ tc.Start();
+ auto im_org = cv::imread(image_file);
+
+ //the input of bmodel should be fixed
+ int new_width = 512;
+ int new_height = 512;
+ cv::Mat im;
+ cv::resize(im_org, im, cv::Size(new_width, new_height), cv::INTER_LINEAR);
+
+ fastdeploy::vision::SegmentationResult res;
+ if (!model.Predict(&im, &res)) {
+ std::cerr << "Failed to predict." << std::endl;
+ return;
+ }
+ auto vis_im = fastdeploy::vision::VisSegmentation(im, res);
+ tc.End();
+ tc.PrintInfo("PPSeg in Sophgo");
+
+ cv::imwrite("infer_sophgo.jpg", vis_im);
+ std::cout
+ << "Visualized result saved in ./infer_sophgo.jpg"
+ << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 3) {
+ std::cout
+ << "Usage: infer_demo path/to/model_dir path/to/image run_option, "
+ "e.g ./infer_model ./bmodel ./test.jpeg"
+ << std::endl;
+ return -1;
+ }
+
+ SophgoInfer(argv[1], argv[2]);
+ return 0;
+}
+
diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/README.md b/examples/vision/segmentation/paddleseg/sophgo/python/README.md
new file mode 100644
index 00000000000..e04ad28c4d1
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/python/README.md
@@ -0,0 +1,26 @@
+# PaddleSeg Python部署示例
+
+在部署前,需确认以下两个步骤
+
+- 1. 软硬件环境满足要求,参考[FastDeploy环境要求](../../../../../../docs/cn/build_and_install/sophgo.md)
+
+本目录下提供`infer.py`快速完成 pp_liteseg 在SOPHGO TPU上部署的示例。执行如下脚本即可完成
+
+```bash
+# 下载部署示例代码
+git clone https://github.com/PaddlePaddle/FastDeploy.git
+cd FastDeploy/examples/vision/segmentation/paddleseg/sophgo/python
+
+# 下载图片
+wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
+
+# 推理
+python3 infer.py --model_file ./bmodel/pp_liteseg_1684x_f32.bmodel --config_file ./bmodel/deploy.yaml --image cityscapes_demo.png
+
+# 运行完成后返回结果如下所示
+运行结果保存在sophgo_img.png中
+```
+
+## 其它文档
+- [pp_liteseg C++部署](../cpp)
+- [转换 pp_liteseg SOPHGO模型文档](../README.md)
diff --git a/examples/vision/segmentation/paddleseg/sophgo/python/infer.py b/examples/vision/segmentation/paddleseg/sophgo/python/infer.py
new file mode 100644
index 00000000000..1b294da6022
--- /dev/null
+++ b/examples/vision/segmentation/paddleseg/sophgo/python/infer.py
@@ -0,0 +1,45 @@
+import fastdeploy as fd
+import cv2
+import os
+
+
+def parse_arguments():
+ import argparse
+ import ast
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--model", required=True, help="Path of model.")
+ parser.add_argument(
+ "--config_file", required=True, help="Path of config file.")
+ parser.add_argument(
+ "--image", type=str, required=True, help="Path of test image file.")
+
+ return parser.parse_args()
+
+
+args = parse_arguments()
+
+# 配置runtime,加载模型
+runtime_option = fd.RuntimeOption()
+runtime_option.use_sophgo()
+
+model_file = args.model
+params_file = ""
+config_file = args.config_file
+
+model = fd.vision.segmentation.PaddleSegModel(
+ model_file,
+ params_file,
+ config_file,
+ runtime_option=runtime_option,
+ model_format=fd.ModelFormat.SOPHGO)
+
+# 预测图片分类结果
+im_org = cv2.imread(args.image)
+#bmodel 是静态模型,模型输入固定,这里设置为[512, 512]
+im = cv2.resize(im_org, [512, 512], interpolation=cv2.INTER_LINEAR)
+result = model.predict(im)
+print(result)
+
+# 预测结果可视化
+vis_im = fd.vision.vis_segmentation(im, result, weight=0.5)
+cv2.imwrite("sophgo_img.png", vis_im)
diff --git a/fastdeploy/backends/backend.h b/fastdeploy/backends/backend.h
index 02c94875d29..5affeb7567e 100644
--- a/fastdeploy/backends/backend.h
+++ b/fastdeploy/backends/backend.h
@@ -19,7 +19,6 @@
#include
#include
-#include "fastdeploy/backends/common/multiclass_nms.h"
#include "fastdeploy/core/fd_tensor.h"
#include "fastdeploy/core/fd_type.h"
diff --git a/fastdeploy/backends/lite/lite_backend.h b/fastdeploy/backends/lite/lite_backend.h
index 261a4af396e..7718dbb0f09 100755
--- a/fastdeploy/backends/lite/lite_backend.h
+++ b/fastdeploy/backends/lite/lite_backend.h
@@ -20,50 +20,10 @@
#include
#include "fastdeploy/backends/backend.h"
+#include "fastdeploy/backends/lite/option.h"
#include "paddle_api.h" // NOLINT
namespace fastdeploy {
-
-struct LiteBackendOption {
- // cpu num threads
- int threads = 1;
- // lite power mode
- // 0: LITE_POWER_HIGH
- // 1: LITE_POWER_LOW
- // 2: LITE_POWER_FULL
- // 3: LITE_POWER_NO_BIND
- // 4: LITE_POWER_RAND_HIGH
- // 5: LITE_POWER_RAND_LOW
- int power_mode = 3;
- // enable fp16
- bool enable_fp16 = false;
- // enable int8
- bool enable_int8 = false;
- // optimized model dir for CxxConfig
- std::string optimized_model_dir = "";
- // TODO(qiuyanjun): support more options for lite backend.
- // Such as fp16, different device target (kARM/kXPU/kNPU/...)
- std::string nnadapter_subgraph_partition_config_path = "";
- std::string nnadapter_subgraph_partition_config_buffer = "";
- std::string nnadapter_context_properties = "";
- std::string nnadapter_model_cache_dir = "";
- std::string nnadapter_mixed_precision_quantization_config_path = "";
- std::map>>
- nnadapter_dynamic_shape_info = {{"", {{0}}}};
- std::vector nnadapter_device_names = {};
- bool enable_timvx = false;
- bool enable_ascend = false;
- bool enable_kunlunxin = false;
- int device_id = 0;
- int kunlunxin_l3_workspace_size = 0xfffc00;
- bool kunlunxin_locked = false;
- bool kunlunxin_autotune = true;
- std::string kunlunxin_autotune_file = "";
- std::string kunlunxin_precision = "int16";
- bool kunlunxin_adaptive_seqlen = false;
- bool kunlunxin_enable_multi_stream = false;
-};
-
// Convert data type from paddle lite to fastdeploy
FDDataType LiteDataTypeToFD(const paddle::lite_api::PrecisionType& dtype);
diff --git a/fastdeploy/backends/lite/option.h b/fastdeploy/backends/lite/option.h
new file mode 100755
index 00000000000..2a4ba7a330d
--- /dev/null
+++ b/fastdeploy/backends/lite/option.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// 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
+#include
+#include
+#include
+#include