Compare commits

...

70 Commits

Author SHA1 Message Date
RunningLeon 5a9ac8765d
Fix readthedocs ()
* [Fix]: limit urllib3 for readthedocs ()

* fix readthedocs for zh_cn

* fix
2023-05-31 15:18:47 +08:00
AllentDan 6cd77c66b7
add deform conv v3 plugin ()
* add deform conv v3 plugin

* update doc

* resolve comments

* update description
2023-05-23 10:22:47 +08:00
RunningLeon 335ef8648d
fix mmseg exportation for out_channels=1 () 2023-05-04 12:51:05 +08:00
RunningLeon c73756366e
bump version to v0.14.0 ()
* update

* bump version

* Update README.md

* fix conflicts

* fix ci

* fix circleci

* upgrade to ubuntu20.04 for github ci

* update

* install glibc

* try to fix cuda build

* try to fix cuda build

* fix build-cu102 && build_cpu_sdk

* revert to setup-python@v2

* try to fix pplnn

* fix protobuf

---------

Co-authored-by: Xin Chen <irexyc@gmail.com>
2023-04-05 14:28:00 +08:00
Chen Xin af16b9a451
Update get_started.md(master) ()
* update generate_build_config to support cxx11abi tag

* test prebuild ci

* update docs/zh_cn/get_started.md

* update docs/en/get_started.md

* fix prebuild ci

* update prebuilt_package_windows.md

* update prebuild ci deps

* try to fix prebuild ci

* fix prebuild ci

* fix prebuild ci

* remove trigger [no ci]

* fix name [no ci]

* fix typos

* fix script
2023-04-04 11:00:53 +08:00
tpoisonooo 1411ed3858
[improvement]: openvino upgrade to 2022.3.0 () 2023-03-31 14:08:07 +08:00
Chen Xin bbee83da6c
update pplnn to v0.9.2 to resolve ci error ()
* [Fix] Fix package_tools ()

* copy mmdeploy_onnx2ncnn when build wheel package

