Add more demos (#305)
* add more examples * change to restore's output image to BGR * use BUILD_SHARED_LIBS * update graph module's cmake * add condition for spdlog package * change cmakelists * update cmakelists * add device_name in each demo * remove duplicate cmake function * use palette to draw segmentation's result * no need to find_package(pplnn) when use MMDeploy's static libs * remove MMDeploy_LIBS' dependency on spdlog * #include <opencv2/imgproc/imgproc.hpp> * change from mmdeploy_core to mmdeploy::corepull/1/head
parent
56e32fdf63
commit
e10a1b7c9e
csrc
apis/c
archive
codebase
core
device
cuda
graph
model
net
ncnn
openvino
preprocess
demo/csrc
tests/test_csrc
|
@ -123,8 +123,8 @@ work_dirs/
|
|||
*.sh~
|
||||
|
||||
#clion's build directory
|
||||
/cmake-build-debug
|
||||
/cmake-build-release
|
||||
/cmake-build-debug*
|
||||
/cmake-build-release*
|
||||
|
||||
# install directory
|
||||
/install
|
||||
|
|
|
@ -15,6 +15,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
|||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# options
|
||||
option(BUILD_SHARED_LIBS "build shared lib" ON)
|
||||
option(MMDEPLOY_BUILD_MODEL_OPTIMIZER "build MMDeploy's model optimizer" ON)
|
||||
option(MMDEPLOY_BUILD_SDK "build MMDeploy's SDK" OFF)
|
||||
option(MMDEPLOY_ZIP_MODEL "support sdk model in zip format" OFF)
|
||||
|
@ -23,7 +24,6 @@ set(MMDEPLOY_TARGET_DEVICES
|
|||
"cpu" CACHE STRING "MMDeploy's target devices")
|
||||
set(MMDEPLOY_TARGET_BACKENDS "" CACHE STRING "MMDeploy's target inference engines")
|
||||
set(MMDEPLOY_CODEBASES "" CACHE STRING "select OpenMMLab's codebases")
|
||||
#set(MMDEPLOY_TRANSFORM_PLATFORMS "cpu" CACHE STRING "select transform operations' platform")
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "choose 'Release' as default build type" FORCE)
|
||||
|
@ -47,14 +47,12 @@ include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
|||
# set INTERFACE target to gather linked modules
|
||||
add_library(MMDeployStaticModules INTERFACE)
|
||||
add_library(MMDeployDynamicModules INTERFACE)
|
||||
add_library(MMDeployLibs INTERFACE)
|
||||
|
||||
add_subdirectory(csrc)
|
||||
if (MMDEPLOY_BUILD_TEST)
|
||||
add_subdirectory(tests/test_csrc)
|
||||
endif ()
|
||||
|
||||
if (MMDEPLOY_BUILD_SDK)
|
||||
# get static modules and dynamic modules from MMDeployStaticModules and MMDeployDynamicModules, respectively
|
||||
# get static modules and dynamic modules from ${MMDeployStaticModules} and ${MMDeployDynamicModules}, respectively
|
||||
set(STATIC_MODULES)
|
||||
get_target_property(STATIC_MODULES MMDeployStaticModules INTERFACE_LINK_LIBRARIES)
|
||||
get_target_list("${STATIC_MODULES}" FILTERED_MODULES)
|
||||
|
@ -67,6 +65,17 @@ if (MMDEPLOY_BUILD_SDK)
|
|||
set(MMDEPLOY_DYNAMIC_MODULES "${FILTERED_MODULES}" CACHE STRING "MMDeploy's dynamic modules")
|
||||
message(STATUS "MMDEPLOY_DYNAMIC_MODULES: ${MMDEPLOY_DYNAMIC_MODULES}")
|
||||
|
||||
# get libs from ${MMDeployLibs}
|
||||
set(LIBS)
|
||||
get_target_property(LIBS MMDeployLibs INTERFACE_LINK_LIBRARIES)
|
||||
get_target_list("${LIBS}" FILTERED_LIBS)
|
||||
set(MMDEPLOY_LIBS "${FILTERED_LIBS}" CACHE STRING "MMDeploy's libs that can be linked directly by application")
|
||||
message(STATUS "MMDEPLOY_LIBS: ${MMDEPLOY_LIBS}")
|
||||
|
||||
if (MMDEPLOY_BUILD_TEST)
|
||||
add_subdirectory(tests/test_csrc)
|
||||
endif ()
|
||||
|
||||
# export MMDeploy package
|
||||
install(EXPORT MMDeployTargets
|
||||
# NAMESPACE mmdeploy::
|
||||
|
|
|
@ -4,22 +4,21 @@ cmake_minimum_required(VERSION 3.14)
|
|||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/MMDeployTargets.cmake")
|
||||
|
||||
find_package(spdlog REQUIRED)
|
||||
|
||||
set(MMDEPLOY_CODEBASES @MMDEPLOY_CODEBASES@)
|
||||
set(MMDEPLOY_TARGET_DEVICES @MMDEPLOY_TARGET_DEVICES@)
|
||||
set(MMDEPLOY_TARGET_BACKENDS @MMDEPLOY_TARGET_BACKENDS@)
|
||||
set(MMDEPLOY_BUILD_TYPE @CMAKE_BUILD_TYPE@)
|
||||
set(MMDeploy_STATIC_MODULES @MMDEPLOY_STATIC_MODULES@)
|
||||
set(MMDeploy_DYNAMIC_MODULES @MMDEPLOY_DYNAMIC_MODULES@)
|
||||
set(MMDEPLOY_STATIC_MODULES @MMDEPLOY_STATIC_MODULES@)
|
||||
set(MMDEPLOY_DYNAMIC_MODULES @MMDEPLOY_DYNAMIC_MODULES@)
|
||||
set(MMDEPLOY_BUILD_SHARED @BUILD_SHARED_LIBS@)
|
||||
set(MMDEPLOY_LIBS @MMDEPLOY_LIBS@)
|
||||
|
||||
if ("trt" IN_LIST MMDEPLOY_BACKENDS)
|
||||
if (NOT MMDEPLOY_BUILD_SHARED)
|
||||
if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
find_package(pplcv REQUIRED)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if ("pplnn" IN_LIST MMDEPLOY_BACKENDS)
|
||||
find_package(pplnn)
|
||||
endif()
|
||||
|
||||
if ("ncnn" IN_LIST MMDEPLOY_BACKENDS)
|
||||
find_package(ncnn)
|
||||
endif ()
|
||||
set(MMDeploy_LIBS ${MMDEPLOY_LIBS}
|
||||
-Wl,--no-as-needed ${MMDEPLOY_DYNAMIC_MODULES} -Wl,--as-needed
|
||||
-Wl,--whole-archive ${MMDEPLOY_STATIC_MODULES} -Wl,--no-whole-archive)
|
||||
|
|
|
@ -15,6 +15,11 @@ function(install_targets TARGET_NAMES)
|
|||
endforeach ()
|
||||
endfunction()
|
||||
|
||||
function(build_target TARGET_NAME TARGET_SRCS)
|
||||
add_library(${TARGET_NAME} ${TARGET_SRCS})
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||
endfunction()
|
||||
|
||||
# When the object target ${TARGET_NAME} has more than one source file,
|
||||
# "${SRCS_VARIABLE}" MUST be passed to ${TARGET_SRCS}. The quotation marks CANNOT be dismissed.
|
||||
function(build_object_target TARGET_NAME TARGET_SRCS)
|
||||
|
@ -69,19 +74,23 @@ function(build_module_target TARGET_NAME OBJECT_TARGET LINK_TYPE)
|
|||
endfunction()
|
||||
|
||||
|
||||
function(export_target STATIC_TARGET SHARED_TARGET OBJECT_TARGET)
|
||||
install(TARGETS ${STATIC_TARGET} ${SHARED_TARGET} ${OBJECT_TARGET}
|
||||
function(export_target TARGET_NAME)
|
||||
target_link_libraries(MMDeployLibs INTERFACE ${TARGET_NAME})
|
||||
install(TARGETS ${TARGET_NAME}
|
||||
EXPORT MMDeployTargets
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(export_module STATIC_TARGET SHARED_TARGET OBJECT_TARGET)
|
||||
target_link_libraries(MMDeployStaticModules INTERFACE ${STATIC_TARGET})
|
||||
target_link_libraries(MMDeployDynamicModules INTERFACE ${SHARED_TARGET})
|
||||
|
||||
install(TARGETS ${STATIC_TARGET} ${SHARED_TARGET} ${OBJECT_TARGET}
|
||||
function(export_module TARGET_NAME)
|
||||
get_target_property(TARGET_TYPE ${TARGET_NAME} TYPE)
|
||||
if (${TARGET_TYPE} STREQUAL "STATIC_LIBRARY")
|
||||
target_link_libraries(MMDeployStaticModules INTERFACE ${TARGET_NAME})
|
||||
elseif (${TARGET_TYPE} STREQUAL "SHARED_LIBRARY")
|
||||
target_link_libraries(MMDeployDynamicModules INTERFACE ${TARGET_NAME})
|
||||
endif ()
|
||||
install(TARGETS ${TARGET_NAME}
|
||||
EXPORT MMDeployTargets
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
|
|
|
@ -27,19 +27,13 @@ else ()
|
|||
endif ()
|
||||
|
||||
foreach (TASK ${TASK_LIST})
|
||||
set_targets(mmdeploy_${TASK} TASK_OBJ TASK_STATIC TASK_SHARED)
|
||||
|
||||
build_object_target(${TASK_OBJ} ${TASK}.cpp)
|
||||
target_link_libraries(${TASK_OBJ} PRIVATE
|
||||
mmdeploy::core::static)
|
||||
target_include_directories(${TASK_OBJ} PUBLIC
|
||||
set(TARGET_NAME mmdeploy_${TASK})
|
||||
build_target(${TARGET_NAME} ${TASK}.cpp)
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE mmdeploy::core)
|
||||
target_include_directories(${TARGET_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:include/c>)
|
||||
|
||||
build_static_target(${TASK_STATIC} ${TASK_OBJ} "PUBLIC")
|
||||
build_shared_target(${TASK_SHARED} ${TASK_OBJ} "PUBLIC")
|
||||
|
||||
export_target(${TASK_STATIC} ${TASK_SHARED} ${TASK_OBJ})
|
||||
export_target(${TARGET_NAME})
|
||||
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TASK}.h
|
||||
DESTINATION include/c)
|
||||
|
|
|
@ -6,11 +6,7 @@ add_library(${PROJECT_NAME} INTERFACE)
|
|||
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
|
||||
add_library(mmdeploy::archive ALIAS mmdeploy_archive)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT MMDeployTargets
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
export_target(${PROJECT_NAME})
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/archive
|
||||
DESTINATION include/cpp
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
|
|
@ -3,17 +3,9 @@ cmake_minimum_required(VERSION 3.14)
|
|||
project(mmdeploy_mmcls)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} MMCLS_OBJ MMCLS_STATIC MMCLS_SHARED)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
|
||||
build_object_target(${MMCLS_OBJ} "${SRCS}")
|
||||
target_link_libraries(${MMCLS_OBJ} PRIVATE
|
||||
mmdeploy::core::static)
|
||||
|
||||
build_static_target(${MMCLS_STATIC} ${MMCLS_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmcls::static ALIAS ${MMCLS_STATIC})
|
||||
|
||||
build_shared_target(${MMCLS_SHARED} ${MMCLS_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmcls ALIAS ${MMCLS_SHARED})
|
||||
|
||||
export_module(${MMCLS_STATIC} ${MMCLS_SHARED} ${MMCLS_OBJ} ${MMCLS_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::mmcls ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,17 +4,9 @@ project(mmdeploy_mmdet)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} MMDET_OBJ MMDET_STATIC MMDET_SHARED)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
|
||||
build_object_target(${MMDET_OBJ} "${SRCS}")
|
||||
target_link_libraries(${MMDET_OBJ} PRIVATE
|
||||
mmdeploy::core::static opencv_core)
|
||||
|
||||
build_static_target(${MMDET_STATIC} ${MMDET_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmdet::static ALIAS ${MMDET_STATIC})
|
||||
|
||||
build_shared_target(${MMDET_SHARED} ${MMDET_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmdet ALIAS ${MMDET_SHARED})
|
||||
|
||||
export_module(${MMDET_STATIC} ${MMDET_SHARED} ${MMDET_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core opencv_core)
|
||||
add_library(mmdeploy::mmdet ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,17 +4,9 @@ project(mmdeploy_mmedit)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} MMEDIT_OBJ MMEDIT_STATIC MMEDIT_SHARED)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
|
||||
build_object_target(${MMEDIT_OBJ} "${SRCS}")
|
||||
target_link_libraries(${MMEDIT_OBJ} PRIVATE
|
||||
mmdeploy::core::static opencv_core)
|
||||
|
||||
build_static_target(${MMEDIT_STATIC} ${MMEDIT_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmedit::static ALIAS ${MMEDIT_STATIC})
|
||||
|
||||
build_shared_target(${MMEDIT_SHARED} ${MMEDIT_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmedit ALIAS ${MMEDIT_SHARED})
|
||||
|
||||
export_module(${MMEDIT_STATIC} ${MMEDIT_SHARED} ${MMEDIT_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core opencv_core)
|
||||
add_library(mmdeploy::mmedit ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,22 +4,12 @@ project(mmdeploy_mmocr)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} MMOCR_OBJ MMOCR_STATIC MMOCR_SHARED)
|
||||
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} OCR_SRCS)
|
||||
aux_source_directory(${CMAKE_SOURCE_DIR}/third_party/clipper CLIPPER_SRCS)
|
||||
set(SRCS ${OCR_SRCS} ${CLIPPER_SRCS})
|
||||
build_object_target(${MMOCR_OBJ} "${SRCS}")
|
||||
target_include_directories(${MMOCR_OBJ} PRIVATE ${CMAKE_SOURCE_DIR}/third_party/clipper)
|
||||
target_link_libraries(${MMOCR_OBJ} PRIVATE
|
||||
mmdeploy::core::static
|
||||
opencv_core opencv_imgproc
|
||||
)
|
||||
|
||||
build_static_target(${MMOCR_STATIC} ${MMOCR_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmocr::static ALIAS ${MMOCR_STATIC})
|
||||
|
||||
build_shared_target(${MMOCR_SHARED} ${MMOCR_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmocr ALIAS ${MMOCR_SHARED})
|
||||
|
||||
export_module(${MMOCR_STATIC} ${MMOCR_SHARED} ${MMOCR_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/third_party/clipper)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core opencv_core opencv_imgproc)
|
||||
add_library(mmdeploy::mmocr ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,17 +4,9 @@ project(mmdeploy_mmseg)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} MMSEG_OBJ MMSEG_STATIC MMSEG_SHARED)
|
||||
|
||||
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
|
||||
build_object_target(${MMSEG_OBJ} "${SRCS}")
|
||||
target_link_libraries(${MMSEG_OBJ} PRIVATE
|
||||
mmdeploy::core::static opencv_core)
|
||||
|
||||
build_static_target(${MMSEG_STATIC} ${MMSEG_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmseg::static ALIAS ${MMSEG_STATIC})
|
||||
|
||||
build_shared_target(${MMSEG_SHARED} ${MMSEG_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::mmseg ALIAS ${MMSEG_SHARED})
|
||||
|
||||
export_module(${MMSEG_STATIC} ${MMSEG_SHARED} ${MMSEG_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core opencv_core)
|
||||
add_library(mmdeploy::mmseg ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -16,11 +16,10 @@ set(SPDLOG_LIB)
|
|||
find_package(spdlog QUIET)
|
||||
if (spdlog_FOUND)
|
||||
message(STATUS "spdlog is found")
|
||||
set(SPDLOG_LIB spdlog::spdlog)
|
||||
set(SPDLOG_LIB $<BUILD_INTERFACE:spdlog::spdlog>)
|
||||
endif ()
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} CORE_OBJ CORE_STATIC CORE_SHARED)
|
||||
|
||||
set(SRCS
|
||||
device_impl.cpp
|
||||
|
@ -36,25 +35,18 @@ set(SRCS
|
|||
utils/device_utils.cpp
|
||||
utils/formatter.cpp
|
||||
utils/stacktrace.cpp)
|
||||
build_object_target(${CORE_OBJ} "${SRCS}")
|
||||
target_compile_definitions(${CORE_OBJ} PUBLIC -DMMDEPLOY_STATUS_USE_SOURCE_LOCATION=1)
|
||||
target_include_directories(${CORE_OBJ}
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC -DMMDEPLOY_STATUS_USE_SOURCE_LOCATION=1)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/csrc>
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/outcome>
|
||||
# TODO(lzhang): remove dependency of `json`
|
||||
# TODO: remove dependency of `json`
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/json>
|
||||
$<INSTALL_INTERFACE:include/cpp>
|
||||
)
|
||||
target_link_libraries(${CORE_OBJ} ${SPDLOG_LIB} stdc++fs)
|
||||
|
||||
build_static_target(${CORE_STATIC} ${CORE_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::core::static ALIAS ${CORE_STATIC})
|
||||
|
||||
build_shared_target(${CORE_SHARED} ${CORE_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::core ALIAS ${CORE_SHARED})
|
||||
|
||||
#install_targets("${CORE_STATIC};${CORE_SHARED}")
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${SPDLOG_LIB} stdc++fs)
|
||||
add_library(mmdeploy::core ALIAS ${PROJECT_NAME})
|
||||
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/core
|
||||
DESTINATION include/cpp
|
||||
|
@ -66,8 +58,4 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/experimental
|
|||
DESTINATION include/cpp
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
install(TARGETS ${CORE_STATIC} ${CORE_SHARED} ${CORE_OBJ}
|
||||
EXPORT MMDeployTargets
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
)
|
||||
export_target(${PROJECT_NAME})
|
||||
|
|
|
@ -3,16 +3,9 @@ cmake_minimum_required(VERSION 3.14)
|
|||
project(mmdeploy_cpu_device)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} CPU_DEVICE_OBJ CPU_DEVICE_STATIC CPU_DEVICE_SHARED)
|
||||
|
||||
file(GLOB_RECURSE SRCS "*.cpp")
|
||||
build_object_target(${CPU_DEVICE_OBJ} "${SRCS}")
|
||||
target_link_libraries(${CPU_DEVICE_OBJ} PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${CPU_DEVICE_STATIC} ${CPU_DEVICE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::device::cpu::static ALIAS ${CPU_DEVICE_STATIC})
|
||||
|
||||
build_shared_target(${CPU_DEVICE_SHARED} ${CPU_DEVICE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::device::cpu ALIAS ${CPU_DEVICE_SHARED})
|
||||
|
||||
export_module(${CPU_DEVICE_STATIC} ${CPU_DEVICE_SHARED} ${CPU_DEVICE_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC pthread PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::device::cpu ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -15,17 +15,11 @@ set_targets(${PROJECT_NAME} CUDA_DEVICE_OBJ CUDA_DEVICE_STATIC CUDA_DEVICE_SHARE
|
|||
set(SRCS
|
||||
cuda_device.cpp
|
||||
cuda_builtin_kernels.cu)
|
||||
build_object_target(${CUDA_DEVICE_OBJ} "${SRCS}")
|
||||
target_include_directories(${CUDA_DEVICE_OBJ} PUBLIC ${CUDA_INCLUDE_DIRS})
|
||||
target_link_directories(${CUDA_DEVICE_OBJ} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
|
||||
target_link_libraries(${CUDA_DEVICE_OBJ}
|
||||
PRIVATE mmdeploy::core::static
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CUDA_INCLUDE_DIRS})
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE mmdeploy::core
|
||||
PUBLIC cudart cuda)
|
||||
|
||||
build_static_target(${CUDA_DEVICE_STATIC} ${CUDA_DEVICE_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::device::cuda::static ALIAS ${CUDA_DEVICE_STATIC})
|
||||
|
||||
build_shared_target(${CUDA_DEVICE_SHARED} ${CUDA_DEVICE_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::device::cuda ALIAS ${CUDA_DEVICE_SHARED})
|
||||
|
||||
export_module(${CUDA_DEVICE_STATIC} ${CUDA_DEVICE_SHARED} ${CUDA_DEVICE_OBJ})
|
||||
add_library(mmdeploy::device::cuda ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.14)
|
|||
project(mmdeploy_graph)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} GRAPH_OBJ GRAPH_STATIC GRAPH_SHARED)
|
||||
|
||||
set(SRCS
|
||||
common.cpp
|
||||
inference.cpp
|
||||
|
@ -12,13 +10,7 @@ set(SRCS
|
|||
task.cpp
|
||||
flatten.cpp
|
||||
unflatten.cpp)
|
||||
build_object_target(${GRAPH_OBJ} "${SRCS}")
|
||||
target_link_libraries(${GRAPH_OBJ} PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${GRAPH_STATIC} ${GRAPH_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::graph::static ALIAS ${GRAPH_STATIC})
|
||||
|
||||
build_shared_target(${GRAPH_SHARED} ${GRAPH_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::graph ALIAS ${GRAPH_SHARED})
|
||||
|
||||
export_module(${GRAPH_STATIC} ${GRAPH_SHARED} ${GRAPH_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::graph ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,31 +4,25 @@ project(model)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
|
||||
set(TARGET_NAMES "directory_model")
|
||||
set(MODEL_NAMES "directory_model")
|
||||
if (${MMDEPLOY_ZIP_MODEL})
|
||||
set(TARGET_NAMES ${TARGET_NAMES} "zip_model")
|
||||
set(MODEL_NAMES ${MODEL_NAMES} "zip_model")
|
||||
endif ()
|
||||
|
||||
foreach (TARGET_NAME ${TARGET_NAMES})
|
||||
set_targets("mmdeploy_${TARGET_NAME}" MODEL_OBJ MODEL_STATIC MODEL_SHARED)
|
||||
build_object_target(${MODEL_OBJ} "${TARGET_NAME}_impl.cpp")
|
||||
target_link_libraries(${MODEL_OBJ}
|
||||
PRIVATE mmdeploy::core::static
|
||||
foreach (MODEL_NAME ${MODEL_NAMES})
|
||||
set(TARGET_MODEL_NAME mmdeploy_${MODEL_NAME})
|
||||
build_target(${TARGET_MODEL_NAME} ${MODEL_NAME}_impl.cpp)
|
||||
target_link_libraries(${TARGET_MODEL_NAME}
|
||||
PRIVATE mmdeploy::core
|
||||
PUBLIC stdc++fs)
|
||||
if (${TARGET_NAME} STREQUAL "zip_model")
|
||||
if (${MODEL_NAME} STREQUAL "zip_model")
|
||||
find_package(libzip QUIET)
|
||||
if (libzip_FOUND)
|
||||
target_link_libraries(${MODEL_OBJ} PUBLIC libzip::zip)
|
||||
target_link_libraries(${TARGET_MODEL_NAME} PUBLIC libzip::zip)
|
||||
else()
|
||||
target_link_libraries(${MODEL_OBJ} PUBLIC zip)
|
||||
target_link_libraries(${TARGET_MODEL_NAME} PUBLIC zip)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
build_static_target(${MODEL_STATIC} ${MODEL_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::${TARGET_NAME}::static ALIAS ${MODEL_STATIC})
|
||||
|
||||
build_shared_target(${MODEL_SHARED} ${MODEL_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::${TARGET_NAME} ALIAS ${MODEL_SHARED})
|
||||
|
||||
export_module(${MODEL_STATIC} ${MODEL_SHARED} ${MODEL_OBJ})
|
||||
add_library(mmdeploy::${MODEL_NAME} ALIAS ${TARGET_MODEL_NAME})
|
||||
export_module(${TARGET_MODEL_NAME})
|
||||
endforeach ()
|
||||
|
|
|
@ -24,14 +24,7 @@ if ("openvino" IN_LIST MMDEPLOY_TARGET_BACKENDS)
|
|||
add_subdirectory(openvino)
|
||||
endif ()
|
||||
|
||||
set_targets(${PROJECT_NAME} NET_MODULE_OBJ NET_MODULE_STATIC NET_MODULE_SHARED)
|
||||
build_object_target(${NET_MODULE_OBJ} net_module.cpp)
|
||||
target_link_libraries(${NET_MODULE_OBJ} PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${NET_MODULE_STATIC} ${NET_MODULE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::net_module::static ALIAS ${NET_MODULE_STATIC})
|
||||
|
||||
build_shared_target(${NET_MODULE_SHARED} ${NET_MODULE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::net_module ALIAS ${NET_MODULE_SHARED})
|
||||
|
||||
export_module(${NET_MODULE_STATIC} ${NET_MODULE_SHARED} ${NET_MODULE_OBJ})
|
||||
build_target(${PROJECT_NAME} net_module.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::net_module ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -5,23 +5,14 @@ project(mmdeploy_ncnn_net)
|
|||
if("cpu" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
|
||||
set_targets(${PROJECT_NAME} NCNN_NET_OBJ NCNN_NET_STATIC NCNN_NET_SHARED)
|
||||
|
||||
find_package(ncnn REQUIRED)
|
||||
|
||||
build_object_target(${NCNN_NET_OBJ} ncnn_net.cpp)
|
||||
target_link_libraries(${NCNN_NET_OBJ} PRIVATE mmdeploy::core::static ncnn)
|
||||
|
||||
build_static_target(${NCNN_NET_STATIC} ${NCNN_NET_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::ncnn_net::static ALIAS ${NCNN_NET_STATIC})
|
||||
|
||||
build_shared_target(${NCNN_NET_SHARED} ${NCNN_NET_OBJ} "PRIVATE")
|
||||
add_library(${PROJECT_NAME} SHARED ncnn_net.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core ncnn)
|
||||
target_link_libraries(
|
||||
${NCNN_NET_SHARED} PRIVATE -Wl,--whole-archive mmdeploy::ncnn_ops::static
|
||||
${PROJECT_NAME} PRIVATE -Wl,--whole-archive mmdeploy::ncnn_ops::static
|
||||
-Wl,--no-whole-archive)
|
||||
add_library(mmdeploy::ncnn_net ALIAS ${NCNN_NET_SHARED})
|
||||
|
||||
export_module(${NCNN_NET_STATIC} ${NCNN_NET_SHARED} ${NCNN_NET_OBJ})
|
||||
add_library(mmdeploy::ncnn_net ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
else()
|
||||
message(
|
||||
ERROR
|
||||
|
|
|
@ -4,23 +4,14 @@ project(mmdeploy_openvino_net)
|
|||
|
||||
if ("cpu" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
|
||||
set_targets(${PROJECT_NAME} OPENVINO_NET_OBJ OPENVINO_NET_STATIC OPENVINO_NET_SHARED)
|
||||
|
||||
find_package(InferenceEngine REQUIRED)
|
||||
|
||||
build_object_target(${OPENVINO_NET_OBJ} openvino_net.cpp)
|
||||
target_link_libraries(${OPENVINO_NET_OBJ} PRIVATE
|
||||
mmdeploy::core::static
|
||||
add_library(${PROJECT_NAME} SHARED openvino_net.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
mmdeploy::core
|
||||
${InferenceEngine_LIBRARIES})
|
||||
|
||||
build_static_target(${OPENVINO_NET_STATIC} ${OPENVINO_NET_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::openvino_net::static ALIAS ${OPENVINO_NET_STATIC})
|
||||
|
||||
build_shared_target(${OPENVINO_NET_SHARED} ${OPENVINO_NET_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::openvino_net ALIAS ${OPENVINO_NET_SHARED})
|
||||
|
||||
export_module(${OPENVINO_NET_STATIC} ${OPENVINO_NET_SHARED} ${OPENVINO_NET_OBJ})
|
||||
add_library(mmdeploy::openvino_net ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
else ()
|
||||
message(ERROR "'openvino_net' is NOT supported in target devices: ${MMDEPLOY_TARGET_DEVICES}")
|
||||
endif ()
|
||||
|
|
|
@ -4,27 +4,17 @@ project(mmdeploy_ort_net)
|
|||
|
||||
if ("cpu" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
|
||||
set_targets(${PROJECT_NAME} ORT_NET_OBJ ORT_NET_STATIC ORT_NET_SHARED)
|
||||
|
||||
build_object_target(${ORT_NET_OBJ} ort_net.cpp)
|
||||
target_include_directories(${ORT_NET_OBJ} PUBLIC ${ONNXRUNTIME_DIR}/include)
|
||||
target_link_directories(${ORT_NET_OBJ} PUBLIC ${ONNXRUNTIME_DIR}/lib)
|
||||
target_link_libraries(${ORT_NET_OBJ} PRIVATE mmdeploy::core::static
|
||||
add_library(${PROJECT_NAME} SHARED ort_net.cpp)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${ONNXRUNTIME_DIR}/include)
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${ONNXRUNTIME_DIR}/lib)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core
|
||||
PUBLIC onnxruntime)
|
||||
|
||||
build_static_target(${ORT_NET_STATIC} ${ORT_NET_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::ort_net::static ALIAS ${ORT_NET_STATIC})
|
||||
|
||||
build_shared_target(${ORT_NET_SHARED} ${ORT_NET_OBJ} "PUBLIC")
|
||||
target_link_libraries(${ORT_NET_SHARED} PRIVATE
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
-Wl,--whole-archive
|
||||
mmdeploy::onnxruntime::ops::static
|
||||
-Wl,--no-whole-archive)
|
||||
add_library(mmdeploy::ort_net ALIAS ${ORT_NET_SHARED})
|
||||
|
||||
export_module(${ORT_NET_STATIC} ${ORT_NET_SHARED} ${ORT_NET_OBJ})
|
||||
export_module(mmdeploy_onnxruntime_ops_static "" mmdeploy_onnxruntime_ops_obj)
|
||||
add_library(mmdeploy::ort_net ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
else ()
|
||||
message(ERROR "'ort_net' is NOT supported in target devices: ${MMDEPLOY_TARGET_DEVICES}")
|
||||
endif ()
|
||||
|
|
|
@ -5,35 +5,19 @@ project(mmdeploy_pplnn_net)
|
|||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
find_package(pplnn REQUIRED)
|
||||
|
||||
set_targets(${PROJECT_NAME} PPL_NET_OBJ PPL_NET_STATIC PPL_NET_SHARED)
|
||||
|
||||
|
||||
build_object_target(${PPL_NET_OBJ} ppl_net.cpp)
|
||||
target_include_directories(${PPL_NET_OBJ} PUBLIC
|
||||
add_library(${PROJECT_NAME} SHARED ppl_net.cpp)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${PPLNN_INCLUDE_DIRS}>)
|
||||
|
||||
target_link_libraries(${PPL_NET_OBJ} PRIVATE
|
||||
mmdeploy::core::static
|
||||
${PPLNN_LIBRARIES}
|
||||
)
|
||||
|
||||
if ("cpu" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
target_compile_definitions(${PPL_NET_OBJ} PRIVATE -DPPL_NN_HAS_X86=1)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DPPL_NN_HAS_X86=1)
|
||||
endif ()
|
||||
|
||||
if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
||||
target_compile_definitions(${PPL_NET_OBJ} PRIVATE -DPPL_NN_HAS_CUDA=1)
|
||||
target_include_directories(${PPL_NET_OBJ} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/include)
|
||||
target_link_directories(${PPL_NET_OBJ} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
|
||||
target_link_libraries(${PPL_NET_OBJ}
|
||||
PUBLIC nvrtc)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE -DPPL_NN_HAS_CUDA=1)
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/include)
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
|
||||
endif ()
|
||||
|
||||
build_static_target(${PPL_NET_STATIC} ${PPL_NET_OBJ} "PUBLIC")
|
||||
|
||||
add_library(mmdeploy::pplnn_net::static ALIAS ${PPL_NET_STATIC})
|
||||
|
||||
build_shared_target(${PPL_NET_SHARED} ${PPL_NET_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::pplnn_net ALIAS ${PPL_NET_SHARED})
|
||||
|
||||
export_module(${PPL_NET_STATIC} ${PPL_NET_SHARED} ${PPL_NET_OBJ})
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE mmdeploy::core ${PPLNN_LIBRARIES}
|
||||
PUBLIC nvrtc)
|
||||
add_library(mmdeploy::pplnn_net ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -5,30 +5,21 @@ project(mmdeploy_trt_net)
|
|||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/tensorrt.cmake)
|
||||
|
||||
set_targets("mmdeploy_trt_net" TRT_NET_OBJ TRT_NET_STATIC TRT_NET_SHARED)
|
||||
|
||||
build_object_target(${TRT_NET_OBJ} trt_net.cpp)
|
||||
target_include_directories(${TRT_NET_OBJ} PRIVATE
|
||||
add_library(${PROJECT_NAME} SHARED trt_net.cpp)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${TENSORRT_INCLUDE_DIR})
|
||||
target_include_directories(${TRT_NET_OBJ} PRIVATE ${CUDNN_DIR}/include)
|
||||
target_include_directories(${TRT_NET_OBJ} PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/include)
|
||||
target_link_directories(${TRT_NET_OBJ} PUBLIC ${CUDNN_DIR}/lib64)
|
||||
target_link_libraries(${TRT_NET_OBJ} PUBLIC ${TENSORRT_LIBRARY} cudnn)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDNN_DIR}/include)
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/include)
|
||||
target_link_directories(${PROJECT_NAME} PUBLIC ${CUDNN_DIR}/lib64)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBRARY} cudnn)
|
||||
|
||||
target_link_libraries(${TRT_NET_OBJ}
|
||||
PRIVATE mmdeploy::core::static
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE mmdeploy::core
|
||||
)
|
||||
|
||||
build_static_target(${TRT_NET_STATIC} ${TRT_NET_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::trt_net::static ALIAS ${TRT_NET_STATIC})
|
||||
|
||||
build_shared_target(${TRT_NET_SHARED} ${TRT_NET_OBJ} "PUBLIC")
|
||||
target_link_libraries(${TRT_NET_SHARED}
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE -Wl,--whole-archive
|
||||
mmdeploy::tensorrt_ops::static
|
||||
-Wl,--no-whole-archive
|
||||
)
|
||||
add_library(mmdeploy::trt_net ALIAS ${TRT_NET_SHARED})
|
||||
|
||||
export_module(${TRT_NET_STATIC} ${TRT_NET_SHARED} ${TRT_NET_OBJ})
|
||||
export_module(mmdeploy_tensorrt_ops_static "" mmdeploy_tensorrt_ops_obj)
|
||||
add_library(mmdeploy::trt_net ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -9,16 +9,7 @@ if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
|
|||
endif ()
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} TRANSFORM_MODULE_OBJ TRANSFORM_MODULE_STATIC TRANSFORM_MODULE_SHARED)
|
||||
|
||||
build_object_target(${TRANSFORM_MODULE_OBJ} transform_module.cpp)
|
||||
target_link_libraries(${TRANSFORM_MODULE_OBJ}
|
||||
PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${TRANSFORM_MODULE_STATIC} ${TRANSFORM_MODULE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::transform_module::static ALIAS ${TRANSFORM_MODULE_STATIC})
|
||||
|
||||
build_shared_target(${TRANSFORM_MODULE_SHARED} ${TRANSFORM_MODULE_OBJ} "PRIVATE")
|
||||
add_library(mmdeploy::transform_module ALIAS ${TRANSFORM_MODULE_SHARED})
|
||||
|
||||
export_module(${TRANSFORM_MODULE_STATIC} ${TRANSFORM_MODULE_SHARED} ${TRANSFORM_MODULE_OBJ})
|
||||
build_target(${PROJECT_NAME} transform_module.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::transform_module ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -4,7 +4,6 @@ project(mmdeploy_cpu_transform_impl)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} CPU_TRANSFORM_OBJ CPU_TRANSFORM_STATIC CPU_TRANSFORM_SHARED)
|
||||
|
||||
set(SRCS
|
||||
collect_impl.cpp
|
||||
|
@ -16,15 +15,9 @@ set(SRCS
|
|||
opencv_utils.h
|
||||
pad_impl.cpp
|
||||
resize_impl.cpp)
|
||||
build_object_target(${CPU_TRANSFORM_OBJ} "${SRCS}")
|
||||
target_link_libraries(${CPU_TRANSFORM_OBJ} PUBLIC opencv_imgproc opencv_core)
|
||||
target_link_libraries(${CPU_TRANSFORM_OBJ}
|
||||
PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${CPU_TRANSFORM_STATIC} ${CPU_TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform_impl::cpu::static ALIAS ${CPU_TRANSFORM_STATIC})
|
||||
|
||||
build_shared_target(${CPU_TRANSFORM_SHARED} ${CPU_TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform_impl::cpu ALIAS ${CPU_TRANSFORM_SHARED})
|
||||
|
||||
export_module(${CPU_TRANSFORM_STATIC} ${CPU_TRANSFORM_SHARED} ${CPU_TRANSFORM_OBJ})
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PUBLIC opencv_imgproc opencv_core
|
||||
PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::transform_impl::cpu ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -10,8 +10,6 @@ endif()
|
|||
find_package(pplcv REQUIRED)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
# include(${CMAKE_SOURCE_DIR}/cmake/cuda.cmake NO_POLICY_SCOPE)
|
||||
set_targets(${PROJECT_NAME} TRANSFORM_OBJ TRANSFORM_STATIC TRANSFORM_SHARED)
|
||||
|
||||
set(SRCS
|
||||
crop_impl.cpp
|
||||
|
@ -24,18 +22,9 @@ set(SRCS
|
|||
crop.cu
|
||||
normalize.cu
|
||||
transpose.cu)
|
||||
build_object_target(${TRANSFORM_OBJ} "${SRCS}")
|
||||
|
||||
target_include_directories(${TRANSFORM_OBJ}
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC ${CUDA_TOOLKIT_ROOT_DIR}/include)
|
||||
target_link_libraries(
|
||||
${TRANSFORM_OBJ} PRIVATE ${PPLCV_LIBRARIES} mmdeploy::transform::static
|
||||
mmdeploy::core::static)
|
||||
|
||||
build_static_target(${TRANSFORM_STATIC} ${TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform_impl::cuda::static ALIAS ${TRANSFORM_STATIC})
|
||||
|
||||
build_shared_target(${TRANSFORM_SHARED} ${TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform_impl::cuda ALIAS ${TRANSFORM_SHARED})
|
||||
|
||||
export_module(${TRANSFORM_STATIC} ${TRANSFORM_SHARED} ${TRANSFORM_OBJ})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${PPLCV_LIBRARIES} mmdeploy::core)
|
||||
add_library(mmdeploy::transform_impl::cuda ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -3,28 +3,20 @@ cmake_minimum_required(VERSION 3.14)
|
|||
project(mmdeploy_transform)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
|
||||
set_targets(${PROJECT_NAME} TRANSFORM_OBJ TRANSFORM_STATIC TRANSFORM_SHARED)
|
||||
|
||||
set(SRCS
|
||||
collect.cpp
|
||||
compose.cpp
|
||||
crop.cpp
|
||||
image2tensor.cpp
|
||||
load.cpp
|
||||
normalize.cpp
|
||||
pad.cpp
|
||||
resize.cpp
|
||||
transform.cpp)
|
||||
|
||||
build_object_target(${TRANSFORM_OBJ} "${SRCS}")
|
||||
target_include_directories(${TRANSFORM_OBJ} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/preprocess>)
|
||||
target_link_libraries(${TRANSFORM_OBJ} PRIVATE mmdeploy::core::static)
|
||||
|
||||
build_static_target(${TRANSFORM_STATIC} ${TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform::static ALIAS ${TRANSFORM_STATIC})
|
||||
|
||||
build_shared_target(${TRANSFORM_SHARED} ${TRANSFORM_OBJ} "PUBLIC")
|
||||
add_library(mmdeploy::transform ALIAS ${TRANSFORM_SHARED})
|
||||
|
||||
export_module(${TRANSFORM_STATIC} ${TRANSFORM_SHARED} ${TRANSFORM_OBJ})
|
||||
collect.cpp
|
||||
compose.cpp
|
||||
crop.cpp
|
||||
image2tensor.cpp
|
||||
load.cpp
|
||||
normalize.cpp
|
||||
pad.cpp
|
||||
resize.cpp
|
||||
transform.cpp)
|
||||
build_target(${PROJECT_NAME} "${SRCS}")
|
||||
target_include_directories(
|
||||
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/preprocess>)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy::core)
|
||||
add_library(mmdeploy::transform ALIAS ${PROJECT_NAME})
|
||||
export_module(${PROJECT_NAME})
|
||||
|
|
|
@ -5,17 +5,14 @@ project(mmdeploy-example)
|
|||
find_package(OpenCV REQUIRED)
|
||||
find_package(MMDeploy REQUIRED)
|
||||
|
||||
function(add_example name libs)
|
||||
|
||||
add_executable(${name} ${name}.cpp)
|
||||
|
||||
target_link_libraries(${name}
|
||||
${libs}
|
||||
-Wl,--no-as-needed
|
||||
${MMDeploy_DYNAMIC_MODULES}
|
||||
-Wl,--as-needed
|
||||
opencv_imgcodecs opencv_imgproc opencv_core)
|
||||
function(add_example name)
|
||||
add_executable(${name} ${name}.cpp)
|
||||
target_link_libraries(${name} ${MMDeploy_LIBS} opencv_imgcodecs
|
||||
opencv_imgproc opencv_core)
|
||||
endfunction()
|
||||
|
||||
add_example(image_classification "mmdeploy_classifier")
|
||||
add_example(object_detection "mmdeploy_detector")
|
||||
add_example(image_classification)
|
||||
add_example(object_detection)
|
||||
add_example(image_restorer)
|
||||
add_example(image_segmentation)
|
||||
add_example(ocr)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"version": "0.1.0",
|
||||
"models": [
|
||||
{
|
||||
"name": "resnet",
|
||||
"net": "end2end.onnx",
|
||||
"weights": "",
|
||||
"backend": "onnxruntime",
|
||||
"precision": "FP32",
|
||||
"batch_size": 1,
|
||||
"dynamic_shape": true
|
||||
}
|
||||
],
|
||||
"customs": []
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
{
|
||||
"pipeline": {
|
||||
"input": [
|
||||
"img"
|
||||
],
|
||||
"output": [
|
||||
"cls"
|
||||
],
|
||||
"tasks": [
|
||||
{
|
||||
"name": "preprocess",
|
||||
"type": "Task",
|
||||
"module": "Transform",
|
||||
"input": [
|
||||
"img"
|
||||
],
|
||||
"output": [
|
||||
"data"
|
||||
],
|
||||
"transforms": [
|
||||
{
|
||||
"type": "LoadImageFromFile"
|
||||
},
|
||||
{
|
||||
"type": "Resize",
|
||||
"size": [
|
||||
256,
|
||||
-1
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CenterCrop",
|
||||
"crop_size": 224
|
||||
},
|
||||
{
|
||||
"type": "Normalize",
|
||||
"mean": [
|
||||
123.675,
|
||||
116.28,
|
||||
103.53
|
||||
],
|
||||
"std": [
|
||||
58.395,
|
||||
57.12,
|
||||
57.375
|
||||
],
|
||||
"to_rgb": true
|
||||
},
|
||||
{
|
||||
"type": "ImageToTensor",
|
||||
"keys": [
|
||||
"img"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Collect",
|
||||
"keys": [
|
||||
"img"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "resnet",
|
||||
"type": "Task",
|
||||
"module": "Net",
|
||||
"input": [
|
||||
"data"
|
||||
],
|
||||
"output": [
|
||||
"cls_res"
|
||||
],
|
||||
"input_map": {
|
||||
"img": "input"
|
||||
},
|
||||
"output_map": {
|
||||
"cls": "output"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "postprocess",
|
||||
"type": "Task",
|
||||
"module": "mmcls",
|
||||
"component": "LinearClsHead",
|
||||
"input": [
|
||||
"data",
|
||||
"cls_res"
|
||||
],
|
||||
"output": [
|
||||
"cls"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"version": "0.1.0",
|
||||
"models": [
|
||||
{
|
||||
"name": "retinanet",
|
||||
"net": "end2end.onnx",
|
||||
"weights": "",
|
||||
"backend": "onnxruntime",
|
||||
"precision": "FP32",
|
||||
"batch_size": 1,
|
||||
"dynamic_shape": true
|
||||
}
|
||||
],
|
||||
"customs": []
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
{
|
||||
"pipeline": {
|
||||
"input": [
|
||||
"img"
|
||||
],
|
||||
"output": [
|
||||
"bboxes"
|
||||
],
|
||||
"tasks": [
|
||||
{
|
||||
"name": "preprocess",
|
||||
"type": "Task",
|
||||
"module": "Transform",
|
||||
"input": [
|
||||
"img"
|
||||
],
|
||||
"output": [
|
||||
"prep_res"
|
||||
],
|
||||
"transforms": [
|
||||
{
|
||||
"type": "LoadImageFromFile"
|
||||
},
|
||||
{
|
||||
"type": "Resize",
|
||||
"size": [
|
||||
800,
|
||||
1333
|
||||
],
|
||||
"keep_ratio": true
|
||||
},
|
||||
{
|
||||
"type": "Normalize",
|
||||
"mean": [
|
||||
123.675,
|
||||
116.28,
|
||||
103.53
|
||||
],
|
||||
"std": [
|
||||
58.395,
|
||||
57.12,
|
||||
57.375
|
||||
],
|
||||
"to_rgb": true
|
||||
},
|
||||
{
|
||||
"type": "Pad",
|
||||
"size_divisor": 32
|
||||
},
|
||||
{
|
||||
"type": "ImageToTensor",
|
||||
"keys": [
|
||||
"img"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Collect",
|
||||
"keys": [
|
||||
"img"
|
||||
],
|
||||
"meta_keys": [
|
||||
"ori_shape",
|
||||
"img_shape",
|
||||
"scale_factor"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "retinanet",
|
||||
"type": "Task",
|
||||
"module": "Net",
|
||||
"input": [
|
||||
"prep_res"
|
||||
],
|
||||
"output": [
|
||||
"infer_res"
|
||||
],
|
||||
"input_map": {
|
||||
"img": "input"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "postprocess",
|
||||
"type": "Task",
|
||||
"module": "mmdet",
|
||||
"component": "ResizeBBox",
|
||||
"input": [
|
||||
"prep_res",
|
||||
"infer_res"
|
||||
],
|
||||
"output": [
|
||||
"bboxes"
|
||||
],
|
||||
"params": {
|
||||
"score_thr": 0.3,
|
||||
"min_bbox_size": 10
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,16 +1,18 @@
|
|||
#include "classifier.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "classifier.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage:\n image_classification model_path image_path\n");
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "usage:\n image_classification device_name model_path image_path\n");
|
||||
return 1;
|
||||
}
|
||||
auto model_path = argv[1];
|
||||
auto image_path = argv[2];
|
||||
cv::Mat img = cv::imread(argv[2]);
|
||||
auto device_name = argv[1];
|
||||
auto model_path = argv[2];
|
||||
auto image_path = argv[3];
|
||||
cv::Mat img = cv::imread(image_path);
|
||||
if (!img.data) {
|
||||
fprintf(stderr, "failed to load image: %s\n", image_path);
|
||||
return 1;
|
||||
|
@ -18,9 +20,9 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mm_handle_t classifier{};
|
||||
int status{};
|
||||
status = mmdeploy_classifier_create_by_path(model_path, "cpu", 0, &classifier);
|
||||
status = mmdeploy_classifier_create_by_path(model_path, device_name, 0, &classifier);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create classifier, code: %d\n", (int) status);
|
||||
fprintf(stderr, "failed to create classifier, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -30,7 +32,7 @@ int main(int argc, char *argv[]) {
|
|||
int *res_count{};
|
||||
status = mmdeploy_classifier_apply(classifier, &mat, 1, &res, &res_count);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply classifier, code: %d\n", (int) status);
|
||||
fprintf(stderr, "failed to apply classifier, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) OpenMMLab. All rights reserved.
|
||||
|
||||
#include <fstream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "restorer.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "usage:\n image_restorer device_name model_path image_path\n");
|
||||
return 1;
|
||||
}
|
||||
auto device_name = argv[1];
|
||||
auto model_path = argv[2];
|
||||
auto image_path = argv[3];
|
||||
cv::Mat img = cv::imread(image_path);
|
||||
if (!img.data) {
|
||||
fprintf(stderr, "failed to load image: %s\n", image_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_handle_t restorer{};
|
||||
int status{};
|
||||
status = mmdeploy_restorer_create_by_path(model_path, device_name, 0, &restorer);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create restorer, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_mat_t mat{img.data, img.rows, img.cols, 3, MM_BGR, MM_INT8};
|
||||
|
||||
mm_mat_t *result{};
|
||||
status = mmdeploy_restorer_apply(restorer, &mat, 1, &result);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply restorer, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cv::Mat sr_img(result->height, result->width, CV_8UC3, result->data);
|
||||
cv::cvtColor(sr_img, sr_img, cv::COLOR_RGB2BGR);
|
||||
cv::imwrite("output_restorer.bmp", sr_img);
|
||||
|
||||
mmdeploy_restorer_release_result(result, 1);
|
||||
mmdeploy_restorer_destroy(restorer);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright (c) OpenMMLab. All rights reserved.
|
||||
|
||||
#include <fstream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "segmentor.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<cv::Vec3b> gen_palette(int num_classes) {
|
||||
std::mt19937 gen;
|
||||
std::uniform_int_distribution<uchar> uniform_dist(0, 255);
|
||||
|
||||
vector<cv::Vec3b> palette;
|
||||
palette.reserve(num_classes);
|
||||
for (auto i = 0; i < num_classes; ++i) {
|
||||
palette.emplace_back(uniform_dist(gen), uniform_dist(gen), uniform_dist(gen));
|
||||
}
|
||||
return palette;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "usage:\n image_segmentation device_name model_path image_path\n");
|
||||
return 1;
|
||||
}
|
||||
auto device_name = argv[1];
|
||||
auto model_path = argv[2];
|
||||
auto image_path = argv[3];
|
||||
cv::Mat img = cv::imread(image_path);
|
||||
if (!img.data) {
|
||||
fprintf(stderr, "failed to load image: %s\n", image_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_handle_t segmentor{};
|
||||
int status{};
|
||||
status = mmdeploy_segmentor_create_by_path(model_path, device_name, 0, &segmentor);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create segmentor, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_mat_t mat{img.data, img.rows, img.cols, 3, MM_BGR, MM_INT8};
|
||||
|
||||
mm_segment_t *result{};
|
||||
status = mmdeploy_segmentor_apply(segmentor, &mat, 1, &result);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply segmentor, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto palette = gen_palette(result->classes + 1);
|
||||
|
||||
cv::Mat color_mask = cv::Mat::zeros(result->height, result->width, CV_8UC3);
|
||||
int pos = 0;
|
||||
for (auto iter = color_mask.begin<cv::Vec3b>(); iter != color_mask.end<cv::Vec3b>(); ++iter) {
|
||||
*iter = palette[result->mask[pos++]];
|
||||
}
|
||||
|
||||
img = img * 0.5 + color_mask * 0.5;
|
||||
cv::imwrite("output_segmentation.png", img);
|
||||
|
||||
mmdeploy_segmentor_release_result(result, 1);
|
||||
mmdeploy_segmentor_destroy(segmentor);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,17 +1,19 @@
|
|||
#include "detector.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "detector.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage:\n object_detection model_path image_path\n");
|
||||
if (argc != 4) {
|
||||
fprintf(stderr, "usage:\n object_detection device_name model_path image_path\n");
|
||||
return 1;
|
||||
}
|
||||
auto model_path = argv[1];
|
||||
auto image_path = argv[2];
|
||||
cv::Mat img = cv::imread(argv[2]);
|
||||
auto device_name = argv[1];
|
||||
auto model_path = argv[2];
|
||||
auto image_path = argv[3];
|
||||
cv::Mat img = cv::imread(image_path);
|
||||
if (!img.data) {
|
||||
fprintf(stderr, "failed to load image: %s\n", image_path);
|
||||
return 1;
|
||||
|
@ -19,9 +21,9 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mm_handle_t detector{};
|
||||
int status{};
|
||||
status = mmdeploy_detector_create_by_path(model_path, "cpu", 0, &detector);
|
||||
status = mmdeploy_detector_create_by_path(model_path, device_name, 0, &detector);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create detector, code: %d\n", (int) status);
|
||||
fprintf(stderr, "failed to create detector, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -31,7 +33,7 @@ int main(int argc, char *argv[]) {
|
|||
int *res_count{};
|
||||
status = mmdeploy_detector_apply(detector, &mat, 1, &bboxes, &res_count);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply detector, code: %d\n", (int) status);
|
||||
fprintf(stderr, "failed to apply detector, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -39,12 +41,13 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
for (int i = 0; i < *res_count; ++i) {
|
||||
const auto &box = bboxes[i].bbox;
|
||||
fprintf(stderr, "box %d, left=%d, top=%d, right=%d, bottom=%d, label=%d, score=%.4f\n",
|
||||
fprintf(stderr, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n",
|
||||
i, box.left, box.top, box.right, box.bottom, bboxes[i].label_id, bboxes[i].score);
|
||||
cv::rectangle(img, cv::Point{box.left, box.top}, cv::Point{box.right, box.bottom}, cv::Scalar{0, 255, 0});
|
||||
cv::rectangle(img, cv::Point{(int)box.left, (int)box.top},
|
||||
cv::Point{(int)box.right, (int)box.bottom}, cv::Scalar{0, 255, 0});
|
||||
}
|
||||
|
||||
cv::imwrite("out.png", img);
|
||||
cv::imwrite("output_detection.png", img);
|
||||
|
||||
mmdeploy_detector_release_result(bboxes, res_count, 1);
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
#include <fstream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "text_detector.h"
|
||||
#include "text_recognizer.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 5) {
|
||||
fprintf(stderr, "usage:\n ocr device_name det_model_path reg_model_path image_path\n");
|
||||
return 1;
|
||||
}
|
||||
auto device_name = argv[1];
|
||||
auto det_model_path = argv[2];
|
||||
auto reg_model_path = argv[3];
|
||||
auto image_path = argv[4];
|
||||
cv::Mat img = cv::imread(image_path);
|
||||
if (!img.data) {
|
||||
fprintf(stderr, "failed to load image: %s\n", image_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_handle_t text_detector{};
|
||||
int status{};
|
||||
status = mmdeploy_text_detector_create_by_path(det_model_path, device_name, 0, &text_detector);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create text_detector, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_handle_t text_recognizer{};
|
||||
status = mmdeploy_text_recognizer_create_by_path(reg_model_path, "cpu", 0, &text_recognizer);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to create text_recognizer, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mm_mat_t mat{img.data, img.rows, img.cols, 3, MM_BGR, MM_INT8};
|
||||
|
||||
mm_text_detect_t *bboxes{};
|
||||
int *bbox_count{};
|
||||
status = mmdeploy_text_detector_apply(text_detector, &mat, 1, &bboxes, &bbox_count);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply text_detector, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
fprintf(stdout, "bbox_count=%d\n", *bbox_count);
|
||||
|
||||
mm_text_recognize_t *texts{};
|
||||
status =
|
||||
mmdeploy_text_recognizer_apply_bbox(text_recognizer, &mat, 1, bboxes, bbox_count, &texts);
|
||||
if (status != MM_SUCCESS) {
|
||||
fprintf(stderr, "failed to apply text_recognizer, code: %d\n", (int)status);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < *bbox_count; ++i) {
|
||||
fprintf(stdout, "box[%d]: %s\n", i, texts[i].text);
|
||||
std::vector<cv::Point> poly_points;
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
auto const &pt = bboxes[i].bbox[j];
|
||||
fprintf(stdout, "x: %.2f, y: %.2f, ", pt.x, pt.y);
|
||||
poly_points.push_back({(int)pt.x, (int)pt.y});
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
cv::polylines(img, poly_points, true, cv::Scalar{0, 255, 0});
|
||||
}
|
||||
|
||||
cv::imwrite("output_ocr.png", img);
|
||||
|
||||
mmdeploy_text_recognizer_release_result(texts, *bbox_count);
|
||||
mmdeploy_text_recognizer_destroy(text_recognizer);
|
||||
|
||||
mmdeploy_text_detector_release_result(bboxes, bbox_count, 1);
|
||||
mmdeploy_text_detector_destroy(text_detector);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -4,36 +4,21 @@ project(tests)
|
|||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
|
||||
|
||||
# find TC source files and related shared libraries and modules that are going
|
||||
# to be linked
|
||||
set(MMDEPLOY_LIBS)
|
||||
set(MMDEPLOY_MODULES mmdeploy::directory_model mmdeploy::transform_module
|
||||
mmdeploy::transform mmdeploy::net_module mmdeploy::graph)
|
||||
|
||||
set(TC_SRCS test_main.cpp)
|
||||
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/archive ARCHIVE_TC)
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/core CORE_TC)
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/preprocess TRANSFORM_TC)
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/net NET_TC)
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/model MODEL_TC)
|
||||
|
||||
set(DEVICE_TC)
|
||||
foreach(DEVICE IN LISTS MMDEPLOY_TARGET_DEVICES)
|
||||
list(APPEND DEVICE_TC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/device/test_${DEVICE}_device.cpp)
|
||||
list(APPEND MMDEPLOY_MODULES mmdeploy::device::${DEVICE}
|
||||
mmdeploy::transform_impl::${DEVICE})
|
||||
endforeach()
|
||||
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/net NET_TC)
|
||||
foreach(BACKEND IN LISTS MMDEPLOY_TARGET_BACKENDS)
|
||||
list(APPEND MMDEPLOY_MODULES mmdeploy::${BACKEND}_net)
|
||||
endforeach()
|
||||
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/model MODEL_TC)
|
||||
if(MMDEPLOY_ZIP_MODEL)
|
||||
message(STATUS "MMDEPLOY_ZIP_MODEL: ${MMDEPLOY_ZIP_MODEL}")
|
||||
list(APPEND MMDEPLOY_MODULES mmdeploy::zip_model)
|
||||
endif()
|
||||
|
||||
set(CAPI_TC)
|
||||
if("all" IN_LIST MMDEPLOY_CODEBASES)
|
||||
set(TASK_LIST
|
||||
|
@ -62,7 +47,6 @@ else()
|
|||
endif()
|
||||
foreach(TASK ${TASK_LIST})
|
||||
list(APPEND CAPI_TC ${CMAKE_CURRENT_SOURCE_DIR}/capi/test_${TASK}.cpp)
|
||||
list(APPEND MMDEPLOY_LIBS mmdeploy_${TASK})
|
||||
endforeach()
|
||||
|
||||
# generate the header file
|
||||
|
@ -73,20 +57,17 @@ set(TC_SRCS
|
|||
${TC_SRCS}
|
||||
${ARCHIVE_TC}
|
||||
${CORE_TC}
|
||||
${DEVICE_TC}
|
||||
${CAPI_TC}
|
||||
${TRANSFORM_TC}
|
||||
${MODEL_TC}
|
||||
${NET_TC})
|
||||
list(APPEND MMDEPLOY_LIBS mmdeploy::core)
|
||||
foreach(CODEBASE IN LISTS CODEBASES)
|
||||
list(APPEND MMDEPLOY_MODULES mmdeploy::${CODEBASE})
|
||||
endforeach()
|
||||
${NET_TC}
|
||||
${DEVICE_TC}
|
||||
${CAPI_TC})
|
||||
|
||||
add_executable(mmdeploy_tests ${TC_SRCS})
|
||||
target_include_directories(mmdeploy_tests
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/third_party/catch2)
|
||||
target_include_directories(mmdeploy_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(
|
||||
mmdeploy_tests PRIVATE ${MMDEPLOY_LIBS} ${OpenCV_LIBS} -Wl,--no-as-needed
|
||||
${MMDEPLOY_MODULES} -Wl,--as-need)
|
||||
mmdeploy_tests PRIVATE ${MMDEPLOY_LIBS} ${OpenCV_LIBS}
|
||||
-Wl,--no-as-needed ${MMDEPLOY_DYNAMIC_MODULES} -Wl,--as-need
|
||||
-Wl,--whole-archive ${MMDEPLOY_STATIC_MODULES} -Wl,--no-whole-archive)
|
||||
|
|
Loading…
Reference in New Issue