* prevent copy build/lib/* when build wheel

* fix mmdeploy_builder.py

* try to fix backend-pplnn ci
2023-03-29 21:14:59 +08:00
Junhwa Song f7c484a046
Add support for converting a inpainting model to ONNX and TensorRT ()
* Add support for inpainting models

* Add configs

* Add comment

* Refactor

* Add test code for inpainting task

* Fix

* Fix

* Update

* Fix

* Fix

* Update docs

* Update

* Fix visualization

* Handle case without Resize
2023-03-29 19:17:24 +08:00
Chen Xin aae9f32623
[Refactor] Rename mmdeploy_python to mmdeploy_runtime ()
* [Feature]: Add github prebuild workflow after new release. ()

* add prebuild dockerfile

* add prebuild test workflw

* update

* update

* rm other workflow for test

* Update docker image

* add win1o prebuild

* add test prebuild

* add windows scripts in prebuilt package

* add linux scripts in prebuilt package

* generate_build_config.py

* fix cudnn search

* fix env

* fix script

* fix rpath

* fix cwd

* fix windows

* fix lint

* windows prebuild ci

* linux prebuild ci

* fix

* update trigger

* Revert "rm other workflow for test"

This reverts commit 0a03872750.

* update sdk build readme

* update prebuild

* fix dll deps for python >= 3.8 on windows

* fix ci

* test prebuild

* update test script to avoid modify upload folder

* add onnxruntime.dll to mmdeploy_python

* update prebuild workflow

* update prebuild

* Update loader.cpp.in

* remove exists prebuild files

* fix opencv env

* update cmake options for mmdeploy python build

* remove test code

* fix lint

---------

Co-authored-by: RunningLeon <mnsheng@yeah.net>
Co-authored-by: RunningLeon <maningsheng@sensetime.com>

* rename mmdeploy_python -> mmdeploy_runtime

* test master prebuild

* fix trt net build

* Revert "test master prebuild"

This reverts commit aad5258648.

* add master branch

* fix linux set_env script

* update package_tools docs

* fix gcc 7.3 aligned_alloc

* comment temporarily as text_det_recog can't be built with prebuild package built under manylinux

---------

Co-authored-by: RunningLeon <mnsheng@yeah.net>
Co-authored-by: RunningLeon <maningsheng@sensetime.com>
2023-03-29 19:02:37 +08:00
Chen Xin c7003bb76a
[Fix] Fix CascadeRoIHead export when reg_class_agnostic=True in box_head ()
* fix convnext

* fix batch inference

* update docs

* add regression test config

* fix pose_tracker.cpp lint
2023-03-28 20:59:26 +08:00
Damon Da Tong d181311dee
fix pose_tracker python api will raise ValueError when result has no human () 2023-03-27 14:50:53 +08:00
RunningLeon 39c3282966
[Fix]: update stale workflow ()
* fix

* add job permission

* update
2023-03-23 14:59:56 +08:00
kumailf dba46c3496
fix typo in docs/en/07-developer-guide/regression_test.md () 2023-03-23 13:33:53 +08:00
Li Zhang 140e0519e6
[Fix] Export `mmdeploy` only in monolithic build ()
* export only `mmdeploy` in monolithic build

* export dynamic backends
2023-03-21 11:21:19 +08:00
Chen Xin 06dac732c9
optimize mmpose postprocess () 2023-03-21 11:06:18 +08:00
hanrui1sensetime 34c68663b6
[Sync] Sync Java API to master ()
* sync rotated detector java api to master

* sync mmseg score output to master

* sync java docs for demo

* sync java docs for master
2023-03-13 11:31:39 +08:00
tpoisonooo 48291f01c8
docs(project): highlight version () 2023-03-13 10:23:52 +08:00
Li Zhang 12a130262f
add unified device guard () 2023-03-10 19:16:13 +08:00
Li Zhang bcb93ead58
[Enhancement] Add optional `softmax` in `LinearClsHead` ()
* add softmax in cls postprocess

* minor
2023-03-09 16:54:15 +08:00
Shengxi Li f69c636a2e
mmocr FPNC neck support asf module ()
* mmocr FPNC neck support asf module

* mmocr FPNC neck support asf module

---------

Co-authored-by: lishengxi <mtdp@MacBook-Pro-8.local>
2023-03-03 15:27:02 +08:00
Li Zhang cb964f6a58
[Fix] Fix Debian aarch64 cross compiling ()
* fix debian cross compiling

* comment

* minor
2023-03-03 12:41:52 +08:00
Chen Xin d95950d705
[Feature] Dynamically load net module to remove dependencies of mmdeploy.so () ()
* dynamic load net module

* export xxx_net

* add runpath

* link dl

* remove -ldl for macos

* fix rpath

* module -> shared

* set MMDEPLOY_DYNAMIC_BACKEND OFF when MMDEPLOY_BUILD_SDK_MONOLITHIC is OFF
2023-03-03 11:48:59 +08:00
Chen Xin 7de413a19c
[Feature] Sync csharp apis with newly added c apis && demo ()
* sync c api to c#

* fix typo

* add pose tracker c# demo

* udpate gitignore

* remove print

* fix lint

* update rotated detection api

* update rotated detection demo

* rename pose_tracking -> pose_tracker

* use input size as default
2023-03-02 09:20:41 +08:00
lvhan028 7fed511f09
disable building demos when preparing prebuilt package () 2023-02-28 21:16:35 +08:00
Li Zhang 7029e90064
avoid linking static libs in monolithic build () 2023-02-23 14:21:51 +08:00
Li Zhang f78a452681
fix missing include for gcc-10 build () 2023-02-23 12:05:25 +08:00
Li Zhang eb75bee921
add `Model::ReadConfig` & simplify handle creation () 2023-02-21 17:09:07 +08:00
SineYuan c941045156
fix normalization to_rgb option () 2023-02-21 17:08:34 +08:00
tripleMu 4bb8920b61
Fix trtlogger instead of mm logger ()
* Fix trtlogger instead of mm logger

* Reset trt logger to mmdeploy logger

* rename logger name
2023-02-20 16:45:47 +08:00
YH fd47fa2071
[Enhance] support TensorRT engine for onnxruntime ()
* Support trt engine for onnxruntime

* Apply lint

* Check trt execution provider

* Fix typo

* Fix provider order

* Check device
2023-02-20 14:18:09 +08:00
Li Zhang b1be9c67f3
[Fix] Fix palette generation on opencv-3.x () 2023-02-17 18:33:38 +08:00
q.yao 02d5a09989
bump version to 0.13.0 () 2023-02-16 14:15:19 +08:00
Songki Choi fa9aaa9d61
[Enhancement] Loosen protobuf version criteria for onnx upgrade ()
- onnx<1.13.0 has high security issue
  (https://github.com/advisories/GHSA-ffxj-547x-5j7c)

- Python packages depending on mmdeploy cannot upgrade onnx as
  - onnx==1.13.0 depends on protobuf>=3.20.2
  - mmdeploy depends on protobuf<=3.20.1

- Suggesting [protobuf<=3.20.2] for quick solution

Signed-off-by: Songki Choi <songki.choi@intel.com>
2023-02-15 16:03:15 +08:00
Chen Xin 599c701655
[Enhancement] Support cmake configure when system exists multiple cuda versions. ()
* update cmake

* typos
2023-02-14 16:20:47 +08:00
Eugene Liu e519898adb
Fix bug in remove_imports ()
* Fix bug in remove_imports

IndexError: list index out of range error as `model.opset_import list` is changing dynamically

* pre-commit fix
2023-02-13 19:46:24 +08:00
Li Zhang cadc2658f3
Fix `WarpBbox` and memory leak in `TextRecognizer` () 2023-02-13 19:43:25 +08:00
q.yao 0f5b149557
fix instance norm double free () 2023-02-13 19:42:37 +08:00
Li Zhang 31b099a37b
add coco whole-body skeleton () 2023-02-09 18:31:35 +08:00
AllentDan a3311b0bbb
enable TRT parse ONNX model from file () 2023-02-09 15:54:37 +08:00
Li Zhang f5a05b5219
[Refactor] Support batch inference with shape clustering ()
* refactor `NetModule`

* name

* fix sorting

* fix indices
2023-02-08 20:14:28 +08:00
q.yao d8e4a78636
[Improvement] Better unit test. ()
* update test for mmcls and mmdet

* update det3d mmedit mmocr mmpose mmrotate

* update mmseg

* bug fixing

* refactor ops

* rename variable

* remove comment
2023-02-08 11:30:59 +08:00
Li Zhang 5de0ecfcaf
[Fix] Add an option to flip webcam inputs for pose tracker demo () 2023-02-07 20:27:43 +08:00
Li Zhang 2b18596795
[Enhancement] Optimize C++ demos ()
* optimize demos

* show text in image

* optimize demos

* fix minor

* fix minor

* fix minor

* install utils & fix demo file extensions

* rename

* parse empty flags

* antialias

* handle video complications
2023-02-07 19:08:46 +08:00
RunningLeon 31f422244b
fix stale workflow ()
* fix stale workflow

* Update stale.yml
2023-02-06 21:17:26 +08:00
AllentDan 12b3d18c7a
[Fix] fix torch allocator resouce releasing ()
* delete root logger and add condition before calling caching_allocator_delete

* fix lint error

* use torch._C._cuda_cudaCachingAllocator_raw_delete
2023-02-06 11:35:44 +08:00
Chen Xin b85f34141b
[Feature] Support feature map output for mmsegmentation ()
* add feature map output for mmseg

* update api

* update demo

* fix return

* update format_shape

* fix lint

* update csharp demo

* update python demo && api

* fix coreml build

* fix lint

* better sort

* update

* update cpp demo & add missing header

* change to CHW

* update csharp api

* update isort version to 5.12.0

* fix python api

* fix log

* more detail api docs

* isort support python3.7

* remove isort change

* remove whitespace

* axes check

* remove FormatShapeImpl

* minor

* add permute tc

* remove stride buffer
2023-02-03 20:47:55 +08:00
AllentDan 7d085bee0e
directly set pytorch metric when it's empty for regression_test.py () 2023-02-03 11:25:11 +08:00
KerwinKai 23eed5c265
[Bug] Fixed ncnn model conversion errors in Dockerfile(no module name 'ncnn. ncnn',) ()
* Update Dockerfile

* Update Dockerfile

* Update Dockerfile
2023-02-03 10:22:25 +08:00
q.yao 5fdf00324b
[Fix] add bounds to avoid large resource usage of nms operator on jetson ()
* fix trt nms jetson

* update-for-comment

* clang format
2023-02-01 14:11:43 +08:00
q.yao 99d6fb3190
fix ascend () 2023-01-31 16:49:41 +08:00
tripleMu 85320df2b4
Fix isort lint error by upgrading it to 5.11.5 () 2023-01-31 13:31:59 +08:00
lvhan028 b101a4af65
[Enhancement] remove MMDEPLOY_BUILD_SDK_CXX_API option ()
* remove MMDEPLOY_BUILD_SDK_CXX_API option

* update

* update
2023-01-31 13:29:59 +08:00
Li Zhang 3d425bbb9f
[Feature] Pose tracker C/C++/Python API&demos ()
* add PoseTracker API

* add mahalanobis distance, add det_pose demo

* simplify api

* simplify api

* fix cmake & fix `CropResizePad`

* ignore out of frame bboxes

* clean-up

* fix lint

* add c api docs

* add c++ api docs/comments

* fix gcc7 build

* fix gcc7+opencv3

* fix stupid lint

* fix ci

* add help info & webcam support for C++ pose tracker demo

* add webcam support for Python pose tracker demo

* fix lint

* minor

* minor

* fix MSVC build

* fix python binding

* simplify module adapter

* fix module adapter

* minor fix
2023-01-31 11:24:24 +08:00
AllentDan 093badf90c
fix rknn output index error in SDK () 2023-01-30 20:50:06 +08:00
q.yao 8a050f10dc
suppress onnx optimizer warning () 2023-01-20 00:25:50 +08:00
tpoisonooo 7e48fb2905
improvement(tools/scripts): pip install with user environment () 2023-01-20 00:19:37 +08:00
Li Zhang 8bb3fcc6d8
fix 'cvtcolor' error in the preprocessing of single channel images () 2023-01-20 00:04:42 +08:00
q.yao 513b1c3cfb
Fix coreml ()
* fix coreml topk

* update

* fix lint
2023-01-19 11:42:18 +08:00
kaizhong bce276ef24
[Feature]: add a tool to generate supported-backends markdown table ()
* convert2markdown

* update yaml2mardown code

* code update

* add parse_args

* add parse_args

* add parse_args

* add parse_args

* add website list

* add website list

* add website list

* add website list

* add website list

* add website list

* add website list

* add url in yaml

* add table in convert

* add table in convert

* From yaml export markdown

* From yaml export markdown

* From yaml export markdown

* From yaml export markdown

* From yaml export markdown

* From yaml export markdown

* Rename convert.py to generate_md_table.py

generate_markdownd_table

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* docs(project): sync en and zh docs

* Update mmaction.yml

* add backends parser

* add backends parser

* Add type for the codeblock.

* move to useful tools
2023-01-18 16:32:26 +08:00
tpoisonooo 968b4b0b60
fix(requirements): codebase version () 2023-01-13 16:09:37 +08:00
Chen Xin c458e2a524
[Enhancement] Speedup TopDownAffine by CropResizePad ()
* "use 'CropResizePad' to speed up topdownaffine"

* add missing header
2023-01-13 16:08:29 +08:00
hanrui1sensetime 9d3b494079
[Fix] Fix visualize api bug ()
* fix visualize api bug

* fix visualize
2023-01-13 10:42:57 +08:00
Chen Xin 9a1f4e6145
[Fix] Fix example standalone build for msvc ()
* fix example build for msvc

* move /Zc:__cplusplus to core
2023-01-11 10:55:17 +08:00
RunningLeon 3527412127
change log file extension to 'txt' in regression test() 2023-01-10 17:42:55 +08:00
Nghia 1b048d88ca
fixed script errors when calling miniconda.sh () 2023-01-10 13:52:24 +08:00
q.yao 0737a59f44
[Improvement] Support auto release note ()
* Support auto release note

* update labels
2023-01-10 10:54:25 +08:00
hanrui1sensetime d5bd0072a2
fix android build command () 2023-01-10 10:44:49 +08:00
Li Zhang e4ad0d4c45
[Fix] Fix aligned allocations on Android ()
* fix android alignment

* fix typo

* fix size
2023-01-06 18:04:28 +08:00
Li Zhang 4463572311
Fix debug build for PoseTracker () 2023-01-03 14:24:11 +08:00
Chen Xin c0ca074c11
Fix build error on windows-cuda platform () 2023-01-03 12:12:20 +08:00
420 changed files with 14796 additions and 6984 deletions
.circleci
scripts/linux

View File

@ -6,7 +6,7 @@ cd mmdeploy
MMDEPLOY_DIR=$(pwd)
mkdir -p build && cd build
cmake .. -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_TEST=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_BUILD_SDK_CXX_API=ON -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON \
-DMMDEPLOY_TARGET_DEVICES="$1" -DMMDEPLOY_TARGET_BACKENDS="$2" "${ARGS[@]:2}"
make -j$(nproc) && make install

View File

@ -74,7 +74,7 @@ commands:
- run:
name: Install mmcv-full
command: |
python -m pip install opencv-python==4.5.4.60
python -m pip install opencv-python==4.5.4.60 opencv-contrib-python==4.5.4.60 opencv-python-headless==4.5.4.60
python -m pip install mmcv-full==<< parameters.version >> -f https://download.openmmlab.com/mmcv/dist/cpu/torch<< parameters.torch >>/index.html
install_mmcv_cuda:
parameters:
@ -91,7 +91,7 @@ commands:
- run:
name: Install mmcv-full
command: |
python -m pip install opencv-python==4.5.4.60
python -m pip install opencv-python==4.5.4.60 opencv-contrib-python==4.5.4.60 opencv-python-headless==4.5.4.60
python -m pip install mmcv-full==<< parameters.version >> -f https://download.openmmlab.com/mmcv/dist/<< parameters.cuda >>/torch<< parameters.torch >>/index.html
install_mmdeploy:
description: "Install MMDeploy"
@ -217,7 +217,6 @@ jobs:
-DMMDEPLOY_BUILD_TEST=ON `
-DMMDEPLOY_BUILD_SDK_PYTHON_API=ON `
-DMMDEPLOY_BUILD_EXAMPLES=ON `
-DMMDEPLOY_BUILD_SDK_CXX_API=ON `
-DMMDEPLOY_BUILD_SDK_CSHARP_API=ON `
-DMMDEPLOY_TARGET_BACKENDS="ort" `
-DOpenCV_DIR="$env:OPENCV_PACKAGE_DIR"

32
.github/release.yml vendored 100644
View File

@ -0,0 +1,32 @@
changelog:
categories:
- title: 🚀 Features
labels:
- feature
- enhancement
- title: 💥 Improvements
labels:
- improvement
- title: 🐞 Bug fixes
labels:
- bug
- Bug:P0
- Bug:P1
- Bug:P2
- Bug:P3
- title: 📚 Documentations
labels:
- documentation
- title: 🌐 Other
labels:
- '*'
exclude:
labels:
- feature
- enhancement
- bug
- documentation
- Bug:P0
- Bug:P1
- Bug:P2
- Bug:P3

View File

@ -47,6 +47,13 @@ PARAMS = [
'configs': [
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/litehrnet.tar' # noqa: E501
]
},
{
'task':
'RotatedDetection',
'configs': [
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/gliding-vertex.tar' # noqa: E501
]
}
]

View File

@ -21,13 +21,13 @@ permissions:
jobs:
build_sdk_demo:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Checkout repository
@ -40,9 +40,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev libc++1-9 libc++abi1-9
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt install libopencv-dev
pkg-config --libs opencv
- name: Install Ascend Toolkit
run: |
mkdir -p $GITHUB_WORKSPACE/Ascend
@ -53,5 +51,5 @@ jobs:
mkdir -p build && pushd build
source $GITHUB_WORKSPACE/Ascend/ascend-toolkit/set_env.sh
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/Ascend/ascend-toolkit/latest/runtime/lib64/stub:$LD_LIBRARY_PATH
cmake .. -DCMAKE_CXX_COMPILER=g++-7 -DMMDEPLOY_SHARED_LIBS=ON -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF -DMMDEPLOY_TARGET_DEVICES=cpu -DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_TARGET_BACKENDS=acl -DMMDEPLOY_CODEBASES=all
cmake .. -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_TARGET_BACKENDS=acl
make install -j4

View File

@ -39,22 +39,21 @@ jobs:
wget https://github.com/irexyc/mmdeploy-ci-resource/releases/download/libtorch/libtorch-osx-arm64-1.8.0.tar.gz
mkdir $GITHUB_WORKSPACE/libtorch-install
tar xf libtorch-osx-arm64-1.8.0.tar.gz -C $GITHUB_WORKSPACE/libtorch-install
- name: build
- name: build-static-lib
run: |
mkdir build && cd build
cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64" \
-DCMAKE_SYSTEM_PROCESSOR="arm64" \
-DMMDEPLOY_BUILD_SDK=ON \
-DMMDEPLOY_TARGET_DEVICES="cpu" \
-DMMDEPLOY_CODEBASES=all \
-DOpenCV_DIR=$GITHUB_WORKSPACE/opencv-install/lib/cmake/opencv4 \
-DTorch_DIR=$GITHUB_WORKSPACE/libtorch-install/share/cmake/Torch \
-DMMDEPLOY_TARGET_BACKENDS="coreml" \
-DMMDEPLOY_BUILD_EXAMPLES=ON \
-DMMDEPLOY_BUILD_SDK_MONOLITHIC=OFF \
-DMMDEPLOY_SHARED_LIBS=OFF
cmake --build . -j 3
cmake --build . --target install
- name: build-shared
- name: build-monolithic-lib
run: |
mkdir build-shared && cd build-shared
cmake .. -DCMAKE_OSX_ARCHITECTURES="arm64" \
@ -65,7 +64,8 @@ jobs:
-DOpenCV_DIR=$GITHUB_WORKSPACE/opencv-install/lib/cmake/opencv4 \
-DTorch_DIR=$GITHUB_WORKSPACE/libtorch-install/share/cmake/Torch \
-DMMDEPLOY_TARGET_BACKENDS="coreml" \
-DMMDEPLOY_BUILD_EXAMPLES=ON \
-DMMDEPLOY_SHARED_LIBS=ON
-DMMDEPLOY_BUILD_SDK_MONOLITHIC=ON \
-DMMDEPLOY_SHARED_LIBS=OFF \
-DMMDEPLOY_BUILD_EXAMPLES=ON
cmake --build . -j 3
cmake --build . --target install

View File

@ -29,7 +29,7 @@ permissions:
jobs:
test_onnx2ncnn:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
@ -39,7 +39,7 @@ jobs:
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install unittest dependencies
@ -82,12 +82,12 @@ jobs:
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_ncnn.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 tools/scripts/build_ubuntu_x64_ncnn.py 8
python3 -c 'import mmdeploy.apis.ncnn as ncnn_api; assert ncnn_api.is_available(with_custom_ops=True)'

View File

@ -31,14 +31,14 @@ jobs:
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_ort.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 tools/scripts/build_ubuntu_x64_ort.py 8
python3 -c 'import mmdeploy.apis.onnxruntime as ort_api; assert ort_api.is_available(with_custom_ops=True)'
- name: test mmcls full pipeline
run: |

View File

@ -21,22 +21,15 @@ permissions:
jobs:
script_install:
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: [3.7]
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_pplnn.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 tools/scripts/build_ubuntu_x64_pplnn.py 8
python3 -c 'import mmdeploy.apis.pplnn as pplnn_api; assert pplnn_api.is_available()'

View File

@ -22,7 +22,7 @@ permissions:
jobs:
build_rknpu2:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
@ -34,7 +34,7 @@ jobs:
run: |
sh -x tools/scripts/ubuntu_cross_build_rknn.sh rk3588
build_rknpu:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3

View File

@ -21,7 +21,7 @@ permissions:
jobs:
build_sdk_demo:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
@ -34,9 +34,7 @@ jobs:
sudo apt install wget libprotobuf-dev protobuf-compiler
sudo apt update
sudo apt install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev libc++1-9 libc++abi1-9
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt install libopencv-dev
pkg-config --libs opencv
- name: Install snpe
run: |
wget https://media.githubusercontent.com/media/tpoisonooo/mmdeploy_snpe_testdata/main/snpe-1.59.tar.gz
@ -50,7 +48,7 @@ jobs:
export SNPE_ROOT=/home/runner/work/mmdeploy/mmdeploy/snpe-1.59.0.3230
export LD_LIBRARY_PATH=${SNPE_ROOT}/lib/x86_64-linux-clang:${LD_LIBRARY_PATH}
export MMDEPLOY_SNPE_X86_CI=1
cmake .. -DCMAKE_CXX_COMPILER=g++-7 -DMMDEPLOY_SHARED_LIBS=ON -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF -DMMDEPLOY_TARGET_DEVICES=cpu -DMMDEPLOY_TARGET_BACKENDS=snpe -DMMDEPLOY_CODEBASES=all
cmake .. -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_TARGET_BACKENDS=snpe
make -j2
make install
pushd install/example

View File

@ -21,7 +21,7 @@ permissions:
jobs:
script_install:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
@ -31,9 +31,9 @@ jobs:
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_torchscript.py
python3 tools/scripts/build_ubuntu_x64_torchscript.py 8

View File

@ -31,14 +31,14 @@ jobs:
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_tvm.py
source ~/mmdeploy.env
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 -m pip install decorator psutil scipy attrs tornado pytest
python3 tools/scripts/build_ubuntu_x64_tvm.py 8
source ~/mmdeploy.env
python3 -c 'import mmdeploy.apis.tvm as tvm_api; assert tvm_api.is_available()'

View File

@ -25,10 +25,9 @@ permissions:
jobs:
build_cpu_model_convert:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
torch: [1.8.0, 1.9.0]
mmcv: [1.4.2]
include:
@ -39,23 +38,23 @@ jobs:
torch_version: torch1.9
torchvision: 0.10.0
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v3
- name: Install PyTorch
run: pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
run: |
python -m pip install --upgrade pip
python -V
python -m pip install torch==${{matrix.torch}}+cpu torchvision==${{matrix.torchvision}}+cpu -f https://download.pytorch.org/whl/torch_stable.html
- name: Install MMCV
run: |
pip install mmcv-full==${{matrix.mmcv}} -f https://download.openmmlab.com/mmcv/dist/cpu/${{matrix.torch_version}}/index.html
python -m pip install mmcv-full==${{matrix.mmcv}} -f https://download.openmmlab.com/mmcv/dist/cpu/${{matrix.torch_version}}/index.html
python -c 'import mmcv; print(mmcv.__version__)'
- name: Install unittest dependencies
run: |
pip install -r requirements.txt
pip install -U numpy
python -m pip install -U numpy
python -m pip install rapidfuzz==2.15.1
python -m pip install -r requirements.txt
- name: Build and install
run: rm -rf .eggs && pip install -e .
run: rm -rf .eggs && python -m pip install -e .
- name: Run python unittests and generate coverage report
run: |
coverage run --branch --source mmdeploy -m pytest -rsE tests
@ -63,7 +62,7 @@ jobs:
coverage report -m
build_cpu_sdk:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
@ -73,16 +72,18 @@ jobs:
run: sudo apt update
- name: gcc-multilib
run: |
sudo apt install gcc-multilib g++-multilib wget libprotobuf-dev protobuf-compiler
sudo apt update
sudo apt install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev libc++1-9 libc++abi1-9
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt install libopencv-dev lcov wget
pkg-config --libs opencv
sudo apt install libopencv-dev lcov wget -y
- name: Build and run SDK unit test without backend
run: |
mkdir -p build && pushd build
cmake .. -DCMAKE_CXX_COMPILER=g++-7 -DMMDEPLOY_CODEBASES=all -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF -DMMDEPLOY_TARGET_DEVICES=cpu -DMMDEPLOY_COVERAGE=ON -DMMDEPLOY_BUILD_TEST=ON
cmake .. \
-DMMDEPLOY_CODEBASES=all \
-DMMDEPLOY_BUILD_SDK=ON \
-DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF \
-DMMDEPLOY_TARGET_DEVICES=cpu \
-DMMDEPLOY_COVERAGE=ON \
-DMMDEPLOY_BUILD_TEST=ON
make -j2
mkdir -p mmdeploy_test_resources/transform
cp ../tests/data/tiger.jpeg mmdeploy_test_resources/transform/
@ -101,7 +102,7 @@ jobs:
- name: update
run: sudo apt update
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: gcc-multilib
@ -109,14 +110,14 @@ jobs:
sh -x tools/scripts/ubuntu_cross_build_aarch64.sh
build_cuda102:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
container:
image: pytorch/pytorch:1.9.0-cuda10.2-cudnn7-devel
env:
FORCE_CUDA: 1
strategy:
matrix:
python-version: [3.7]
python-version: [3.8]
torch: [1.9.0+cu102]
mmcv: [1.4.2]
include:
@ -124,26 +125,20 @@ jobs:
torch_version: torch1.9
torchvision: 0.10.0+cu102
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev python${{matrix.python-version}}-dev
apt-get clean
rm -rf /var/lib/apt/lists/*
apt-get update && apt-get install -y git
- name: Install PyTorch
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
- name: Install dependencies
run: |
python -V
python -m pip install -U pip
python -m pip install mmcv-full==${{matrix.mmcv}} -f https://download.openmmlab.com/mmcv/dist/cu102/${{matrix.torch_version}}/index.html
CFLAGS=`python -c 'import sysconfig;print("-I"+sysconfig.get_paths()["include"])'` python -m pip install -r requirements.txt
pip install -U pycuda
python -m pip install -U numpy
python -m pip install -r requirements.txt
python -m pip install rapidfuzz==2.15.1
- name: Build and install
run: |
rm -rf .eggs && python -m pip install -e .
@ -155,41 +150,31 @@ jobs:
coverage report -m
build_cuda111:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel
strategy:
matrix:
python-version: [3.7]
python-version: [3.8]
torch: [1.8.0+cu111]
mmcv: [1.4.2]
include:
- torch: 1.8.0+cu111
torch_version: torch1.8
torchvision: 0.9.0+cu111
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
apt-get update && apt-get install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev python${{matrix.python-version}}-dev
apt-get clean
rm -rf /var/lib/apt/lists/*
- name: Install PyTorch
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
apt-get update && apt-get install -y git
- name: Install dependencies
run: |
python -V
python -m pip install -U pip
python -m pip install mmcv-full==${{matrix.mmcv}} -f https://download.openmmlab.com/mmcv/dist/cu111/${{matrix.torch_version}}/index.html
CFLAGS=`python -c 'import sysconfig;print("-I"+sysconfig.get_paths()["include"])'` python -m pip install -r requirements.txt
pip install -U pycuda
python -m pip install -U numpy
python -m pip install -r requirements.txt
python -m pip install rapidfuzz==2.15.1
- name: Build and install
run: |
rm -rf .eggs && python -m pip install -e .

View File

@ -19,14 +19,14 @@ permissions:
jobs:
test_java_api:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install unittest dependencies

View File

@ -7,11 +7,11 @@ permissions:
jobs:
lint:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install pre-commit hook

View File

@ -48,12 +48,9 @@ jobs:
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/riscv64-linux-gnu.cmake \
-DMMDEPLOY_BUILD_SDK=ON \
-DMMDEPLOY_SHARED_LIBS=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON \
-DMMDEPLOY_TARGET_DEVICES="cpu" \
-DMMDEPLOY_TARGET_BACKENDS="ncnn" \
-Dncnn_DIR=$GITHUB_WORKSPACE/ncnn-install/lib/cmake/ncnn/ \
-DMMDEPLOY_CODEBASES=all \
-DOpenCV_DIR=$GITHUB_WORKSPACE/opencv-install/lib/cmake/opencv4
make -j$(nproc)
make install

277
.github/workflows/prebuild.yml vendored 100644
View File

@ -0,0 +1,277 @@
name: prebuild
on:
push:
branches:
- main
- dev-1.x
- master
paths:
- "mmdeploy/version.py"
permissions: write-all
jobs:
linux_build:
runs-on: [self-hosted, linux-3090]
container:
image: openmmlab/mmdeploy:manylinux2014_x86_64-cuda11.3
options: "--gpus=all --ipc=host"
volumes:
- /data2/actions-runner/prebuild:/__w/mmdeploy/prebuild
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
echo "OUTPUT_DIR=$MMDEPLOY_VERSION-$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Build MMDeploy
run: |
source activate mmdeploy-3.6
pip install pyyaml packaging setuptools wheel
mkdir pack; cd pack
python ../tools/package_tools/generate_build_config.py --backend 'trt;ort' \
--system linux --output config.yml --build-mmdeploy
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cpu backend
run: |
source activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort' \
--system linux --output config.yml --device cpu --build-sdk --build-sdk-monolithic \
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cuda backend
run: |
source activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort;trt' \
--system linux --output config.yml --device cuda --build-sdk --build-sdk-monolithic \
--build-sdk-python --sdk-dynamic-net --onnxruntime-dir=$ONNXRUNTIME_GPU_DIR
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Move artifact
run: |
mkdir -p /__w/mmdeploy/prebuild/$OUTPUT_DIR
cp -r pack/* /__w/mmdeploy/prebuild/$OUTPUT_DIR
linux_build_cxx11abi:
runs-on: [self-hosted, linux-3090]
container:
image: openmmlab/mmdeploy:build-ubuntu16.04-cuda11.3
options: "--gpus=all --ipc=host"
volumes:
- /data2/actions-runner/prebuild:/__w/mmdeploy/prebuild
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
echo "OUTPUT_DIR=$MMDEPLOY_VERSION-$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Build sdk cpu backend
run: |
mkdir pack; cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort' \
--system linux --output config.yml --device cpu --build-sdk --build-sdk-monolithic \
--sdk-dynamic-net --cxx11abi
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cuda backend
run: |
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort;trt' \
--system linux --output config.yml --device cuda --build-sdk --build-sdk-monolithic \
--sdk-dynamic-net --cxx11abi --onnxruntime-dir=$ONNXRUNTIME_GPU_DIR --cudnn-dir /usr
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Move artifact
run: |
mkdir -p /__w/mmdeploy/prebuild/$OUTPUT_DIR
cp -r pack/* /__w/mmdeploy/prebuild/$OUTPUT_DIR
linux_test:
runs-on: [self-hosted, linux-3090]
needs:
- linux_build
- linux_build_cxx11abi
container:
image: openmmlab/mmdeploy:ubuntu20.04-cuda11.3
options: "--gpus=all --ipc=host"
volumes:
- /data2/actions-runner/prebuild:/__w/mmdeploy/prebuild
- /data2/actions-runner/testmodel:/__w/mmdeploy/testmodel
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
echo "OUTPUT_DIR=$MMDEPLOY_VERSION-$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Test python
run: |
cd /__w/mmdeploy/prebuild/$OUTPUT_DIR
bash $GITHUB_WORKSPACE/tools/package_tools/test/test_sdk_python.sh
- name: Test c/cpp
run: |
cd /__w/mmdeploy/prebuild/$OUTPUT_DIR
bash $GITHUB_WORKSPACE/tools/package_tools/test/test_sdk.sh
linux_upload:
runs-on: [self-hosted, linux-3090]
if: startsWith(github.ref, 'refs/tags/')
environment: 'prod'
needs: linux_test
env:
PREBUILD_DIR: /data2/actions-runner/prebuild
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
echo "OUTPUT_DIR=$MMDEPLOY_VERSION-$GITHUB_RUN_ID" >> $GITHUB_ENV
- name: Upload mmdeploy
run: |
cd $PREBUILD_DIR/$OUTPUT_DIR/mmdeploy
pip install twine
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Upload mmdeploy_runtime
run: |
cd $PREBUILD_DIR/$OUTPUT_DIR/mmdeploy_runtime
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Zip mmdeploy sdk
run: |
cd $PREBUILD_DIR/$OUTPUT_DIR/sdk
for folder in *
do
tar czf $folder.tar.gz $folder
done
- name: Upload mmdeploy sdk
uses: softprops/action-gh-release@v1
with:
files: |
$PREBUILD_DIR/$OUTPUT_DIR/sdk/*.tar.gz
windows_build:
runs-on: [self-hosted, win10-3080]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
echo "OUTPUT_DIR=$env:MMDEPLOY_VERSION-$env:GITHUB_RUN_ID" >> $env:GITHUB_ENV
- name: Build MMDeploy
run: |
. D:\DEPS\cienv\prebuild_gpu_env.ps1
conda activate mmdeploy-3.6
mkdir pack; cd pack
python ../tools/package_tools/generate_build_config.py --backend 'trt;ort' `
--system windows --output config.yml --build-mmdeploy
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cpu backend
run: |
. D:\DEPS\cienv\prebuild_cpu_env.ps1
conda activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort' `
--system windows --output config.yml --device cpu --build-sdk --build-sdk-monolithic `
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cuda backend
run: |
. D:\DEPS\cienv\prebuild_gpu_env.ps1
conda activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort;trt' `
--system windows --output config.yml --device cuda --build-sdk --build-sdk-monolithic `
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Move artifact
run: |
New-Item "D:/DEPS/ciartifact/$env:OUTPUT_DIR" -ItemType Directory -Force
Move-Item pack/* "D:/DEPS/ciartifact/$env:OUTPUT_DIR"
windows_test:
runs-on: [self-hosted, win10-3080]
needs: windows_build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
echo "OUTPUT_DIR=$env:MMDEPLOY_VERSION-$env:GITHUB_RUN_ID" >> $env:GITHUB_ENV
- name: Test python
run: |
cd "D:/DEPS/ciartifact/$env:OUTPUT_DIR"
. D:\DEPS\cienv\prebuild_cpu_env.ps1
conda activate ci-test
& "$env:GITHUB_WORKSPACE/tools/package_tools/test/test_sdk_python.ps1"
- name: Test c/cpp
run: |
cd "D:/DEPS/ciartifact/$env:OUTPUT_DIR"
. D:\DEPS\cienv\prebuild_cpu_env.ps1
& "$env:GITHUB_WORKSPACE/tools/package_tools/test/test_sdk.ps1"
windows_upload:
runs-on: [self-hosted, win10-3080]
if: startsWith(github.ref, 'refs/tags/')
environment: 'prod'
needs: windows_test
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
echo "OUTPUT_DIR=$env:MMDEPLOY_VERSION-$env:GITHUB_RUN_ID" >> $env:GITHUB_ENV
- name: Upload mmdeploy
run: |
cd "D:/DEPS/ciartifact/$env:OUTPUT_DIR/mmdeploy"
conda activate mmdeploy-3.8
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Upload mmdeploy_runtime
run: |
cd "D:/DEPS/ciartifact/$env:OUTPUT_DIR/mmdeploy_runtime"
conda activate mmdeploy-3.8
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Zip mmdeploy sdk
run: |
cd "D:/DEPS/ciartifact/$env:OUTPUT_DIR/sdk"
$folders = $(ls).Name
foreach ($folder in $folders) {
Compress-Archive -Path $folder -DestinationPath "$folder.zip"
}
- name: Upload mmdeploy sdk
uses: softprops/action-gh-release@v1
with:
files: |
D:/DEPS/ciartifact/$env:OUTPUT_DIR/sdk/*.zip

View File

@ -21,7 +21,7 @@ permissions:
jobs:
test_ncnn_PTQ:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel
@ -36,45 +36,31 @@ jobs:
torchvision: 0.9.0+cu111
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v3
- name: Install system dependencies
run: |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
apt-get update && apt-get install -y wget ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev python${{matrix.python-version}}-dev
apt-get clean
rm -rf /var/lib/apt/lists/*
- name: Install PyTorch
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
apt-get update && apt-get install -y git wget
- name: Install dependencies
run: |
python -V
python -m pip install -U pip
python -m pip install mmcv-full==${{matrix.mmcv}} -f https://download.openmmlab.com/mmcv/dist/cu111/${{matrix.torch_version}}/index.html
CFLAGS=`python -c 'import sysconfig;print("-I"+sysconfig.get_paths()["include"])'` python -m pip install -r requirements.txt
python -m pip install -U numpy
python -m pip install -r requirements.txt
python -m pip install rapidfuzz==2.15.1
- name: Install mmcls
run: |
cd ~
git clone https://github.com/open-mmlab/mmclassification.git
git clone -b v0.23.0 --depth 1 https://github.com/open-mmlab/mmclassification.git
cd mmclassification
git checkout v0.23.0
python3 -m pip install -e .
cd -
- name: Install ppq
run: |
cd ~
python -m pip install protobuf==3.20.0
git clone https://github.com/openppl-public/ppq
git clone -b v0.6.6 --depth 1 https://github.com/openppl-public/ppq
cd ppq
git checkout edbecf44c7b203515640e4f4119c000a1b66b33a
python3 -m pip install -r requirements.txt
python3 setup.py install
cd -
- name: Run tests
run: |
echo $(pwd)
export PYTHONPATH=${PWD}/ppq:${PYTHONPATH}
python3 .github/scripts/quantize_to_ncnn.py

View File

@ -19,7 +19,7 @@ permissions:
jobs:
test_rust_api:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
@ -27,7 +27,7 @@ jobs:
submodules: 'recursive'
- name: Set up Python 3.7
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install latest nightly Rust

View File

@ -10,9 +10,12 @@ permissions:
jobs:
stale:
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v7
with:
stale-issue-message: 'This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.'
stale-pr-message: 'This PR is marked as stale because there has been no activity in the past 45 days. It will be closed in 10 days if the stale label is not removed or if there is no further updates.'
@ -26,3 +29,4 @@ jobs:
days-before-pr-close: 10
# automatically remove the stale label when the issues or the pull reqquests are updated or commented
remove-stale-when-updated: true
operations-per-run: 50

3
.gitignore vendored
View File

@ -164,3 +164,6 @@ service/snpe/grpc_cpp_plugin
csrc/mmdeploy/preprocess/elena/json
csrc/mmdeploy/preprocess/elena/cpu_kernel/*
csrc/mmdeploy/preprocess/elena/cuda_kernel/*
# c#
demo/csharp/*/Properties

View File

@ -3,9 +3,11 @@ repos:
rev: 4.0.1
hooks:
- id: flake8
args: ["--exclude=*/client/inference_pb2.py,*/client/inference_pb2_grpc.py"]
args: ["--exclude=*/client/inference_pb2.py, \
*/client/inference_pb2_grpc.py, \
tools/package_tools/packaging/setup.py"]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.11.5
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-yapf

View File

@ -5,7 +5,7 @@ endif ()
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
cmake_minimum_required(VERSION 3.14)
project(MMDeploy VERSION 0.12.0)
project(MMDeploy VERSION 0.14.0)
set(CMAKE_CXX_STANDARD 17)
@ -24,10 +24,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# options
option(MMDEPLOY_SHARED_LIBS "build shared libs" OFF)
option(MMDEPLOY_BUILD_SDK "build MMDeploy SDK" OFF)
option(MMDEPLOY_DYNAMIC_BACKEND "dynamic load backend" OFF)
option(MMDEPLOY_BUILD_SDK_MONOLITHIC "build single lib for SDK API" ON)
option(MMDEPLOY_BUILD_TEST "build unittests" OFF)
option(MMDEPLOY_BUILD_SDK_PYTHON_API "build SDK Python API" OFF)
option(MMDEPLOY_BUILD_SDK_CXX_API "build SDK C++ API" OFF)
option(MMDEPLOY_BUILD_SDK_CSHARP_API "build SDK C# API support" OFF)
option(MMDEPLOY_BUILD_SDK_JAVA_API "build SDK JAVA API" OFF)
option(MMDEPLOY_BUILD_EXAMPLES "build examples" OFF)
@ -40,6 +40,10 @@ set(MMDEPLOY_TARGET_DEVICES "cpu" CACHE STRING "target devices to support")
set(MMDEPLOY_TARGET_BACKENDS "" CACHE STRING "target inference engines to support")
set(MMDEPLOY_CODEBASES "all" CACHE STRING "select OpenMMLab codebases")
if ((NOT MMDEPLOY_BUILD_SDK_MONOLITHIC) AND MMDEPLOY_DYNAMIC_BACKEND)
set(MMDEPLOY_DYNAMIC_BACKEND OFF)
endif ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "choose 'Release' as default build type" FORCE)
endif ()
@ -73,8 +77,6 @@ endif ()
if (MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/diagnostics:classic>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor>) # /experimental:preprocessor on VS2017
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4251>)
endif ()
@ -97,10 +99,12 @@ include(cmake/MMDeploy.cmake)
add_subdirectory(csrc/mmdeploy)
if (MMDEPLOY_BUILD_SDK)
install(TARGETS MMDeployStaticModules
MMDeployDynamicModules
MMDeployLibs
EXPORT MMDeployTargets)
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
install(TARGETS MMDeployStaticModules
MMDeployDynamicModules
MMDeployLibs
EXPORT MMDeployTargets)
endif ()
if (MMDEPLOY_BUILD_TEST)
add_subdirectory(tests/test_csrc)

View File

@ -2,7 +2,9 @@ include requirements/*.txt
include mmdeploy/backend/ncnn/*.so
include mmdeploy/backend/ncnn/*.dll
include mmdeploy/backend/ncnn/*.pyd
include mmdeploy/backend/ncnn/mmdeploy_onnx2ncnn*
include mmdeploy/lib/*.so
include mmdeploy/lib/*.so*
include mmdeploy/lib/*.dll
include mmdeploy/lib/*.pyd
include mmdeploy/backend/torchscript/*.so

View File

@ -28,6 +28,16 @@
English | [简体中文](README_zh-CN.md)
## Highlights
The MMDeploy 1.x has been released, which is adapted to upstream codebases from OpenMMLab 2.0. Please **align the version** when using it.
The default branch has been switched to `main` from `master`. MMDeploy 0.x (`master`) will be deprecated and new features will only be added to MMDeploy 1.x (`main`) in future.
| mmdeploy | mmengine | mmcv | mmdet | others |
| :------: | :------: | :------: | :------: | :----: |
| 0.x.y | - | \<=1.x.y | \<=2.x.y | 0.x.y |
| 1.x.y | 0.x.y | 2.x.y | 3.x.y | 1.x.y |
## Introduction
MMDeploy is an open-source deep learning model deployment toolset. It is a part of the [OpenMMLab](https://openmmlab.com/) project.

View File

@ -28,6 +28,16 @@
[English](README.md) | 简体中文
## MMDeploy 1.x 版本
全新的 MMDeploy 1.x 已发布该版本适配OpenMMLab 2.0生态体系,使用时务必**对齐版本**。
MMDeploy 代码库默认分支从`master`切换至`main`。 MMDeploy 0.x (`master`)将逐步废弃,新特性将只添加到 MMDeploy 1.x (`main`)。
| mmdeploy | mmengine | mmcv | mmdet | mmcls and others |
| :------: | :------: | :------: | :------: | :--------------: |
| 0.x.y | - | \<=1.x.y | \<=2.x.y | 0.x.y |
| 1.x.y | 0.x.y | 2.x.y | 3.x.y | 1.x.y |
## 介绍
MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为各算法库提供统一的部署体验**。基于 MMDeploy开发者可以轻松从训练 repo 生成指定硬件所需 SDK省去大量适配时间。

View File

@ -1,6 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
function (mmdeploy_export NAME)
function (mmdeploy_export_impl NAME)
set(_LIB_DIR lib)
if (MSVC)
set(_LIB_DIR bin)
@ -12,6 +12,24 @@ function (mmdeploy_export NAME)
RUNTIME DESTINATION bin)
endfunction ()
macro(mmdeploy_add_net NAME)
if (MMDEPLOY_DYNAMIC_BACKEND)
mmdeploy_add_library(${NAME} SHARED ${ARGN})
# DYNAMIC_BACKEND implies BUILD_SDK_MONOLITHIC
mmdeploy_export_impl(${NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy)
set(BACKEND_LIB_NAMES ${BACKEND_LIB_NAMES} ${PROJECT_NAME} PARENT_SCOPE)
else ()
mmdeploy_add_module(${NAME} ${ARGN})
endif ()
endmacro()
function (mmdeploy_export NAME)
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
mmdeploy_export_impl(${NAME})
endif ()
endfunction ()
function (mmdeploy_add_library NAME)
# EXCLUDE: exclude from registering & exporting

View File

@ -10,13 +10,12 @@ set(MMDEPLOY_TARGET_DEVICES @MMDEPLOY_TARGET_DEVICES@)
set(MMDEPLOY_TARGET_BACKENDS @MMDEPLOY_TARGET_BACKENDS@)
set(MMDEPLOY_BUILD_TYPE @CMAKE_BUILD_TYPE@)
set(MMDEPLOY_BUILD_SHARED @MMDEPLOY_SHARED_LIBS@)
set(MMDEPLOY_BUILD_SDK_CXX_API @MMDEPLOY_BUILD_SDK_CXX_API@)
set(MMDEPLOY_BUILD_SDK_MONOLITHIC @MMDEPLOY_BUILD_SDK_MONOLITHIC@)
set(MMDEPLOY_VERSION_MAJOR @MMDEPLOY_VERSION_MAJOR@)
set(MMDEPLOY_VERSION_MINOR @MMDEPLOY_VERSION_MINOR@)
set(MMDEPLOY_VERSION_PATCH @MMDEPLOY_VERSION_PATCH@)
if (NOT MMDEPLOY_BUILD_SHARED)
if (NOT MMDEPLOY_BUILD_SHARED AND NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
find_package(CUDA REQUIRED)
if(MSVC)

View File

@ -11,6 +11,37 @@ if (MSVC OR (NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY))
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
endif ()
if (MSVC)
# no plugin in BuildCustomizations and no specify cuda toolset
if (NOT CMAKE_VS_PLATFORM_TOOLSET_CUDA)
message(FATAL_ERROR "Please install CUDA MSBuildExtensions")
endif ()
if (CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR)
# find_package(CUDA) required ENV{CUDA_PATH}
set(ENV{CUDA_PATH} ${CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR})
else ()
# we use CUDA_PATH and ignore nvcc.exe
# cmake will import highest cuda props version, which may not equal to CUDA_PATH
if (NOT (DEFINED ENV{CUDA_PATH}))
message(FATAL_ERROR "Please set CUDA_PATH environment variable")
endif ()
string(REGEX REPLACE ".*v([0-9]+)\\..*" "\\1" _MAJOR $ENV{CUDA_PATH})
string(REGEX REPLACE ".*v[0-9]+\\.([0-9]+).*" "\\1" _MINOR $ENV{CUDA_PATH})
if (NOT (${CMAKE_VS_PLATFORM_TOOLSET_CUDA} STREQUAL "${_MAJOR}.${_MINOR}"))
message(FATAL_ERROR "Auto detected cuda version ${CMAKE_VS_PLATFORM_TOOLSET_CUDA}"
" is mismatch with ENV{CUDA_PATH} $ENV{CUDA_PATH}. Please modify CUDA_PATH"
" to match ${CMAKE_VS_PLATFORM_TOOLSET_CUDA} or specify cuda toolset by"
" cmake -T cuda=/path/to/cuda ..")
endif ()
if (NOT (DEFINED ENV{CUDA_PATH_V${_MAJOR}_${_MINOR}}))
message(FATAL_ERROR "Please set CUDA_PATH_V${_MAJOR}_${_MINOR} environment variable")
endif ()
endif ()
endif ()
# nvcc compiler settings
find_package(CUDA REQUIRED)

View File

@ -1,15 +1,53 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include <Windows.h>
#include <string>
#include <cstdio>
#ifdef _WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
#ifdef _WIN32
#define LIBPREFIX ""
#define LIBSUFFIX ".dll"
#elif defined(__APPLE__)
#define LIBPREFIX "lib"
#define LIBSUFFIX ".dylib"
#else
#define LIBPREFIX "lib"
#define LIBSUFFIX ".so"
#endif
namespace mmdeploy {
namespace {
#ifdef _WIN32
inline static const std::wstring GetDllPath() {
HMODULE hm = NULL;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPWSTR)&GetDllPath, &hm);
std::wstring ret;
ret.resize(MAX_PATH);
GetModuleFileNameW(hm, &ret[0], ret.size());
ret = ret.substr(0, ret.find_last_of(L"/\\"));
return ret;
}
#endif
void* mmdeploy_load_library(const char* name) {
fprintf(stderr, "loading %s ...\n", name);
auto handle = LoadLibraryA(name);
#ifdef _WIN32
auto handle = LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
if (handle == NULL) {
handle = LoadLibraryExA(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
}
#else
auto handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
#endif
if (!handle) {
fprintf(stderr, "failed to load library %s\n", name);
return nullptr;
@ -22,11 +60,15 @@ void* mmdeploy_load_library(const char* name) {
class Loader {
public:
Loader() {
#ifdef _WIN32
AddDllDirectory(GetDllPath().c_str());
#endif
const char* modules[] = {
@_MMDEPLOY_DYNAMIC_MODULES@
};
for (const auto name : modules) {
mmdeploy_load_library(name);
std::string libname = std::string{} + LIBPREFIX + name + LIBSUFFIX;
mmdeploy_load_library(libname.c_str());
}
}
};

View File

@ -29,6 +29,7 @@ else ()
message(FATAL_ERROR "Cannot find TensorRT libs")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TENSORRT DEFAULT_MSG TENSORRT_INCLUDE_DIR
TENSORRT_LIBRARY)
if (NOT TENSORRT_FOUND)

View File

@ -0,0 +1,11 @@
_base_ = ['./classification_coreml_dynamic-224x224-224x224.py']
ir_config = dict(input_shape=(384, 384))
backend_config = dict(model_inputs=[
dict(
input_shapes=dict(
input=dict(
min_shape=[1, 3, 384, 384],
max_shape=[1, 3, 384, 384],
default_shape=[1, 3, 384, 384])))
])

View File

@ -0,0 +1,11 @@
_base_ = ['../_base_/base_torchscript.py', '../../_base_/backends/coreml.py']
ir_config = dict(input_shape=(608, 608))
backend_config = dict(model_inputs=[
dict(
input_shapes=dict(
input=dict(
min_shape=[1, 3, 608, 608],
max_shape=[1, 3, 608, 608],
default_shape=[1, 3, 608, 608])))
])

View File

@ -0,0 +1,20 @@
_base_ = ['./inpainting_static.py']
onnx_config = dict(
dynamic_axes=dict(
masked_img={
0: 'batch',
2: 'height',
3: 'width'
},
mask={
0: 'batch',
2: 'height',
3: 'width'
},
output={
0: 'batch',
2: 'height',
3: 'width'
}),
input_shape=None)

View File

@ -0,0 +1 @@
_base_ = ['./inpainting_dynamic.py', '../../_base_/backends/onnxruntime.py']

View File

@ -0,0 +1,3 @@
_base_ = ['./inpainting_static.py', '../../_base_/backends/onnxruntime.py']
onnx_config = dict(input_shape=[256, 256])

View File

@ -0,0 +1,5 @@
_base_ = ['../../_base_/onnx_config.py']
codebase_config = dict(type='mmedit', task='Inpainting')
onnx_config = dict(
input_names=['masked_img', 'mask'], output_names=['fake_img'])

View File

@ -0,0 +1,17 @@
_base_ = ['./inpainting_static.py', '../../_base_/backends/tensorrt-fp16.py']
onnx_config = dict(input_shape=[256, 256])
backend_config = dict(
common_config=dict(max_workspace_size=1 << 30),
model_inputs=[
dict(
input_shapes=dict(
masked_img=dict(
min_shape=[1, 3, 256, 256],
opt_shape=[1, 3, 256, 256],
max_shape=[1, 3, 256, 256]),
mask=dict(
min_shape=[1, 1, 256, 256],
opt_shape=[1, 1, 256, 256],
max_shape=[1, 1, 256, 256])))
])

View File

@ -0,0 +1,17 @@
_base_ = ['./inpainting_static.py', '../../_base_/backends/tensorrt-int8.py']
onnx_config = dict(input_shape=[256, 256])
backend_config = dict(
common_config=dict(max_workspace_size=1 << 30),
model_inputs=[
dict(
input_shapes=dict(
masked_img=dict(
min_shape=[1, 3, 256, 256],
opt_shape=[1, 3, 256, 256],
max_shape=[1, 3, 256, 256]),
mask=dict(
min_shape=[1, 1, 256, 256],
opt_shape=[1, 1, 256, 256],
max_shape=[1, 1, 256, 256])))
])

View File

@ -0,0 +1,17 @@
_base_ = ['./inpainting_static.py', '../../_base_/backends/tensorrt.py']
onnx_config = dict(input_shape=[256, 256])
backend_config = dict(
common_config=dict(max_workspace_size=1 << 30),
model_inputs=[
dict(
input_shapes=dict(
masked_img=dict(
min_shape=[1, 3, 256, 256],
opt_shape=[1, 3, 256, 256],
max_shape=[1, 3, 256, 256]),
mask=dict(
min_shape=[1, 1, 256, 256],
opt_shape=[1, 1, 256, 256],
max_shape=[1, 1, 256, 256])))
])

View File

@ -0,0 +1,13 @@
_base_ = [
'../../_base_/torchscript_config.py', '../../_base_/backends/coreml.py'
]
codebase_config = dict(type='mmocr', task='TextRecognition')
backend_config = dict(model_inputs=[
dict(
input_shapes=dict(
input=dict(
min_shape=[1, 3, 32, 32],
max_shape=[1, 3, 32, 640],
default_shape=[1, 3, 32, 64])))
])

View File

@ -1,10 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
# Python API depends on C++ API
if (MMDEPLOY_BUILD_SDK_PYTHON_API)
set(MMDEPLOY_BUILD_SDK_CXX_API ON)
endif ()
add_subdirectory(c)
add_subdirectory(cxx)
add_subdirectory(java)

View File

@ -12,6 +12,9 @@ macro(add_object name)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fvisibility=hidden>)
endif ()
target_link_libraries(${name} PRIVATE mmdeploy::core)
target_include_directories(${name} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
set(CAPI_OBJS ${CAPI_OBJS} ${name})
mmdeploy_export(${name})
endmacro()
@ -31,6 +34,7 @@ foreach (TASK ${COMMON_LIST})
mmdeploy_add_library(${TARGET_NAME})
target_link_libraries(${TARGET_NAME} PRIVATE ${OBJECT_NAME})
target_include_directories(${TARGET_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${TASK}.h
DESTINATION include/mmdeploy)
@ -76,5 +80,14 @@ if (MMDEPLOY_BUILD_SDK_CSHARP_API OR MMDEPLOY_BUILD_SDK_MONOLITHIC)
set_target_properties(mmdeploy PROPERTIES
VERSION ${MMDEPLOY_VERSION}
SOVERSION ${MMDEPLOY_VERSION_MAJOR})
mmdeploy_export(mmdeploy)
if (APPLE)
set_target_properties(mmdeploy PROPERTIES
INSTALL_RPATH "@loader_path"
BUILD_RPATH "@loader_path")
else ()
set_target_properties(mmdeploy PROPERTIES
INSTALL_RPATH "\$ORIGIN"
BUILD_RPATH "\$ORIGIN")
endif ()
mmdeploy_export_impl(mmdeploy)
endif ()

View File

@ -1,52 +1,21 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "classifier.h"
#include "mmdeploy/classifier.h"
#include <numeric>
#include "common_internal.h"
#include "handle.h"
#include "mmdeploy/archive/value_archive.h"
#include "mmdeploy/codebase/mmcls/mmcls.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/utils/formatter.h"
#include "pipeline.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/pipeline.h"
using namespace mmdeploy;
using namespace std;
namespace {
Value config_template(const Model& model) {
// clang-format off
static Value v{
{
"pipeline", {
{"input", {"img"}},
{"output", {"cls"}},
{
"tasks", {
{
{"name", "classifier"},
{"type", "Inference"},
{"params", {{"model", "TBD"}}},
{"input", {"img"}},
{"output", {"cls"}}
}
}
}
}
}
};
// clang-format on
auto config = v;
config["pipeline"]["tasks"][0]["params"]["model"] = model;
return config;
}
} // namespace
int mmdeploy_classifier_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_classifier_t* classifier) {
mmdeploy_context_t context{};
@ -73,8 +42,7 @@ int mmdeploy_classifier_create_by_path(const char* model_path, const char* devic
int mmdeploy_classifier_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_classifier_t* classifier) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)classifier);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)classifier);
}
int mmdeploy_classifier_create_input(const mmdeploy_mat_t* mats, int mat_count,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_CLASSIFIER_H
#define MMDEPLOY_CLASSIFIER_H
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,9 +1,9 @@
#include "common.h"
#include "mmdeploy/common.h"
#include "common_internal.h"
#include "executor_internal.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/profiler.h"
#include "mmdeploy/executor_internal.h"
mmdeploy_value_t mmdeploy_value_copy(mmdeploy_value_t value) {
if (!value) {

View File

@ -3,12 +3,12 @@
#ifndef MMDEPLOY_CSRC_APIS_C_COMMON_INTERNAL_H_
#define MMDEPLOY_CSRC_APIS_C_COMMON_INTERNAL_H_
#include "common.h"
#include "handle.h"
#include "mmdeploy/common.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/value.h"
#include "model.h"
#include "pipeline.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/model.h"
#include "mmdeploy/pipeline.h"
using namespace mmdeploy;

View File

@ -1,6 +1,6 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "detector.h"
#include "mmdeploy/detector.h"
#include <deque>
#include <numeric>
@ -19,27 +19,11 @@
using namespace std;
using namespace mmdeploy;
namespace {
Value config_template(Model model) {
// clang-format off
return {
{"name", "detector"},
{"type", "Inference"},
{"params", {{"model", std::move(model)}}},
{"input", {"image"}},
{"output", {"dets"}}
};
// clang-format on
}
using ResultType = mmdeploy::Structure<mmdeploy_detection_t, //
std::vector<int>, //
std::deque<mmdeploy_instance_mask_t>, //
std::vector<mmdeploy::framework::Buffer>>; //
} // namespace
int mmdeploy_detector_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_detector_t* detector) {
mmdeploy_context_t context{};
@ -54,8 +38,7 @@ int mmdeploy_detector_create(mmdeploy_model_t model, const char* device_name, in
int mmdeploy_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_detector_t* detector) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)detector);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)detector);
}
int mmdeploy_detector_create_by_path(const char* model_path, const char* device_name, int device_id,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_DETECTOR_H
#define MMDEPLOY_DETECTOR_H
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,11 +1,11 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "executor.h"
#include "mmdeploy/executor.h"
#include "common.h"
#include "common_internal.h"
#include "executor_internal.h"
#include "mmdeploy/common.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/execution/when_all_value.h"
#include "mmdeploy/executor_internal.h"
using namespace mmdeploy;

View File

@ -3,7 +3,7 @@
#ifndef MMDEPLOY_CSRC_APIS_C_EXECUTOR_H_
#define MMDEPLOY_CSRC_APIS_C_EXECUTOR_H_
#include "common.h"
#include "mmdeploy/common.h"
#if __cplusplus
extern "C" {

View File

@ -3,8 +3,8 @@
#ifndef MMDEPLOY_CSRC_APIS_C_EXECUTOR_INTERNAL_H_
#define MMDEPLOY_CSRC_APIS_C_EXECUTOR_INTERNAL_H_
#include "executor.h"
#include "mmdeploy/execution/schedulers/registry.h"
#include "mmdeploy/executor.h"
using namespace mmdeploy;

View File

@ -1,11 +1,11 @@
// Copyright (c) OpenMMLab. All rights reserved.
// clang-format off
#include "model.h"
#include "mmdeploy/model.h"
#include <memory>
#include "common_internal.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/logger.h"
#include "mmdeploy/core/model.h"
// clang-format on

View File

@ -8,7 +8,7 @@
#ifndef MMDEPLOY_SRC_APIS_C_MODEL_H_
#define MMDEPLOY_SRC_APIS_C_MODEL_H_
#include "common.h"
#include "mmdeploy/common.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,10 +1,10 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "pipeline.h"
#include "mmdeploy/pipeline.h"
#include "common_internal.h"
#include "executor_internal.h"
#include "handle.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/executor_internal.h"
#include "mmdeploy/handle.h"
int mmdeploy_pipeline_create_v3(mmdeploy_value_t config, mmdeploy_context_t context,
mmdeploy_pipeline_t* pipeline) {
@ -27,6 +27,15 @@ int mmdeploy_pipeline_create_v3(mmdeploy_value_t config, mmdeploy_context_t cont
return MMDEPLOY_E_FAIL;
}
int mmdeploy_pipeline_create_from_model(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_pipeline_t* pipeline) {
auto config = Cast(model)->ReadConfig("pipeline.json");
auto _context = *Cast(context);
_context["model"] = *Cast(model);
return mmdeploy_pipeline_create_v3(Cast(&config.value()), (mmdeploy_context_t)&_context,
pipeline);
}
int mmdeploy_pipeline_apply_async(mmdeploy_pipeline_t pipeline, mmdeploy_sender_t input,
mmdeploy_sender_t* output) {
if (!pipeline || !input || !output) {

View File

@ -3,8 +3,9 @@
#ifndef MMDEPLOY_CSRC_APIS_C_PIPELINE_H_
#define MMDEPLOY_CSRC_APIS_C_PIPELINE_H_
#include "common.h"
#include "executor.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {
@ -24,6 +25,16 @@ typedef struct mmdeploy_pipeline* mmdeploy_pipeline_t;
*/
MMDEPLOY_API int mmdeploy_pipeline_create_v3(mmdeploy_value_t config, mmdeploy_context_t context,
mmdeploy_pipeline_t* pipeline);
/**
* Create pipeline from internal pipeline config of the model
* @param model
* @param context
* @param pipeline
* @return
*/
MMDEPLOY_API int mmdeploy_pipeline_create_from_model(mmdeploy_model_t model,
mmdeploy_context_t context,
mmdeploy_pipeline_t* pipeline);
/**
* @brief Apply pipeline

View File

@ -1,37 +1,21 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "pose_detector.h"
#include "mmdeploy/pose_detector.h"
#include <numeric>
#include "common_internal.h"
#include "handle.h"
#include "mmdeploy/codebase/mmpose/mmpose.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/utils/formatter.h"
#include "pipeline.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/pipeline.h"
using namespace std;
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"name", "pose-detector"},
{"type", "Inference"},
{"params", {{"model", model}, {"batch_size", 1}}},
{"input", {"image"}},
{"output", {"dets"}}
};
// clang-format on
}
} // namespace
int mmdeploy_pose_detector_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_pose_detector_t* detector) {
mmdeploy_context_t context{};
@ -95,8 +79,7 @@ void mmdeploy_pose_detector_destroy(mmdeploy_pose_detector_t detector) {
int mmdeploy_pose_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_pose_detector_t* detector) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)detector);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)detector);
}
int mmdeploy_pose_detector_create_input(const mmdeploy_mat_t* mats, int mat_count,
@ -117,7 +100,7 @@ int mmdeploy_pose_detector_create_input(const mmdeploy_mat_t* mats, int mat_coun
} else {
b = {0, 0, img.width(), img.height(), 1.0};
}
input_images.push_back({{"ori_img", img}, {"bbox", std::move(b)}, {"rotation", 0.f}});
input_images.push_back({{"ori_img", img}, {"bbox", std::move(b)}});
};
for (int i = 0; i < mat_count; ++i) {

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_SRC_APIS_C_POSE_DETECTOR_H_
#define MMDEPLOY_SRC_APIS_C_POSE_DETECTOR_H_
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,225 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "mmdeploy/pose_tracker.h"
#include "mmdeploy/archive/json_archive.h"
#include "mmdeploy/archive/value_archive.h"
#include "mmdeploy/codebase/mmpose/pose_tracker/common.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/mpl/structure.h"
#include "mmdeploy/pipeline.h"
namespace mmdeploy {
using namespace framework;
} // namespace mmdeploy
using namespace mmdeploy;
namespace {
Value config_template() {
static const auto json = R"(
{
"type": "Pipeline",
"input": ["img", "force_det", "state"],
"output": "targets",
"tasks": [
{
"type": "Task",
"name": "prepare",
"module": "pose_tracker::Prepare",
"input": ["img", "force_det", "state"],
"output": "use_det"
},
{
"type": "Task",
"module": "Transform",
"name": "preload",
"input": "img",
"output": "data",
"transforms": [ { "type": "LoadImageFromFile" } ]
},
{
"type": "Cond",
"name": "cond",
"input": ["use_det", "data"],
"output": "dets",
"body": {
"name": "detection",
"type": "Inference",
"params": { "model": "detection" }
}
},
{
"type": "Task",
"name": "process_bboxes",
"module": "pose_tracker::ProcessBboxes",
"input": ["dets", "data", "state"],
"output": ["rois", "track_ids"]
},
{
"input": "*rois",
"output": "*keypoints",
"name": "pose",
"type": "Inference",
"params": { "model": "pose" }
},
{
"type": "Task",
"name": "track_step",
"module": "pose_tracker::TrackStep",
"scheduler": "pool",
"input": ["keypoints", "track_ids", "state"],
"output": "targets"
}
]
}
)"_json;
static const auto config = from_json<Value>(json);
return config;
}
} // namespace
int mmdeploy_pose_tracker_default_params(mmdeploy_pose_tracker_param_t* params) {
mmpose::_pose_tracker::SetDefaultParams(*params);
return 0;
}
int mmdeploy_pose_tracker_create(mmdeploy_model_t det_model, mmdeploy_model_t pose_model,
mmdeploy_context_t context, mmdeploy_pose_tracker_t* pipeline) {
mmdeploy_context_add(context, MMDEPLOY_TYPE_MODEL, "detection", det_model);
mmdeploy_context_add(context, MMDEPLOY_TYPE_MODEL, "pose", pose_model);
auto config = config_template();
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)pipeline);
}
void mmdeploy_pose_tracker_destroy(mmdeploy_pose_tracker_t pipeline) {
mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)pipeline);
}
int mmdeploy_pose_tracker_create_state(mmdeploy_pose_tracker_t pipeline,
const mmdeploy_pose_tracker_param_t* params,
mmdeploy_pose_tracker_state_t* state) {
try {
auto create_fn = gRegistry<Module>().Create("pose_tracker::Create", Value()).value();
*state = reinterpret_cast<mmdeploy_pose_tracker_state_t>(new Value(
create_fn->Process({const_cast<mmdeploy_pose_tracker_param_t*>(params)}).value()[0]));
return MMDEPLOY_SUCCESS;
} catch (const std::exception& e) {
MMDEPLOY_ERROR("unhandled exception: {}", e.what());
} catch (...) {
MMDEPLOY_ERROR("unknown exception caught");
}
return MMDEPLOY_E_FAIL;
}
void mmdeploy_pose_tracker_destroy_state(mmdeploy_pose_tracker_state_t state) {
delete reinterpret_cast<Value*>(state);
}
int mmdeploy_pose_tracker_create_input(mmdeploy_pose_tracker_state_t* states,
const mmdeploy_mat_t* frames, const int32_t* use_detect,
int batch_size, mmdeploy_value_t* value) {
try {
Value::Array images;
Value::Array use_dets;
Value::Array trackers;
for (int i = 0; i < batch_size; ++i) {
images.push_back({{"ori_img", Cast(frames[i])}});
use_dets.emplace_back(use_detect ? use_detect[i] : -1);
trackers.push_back(*reinterpret_cast<Value*>(states[i]));
}
*value = Take(Value{std::move(images), std::move(use_dets), std::move(trackers)});
return MMDEPLOY_SUCCESS;
} catch (const std::exception& e) {
MMDEPLOY_ERROR("unhandled exception: {}", e.what());
} catch (...) {
MMDEPLOY_ERROR("unknown exception caught");
}
return MMDEPLOY_E_FAIL;
}
using ResultType = mmdeploy::Structure<mmdeploy_pose_tracker_target_t, std::vector<int32_t>,
std::vector<mmpose::_pose_tracker::TrackerResult>>;
int mmdeploy_pose_tracker_get_result(mmdeploy_value_t output,
mmdeploy_pose_tracker_target_t** results,
int32_t** result_count) {
if (!output || !results) {
return MMDEPLOY_E_INVALID_ARG;
}
try {
// convert result from Values
std::vector<mmpose::_pose_tracker::TrackerResult> res;
from_value(Cast(output)->front(), res);
size_t total = 0;
for (const auto& r : res) {
total += r.bboxes.size();
}
// preserve space for the output structure
ResultType result_type({total, 1, 1});
auto [result_data, result_cnt, result_holder] = result_type.pointers();
auto result_ptr = result_data;
result_holder->swap(res);
// build output structure
for (auto& r : *result_holder) {
for (int j = 0; j < r.bboxes.size(); ++j) {
auto& p = *result_ptr++;
p.keypoint_count = static_cast<int32_t>(r.keypoints[j].size());
p.keypoints = r.keypoints[j].data();
p.scores = r.scores[j].data();
p.bbox = r.bboxes[j];
p.target_id = r.track_ids[j];
}
result_cnt->push_back(r.bboxes.size());
// debug info
// p.reserved0 = new std::vector(r.pose_input_bboxes);
// p.reserved1 = new std::vector(r.pose_output_bboxes);
}
*results = result_data;
*result_count = result_cnt->data();
result_type.release();
return MMDEPLOY_SUCCESS;
} catch (const std::exception& e) {
MMDEPLOY_ERROR("unhandled exception: {}", e.what());
} catch (...) {
MMDEPLOY_ERROR("unknown exception caught");
}
return MMDEPLOY_E_FAIL;
}
int mmdeploy_pose_tracker_apply(mmdeploy_pose_tracker_t pipeline,
mmdeploy_pose_tracker_state_t* states, const mmdeploy_mat_t* frames,
const int32_t* use_detect, int32_t count,
mmdeploy_pose_tracker_target_t** results, int32_t** result_count) {
wrapped<mmdeploy_value_t> input;
if (auto ec =
mmdeploy_pose_tracker_create_input(states, frames, use_detect, count, input.ptr())) {
return ec;
}
wrapped<mmdeploy_value_t> output;
if (auto ec = mmdeploy_pipeline_apply((mmdeploy_pipeline_t)pipeline, input, output.ptr())) {
return ec;
}
if (auto ec = mmdeploy_pose_tracker_get_result(output, results, result_count)) {
return ec;
}
return MMDEPLOY_SUCCESS;
}
void mmdeploy_pose_tracker_release_result(mmdeploy_pose_tracker_target_t* results,
const int32_t* result_count, int count) {
auto total = std::accumulate(result_count, result_count + count, 0);
ResultType deleter({static_cast<size_t>(total), 1, 1}, results);
}

View File

@ -0,0 +1,158 @@
// Copyright (c) OpenMMLab. All rights reserved.
/**
* @file pose_tracker.h
* @brief Pose tracker C API
*/
#ifndef MMDEPLOY_POSE_TRACKER_H
#define MMDEPLOY_POSE_TRACKER_H
#include "mmdeploy/common.h"
#include "mmdeploy/detector.h"
#include "mmdeploy/model.h"
#include "mmdeploy/pose_detector.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mmdeploy_pose_tracker* mmdeploy_pose_tracker_t;
typedef struct mmdeploy_pose_tracker_state* mmdeploy_pose_tracker_state_t;
typedef struct mmdeploy_pose_tracker_param_t {
// detection interval, default = 1
int32_t det_interval;
// detection label use for pose estimation, default = 0
int32_t det_label;
// detection score threshold, default = 0.5
float det_thr;
// detection minimum bbox size (compute as sqrt(area)), default = -1
float det_min_bbox_size;
// nms iou threshold for merging detected bboxes and bboxes from tracked targets, default = 0.7
float det_nms_thr;
// max number of bboxes used for pose estimation per frame, default = -1
int32_t pose_max_num_bboxes;
// threshold for visible key-points, default = 0.5
float pose_kpt_thr;
// min number of key-points for valid poses (-1 indicates ceil(n_kpts/2)), default = -1
int32_t pose_min_keypoints;
// scale for expanding key-points to bbox, default = 1.25
float pose_bbox_scale;
// min pose bbox size, tracks with bbox size smaller than the threshold will be dropped,
// default = -1
float pose_min_bbox_size;
// nms oks/iou threshold for suppressing overlapped poses, useful when multiple pose estimations
// collapse to the same target, default = 0.5
float pose_nms_thr;
// keypoint sigmas for computing OKS, will use IOU if not set, default = nullptr
float* keypoint_sigmas;
// size of keypoint sigma array, must be consistent with the number of key-points, default = 0
int32_t keypoint_sigmas_size;
// iou threshold for associating missing tracks, default = 0.4
float track_iou_thr;
// max number of missing frames before a missing tracks is removed, default = 10
int32_t track_max_missing;
// track history size, default = 1
int32_t track_history_size;
// weight of position for setting covariance matrices of kalman filters, default = 0.05
float std_weight_position;
// weight of velocity for setting covariance matrices of kalman filters, default = 0.00625
float std_weight_velocity;
// params for the one-euro filter for smoothing the outputs - (beta, fc_min, fc_derivative)
// default = (0.007, 1, 1)
float smooth_params[3];
} mmdeploy_pose_tracker_param_t;
typedef struct mmdeploy_pose_tracker_target_t {
mmdeploy_point_t* keypoints; // key-points of the target
int32_t keypoint_count; // size of `keypoints` array
float* scores; // scores of each key-point
mmdeploy_rect_t bbox; // estimated bbox from key-points
uint32_t target_id; // target id from internal tracker
} mmdeploy_pose_tracker_target_t;
/**
* @brief Fill params with default parameters
* @param[in,out] params
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_pose_tracker_default_params(mmdeploy_pose_tracker_param_t* params);
/**
* @brief Create pose tracker pipeline
* @param[in] det_model detection model object, created by \ref mmdeploy_model_create
* @param[in] pose_model pose model object
* @param[in] context context object describing execution environment (device, profiler, etc...),
* created by \ref mmdeploy_context_create
* @param[out] pipeline handle of the created pipeline
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_pose_tracker_create(mmdeploy_model_t det_model,
mmdeploy_model_t pose_model,
mmdeploy_context_t context,
mmdeploy_pose_tracker_t* pipeline);
/**
* @brief Destroy pose tracker pipeline
* @param[in] pipeline
*/
MMDEPLOY_API void mmdeploy_pose_tracker_destroy(mmdeploy_pose_tracker_t pipeline);
/**
* @brief Create a tracker state handle corresponds to a video stream
* @param[in] pipeline handle of a pose tracker pipeline
* @param[in] params params for creating the tracker state
* @param[out] state handle of the created tracker state
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_pose_tracker_create_state(mmdeploy_pose_tracker_t pipeline,
const mmdeploy_pose_tracker_param_t* params,
mmdeploy_pose_tracker_state_t* state);
/**
* @brief Destroy tracker state
* @param[in] state handle of the tracker state
*/
MMDEPLOY_API void mmdeploy_pose_tracker_destroy_state(mmdeploy_pose_tracker_state_t state);
/**
* @brief Apply pose tracker pipeline, notice that this function supports batch operation by feeding
* arrays of size \p count to \p states, \p frames and \p use_detect
* @param[in] pipeline handle of a pose tracker pipeline
* @param[in] states tracker states handles, array of size \p count
* @param[in] frames input frames of size \p count
* @param[in] use_detect control the use of detector, array of size \p count
* -1: use params.det_interval, 0: don't use detector, 1: force use detector
* @param[in] count batch size
* @param[out] results a linear buffer contains the tracked targets of input frames. Should be
* released by \ref mmdeploy_pose_tracker_release_result
* @param[out] result_count a linear buffer of size \p count contains the number of tracked
* targets of the frames. Should be released by \ref mmdeploy_pose_tracker_release_result
* @return status of the operation
*/
MMDEPLOY_API int mmdeploy_pose_tracker_apply(mmdeploy_pose_tracker_t pipeline,
mmdeploy_pose_tracker_state_t* states,
const mmdeploy_mat_t* frames,
const int32_t* use_detect, int32_t count,
mmdeploy_pose_tracker_target_t** results,
int32_t** result_count);
/**
* @brief Release result objects
* @param[in] results
* @param[in] result_count
* @param[in] count
*/
MMDEPLOY_API void mmdeploy_pose_tracker_release_result(mmdeploy_pose_tracker_target_t* results,
const int32_t* result_count, int count);
#ifdef __cplusplus
}
#endif
#endif // MMDEPLOY_POSE_TRACKER_H

View File

@ -1,37 +1,21 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "restorer.h"
#include "mmdeploy/restorer.h"
#include "common_internal.h"
#include "executor_internal.h"
#include "handle.h"
#include "mmdeploy/codebase/mmedit/mmedit.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/mpl/structure.h"
#include "mmdeploy/core/utils/formatter.h"
#include "pipeline.h"
#include "mmdeploy/executor_internal.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/pipeline.h"
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"name", "restorer"},
{"type", "Inference"},
{"params", {{"model", model}}},
{"input", {"img"}},
{"output", {"out"}}
};
// clang-format on
}
using ResultType = mmdeploy::Structure<mmdeploy_mat_t, mmdeploy::framework::Buffer>;
} // namespace
int mmdeploy_restorer_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_restorer_t* restorer) {
mmdeploy_context_t context{};
@ -81,8 +65,7 @@ void mmdeploy_restorer_destroy(mmdeploy_restorer_t restorer) {
int mmdeploy_restorer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_restorer_t* restorer) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)restorer);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)restorer);
}
int mmdeploy_restorer_create_input(const mmdeploy_mat_t* mats, int mat_count,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_SRC_APIS_C_RESTORER_H_
#define MMDEPLOY_SRC_APIS_C_RESTORER_H_
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,36 +1,20 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "rotated_detector.h"
#include "mmdeploy/rotated_detector.h"
#include <numeric>
#include "common_internal.h"
#include "handle.h"
#include "mmdeploy/codebase/mmrotate/mmrotate.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/utils/formatter.h"
#include "pipeline.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/pipeline.h"
using namespace std;
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"name", "mmrotate"},
{"type", "Inference"},
{"params", {{"model", model}}},
{"input", {"image"}},
{"output", {"det"}}
};
// clang-format on
}
} // namespace
int mmdeploy_rotated_detector_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_rotated_detector_t* detector) {
mmdeploy_context_t context{};
@ -84,8 +68,7 @@ void mmdeploy_rotated_detector_destroy(mmdeploy_rotated_detector_t detector) {
int mmdeploy_rotated_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_rotated_detector_t* detector) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)detector);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)detector);
}
int mmdeploy_rotated_detector_create_input(const mmdeploy_mat_t* mats, int mat_count,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_SRC_APIS_C_ROTATED_DETECTOR_H_
#define MMDEPLOY_SRC_APIS_C_ROTATED_DETECTOR_H_
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,39 +1,23 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "segmentor.h"
#include "mmdeploy/segmentor.h"
#include "common_internal.h"
#include "handle.h"
#include "mmdeploy/codebase/mmseg/mmseg.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/graph.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/mpl/structure.h"
#include "mmdeploy/core/tensor.h"
#include "mmdeploy/core/utils/formatter.h"
#include "pipeline.h"
#include "mmdeploy/handle.h"
#include "mmdeploy/pipeline.h"
using namespace std;
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"name", "segmentor"},
{"type", "Inference"},
{"params", {{"model", model}}},
{"input", {"img"}},
{"output", {"mask"}}
};
// clang-format on
}
using ResultType = mmdeploy::Structure<mmdeploy_segmentation_t, mmdeploy::framework::Buffer>;
} // namespace
int mmdeploy_segmentor_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_segmentor_t* segmentor) {
mmdeploy_context_t context{};
@ -83,8 +67,7 @@ void mmdeploy_segmentor_destroy(mmdeploy_segmentor_t segmentor) {
int mmdeploy_segmentor_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_segmentor_t* segmentor) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)segmentor);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)segmentor);
}
int mmdeploy_segmentor_create_input(const mmdeploy_mat_t* mats, int mat_count,
@ -119,10 +102,17 @@ int mmdeploy_segmentor_get_result(mmdeploy_value_t output, mmdeploy_segmentation
results_ptr->height = segmentor_output.height;
results_ptr->width = segmentor_output.width;
results_ptr->classes = segmentor_output.classes;
auto mask_size = results_ptr->height * results_ptr->width;
auto& mask = segmentor_output.mask;
results_ptr->mask = mask.data<int>();
buffers[i] = mask.buffer();
auto& score = segmentor_output.score;
results_ptr->mask = nullptr;
results_ptr->score = nullptr;
if (mask.shape().size()) {
results_ptr->mask = mask.data<int>();
buffers[i] = mask.buffer();
} else {
results_ptr->score = score.data<float>();
buffers[i] = score.buffer();
}
}
*results = results_data;

View File

@ -8,20 +8,23 @@
#ifndef MMDEPLOY_SEGMENTOR_H
#define MMDEPLOY_SEGMENTOR_H
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mmdeploy_segmentation_t {
int height; ///< height of \p mask that equals to the input image's height
int width; ///< width of \p mask that equals to the input image's width
int classes; ///< the number of labels in \p mask
int* mask; ///< segmentation mask of the input image, in which mask[i * width + j] indicates
///< the label id of pixel at (i, j)
int height; ///< height of \p mask that equals to the input image's height
int width; ///< width of \p mask that equals to the input image's width
int classes; ///< the number of labels in \p mask
int* mask; ///< segmentation mask of the input image, in which mask[i * width + j] indicates
///< the label id of pixel at (i, j), this field might be null
float* score; ///< segmentation score map of the input image in CHW format, in which
///< score[height * width * k + i * width + j] indicates the score
///< of class k at pixel (i, j), this field might be null
} mmdeploy_segmentation_t;
typedef struct mmdeploy_segmentor* mmdeploy_segmentor_t;

View File

@ -1,37 +1,21 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "text_detector.h"
#include "mmdeploy/text_detector.h"
#include <numeric>
#include "common_internal.h"
#include "executor_internal.h"
#include "mmdeploy/codebase/mmocr/mmocr.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/model.h"
#include "mmdeploy/core/status_code.h"
#include "mmdeploy/core/utils/formatter.h"
#include "model.h"
#include "pipeline.h"
#include "mmdeploy/executor_internal.h"
#include "mmdeploy/model.h"
#include "mmdeploy/pipeline.h"
using namespace std;
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"name", "detector"},
{"type", "Inference"},
{"params", {{"model", model}}},
{"input", {"img"}},
{"output", {"dets"}}
};
// clang-format on
}
} // namespace
int mmdeploy_text_detector_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_text_detector_t* detector) {
mmdeploy_context_t context{};
@ -46,8 +30,7 @@ int mmdeploy_text_detector_create(mmdeploy_model_t model, const char* device_nam
int mmdeploy_text_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_text_detector_t* detector) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)detector);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)detector);
}
int mmdeploy_text_detector_create_by_path(const char* model_path, const char* device_name,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_TEXT_DETECTOR_H
#define MMDEPLOY_TEXT_DETECTOR_H
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,21 +1,21 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "text_recognizer.h"
#include "mmdeploy/text_recognizer.h"
#include <numeric>
#include "common_internal.h"
#include "executor_internal.h"
#include "mmdeploy/archive/value_archive.h"
#include "mmdeploy/codebase/mmocr/mmocr.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/model.h"
#include "mmdeploy/core/status_code.h"
#include "mmdeploy/core/utils/formatter.h"
#include "mmdeploy/core/value.h"
#include "model.h"
#include "pipeline.h"
#include "mmdeploy/executor_internal.h"
#include "mmdeploy/model.h"
#include "mmdeploy/pipeline.h"
using namespace mmdeploy;
@ -38,7 +38,7 @@ Value config_template(const Model& model) {
{"type", "Inference"},
{"input", "patches"},
{"output", "texts"},
{"params", {{"model", std::move(model)}}},
{"params", {{"model", model}}},
}
}
},

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_SRC_APIS_C_TEXT_RECOGNIZER_H_
#define MMDEPLOY_SRC_APIS_C_TEXT_RECOGNIZER_H_
#include "common.h"
#include "executor.h"
#include "text_detector.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/text_detector.h"
#ifdef __cplusplus
extern "C" {

View File

@ -1,49 +1,25 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include "video_recognizer.h"
#include "mmdeploy/video_recognizer.h"
#include <numeric>
#include <vector>
#include "common_internal.h"
#include "executor_internal.h"
#include "mmdeploy/archive/value_archive.h"
#include "mmdeploy/codebase/mmaction/mmaction.h"
#include "mmdeploy/common_internal.h"
#include "mmdeploy/core/device.h"
#include "mmdeploy/core/mat.h"
#include "mmdeploy/core/model.h"
#include "mmdeploy/core/status_code.h"
#include "mmdeploy/core/utils/formatter.h"
#include "mmdeploy/core/value.h"
#include "model.h"
#include "pipeline.h"
#include "mmdeploy/executor_internal.h"
#include "mmdeploy/model.h"
#include "mmdeploy/pipeline.h"
using namespace mmdeploy;
namespace {
Value config_template(const Model& model) {
// clang-format off
return {
{"type", "Pipeline"},
{"input", {"video"}},
{
"tasks", {
{
{"name", "Video Recognizer"},
{"type", "Inference"},
{"input", "video"},
{"output", "label"},
{"params", {{"model", std::move(model)}}},
}
}
},
{"output", "label"},
};
// clang-format on
}
} // namespace
int mmdeploy_video_recognizer_create(mmdeploy_model_t model, const char* device_name, int device_id,
mmdeploy_video_recognizer_t* recognizer) {
mmdeploy_context_t context{};
@ -101,8 +77,7 @@ void mmdeploy_video_recognizer_destroy(mmdeploy_video_recognizer_t recognizer) {
int mmdeploy_video_recognizer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context,
mmdeploy_video_recognizer_t* recognizer) {
auto config = config_template(*Cast(model));
return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)recognizer);
return mmdeploy_pipeline_create_from_model(model, context, (mmdeploy_pipeline_t*)recognizer);
}
int mmdeploy_video_recognizer_create_input(const mmdeploy_mat_t* images,

View File

@ -8,9 +8,9 @@
#ifndef MMDEPLOY_VIDEO_RECOGNIZER_H
#define MMDEPLOY_VIDEO_RECOGNIZER_H
#include "common.h"
#include "executor.h"
#include "model.h"
#include "mmdeploy/common.h"
#include "mmdeploy/executor.h"
#include "mmdeploy/model.h"
#ifdef __cplusplus
extern "C" {

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMDeploy", "MMDeploy\MMDeploy.csproj", "{3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMDeploy", "MMDeploy\MMDeployCSharp.csproj", "{3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}"
EndProject
Global

View File

@ -0,0 +1,69 @@
namespace MMDeploy
{
/// <summary>
/// Context.
/// </summary>
public class Context : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Context"/> class.
/// </summary>
public Context()
{
ThrowException(NativeMethods.mmdeploy_context_create(out _handle));
}
/// <summary>
/// Initializes a new instance of the <see cref="Context"/> class with device.
/// </summary>
/// <param name="device">device.</param>
public Context(Device device) : this()
{
Add(device);
}
/// <summary>
/// Add model to the context.
/// </summary>
/// <param name="name">name.</param>
/// <param name="model">model.</param>
public void Add(string name, Model model)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.MODEL, name, model));
}
/// <summary>
/// Add scheduler to the context.
/// </summary>
/// <param name="name">name.</param>
/// <param name="scheduler">scheduler.</param>
public void Add(string name, Scheduler scheduler)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.SCHEDULER, name, scheduler));
}
/// <summary>
/// Add device to the context.
/// </summary>
/// <param name="device">device.</param>
public void Add(Device device)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.DEVICE, "", device));
}
/// <summary>
/// Add profiler to the context.
/// </summary>
/// <param name="profiler">profiler.</param>
public void Add(Profiler profiler)
{
ThrowException(NativeMethods.mmdeploy_context_add(this, (int)ContextType.PROFILER, "", profiler));
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_model_destroy(_handle);
}
}
}

View File

@ -0,0 +1,39 @@
namespace MMDeploy
{
/// <summary>
/// Device.
/// </summary>
public class Device : DisposableObject
{
private readonly string _name;
private readonly int _index;
/// <summary>
/// Initializes a new instance of the <see cref="Device"/> class.
/// </summary>
/// <param name="name">device name.</param>
/// <param name="index">device index.</param>
public Device(string name, int index = 0)
{
this._name = name;
this._index = index;
ThrowException(NativeMethods.mmdeploy_device_create(name, index, out _handle));
}
/// <summary>
/// Gets device name.
/// </summary>
public string Name { get => _name; }
/// <summary>
/// Gets device index.
/// </summary>
public int Index { get => _index; }
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_device_destroy(_handle);
}
}
}

View File

@ -92,5 +92,11 @@ namespace MMDeploy
throw new Exception(result.ToString());
}
}
/// <summary>
/// Gets internal handle.
/// </summary>
/// <param name="obj">instance.</param>
public static implicit operator IntPtr(DisposableObject obj) => obj._handle;
}
}

View File

@ -0,0 +1,23 @@
namespace MMDeploy
{
/// <summary>
/// model.
/// </summary>
public class Model : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Model"/> class.
/// </summary>
/// <param name="modelPath">model path.</param>
public Model(string modelPath)
{
ThrowException(NativeMethods.mmdeploy_model_create_by_path(modelPath, out _handle));
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_model_destroy(_handle);
}
}
}

View File

@ -0,0 +1,350 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace MMDeploy
{
#pragma warning disable 0649
internal unsafe struct CPoseTrack
{
public Pointf* Keypoints;
public int KeypointCount;
public float* Scores;
public Rect Bbox;
public int TargetId;
}
#pragma warning restore 0649
/// <summary>
/// Single tracking result of a bbox.
/// A picture may contains multiple reuslts.
/// </summary>
public struct PoseTrack
{
/// <summary>
/// Keypoints.
/// </summary>
public List<Pointf> Keypoints;
/// <summary>
/// Scores.
/// </summary>
public List<float> Scores;
/// <summary>
/// Bbox.
/// </summary>
public Rect Bbox;
/// <summary>
/// TargetId.
/// </summary>
public int TargetId;
/// <summary>
/// Init data.
/// </summary>
private void Init()
{
if (Keypoints == null || Scores == null)
{
Keypoints = new List<Pointf>();
Scores = new List<float>();
}
}
internal unsafe void Add(CPoseTrack* result)
{
Init();
for (int i = 0; i < result->KeypointCount; i++)
{
Keypoints.Add(new Pointf(result->Keypoints[i].X, result->Keypoints[i].Y));
Scores.Add(result->Scores[i]);
}
Bbox = result->Bbox;
TargetId = result->TargetId;
}
}
/// <summary>
/// Output of PoseTracker.
/// </summary>
public struct PoseTrackerOutput
{
/// <summary>
/// Tracking results for single image.
/// </summary>
public List<PoseTrack> Results;
/// <summary>
/// Gets number of output.
/// </summary>
public int Count
{
get { return (Results == null) ? 0 : Results.Count; }
}
/// <summary>
/// Result for box level.
/// </summary>
/// <param name="boxRes">Box res.</param>
public void Add(PoseTrack boxRes)
{
if (Results == null)
{
Results = new List<PoseTrack>();
}
Results.Add(boxRes);
}
}
/// <summary>
/// PoseTracker.
/// </summary>
public class PoseTracker : DisposableObject
{
/// <summary>
/// Params.
/// </summary>
public struct Params
{
/// <summary>
/// init with default value.
/// </summary>
public void Init()
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Params)));
NativeMethods.mmdeploy_pose_tracker_default_params(ptr);
this = Marshal.PtrToStructure<Params>(ptr);
Marshal.DestroyStructure<Params>(ptr);
Marshal.FreeHGlobal(ptr);
}
/// <summary>
/// Sets keypoint sigmas.
/// </summary>
/// <param name="array">keypoint sigmas.</param>
public void SetKeypointSigmas(float[] array)
{
this.KeypointSigmasSize = array.Length;
this.KeypointSigmas = Marshal.AllocHGlobal(sizeof(float) * array.Length);
Marshal.Copy(array, 0, this.KeypointSigmas, array.Length);
}
/// <summary>
/// Release ptr.
/// </summary>
public void DeleteKeypointSigmas()
{
if (this.KeypointSigmas != null)
{
Marshal.FreeHGlobal(this.KeypointSigmas);
this.KeypointSigmasSize = 0;
}
}
/// <summary>
/// detection interval, default = 1.
/// </summary>
public int DetInterval;
/// <summary>
/// detection label use for pose estimation, default = 0.
/// </summary>
public int DetLabel;
/// <summary>
/// detection score threshold, default = 0.5.
/// </summary>
public float DetThr;
/// <summary>
/// detection minimum bbox size (compute as sqrt(area)), default = -1.
/// </summary>
public float DetMinBboxSize;
/// <summary>
/// nms iou threshold for merging detected bboxes and bboxes from tracked targets, default = 0.7.
/// </summary>
public float DetNmsThr;
/// <summary>
/// max number of bboxes used for pose estimation per frame, default = -1.
/// </summary>
public int PoseMaxNumBboxes;
/// <summary>
/// threshold for visible key-points, default = 0.5.
/// </summary>
public float PoseKptThr;
/// <summary>
/// min number of key-points for valid poses, default = -1.
/// </summary>
public int PoseMinKeypoints;
/// <summary>
/// scale for expanding key-points to bbox, default = 1.25.
/// </summary>
public float PoseBboxScale;
/// <summary>
/// min pose bbox size, tracks with bbox size smaller than the threshold will be dropped,default = -1.
/// </summary>
public float PoseMinBboxSize;
/// <summary>
/// nms oks/iou threshold for suppressing overlapped poses, useful when multiple pose estimations
/// collapse to the same target, default = 0.5.
/// </summary>
public float PoseNmsThr;
/// <summary>
/// keypoint sigmas for computing OKS, will use IOU if not set, default = nullptr.
/// </summary>
public IntPtr KeypointSigmas;
/// <summary>
/// size of keypoint sigma array, must be consistent with the number of key-points, default = 0.
/// </summary>
public int KeypointSigmasSize;
/// <summary>
/// iou threshold for associating missing tracks, default = 0.4.
/// </summary>
public float TrackIouThr;
/// <summary>
/// max number of missing frames before a missing tracks is removed, default = 10.
/// </summary>
public int TrackMaxMissing;
/// <summary>
/// track history size, default = 1.
/// </summary>
public int TrackHistorySize;
/// <summary>
/// weight of position for setting covariance matrices of kalman filters, default = 0.05.
/// </summary>
public float StdWeightPosition;
/// <summary>
/// weight of velocity for setting covariance matrices of kalman filters, default = 0.00625.
/// </summary>
public float StdWeightVelocity;
/// <summary>
/// params for the one-euro filter for smoothing the outputs - (beta, fc_min, fc_derivative)
/// default = (0.007, 1, 1).
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public float[] SmoothParams;
}
/// <summary>
/// tracking state.
/// </summary>
public class State : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="State"/> class.
/// </summary>
/// <param name="pipeline">pipeline.</param>
/// <param name="param">param.</param>
public State(IntPtr pipeline, Params param)
{
ThrowException(NativeMethods.mmdeploy_pose_tracker_create_state(pipeline, param, out _handle));
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_pose_tracker_destroy_state(_handle);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="PoseTracker"/> class.
/// </summary>
/// <param name="detect">detect model.</param>
/// <param name="pose">pose model.</param>
/// <param name="context">context.</param>
public PoseTracker(Model detect, Model pose, Context context)
{
ThrowException(NativeMethods.mmdeploy_pose_tracker_create(detect, pose, context, out _handle));
}
/// <summary>
/// Get track information of image.
/// </summary>
/// <param name="state">state for video.</param>
/// <param name="mat">input mat.</param>
/// <param name="detect">control the use of detector.
/// -1: use params.DetInterval, 0: don't use detector, 1: force use detector.</param>
/// <returns>results of this frame.</returns>
public PoseTrackerOutput Apply(State state, Mat mat, int detect = -1)
{
PoseTrackerOutput output = default;
IntPtr[] states = new IntPtr[1] { state };
Mat[] mats = new Mat[1] { mat };
int[] detects = new int[1] { -1 };
unsafe
{
CPoseTrack* results = null;
int* resultCount = null;
fixed (Mat* _mats = mats)
fixed (IntPtr* _states = states)
fixed (int* _detects = detects)
{
ThrowException(NativeMethods.mmdeploy_pose_tracker_apply(_handle, _states, _mats, _detects,
mats.Length, &results, &resultCount));
FormatResult(resultCount, results, ref output, out var total);
ReleaseResult(results, resultCount, mats.Length);
}
}
return output;
}
private unsafe void FormatResult(int* resultCount, CPoseTrack* results, ref PoseTrackerOutput output, out int total)
{
total = resultCount[0];
for (int i = 0; i < total; i++)
{
PoseTrack outi = default;
outi.Add(results);
output.Add(outi);
results++;
}
}
private unsafe void ReleaseResult(CPoseTrack* results, int* resultCount, int count)
{
NativeMethods.mmdeploy_pose_tracker_release_result(results, resultCount, count);
}
/// <summary>
/// Create internal state.
/// </summary>
/// <param name="param">instance of Params.</param>
/// <returns>instance of State.</returns>
public State CreateState(Params param)
{
State state = new State(_handle, param);
return state;
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
// _state.Dispose();
NativeMethods.mmdeploy_pose_tracker_destroy(_handle);
}
}
}

View File

@ -0,0 +1,23 @@
namespace MMDeploy
{
/// <summary>
/// Profiler.
/// </summary>
public class Profiler : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Profiler"/> class.
/// </summary>
/// <param name="path">path.</param>
public Profiler(string path)
{
ThrowException(NativeMethods.mmdeploy_profiler_create(path, out _handle));
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_profiler_destroy(_handle);
}
}
}

View File

@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
namespace MMDeploy
{
/// <summary>
/// Single detection result of a picture.
/// A picture may contains multiple reuslts.
/// </summary>
public struct RDetect
{
/// <summary>
/// Label id.
/// </summary>
public int LabelId;
/// <summary>
/// Score.
/// </summary>
public float Score;
/// <summary>
/// Center x.
/// </summary>
public float Cx;
/// <summary>
/// Center y.
/// </summary>
public float Cy;
/// <summary>
/// Width.
/// </summary>
public float Width;
/// <summary>
/// Height.
/// </summary>
public float Height;
/// <summary>
/// Angle.
/// </summary>
public float Angle;
internal unsafe RDetect(RDetect* result) : this()
{
this = *result;
}
}
/// <summary>
/// Output of RotatedDetector.
/// </summary>
public struct RotatedDetectorOutput
{
/// <summary>
/// Rotated detection results for single image.
/// </summary>
public List<RDetect> Results;
private void Init()
{
if (Results == null)
{
Results = new List<RDetect>();
}
}
internal unsafe void Add(RDetect* result)
{
Init();
Results.Add(new RDetect(result));
}
/// <summary>
/// Gets number of output.
/// </summary>
public int Count
{
get { return (Results == null) ? 0 : Results.Count; }
}
}
/// <summary>
/// RotatedDetector.
/// </summary>
public class RotatedDetector : DisposableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="RotatedDetector"/> class.
/// </summary>
/// <param name="modelPath">model path.</param>
/// <param name="deviceName">device name.</param>
/// <param name="deviceId">device id.</param>
public RotatedDetector(string modelPath, string deviceName, int deviceId)
{
ThrowException(NativeMethods.mmdeploy_rotated_detector_create_by_path(modelPath,
deviceName, deviceId, out _handle));
}
/// <summary>
/// Get information of each image in a batch.
/// </summary>
/// <param name="mats">input mats.</param>
/// <returns>Results of each input mat.</returns>
public List<RotatedDetectorOutput> Apply(Mat[] mats)
{
List<RotatedDetectorOutput> output = new List<RotatedDetectorOutput>();
unsafe
{
RDetect* results = null;
int* resultCount = null;
fixed (Mat* _mats = mats)
{
ThrowException(NativeMethods.mmdeploy_rotated_detector_apply(_handle,
_mats, mats.Length, &results, &resultCount));
}
FormatResult(mats.Length, resultCount, results, ref output, out var total);
ReleaseResult(results, resultCount);
}
return output;
}
private unsafe void FormatResult(int matCount, int* resultCount, RDetect* results,
ref List<RotatedDetectorOutput> output, out int total)
{
total = matCount;
for (int i = 0; i < matCount; i++)
{
RotatedDetectorOutput outi = default;
for (int j = 0; j < resultCount[i]; j++)
{
outi.Add(results);
results++;
}
output.Add(outi);
}
}
private unsafe void ReleaseResult(RDetect* results, int* resultCount)
{
NativeMethods.mmdeploy_rotated_detector_release_result(results, resultCount);
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_rotated_detector_destroy(_handle);
}
}
}

View File

@ -0,0 +1,51 @@
using System;
namespace MMDeploy
{
/// <summary>
/// Scheduler.
/// </summary>
public class Scheduler : DisposableObject
{
private Scheduler()
{
}
/// <summary>
/// Create thread pool scheduler.
/// </summary>
/// <param name="num_threads">thread number.</param>
/// <returns>scheduler.</returns>
public static Scheduler ThreadPool(int num_threads)
{
Scheduler result = new Scheduler();
unsafe
{
result._handle = (IntPtr)NativeMethods.mmdeploy_executor_create_thread_pool(num_threads);
}
return result;
}
/// <summary>
/// Create single thread scheduler.
/// </summary>
/// <returns>scheduler.</returns>
public static Scheduler Thread()
{
Scheduler result = new Scheduler();
unsafe
{
result._handle = (IntPtr)NativeMethods.mmdeploy_executor_create_thread();
}
return result;
}
/// <inheritdoc/>
protected override void ReleaseHandle()
{
NativeMethods.mmdeploy_scheduler_destroy(_handle);
}
}
}

View File

@ -10,6 +10,7 @@ namespace MMDeploy
public int Width;
public int Classes;
public int* Mask;
public float* Score;
}
#pragma warning restore 0649
@ -34,10 +35,16 @@ namespace MMDeploy
public int Classes;
/// <summary>
/// Mask data.
/// Mask data, mask[i * width + j] indicates the label id of pixel at (i, j).
/// </summary>
public int[] Mask;
/// <summary>
/// Score data, score[height * width * k + i * width + j] indicates the score
/// of class k at pixel (i, j).
/// </summary>
public float[] Score;
/// <summary>
/// Initializes a new instance of the <see cref="SegmentorOutput"/> struct.
/// </summary>
@ -45,13 +52,31 @@ namespace MMDeploy
/// <param name="width">width.</param>
/// <param name="classes">classes.</param>
/// <param name="mask">mask.</param>
public SegmentorOutput(int height, int width, int classes, int[] mask)
/// <param name="score">score.</param>
public SegmentorOutput(int height, int width, int classes, int[] mask, float[] score)
{
Height = height;
Width = width;
Classes = classes;
Mask = new int[Height * Width];
Array.Copy(mask, this.Mask, mask.Length);
if (mask.Length > 0)
{
Mask = new int[Height * Width];
Array.Copy(mask, this.Mask, mask.Length);
}
else
{
Mask = new int[] { };
}
if (score.Length > 0)
{
Score = new float[Height * Width * Classes];
Array.Copy(score, this.Score, score.Length);
}
else
{
Score = new float[] { };
}
}
internal unsafe SegmentorOutput(CSegment* result)
@ -59,11 +84,34 @@ namespace MMDeploy
Height = result->Height;
Width = result->Width;
Classes = result->Classes;
Mask = new int[Height * Width];
int nbytes = Height * Width * sizeof(int);
fixed (int* data = this.Mask)
if (result->Mask != null)
{
Buffer.MemoryCopy(result->Mask, data, nbytes, nbytes);
Mask = new int[Height * Width];
int nbytes = Height * Width * sizeof(int);
fixed (int* data = this.Mask)
{
Buffer.MemoryCopy(result->Mask, data, nbytes, nbytes);
}
}
else
{
Mask = new int[] { };
}
if (result->Score != null)
{
Score = new float[Height * Width * Classes];
int nbytes = Height * Width * Classes * sizeof(float);
fixed (float* data = this.Score)
{
Buffer.MemoryCopy(result->Score, data, nbytes, nbytes);
}
}
else
{
Score = new float[] { };
}
}
}

View File

@ -99,7 +99,7 @@ namespace MMDeploy
}
/// <summary>
/// Output of DetectorOutput.
/// Output of TextDetector.
/// </summary>
public struct TextDetectorOutput
{

View File

@ -89,4 +89,17 @@ namespace MMDeploy
Y = y;
}
}
/// <summary>
/// Context type.
/// </summary>
public enum ContextType
{
DEVICE = 0,
STREAM = 1,
MODEL = 2,
SCHEDULER = 3,
MAT = 4,
PROFILER = 5,
}
}

View File

@ -9,6 +9,37 @@ namespace MMDeploy
/// </summary>
internal static partial class NativeMethods
{
#region common.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_context_create(out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_context_create_by_device(string deviceName, int deviceId,
out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void mmdeploy_context_destroy(IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_context_add(IntPtr handle, int type, string name,
IntPtr obj);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_device_create(string device_name, int device_id,
out IntPtr device);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void mmdeploy_device_destroy(IntPtr device);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_profiler_create(string path, out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe void mmdeploy_profiler_destroy(IntPtr handle);
#endregion
#region scheduler.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe void* mmdeploy_executor_create_thread();
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe void* mmdeploy_executor_create_thread_pool(int num_threads);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void mmdeploy_scheduler_destroy(IntPtr handle);
#endregion
#region model.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_model_create_by_path(string path, out IntPtr handle);
@ -38,6 +69,27 @@ namespace MMDeploy
public static extern void mmdeploy_pose_detector_destroy(IntPtr handle);
#endregion
#region pose_tracker.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_pose_tracker_create(IntPtr det_model, IntPtr pose_model,
IntPtr context, out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_pose_tracker_destroy(IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_pose_tracker_default_params(IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_pose_tracker_create_state(IntPtr pipeline,
PoseTracker.Params param, out IntPtr state);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void mmdeploy_pose_tracker_destroy_state(IntPtr state);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe int mmdeploy_pose_tracker_apply(IntPtr handle, IntPtr* state,
Mat* mats, int* useDet, int count, CPoseTrack** results, int** resultCount);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe void mmdeploy_pose_tracker_release_result(CPoseTrack* results,
int* resultCount, int count);
#endregion
#region classifier.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_classifier_create(IntPtr model, string deviceName,
@ -55,6 +107,23 @@ namespace MMDeploy
public static extern void mmdeploy_classifier_destroy(IntPtr handle);
#endregion
#region rotated_detector.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_rotated_detector_create(IntPtr model,
string deviceName, int deviceId, out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_rotated_detector_create_by_path(string modelPath,
string deviceName, int deviceId, out IntPtr handle);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe int mmdeploy_rotated_detector_apply(IntPtr handle, Mat* mats,
int matCount, RDetect** results, int** resultCount);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern unsafe void mmdeploy_rotated_detector_release_result(RDetect* results,
int* resultCount);
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void mmdeploy_rotated_detector_destroy(IntPtr handle);
#endregion
#region detector.h
[Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int mmdeploy_detector_create(IntPtr model, string deviceName,

View File

@ -3,27 +3,42 @@
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_cxx_api)
if (MMDEPLOY_BUILD_SDK_CXX_API)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
set(_tasks ${MMDEPLOY_TASKS} pipeline)
foreach (task ${_tasks})
target_link_libraries(mmdeploy_${task} INTERFACE ${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${task}.hpp
DESTINATION include/mmdeploy)
endforeach ()
if (TARGET mmdeploy)
target_link_libraries(mmdeploy INTERFACE ${PROJECT_NAME})
endif ()
mmdeploy_export(${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
set(_tasks ${MMDEPLOY_TASKS} pipeline)
foreach (task ${_tasks})
target_link_libraries(mmdeploy_${task} INTERFACE ${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${task}.hpp
DESTINATION include/mmdeploy)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
FILES_MATCHING
PATTERN "*.cxx"
endforeach ()
if (TARGET mmdeploy)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/csrc>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/outcome>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/json>
)
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/outcome>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/json>
)
if (NOT MMDEPLOY_SPDLOG_EXTERNAL)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/spdlog/include>
$<INSTALL_INTERFACE:include/mmdeploy/third_party>)
endif ()
target_link_libraries(mmdeploy INTERFACE ${PROJECT_NAME})
else ()
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
endif ()
mmdeploy_export_impl(${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
DESTINATION include/mmdeploy)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
FILES_MATCHING
PATTERN "*.cxx"
PATTERN "*.h"
)

View File

@ -6,6 +6,7 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "mmdeploy/common.h"
#include "mmdeploy/core/mpl/span.h"
@ -28,6 +29,30 @@ namespace cxx {
using Rect = mmdeploy_rect_t;
template <typename T>
class UniqueHandle : public NonCopyable {
public:
UniqueHandle() = default;
explicit UniqueHandle(T handle) : handle_(handle) {}
// derived class must destroy the object and reset `handle_`
~UniqueHandle() { assert(handle_ == nullptr); }
UniqueHandle(UniqueHandle&& o) noexcept : handle_(std::exchange(o.handle_, nullptr)) {}
UniqueHandle& operator=(UniqueHandle&& o) noexcept {
if (this != &o) {
handle_ = std::exchange(o.handle_, nullptr);
}
return *this;
}
explicit operator T() const noexcept { return handle_; }
T operator->() const noexcept { return handle_; }
protected:
T handle_{};
};
class Model {
public:
explicit Model(const char* path) {
@ -39,6 +64,8 @@ class Model {
model_.reset(model, [](auto p) { mmdeploy_model_destroy(p); });
}
explicit Model(const std::string& path) : Model(path.c_str()) {}
Model(const void* buffer, size_t size) {
mmdeploy_model_t model{};
auto ec = mmdeploy_model_create(buffer, static_cast<int>(size), &model);
@ -102,6 +129,8 @@ class Mat {
mmdeploy_data_type_t type, uint8_t* data, mmdeploy_device_t device = nullptr)
: desc_{data, height, width, channels, format, type, device} {}
Mat(const mmdeploy_mat_t& desc) : desc_(desc) {} // NOLINT
const mmdeploy_mat_t& desc() const noexcept { return desc_; }
#if MMDEPLOY_CXX_USE_OPENCV
@ -146,6 +175,16 @@ class Mat {
template <typename T>
class Result_ {
public:
using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using reference = T&;
using const_reference = const T&;
using pointer = T*;
using const_pointer = const T*;
using iterator = T*;
using const_iterator = T*;
Result_(size_t offset, size_t size, std::shared_ptr<T> data)
: offset_(offset), size_(size), data_(std::move(data)) {}

View File

@ -0,0 +1,151 @@
// Copyright (c) OpenMMLab. All rights reserved.
#ifndef MMDEPLOY_POSE_TRACKER_HPP
#define MMDEPLOY_POSE_TRACKER_HPP
#include "mmdeploy/common.hpp"
#include "mmdeploy/pose_tracker.h"
namespace mmdeploy {
namespace cxx {
class PoseTracker : public UniqueHandle<mmdeploy_pose_tracker_t> {
public:
using Result = Result_<mmdeploy_pose_tracker_target_t>;
class State;
class Params;
public:
/**
* @brief Create pose tracker pipeline
* @param detect object detection model
* @param pose pose estimation model
* @param context execution context
*/
PoseTracker(const Model& detect, const Model& pose, const Context& context) {
auto ec = mmdeploy_pose_tracker_create(detect, pose, context, &handle_);
if (ec != MMDEPLOY_SUCCESS) {
throw_exception(static_cast<ErrorCode>(ec));
}
}
~PoseTracker() {
if (handle_) {
mmdeploy_pose_tracker_destroy(handle_);
handle_ = {};
}
}
PoseTracker(PoseTracker&&) noexcept = default;
/**
* @brief Create a tracker state corresponds to a video stream
* @param params params for creating the tracker state
* @return created tracker state
*/
State CreateState(const Params& params);
/**
* @brief Apply pose tracker pipeline
* @param state tracker state
* @param frame input video frame
* @param detect control the use of detector
* -1: use params.det_interval, 0: don't use detector, 1: force use detector
* @return
*/
Result Apply(State& state, const Mat& frame, int detect = -1);
/**
* @brief batched version of Apply
* @param states
* @param frames
* @param detects
* @return
*/
std::vector<Result> Apply(const Span<State>& states, const Span<const Mat>& frames,
const Span<const int>& detects = {});
public:
/**
* see \ref mmdeploy/pose_tracker.h for detail
*/
class Params : public UniqueHandle<mmdeploy_pose_tracker_param_t*> {
public:
explicit Params() {
handle_ = new mmdeploy_pose_tracker_param_t{};
mmdeploy_pose_tracker_default_params(handle_);
}
~Params() {
if (handle_) {
delete handle_;
handle_ = {};
}
}
};
class State : public UniqueHandle<mmdeploy_pose_tracker_state_t> {
public:
explicit State(mmdeploy_pose_tracker_t pipeline, const mmdeploy_pose_tracker_param_t* params) {
auto ec = mmdeploy_pose_tracker_create_state(pipeline, params, &handle_);
if (ec != MMDEPLOY_SUCCESS) {
throw_exception(static_cast<ErrorCode>(ec));
}
}
~State() {
if (handle_) {
mmdeploy_pose_tracker_destroy_state(handle_);
handle_ = {};
}
}
State(State&&) noexcept = default;
};
};
inline PoseTracker::State PoseTracker::CreateState(const PoseTracker::Params& params) {
return State(handle_, static_cast<mmdeploy_pose_tracker_param_t*>(params));
}
inline std::vector<PoseTracker::Result> PoseTracker::Apply(const Span<State>& states,
const Span<const Mat>& frames,
const Span<const int32_t>& detects) {
if (frames.empty()) {
return {};
}
mmdeploy_pose_tracker_target_t* results{};
int32_t* result_count{};
auto ec = mmdeploy_pose_tracker_apply(
handle_, reinterpret_cast<mmdeploy_pose_tracker_state_t*>(states.data()),
reinterpret(frames.data()), detects.data(), static_cast<int32_t>(frames.size()), &results,
&result_count);
if (ec != MMDEPLOY_SUCCESS) {
throw_exception(static_cast<ErrorCode>(ec));
}
std::shared_ptr<mmdeploy_pose_tracker_target_t> data(
results, [result_count, count = frames.size()](auto p) {
mmdeploy_pose_tracker_release_result(p, result_count, count);
});
std::vector<Result> rets;
rets.reserve(frames.size());
size_t offset = 0;
for (size_t i = 0; i < frames.size(); ++i) {
offset += rets.emplace_back(offset, result_count[i], data).size();
}
return rets;
}
inline PoseTracker::Result PoseTracker::Apply(PoseTracker::State& state, const Mat& frame,
int32_t detect) {
return Apply(Span(&state, 1), Span{frame}, Span{detect})[0];
}
} // namespace cxx
using cxx::PoseTracker;
} // namespace mmdeploy
#endif // MMDEPLOY_POSE_TRACKER_HPP

View File

@ -3,6 +3,8 @@
#ifndef MMDEPLOY_CSRC_MMDEPLOY_APIS_CXX_TEXT_RECOGNIZER_HPP_
#define MMDEPLOY_CSRC_MMDEPLOY_APIS_CXX_TEXT_RECOGNIZER_HPP_
#include <numeric>
#include "mmdeploy/common.hpp"
#include "mmdeploy/text_detector.hpp"
#include "mmdeploy/text_recognizer.h"
@ -40,9 +42,12 @@ class TextRecognizer : public NonMovable {
const TextDetection* p_bboxes{};
const int* p_bbox_count{};
auto n_total_bboxes = static_cast<int>(images.size());
if (!bboxes.empty()) {
p_bboxes = bboxes.data();
p_bbox_count = bbox_count.data();
n_total_bboxes = std::accumulate(bbox_count.begin(), bbox_count.end(), 0);
}
TextRecognition* results{};
@ -53,7 +58,7 @@ class TextRecognizer : public NonMovable {
throw_exception(static_cast<ErrorCode>(ec));
}
std::shared_ptr<TextRecognition> data(results, [count = images.size()](auto p) {
std::shared_ptr<TextRecognition> data(results, [count = n_total_bboxes](auto p) {
mmdeploy_text_recognizer_release_result(p, count);
});

View File

@ -23,5 +23,6 @@ add_jar(${PROJECT_NAME} SOURCES
mmdeploy/TextRecognizer.java
mmdeploy/Restorer.java
mmdeploy/PoseDetector.java
mmdeploy/RotatedDetector.java
OUTPUT_NAME mmdeploy
OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

View File

@ -1,5 +1,6 @@
package mmdeploy;
/** @description: the Java API class of Classifier. */
public class Classifier {
static {
System.loadLibrary("mmdeploy_java");
@ -7,22 +8,49 @@ public class Classifier {
private final long handle;
/** @description: Single classification result of a picture. */
public static class Result {
/** Class id. */
public int label_id;
/** Class score. */
public float score;
/** Initializes a new instance of the Result class.
* @param label_id: class id.
* @param score: class score.
*/
public Result(int label_id, float score) {
this.label_id = label_id;
this.score = score;
}
}
public Classifier(String modelPath, String deviceName, int deviceId) {
/** Initializes a new instance of the Classifier class.
* @param modelPath: model path.
* @param deviceName: device name.
* @param deviceId: device ID.
* @exception Exception: create Classifier failed exception.
*/
public Classifier(String modelPath, String deviceName, int deviceId) throws Exception{
handle = create(modelPath, deviceName, deviceId);
if (handle == -1) {
throw new Exception("Create Classifier failed!");
}
}
public Result[][] apply(Mat[] images) {
/** Get label information of each image in a batch.
* @param images: input mats.
* @return: results of each input mat.
* @exception Exception: apply Classifier failed exception.
*/
public Result[][] apply(Mat[] images) throws Exception{
int[] counts = new int[images.length];
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Classifier failed!");
}
Result[][] rets = new Result[images.length][];
int offset = 0;
for (int i = 0; i < images.length; ++i) {
@ -36,12 +64,22 @@ public class Classifier {
return rets;
}
public Result[] apply(Mat image) {
/** Get label information of one image.
* @param image: input mat.
* @return: result of input mat.
* @exception Exception: apply Classifier failed exception.
*/
public Result[] apply(Mat image) throws Exception{
int[] counts = new int[1];
Mat[] images = new Mat[]{image};
return apply(handle, images, counts);
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Classifier failed!");
}
return results;
}
/** Release the instance of Classifier. */
public void release() {
destroy(handle);
}

View File

@ -1,5 +1,6 @@
package mmdeploy;
/** @description: DataType. */
public enum DataType {
FLOAT(0),
HALF(1),
@ -7,6 +8,9 @@ public enum DataType {
INT32(3);
final int value;
/** Initializes a new instance of the DataType class.
* @param value: the value.
*/
DataType(int value) {
this.value = value;
}

View File

@ -1,5 +1,6 @@
package mmdeploy;
/** @description: the Java API class of Detector. */
public class Detector {
static {
System.loadLibrary("mmdeploy_java");
@ -7,11 +8,27 @@ public class Detector {
private final long handle;
/** @description: Single detection result of a picture. */
public static class Result {
/** Bbox class id. */
public int label_id;
/** Bbox score. */
public float score;
/** Bbox coordinates. */
public Rect bbox;
/** Bbox mask. */
public InstanceMask mask;
/** Initializes a new instance of the Result class.
* @param label_id: bbox class id.
* @param score: bbox score.
* @param bbox: bbox coordinates.
* @param mask: bbox mask.
*/
public Result(int label_id, float score, Rect bbox, InstanceMask mask) {
this.label_id = label_id;
this.score = score;
@ -20,13 +37,30 @@ public class Detector {
}
}
public Detector(String modelPath, String deviceName, int deviceId) {
/** Initializes a new instance of the Detector class.
* @param modelPath: model path.
* @param deviceName: device name.
* @param deviceId: device ID.
* @exception Exception: create Detector failed exception.
*/
public Detector(String modelPath, String deviceName, int deviceId) throws Exception {
handle = create(modelPath, deviceName, deviceId);
if (handle == -1) {
throw new Exception("Create Detector failed!");
}
}
public Result[][] apply(Mat[] images) {
/** Get information of each image in a batch.
* @param images: input mats.
* @return: results of each input mat.
* @exception Exception: apply Detector failed exception.
*/
public Result[][] apply(Mat[] images) throws Exception {
int[] counts = new int[images.length];
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Detector failed!");
}
Result[][] rets = new Result[images.length][];
int offset = 0;
for (int i = 0; i < images.length; ++i) {
@ -40,12 +74,22 @@ public class Detector {
return rets;
}
public Result[] apply(Mat image) {
/** Get information of one image.
* @param image: input mat.
* @return: result of input mat.
* @exception Exception: apply Detector failed exception.
*/
public Result[] apply(Mat image) throws Exception{
int[] counts = new int[1];
Mat[] images = new Mat[]{image};
return apply(handle, images, counts);
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Detector failed!");
}
return results;
}
/** Release the instance of Detector. */
public void release() {
destroy(handle);
}

View File

@ -1,10 +1,19 @@
package mmdeploy;
/** @description: InstanceMask. */
public class InstanceMask {
/** Mask shape. */
public int[] shape;
/** Mask data. */
public char[] data;
/** Initialize a new instance of the InstanceMask class.
* @param height: height.
* @param width: width.
* @param data: mask data.
*/
public InstanceMask(int height, int width, char[] data) {
shape = new int[]{height, width};
this.data = data;

View File

@ -1,12 +1,28 @@
package mmdeploy;
/** @description: Mat. */
public class Mat {
/** Shape. */
public int[] shape;
/** Pixel format. */
public int format;
/** Data type. */
public int type;
/** Mat data. */
public byte[] data;
/** Initialize a new instance of the Mat class.
* @param height: height.
* @param width: width.
* @param channel: channel.
* @param format: pixel format.
* @param type: data type.
* @param data: mat data.
*/
public Mat(int height, int width, int channel,
PixelFormat format, DataType type, byte[] data) {
shape = new int[]{height, width, channel};

View File

@ -1,5 +1,6 @@
package mmdeploy;
/** @description: PixelFormat. */
public enum PixelFormat {
BGR(0),
RGB(1),
@ -9,6 +10,9 @@ public enum PixelFormat {
BGRA(5);
final int value;
/** Initialize a new instance of the PixelFormat class.
* @param value: the value.
*/
PixelFormat(int value) {
this.value = value;
}

View File

@ -1,10 +1,18 @@
package mmdeploy;
/** @description: the PointF class. */
public class PointF {
/** x coordinate. */
public float x;
/** y coordinate. */
public float y;
/** Initialize a new instance of the PointF class.
* @param x: x coordinate.
* @param y: y coordinate.
*/
public PointF(float x, float y) {
this.x = x;
this.y = y;

View File

@ -1,5 +1,6 @@
package mmdeploy;
/** @description: the Java API class of PoseDetector. */
public class PoseDetector {
static {
System.loadLibrary("mmdeploy_java");
@ -7,21 +8,48 @@ public class PoseDetector {
private final long handle;
/** @description: Single pose estimation result of a picture. */
public static class Result {
/** Points. */
public PointF[] point;
/** Scores of points */
public float[] score;
/** Initializes a new instance of the Result class.
* @param point: points.
* @param score: scores of points.
*/
public Result(PointF[] point, float [] score) {
this.point = point;
this.score = score;
}
}
public PoseDetector(String modelPath, String deviceName, int deviceId) {
/** Initializes a new instance of the PoseDetector class.
* @param modelPath: model path.
* @param deviceName: device name.
* @param deviceId: device ID.
* @exception Exception: create PoseDetector failed exception.
*/
public PoseDetector(String modelPath, String deviceName, int deviceId) throws Exception{
handle = create(modelPath, deviceName, deviceId);
if (handle == -1) {
throw new Exception("Create PoseDetector failed!");
}
}
public Result[][] apply(Mat[] images) {
/** Get information of each image in a batch.
* @param images: input mats.
* @return: results of each input mat.
* @exception Exception: apply PoseDetector failed exception.
*/
public Result[][] apply(Mat[] images) throws Exception{
Result[] results = apply(handle, images);
if (results == null) {
throw new Exception("Apply PoseDetector failed!");
}
Result[][] rets = new Result[images.length][];
int offset = 0;
for (int i = 0; i < images.length; ++i) {
@ -33,11 +61,21 @@ public class PoseDetector {
return rets;
}
public Result[] apply(Mat image) {
/** Get information of one image.
* @param image: input mat.
* @return: result of input mat.
* @exception Exception: apply PoseDetector failed exception.
*/
public Result[] apply(Mat image) throws Exception{
Mat[] images = new Mat[]{image};
return apply(handle, images);
Result[] results = apply(handle, images);
if (results == null) {
throw new Exception("Apply PoseDetector failed!");
}
return results;
}
/** Release the instance of PoseDetector. */
public void release() {
destroy(handle);
}

View File

@ -1,12 +1,26 @@
package mmdeploy;
/** @description: the Rect class. */
public class Rect {
/** left coordinate. */
public float left;
/** top coordinate. */
public float top;
/** right coordinate. */
public float right;
/** bottom coordinate. */
public float bottom;
/** Initialize a new instance of the Rect class.
* @param left: left coordinate.
* @param top: top coordinate.
* @param right: right coordinate.
* @param bottom: bottom coordinate.
*/
public Rect(float left, float top, float right, float bottom) {
this.left = left;
this.top = top;

Some files were not shown because too many files have changed in this diff Show More