From 546b4279d9cd337caadac19d8cd9a098adda66e3 Mon Sep 17 00:00:00 2001 From: limm Date: Wed, 25 Jun 2025 16:35:21 +0800 Subject: [PATCH] add csrc and mmdeploy module --- csrc/mmdeploy/CMakeLists.txt | 21 + csrc/mmdeploy/apis/CMakeLists.txt | 11 + csrc/mmdeploy/apis/c/CMakeLists.txt | 86 + csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp | 133 + csrc/mmdeploy/apis/c/mmdeploy/classifier.h | 139 + csrc/mmdeploy/apis/c/mmdeploy/common.cpp | 115 + csrc/mmdeploy/apis/c/mmdeploy/common.h | 192 ++ .../apis/c/mmdeploy/common_internal.h | 105 + csrc/mmdeploy/apis/c/mmdeploy/detector.cpp | 149 + csrc/mmdeploy/apis/c/mmdeploy/detector.h | 139 + csrc/mmdeploy/apis/c/mmdeploy/executor.cpp | 207 ++ csrc/mmdeploy/apis/c/mmdeploy/executor.h | 141 + .../apis/c/mmdeploy/executor_internal.h | 41 + csrc/mmdeploy/apis/c/mmdeploy/handle.h | 53 + csrc/mmdeploy/apis/c/mmdeploy/model.cpp | 41 + csrc/mmdeploy/apis/c/mmdeploy/model.h | 47 + csrc/mmdeploy/apis/c/mmdeploy/pipeline.cpp | 78 + csrc/mmdeploy/apis/c/mmdeploy/pipeline.h | 69 + .../apis/c/mmdeploy/pose_detector.cpp | 179 ++ csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h | 126 + .../mmdeploy/apis/c/mmdeploy/pose_tracker.cpp | 225 ++ csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h | 158 + csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp | 121 + csrc/mmdeploy/apis/c/mmdeploy/restorer.h | 91 + .../apis/c/mmdeploy/rotated_detector.cpp | 138 + .../apis/c/mmdeploy/rotated_detector.h | 140 + csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp | 128 + csrc/mmdeploy/apis/c/mmdeploy/segmentor.h | 106 + .../apis/c/mmdeploy/text_detector.cpp | 189 ++ csrc/mmdeploy/apis/c/mmdeploy/text_detector.h | 156 + .../apis/c/mmdeploy/text_recognizer.cpp | 252 ++ .../apis/c/mmdeploy/text_recognizer.h | 164 + .../apis/c/mmdeploy/video_recognizer.cpp | 165 + .../apis/c/mmdeploy/video_recognizer.h | 139 + csrc/mmdeploy/apis/csharp/MMDeploy.sln | 50 + .../apis/csharp/MMDeploy/.editorconfig | 110 + .../apis/csharp/MMDeploy/APIs/Classifier.cs | 134 + .../apis/csharp/MMDeploy/APIs/Context.cs | 69 + .../apis/csharp/MMDeploy/APIs/Detector.cs | 233 ++ .../apis/csharp/MMDeploy/APIs/Device.cs | 39 + .../csharp/MMDeploy/APIs/DisposableObject.cs | 102 + .../apis/csharp/MMDeploy/APIs/Model.cs | 23 + .../apis/csharp/MMDeploy/APIs/PoseDetector.cs | 199 ++ .../apis/csharp/MMDeploy/APIs/PoseTracker.cs | 350 +++ .../apis/csharp/MMDeploy/APIs/Profiler.cs | 23 + .../apis/csharp/MMDeploy/APIs/Restorer.cs | 114 + .../csharp/MMDeploy/APIs/RotatedDetector.cs | 157 + .../apis/csharp/MMDeploy/APIs/Scheduler.cs | 51 + .../apis/csharp/MMDeploy/APIs/Segmentor.cs | 181 ++ .../apis/csharp/MMDeploy/APIs/TextDetector.cs | 212 ++ .../csharp/MMDeploy/APIs/TextRecognizer.cs | 189 ++ .../apis/csharp/MMDeploy/APIs/common.cs | 105 + .../csharp/MMDeploy/MMDeployCSharp.csproj | 58 + .../apis/csharp/MMDeploy/MMDeployCSharp.props | 11 + .../MMDeploy/NativeAPIs/NativeMethods.cs | 10 + .../NativeAPIs/NativeMethods_c_api.cs | 216 ++ .../MMDeploy/Properties/AssemblyInfo.cs | 22 + csrc/mmdeploy/apis/csharp/README.md | 46 + csrc/mmdeploy/apis/cxx/CMakeLists.txt | 44 + .../mmdeploy/apis/cxx/mmdeploy/classifier.hpp | 74 + csrc/mmdeploy/apis/cxx/mmdeploy/common.hpp | 269 ++ csrc/mmdeploy/apis/cxx/mmdeploy/detector.hpp | 74 + csrc/mmdeploy/apis/cxx/mmdeploy/pipeline.hpp | 79 + .../apis/cxx/mmdeploy/pose_detector.hpp | 85 + .../apis/cxx/mmdeploy/pose_tracker.hpp | 151 + csrc/mmdeploy/apis/cxx/mmdeploy/restorer.hpp | 68 + .../apis/cxx/mmdeploy/rotated_detector.hpp | 75 + csrc/mmdeploy/apis/cxx/mmdeploy/segmentor.hpp | 71 + .../apis/cxx/mmdeploy/text_detector.hpp | 75 + .../apis/cxx/mmdeploy/text_recognizer.hpp | 91 + .../apis/cxx/mmdeploy/video_recognizer.hpp | 91 + csrc/mmdeploy/apis/java/CMakeLists.txt | 34 + csrc/mmdeploy/apis/java/README.md | 48 + .../apis/java/mmdeploy/Classifier.java | 92 + csrc/mmdeploy/apis/java/mmdeploy/Context.java | 74 + .../mmdeploy/apis/java/mmdeploy/DataType.java | 17 + .../mmdeploy/apis/java/mmdeploy/Detector.java | 102 + csrc/mmdeploy/apis/java/mmdeploy/Device.java | 52 + .../apis/java/mmdeploy/InstanceMask.java | 21 + csrc/mmdeploy/apis/java/mmdeploy/Mat.java | 33 + csrc/mmdeploy/apis/java/mmdeploy/Model.java | 33 + .../apis/java/mmdeploy/PixelFormat.java | 19 + csrc/mmdeploy/apis/java/mmdeploy/PointF.java | 20 + .../apis/java/mmdeploy/PoseDetector.java | 88 + .../apis/java/mmdeploy/PoseTracker.java | 244 ++ .../mmdeploy/apis/java/mmdeploy/Profiler.java | 33 + csrc/mmdeploy/apis/java/mmdeploy/Rect.java | 30 + .../mmdeploy/apis/java/mmdeploy/Restorer.java | 83 + .../apis/java/mmdeploy/RotatedDetector.java | 97 + .../apis/java/mmdeploy/Scheduler.java | 52 + .../apis/java/mmdeploy/Segmentor.java | 102 + .../apis/java/mmdeploy/TextDetector.java | 92 + .../apis/java/mmdeploy/TextRecognizer.java | 101 + csrc/mmdeploy/apis/java/native/CMakeLists.txt | 35 + csrc/mmdeploy/apis/java/native/common.h | 54 + .../apis/java/native/mmdeploy_Classifier.cpp | 60 + .../apis/java/native/mmdeploy_Classifier.h | 35 + .../apis/java/native/mmdeploy_Context.cpp | 43 + .../apis/java/native/mmdeploy_Context.h | 34 + .../apis/java/native/mmdeploy_Detector.cpp | 84 + .../apis/java/native/mmdeploy_Detector.h | 35 + .../apis/java/native/mmdeploy_Device.cpp | 24 + .../apis/java/native/mmdeploy_Device.h | 27 + .../apis/java/native/mmdeploy_Model.cpp | 24 + .../apis/java/native/mmdeploy_Model.h | 27 + .../java/native/mmdeploy_PoseDetector.cpp | 60 + .../apis/java/native/mmdeploy_PoseDetector.h | 36 + .../apis/java/native/mmdeploy_PoseTracker.cpp | 194 ++ .../apis/java/native/mmdeploy_PoseTracker.h | 56 + .../apis/java/native/mmdeploy_Profiler.cpp | 24 + .../apis/java/native/mmdeploy_Profiler.h | 27 + .../apis/java/native/mmdeploy_Restorer.cpp | 73 + .../apis/java/native/mmdeploy_Restorer.h | 34 + .../java/native/mmdeploy_RotatedDetector.cpp | 61 + .../java/native/mmdeploy_RotatedDetector.h | 36 + .../apis/java/native/mmdeploy_Scheduler.cpp | 23 + .../apis/java/native/mmdeploy_Scheduler.h | 34 + .../apis/java/native/mmdeploy_Segmentor.cpp | 70 + .../apis/java/native/mmdeploy_Segmentor.h | 35 + .../java/native/mmdeploy_TextDetector.cpp | 66 + .../apis/java/native/mmdeploy_TextDetector.h | 36 + .../java/native/mmdeploy_TextRecognizer.cpp | 105 + .../java/native/mmdeploy_TextRecognizer.h | 45 + csrc/mmdeploy/apis/python/CMakeLists.txt | 55 + csrc/mmdeploy/apis/python/classifier.cpp | 67 + csrc/mmdeploy/apis/python/common.cpp | 172 ++ csrc/mmdeploy/apis/python/common.h | 37 + csrc/mmdeploy/apis/python/detector.cpp | 85 + csrc/mmdeploy/apis/python/executor.cpp | 46 + csrc/mmdeploy/apis/python/internal.cpp | 57 + csrc/mmdeploy/apis/python/pipeline.cpp | 47 + csrc/mmdeploy/apis/python/pose_detector.cpp | 128 + csrc/mmdeploy/apis/python/pose_tracker.cpp | 150 + csrc/mmdeploy/apis/python/restorer.cpp | 66 + .../mmdeploy/apis/python/rotated_detector.cpp | 77 + csrc/mmdeploy/apis/python/segmentor.cpp | 77 + csrc/mmdeploy/apis/python/text_detector.cpp | 71 + csrc/mmdeploy/apis/python/text_recognizer.cpp | 82 + .../mmdeploy/apis/python/video_recognizer.cpp | 88 + csrc/mmdeploy/archive/CMakeLists.txt | 13 + csrc/mmdeploy/archive/json_archive.h | 214 ++ csrc/mmdeploy/archive/value_archive.h | 137 + csrc/mmdeploy/backend_ops/CMakeLists.txt | 39 + .../common_cuda_helper.cuh | 94 + .../modulated_deform_conv_cpu.h | 82 + .../modulated_deform_conv_cuda.cuh | 180 ++ csrc/mmdeploy/backend_ops/ncnn/CMakeLists.txt | 22 + .../backend_ops/ncnn/onnx2ncnn/CMakeLists.txt | 25 + .../backend_ops/ncnn/onnx2ncnn/fuse_pass.cpp | 2402 +++++++++++++++ .../backend_ops/ncnn/onnx2ncnn/fuse_pass.h | 130 + .../backend_ops/ncnn/onnx2ncnn/onnx.proto | 505 +++ .../backend_ops/ncnn/onnx2ncnn/onnx2ncnn.cpp | 2744 +++++++++++++++++ .../ncnn/onnx2ncnn/shape_inference.cpp | 170 + .../ncnn/onnx2ncnn/shape_inference.h | 19 + .../backend_ops/ncnn/onnx2ncnn/utils.h | 401 +++ .../backend_ops/ncnn/ops/CMakeLists.txt | 26 + .../ops/constantofshape/constantofshape.cpp | 53 + .../ops/constantofshape/constantofshape.h | 24 + .../backend_ops/ncnn/ops/expand/expand.cpp | 333 ++ .../backend_ops/ncnn/ops/expand/expand.h | 19 + .../backend_ops/ncnn/ops/gather/gather.cpp | 160 + .../backend_ops/ncnn/ops/gather/gather.h | 24 + .../backend_ops/ncnn/ops/ncnn_ops_definer.h | 29 + .../ncnn/ops/ncnn_ops_register.cpp | 34 + .../backend_ops/ncnn/ops/ncnn_ops_register.h | 16 + .../backend_ops/ncnn/ops/shape/shape.cpp | 47 + .../backend_ops/ncnn/ops/shape/shape.h | 19 + .../ncnn/ops/tensorslice/tensorslice.cpp | 206 ++ .../ncnn/ops/tensorslice/tensorslice.h | 27 + .../backend_ops/ncnn/ops/topk/topk.cpp | 877 ++++++ .../mmdeploy/backend_ops/ncnn/ops/topk/topk.h | 25 + .../ncnn/pyncnn_ext/CMakeLists.txt | 17 + .../backend_ops/ncnn/pyncnn_ext/ncnn_ext.cpp | 12 + .../backend_ops/onnxruntime/CMakeLists.txt | 30 + .../onnxruntime/common/onnxruntime_register.h | 18 + .../onnxruntime_session_options_config_keys.h | 40 + .../onnxruntime/common/ort_utils.cpp | 10 + .../onnxruntime/common/ort_utils.h | 37 + .../onnxruntime/grid_sample/grid_sample.cpp | 294 ++ .../onnxruntime/grid_sample/grid_sample.h | 44 + .../modulated_deform_conv.cpp | 198 ++ .../modulated_deform_conv.h | 58 + .../onnxruntime/nms_match/nms_match.cpp | 129 + .../onnxruntime/nms_match/nms_match.h | 46 + .../onnxruntime/nms_rotated/nms_rotated.cpp | 368 +++ .../onnxruntime/nms_rotated/nms_rotated.h | 48 + .../onnxruntime/onnxruntime_register.cpp | 27 + .../roi_align_rotated/roi_align_rotated.cpp | 237 ++ .../roi_align_rotated/roi_align_rotated.h | 59 + .../backend_ops/tensorrt/CMakeLists.txt | 37 + .../tensorrt/batched_nms/trt_batched_nms.cpp | 233 ++ .../tensorrt/batched_nms/trt_batched_nms.hpp | 82 + .../trt_batched_rotated_nms.cpp | 229 ++ .../trt_batched_rotated_nms.hpp | 78 + .../trt_bicubic_interpolate.cpp | 185 ++ .../trt_bicubic_interpolate.hpp | 67 + .../trt_bicubic_interpolate_kernel.cu | 170 + .../trt_bicubic_interpolate_kernel.hpp | 11 + .../tensorrt/common/common_cuda_helper.hpp | 82 + .../common/nms/batched_nms_kernel.hpp | 19 + .../tensorrt/common/nms/cub_helper.h | 15 + .../backend_ops/tensorrt/common/nms/kernel.h | 86 + .../tensorrt/common/trt_plugin_base.hpp | 77 + .../tensorrt/common/trt_plugin_helper.hpp | 155 + .../tensorrt/common/trt_serialize.hpp | 97 + .../tensorrt/common_impl/nms/allClassNMS.cu | 267 ++ .../common_impl/nms/allClassRotatedNMS.cu | 495 +++ .../common_impl/nms/batched_nms_kernel.cpp | 125 + .../common_impl/nms/gatherNMSOutputs.cu | 164 + .../tensorrt/common_impl/nms/kernel.cu | 107 + .../tensorrt/common_impl/nms/permuteData.cu | 76 + .../common_impl/nms/sortScoresPerClass.cu | 141 + .../common_impl/nms/sortScoresPerImage.cu | 81 + .../tensorrt/common_impl/trt_cuda_helper.cu | 95 + .../tensorrt/deform_conv/trt_deform_conv.cpp | 263 ++ .../tensorrt/deform_conv/trt_deform_conv.hpp | 81 + .../deform_conv/trt_deform_conv_kernel.cu | 172 ++ .../deform_conv/trt_deform_conv_kernel.cuh | 174 ++ .../deform_conv/trt_deform_conv_kernel.hpp | 20 + .../tensorrt/gather_topk/gather_topk.cpp | 150 + .../tensorrt/gather_topk/gather_topk.hpp | 64 + .../gather_topk/gather_topk_kernel.cu | 46 + .../gather_topk/gather_topk_kernel.hpp | 10 + .../tensorrt/grid_priors/trt_grid_priors.cpp | 154 + .../tensorrt/grid_priors/trt_grid_priors.hpp | 66 + .../grid_priors/trt_grid_priors_kernel.cu | 43 + .../grid_priors/trt_grid_priors_kernel.hpp | 10 + .../grid_sampler/trt_grid_sampler.cpp | 202 ++ .../grid_sampler/trt_grid_sampler.hpp | 84 + .../grid_sampler/trt_grid_sampler_kernel.cu | 396 +++ .../grid_sampler/trt_grid_sampler_kernel.hpp | 13 + .../instance_norm/trt_instance_norm.cpp | 214 ++ .../instance_norm/trt_instance_norm.hpp | 93 + .../trt_modulated_deform_conv.cpp | 306 ++ .../trt_modulated_deform_conv.hpp | 82 + .../trt_modulated_deform_conv_kernel.cu | 138 + .../trt_modulated_deform_conv_kernel.hpp | 15 + .../trt_multi_level_roi_align.cpp | 227 ++ .../trt_multi_level_roi_align.hpp | 78 + .../trt_multi_level_roi_align_kernel.cu | 176 ++ .../trt_multi_level_roi_align_kernel.hpp | 13 + .../trt_multi_level_rotated_roi_align.cpp | 228 ++ .../trt_multi_level_rotated_roi_align.hpp | 79 + ...rt_multi_level_rotated_roi_align_kernel.cu | 164 + ...t_multi_level_rotated_roi_align_kernel.hpp | 13 + .../trt_ms_deform_attn.cpp | 173 ++ .../trt_ms_deform_attn.hpp | 70 + .../trt_ms_deform_attn_kernel.cu | 64 + .../trt_ms_deform_attn_kernel.cuh | 257 ++ .../trt_ms_deform_attn_kernel.hpp | 15 + .../tensorrt/roi_align/trt_roi_align.cpp | 241 ++ .../tensorrt/roi_align/trt_roi_align.hpp | 72 + .../roi_align/trt_roi_align_kernel.cu | 107 + .../roi_align/trt_roi_align_kernel.hpp | 15 + .../scaled_dot_product_attention.cpp | 183 ++ .../scaled_dot_product_attention.hpp | 73 + .../scaled_dot_product_attention_kernel.cu | 103 + .../scaled_dot_product_attention_kernel.hpp | 17 + .../tensorrt/scatternd/trt_scatternd.cpp | 156 + .../tensorrt/scatternd/trt_scatternd.hpp | 64 + .../scatternd/trt_scatternd_kernel.cu | 75 + .../scatternd/trt_scatternd_kernel.hpp | 11 + .../backend_ops/torchscript/CMakeLists.txt | 3 + .../torchscript/ops/CMakeLists.txt | 49 + .../backend_ops/torchscript/ops/bind.cpp | 13 + .../ops/coreml_nms/coreml_nms_cpu.cpp | 31 + .../modulated_deform_conv_cpu.cpp | 94 + .../modulated_deform_conv_cuda.cu | 97 + .../torchscript/optimizer/CMakeLists.txt | 18 + .../torchscript/optimizer/bind.cpp | 47 + .../optimizer/ir/subgraph_matcher.cpp | 313 ++ .../optimizer/ir/subgraph_matcher.h | 38 + .../torchscript/optimizer/optimizer.cpp | 70 + .../torchscript/optimizer/optimizer.h | 10 + .../onnx/common_subgraph_elimination.cpp | 138 + .../passes/onnx/common_subgraph_elimination.h | 20 + .../passes/onnx/flatten_cls_head.cpp | 119 + .../optimizer/passes/onnx/flatten_cls_head.h | 14 + .../passes/onnx/fuse_select_assign.cpp | 163 + .../passes/onnx/fuse_select_assign.h | 17 + .../passes/onnx/merge_shape_concate.cpp | 115 + .../passes/onnx/merge_shape_concate.h | 14 + .../optimizer/passes/onnx/onnx_peephole.cpp | 81 + .../optimizer/passes/onnx/onnx_peephole.h | 15 + .../torchscript/optimizer/passes/onnx/utils.h | 20 + csrc/mmdeploy/codebase/CMakeLists.txt | 31 + csrc/mmdeploy/codebase/common.h | 78 + .../mmdeploy/codebase/mmaction/CMakeLists.txt | 15 + csrc/mmdeploy/codebase/mmaction/base_head.cpp | 72 + .../codebase/mmaction/format_shape.cpp | 128 + .../mmdeploy/codebase/mmaction/format_shape.h | 39 + csrc/mmdeploy/codebase/mmaction/mmaction.cpp | 9 + csrc/mmdeploy/codebase/mmaction/mmaction.h | 25 + csrc/mmdeploy/codebase/mmcls/CMakeLists.txt | 11 + csrc/mmdeploy/codebase/mmcls/linear_cls.cpp | 116 + csrc/mmdeploy/codebase/mmcls/mmcls.cpp | 9 + csrc/mmdeploy/codebase/mmcls/mmcls.h | 25 + .../codebase/mmcls/multi_label_linear_cls.cpp | 55 + csrc/mmdeploy/codebase/mmdet/CMakeLists.txt | 12 + .../codebase/mmdet/base_dense_head.cpp | 104 + .../mmdeploy/codebase/mmdet/base_dense_head.h | 26 + .../codebase/mmdet/instance_segmentation.cpp | 202 ++ csrc/mmdeploy/codebase/mmdet/mmdet.cpp | 9 + csrc/mmdeploy/codebase/mmdet/mmdet.h | 32 + .../codebase/mmdet/object_detection.cpp | 184 ++ .../codebase/mmdet/object_detection.h | 35 + csrc/mmdeploy/codebase/mmdet/rtmdet_head.cpp | 194 ++ csrc/mmdeploy/codebase/mmdet/rtmdet_head.h | 34 + csrc/mmdeploy/codebase/mmdet/utils.cpp | 94 + csrc/mmdeploy/codebase/mmdet/utils.h | 33 + csrc/mmdeploy/codebase/mmdet/yolo_head.cpp | 229 ++ csrc/mmdeploy/codebase/mmdet/yolo_head.h | 51 + csrc/mmdeploy/codebase/mmedit/CMakeLists.txt | 11 + csrc/mmdeploy/codebase/mmedit/mmedit.cpp | 11 + csrc/mmdeploy/codebase/mmedit/mmedit.h | 20 + csrc/mmdeploy/codebase/mmedit/restorer.cpp | 58 + csrc/mmdeploy/codebase/mmocr/CMakeLists.txt | 23 + .../codebase/mmocr/attention_convertor.cpp | 77 + .../codebase/mmocr/base_convertor.cpp | 146 + csrc/mmdeploy/codebase/mmocr/base_convertor.h | 58 + .../codebase/mmocr/contour_expand.cpp | 124 + .../codebase/mmocr/cpu/CMakeLists.txt | 16 + csrc/mmdeploy/codebase/mmocr/cpu/dbnet.cpp | 70 + csrc/mmdeploy/codebase/mmocr/cpu/panet.cpp | 55 + csrc/mmdeploy/codebase/mmocr/cpu/psenet.cpp | 56 + csrc/mmdeploy/codebase/mmocr/crnn.cpp | 79 + .../codebase/mmocr/cuda/CMakeLists.txt | 23 + .../mmocr/cuda/connected_component.cu | 431 +++ .../codebase/mmocr/cuda/connected_component.h | 37 + csrc/mmdeploy/codebase/mmocr/cuda/dbnet.cpp | 79 + csrc/mmdeploy/codebase/mmocr/cuda/panet.cpp | 102 + csrc/mmdeploy/codebase/mmocr/cuda/psenet.cpp | 77 + csrc/mmdeploy/codebase/mmocr/cuda/utils.cu | 105 + csrc/mmdeploy/codebase/mmocr/cuda/utils.h | 41 + csrc/mmdeploy/codebase/mmocr/dbnet.cpp | 139 + csrc/mmdeploy/codebase/mmocr/dbnet.h | 32 + csrc/mmdeploy/codebase/mmocr/mmocr.cpp | 12 + csrc/mmdeploy/codebase/mmocr/mmocr.h | 32 + csrc/mmdeploy/codebase/mmocr/panet.cpp | 126 + csrc/mmdeploy/codebase/mmocr/panet.h | 40 + csrc/mmdeploy/codebase/mmocr/pixel_group.cpp | 125 + csrc/mmdeploy/codebase/mmocr/psenet.cpp | 124 + csrc/mmdeploy/codebase/mmocr/psenet.h | 35 + .../codebase/mmocr/rescale_to_height.cpp | 85 + csrc/mmdeploy/codebase/mmocr/resize_ocr.cpp | 102 + .../mmocr/short_scale_aspect_jitter.cpp | 96 + csrc/mmdeploy/codebase/mmocr/warp.cpp | 70 + csrc/mmdeploy/codebase/mmpose/CMakeLists.txt | 18 + .../mmpose/keypoints_from_heatmap.cpp | 371 +++ .../mmpose/keypoints_from_regression.cpp | 113 + csrc/mmdeploy/codebase/mmpose/mmpose.cpp | 9 + csrc/mmdeploy/codebase/mmpose/mmpose.h | 28 + .../codebase/mmpose/pose_tracker/common.h | 57 + .../codebase/mmpose/pose_tracker/pipeline.cpp | 117 + .../mmpose/pose_tracker/pose_tracker.cpp | 399 +++ .../mmpose/pose_tracker/pose_tracker.h | 101 + .../mmpose/pose_tracker/smoothing_filter.cpp | 49 + .../mmpose/pose_tracker/smoothing_filter.h | 58 + .../codebase/mmpose/pose_tracker/track.cpp | 70 + .../codebase/mmpose/pose_tracker/track.h | 65 + .../mmpose/pose_tracker/tracking_filter.cpp | 199 ++ .../mmpose/pose_tracker/tracking_filter.h | 50 + .../codebase/mmpose/pose_tracker/utils.cpp | 136 + .../codebase/mmpose/pose_tracker/utils.h | 96 + csrc/mmdeploy/codebase/mmpose/simcc_label.cpp | 124 + .../codebase/mmpose/topdown_affine.cpp | 154 + .../mmpose/topdown_get_bbox_center_scale.cpp | 66 + .../mmdeploy/codebase/mmrotate/CMakeLists.txt | 10 + csrc/mmdeploy/codebase/mmrotate/mmrotate.cpp | 9 + csrc/mmdeploy/codebase/mmrotate/mmrotate.h | 29 + .../mmrotate/oriented_object_detection.cpp | 113 + csrc/mmdeploy/codebase/mmseg/CMakeLists.txt | 12 + csrc/mmdeploy/codebase/mmseg/mmseg.cpp | 9 + csrc/mmdeploy/codebase/mmseg/mmseg.h | 26 + csrc/mmdeploy/codebase/mmseg/segment.cpp | 132 + csrc/mmdeploy/core/CMakeLists.txt | 93 + csrc/mmdeploy/core/archive.h | 108 + csrc/mmdeploy/core/device.h | 384 +++ csrc/mmdeploy/core/device_impl.cpp | 410 +++ csrc/mmdeploy/core/device_impl.h | 186 ++ csrc/mmdeploy/core/graph.cpp | 132 + csrc/mmdeploy/core/graph.h | 73 + csrc/mmdeploy/core/logger.cpp | 75 + csrc/mmdeploy/core/logger.h | 91 + csrc/mmdeploy/core/macro.h | 123 + csrc/mmdeploy/core/mat.cpp | 72 + csrc/mmdeploy/core/mat.h | 99 + csrc/mmdeploy/core/model.cpp | 81 + csrc/mmdeploy/core/model.h | 109 + csrc/mmdeploy/core/model_impl.h | 48 + csrc/mmdeploy/core/module.cpp | 11 + csrc/mmdeploy/core/module.h | 23 + csrc/mmdeploy/core/mpl/detected.h | 54 + csrc/mmdeploy/core/mpl/iterator.h | 20 + csrc/mmdeploy/core/mpl/priority_tag.h | 15 + csrc/mmdeploy/core/mpl/span.h | 134 + csrc/mmdeploy/core/mpl/static_any.h | 465 +++ csrc/mmdeploy/core/mpl/structure.h | 237 ++ csrc/mmdeploy/core/mpl/type_traits.h | 50 + csrc/mmdeploy/core/net.cpp | 11 + csrc/mmdeploy/core/net.h | 29 + csrc/mmdeploy/core/operator.cpp | 206 ++ csrc/mmdeploy/core/operator.h | 122 + csrc/mmdeploy/core/profiler.cpp | 87 + csrc/mmdeploy/core/profiler.h | 86 + csrc/mmdeploy/core/registry.cpp | 81 + csrc/mmdeploy/core/registry.h | 231 ++ csrc/mmdeploy/core/serialization.h | 301 ++ csrc/mmdeploy/core/status_code.cpp | 47 + csrc/mmdeploy/core/status_code.h | 201 ++ csrc/mmdeploy/core/tensor.cpp | 201 ++ csrc/mmdeploy/core/tensor.h | 91 + csrc/mmdeploy/core/types.h | 76 + csrc/mmdeploy/core/utils/device_utils.cpp | 45 + csrc/mmdeploy/core/utils/device_utils.h | 34 + csrc/mmdeploy/core/utils/filesystem.h | 14 + csrc/mmdeploy/core/utils/formatter.cpp | 12 + csrc/mmdeploy/core/utils/formatter.h | 119 + csrc/mmdeploy/core/utils/source_location.h | 47 + csrc/mmdeploy/core/utils/stacktrace.cpp | 56 + csrc/mmdeploy/core/utils/stacktrace.h | 29 + csrc/mmdeploy/core/value.h | 1057 +++++++ csrc/mmdeploy/device/CMakeLists.txt | 11 + csrc/mmdeploy/device/acl/CMakeLists.txt | 7 + csrc/mmdeploy/device/acl/acl_device.cpp | 14 + csrc/mmdeploy/device/cpu/CMakeLists.txt | 13 + csrc/mmdeploy/device/cpu/cpu_device.cpp | 426 +++ csrc/mmdeploy/device/cpu/cpu_device.h | 151 + csrc/mmdeploy/device/cuda/CMakeLists.txt | 9 + csrc/mmdeploy/device/cuda/buddy_allocator.h | 183 ++ csrc/mmdeploy/device/cuda/cuda_device.cpp | 501 +++ csrc/mmdeploy/device/cuda/cuda_device.h | 198 ++ csrc/mmdeploy/device/cuda/default_allocator.h | 69 + csrc/mmdeploy/device/cuda/linear_allocator.h | 69 + csrc/mmdeploy/device/device_allocator.h | 352 +++ csrc/mmdeploy/execution/CMakeLists.txt | 7 + csrc/mmdeploy/execution/bulk.h | 125 + csrc/mmdeploy/execution/closure.h | 86 + csrc/mmdeploy/execution/concepts.h | 135 + csrc/mmdeploy/execution/dynamic_batch.h | 63 + csrc/mmdeploy/execution/ensure_started.h | 172 ++ csrc/mmdeploy/execution/execute.h | 36 + csrc/mmdeploy/execution/execution.h | 33 + csrc/mmdeploy/execution/expand.h | 62 + csrc/mmdeploy/execution/just.h | 72 + csrc/mmdeploy/execution/let_value.h | 155 + csrc/mmdeploy/execution/on.h | 124 + csrc/mmdeploy/execution/run_loop.h | 164 + csrc/mmdeploy/execution/schedule_from.h | 140 + .../schedulers/dynamic_batch_scheduler.h | 282 ++ .../execution/schedulers/inlined_scheduler.h | 73 + .../execution/schedulers/intrusive_queue.h | 115 + csrc/mmdeploy/execution/schedulers/registry.h | 19 + .../execution/schedulers/schedulers.cpp | 118 + .../schedulers/single_thread_context.h | 57 + .../execution/schedulers/static_thread_pool.h | 361 +++ .../schedulers/timed_single_thread_context.h | 202 ++ csrc/mmdeploy/execution/split.h | 174 ++ csrc/mmdeploy/execution/start_detached.h | 43 + csrc/mmdeploy/execution/submit.h | 59 + csrc/mmdeploy/execution/sync_wait.h | 85 + csrc/mmdeploy/execution/tag_invoke.h | 83 + csrc/mmdeploy/execution/then.h | 111 + csrc/mmdeploy/execution/transfer.h | 55 + csrc/mmdeploy/execution/transfer_just.h | 36 + csrc/mmdeploy/execution/type_erased.h | 465 +++ csrc/mmdeploy/execution/type_traits.h | 86 + csrc/mmdeploy/execution/utility.h | 84 + csrc/mmdeploy/execution/when_all.h | 175 ++ csrc/mmdeploy/execution/when_all_value.h | 92 + csrc/mmdeploy/experimental/module_adapter.h | 112 + csrc/mmdeploy/graph/CMakeLists.txt | 12 + csrc/mmdeploy/graph/common.h | 56 + csrc/mmdeploy/graph/cond.cpp | 141 + csrc/mmdeploy/graph/cond.h | 33 + csrc/mmdeploy/graph/flattened.h | 55 + csrc/mmdeploy/graph/inference.cpp | 78 + csrc/mmdeploy/graph/inference.h | 24 + csrc/mmdeploy/graph/pipeline.cpp | 21 + csrc/mmdeploy/graph/pipeline.h | 20 + csrc/mmdeploy/graph/static_router.cpp | 238 ++ csrc/mmdeploy/graph/static_router.h | 58 + csrc/mmdeploy/graph/task.cpp | 108 + csrc/mmdeploy/graph/task.h | 36 + csrc/mmdeploy/model/CMakeLists.txt | 106 + csrc/mmdeploy/model/directory_model_impl.cpp | 68 + csrc/mmdeploy/model/zip_model_impl.cpp | 147 + csrc/mmdeploy/net/CMakeLists.txt | 69 + csrc/mmdeploy/net/acl/CMakeLists.txt | 14 + csrc/mmdeploy/net/acl/acl_net.cpp | 654 ++++ csrc/mmdeploy/net/acl/acl_net.h | 70 + csrc/mmdeploy/net/coreml/CMakeLists.txt | 14 + csrc/mmdeploy/net/coreml/coreml_net.h | 37 + csrc/mmdeploy/net/coreml/coreml_net.mm | 320 ++ csrc/mmdeploy/net/ncnn/CMakeLists.txt | 17 + csrc/mmdeploy/net/ncnn/ncnn_net.cpp | 148 + csrc/mmdeploy/net/ncnn/ncnn_net.h | 37 + csrc/mmdeploy/net/net_module.cpp | 332 ++ csrc/mmdeploy/net/net_module.h | 27 + csrc/mmdeploy/net/openvino/CMakeLists.txt | 14 + csrc/mmdeploy/net/openvino/openvino_net.cpp | 260 ++ csrc/mmdeploy/net/openvino/openvino_net.h | 36 + csrc/mmdeploy/net/ort/CMakeLists.txt | 11 + csrc/mmdeploy/net/ort/ort_net.cpp | 212 ++ csrc/mmdeploy/net/ort/ort_net.h | 34 + csrc/mmdeploy/net/ppl/CMakeLists.txt | 24 + csrc/mmdeploy/net/ppl/ppl_net.cpp | 358 +++ csrc/mmdeploy/net/ppl/ppl_net.h | 58 + csrc/mmdeploy/net/rknn/CMakeLists.txt | 37 + csrc/mmdeploy/net/rknn/rknn_net.cpp | 284 ++ csrc/mmdeploy/net/rknn/rknn_net.h | 45 + csrc/mmdeploy/net/snpe/CMakeLists.txt | 25 + csrc/mmdeploy/net/snpe/snpe_net.cpp | 257 ++ csrc/mmdeploy/net/snpe/snpe_net.h | 61 + csrc/mmdeploy/net/torchscript/CMakeLists.txt | 28 + csrc/mmdeploy/net/torchscript/torch_net.cpp | 233 ++ csrc/mmdeploy/net/torchscript/torch_net.h | 35 + csrc/mmdeploy/net/trt/CMakeLists.txt | 15 + csrc/mmdeploy/net/trt/trt_net.cpp | 227 ++ csrc/mmdeploy/net/trt/trt_net.h | 81 + csrc/mmdeploy/net/tvm/CMakeLists.txt | 11 + csrc/mmdeploy/net/tvm/tvm_net.cpp | 282 ++ csrc/mmdeploy/net/tvm/tvm_net.h | 40 + csrc/mmdeploy/operation/CMakeLists.txt | 12 + csrc/mmdeploy/operation/cpu/CMakeLists.txt | 21 + csrc/mmdeploy/operation/cpu/crop.cpp | 21 + .../operation/cpu/crop_resize_pad.cpp | 25 + csrc/mmdeploy/operation/cpu/cvtcolor.cpp | 20 + csrc/mmdeploy/operation/cpu/flip.cpp | 24 + csrc/mmdeploy/operation/cpu/hwc2chw.cpp | 28 + csrc/mmdeploy/operation/cpu/normalize.cpp | 29 + csrc/mmdeploy/operation/cpu/pad.cpp | 39 + csrc/mmdeploy/operation/cpu/permute.cpp | 91 + csrc/mmdeploy/operation/cpu/resize.cpp | 27 + csrc/mmdeploy/operation/cpu/to_float.cpp | 42 + csrc/mmdeploy/operation/cpu/warp_affine.cpp | 29 + csrc/mmdeploy/operation/cuda/CMakeLists.txt | 32 + csrc/mmdeploy/operation/cuda/cast.cu | 28 + csrc/mmdeploy/operation/cuda/crop.cpp | 68 + csrc/mmdeploy/operation/cuda/crop.cu | 53 + .../operation/cuda/crop_resize_pad.cpp | 90 + csrc/mmdeploy/operation/cuda/cvtcolor.cpp | 128 + csrc/mmdeploy/operation/cuda/flip.cpp | 61 + csrc/mmdeploy/operation/cuda/hwc2chw.cpp | 43 + csrc/mmdeploy/operation/cuda/normalize.cpp | 74 + csrc/mmdeploy/operation/cuda/normalize.cu | 64 + csrc/mmdeploy/operation/cuda/pad.cpp | 97 + csrc/mmdeploy/operation/cuda/permute.cpp | 91 + csrc/mmdeploy/operation/cuda/permute.cu | 49 + csrc/mmdeploy/operation/cuda/permute.h | 24 + csrc/mmdeploy/operation/cuda/resize.cpp | 92 + csrc/mmdeploy/operation/cuda/to_float.cpp | 38 + csrc/mmdeploy/operation/cuda/transpose.cu | 42 + csrc/mmdeploy/operation/cuda/warp_affine.cpp | 119 + csrc/mmdeploy/operation/dummy/CMakeLists.txt | 9 + csrc/mmdeploy/operation/dummy/operations.cpp | 98 + csrc/mmdeploy/operation/managed.h | 182 ++ csrc/mmdeploy/operation/operation.cpp | 39 + csrc/mmdeploy/operation/operation.h | 113 + csrc/mmdeploy/operation/vision.cpp | 19 + csrc/mmdeploy/operation/vision.h | 103 + csrc/mmdeploy/preprocess/CMakeLists.txt | 13 + csrc/mmdeploy/preprocess/elena/CMakeLists.txt | 23 + .../preprocess/elena/cpu_kernel/.gitkeep | 0 .../preprocess/elena/cuda_kernel/.gitkeep | 0 .../preprocess/elena/elena_registry.cpp | 32 + .../preprocess/elena/elena_registry.h | 45 + csrc/mmdeploy/preprocess/elena/fused.cpp | 138 + .../preprocess/transform/CMakeLists.txt | 25 + .../preprocess/transform/center_crop.cpp | 93 + .../mmdeploy/preprocess/transform/collect.cpp | 69 + .../mmdeploy/preprocess/transform/compose.cpp | 99 + .../transform/default_format_bundle.cpp | 74 + .../preprocess/transform/image2tensor.cpp | 52 + .../preprocess/transform/letter_resize.cpp | 149 + csrc/mmdeploy/preprocess/transform/lift.cpp | 35 + csrc/mmdeploy/preprocess/transform/load.cpp | 106 + .../preprocess/transform/normalize.cpp | 139 + csrc/mmdeploy/preprocess/transform/pad.cpp | 151 + csrc/mmdeploy/preprocess/transform/resize.cpp | 141 + .../preprocess/transform/ten_crop.cpp | 90 + .../preprocess/transform/three_crop.cpp | 94 + csrc/mmdeploy/preprocess/transform/tracer.cpp | 77 + csrc/mmdeploy/preprocess/transform/tracer.h | 102 + .../preprocess/transform/transform.cpp | 26 + .../mmdeploy/preprocess/transform/transform.h | 40 + csrc/mmdeploy/preprocess/transform_module.cpp | 55 + csrc/mmdeploy/utils/CMakeLists.txt | 4 + csrc/mmdeploy/utils/dlpack/CMakeLists.txt | 14 + csrc/mmdeploy/utils/dlpack/dlpack_utils.cpp | 187 ++ csrc/mmdeploy/utils/dlpack/dlpack_utils.h | 17 + csrc/mmdeploy/utils/opencv/CMakeLists.txt | 12 + csrc/mmdeploy/utils/opencv/opencv_utils.cpp | 323 ++ csrc/mmdeploy/utils/opencv/opencv_utils.h | 167 + mmdeploy/__init__.py | 17 + mmdeploy/apis/__init__.py | 14 + mmdeploy/apis/ascend/__init__.py | 11 + mmdeploy/apis/calibration.py | 81 + mmdeploy/apis/core/__init__.py | 4 + mmdeploy/apis/core/pipeline_manager.py | 378 +++ mmdeploy/apis/coreml/__init__.py | 13 + mmdeploy/apis/extract_model.py | 67 + mmdeploy/apis/inference.py | 54 + mmdeploy/apis/ncnn/__init__.py | 18 + mmdeploy/apis/onnx/__init__.py | 5 + mmdeploy/apis/onnx/export.py | 151 + mmdeploy/apis/onnx/optimizer.py | 62 + mmdeploy/apis/onnx/partition.py | 209 ++ mmdeploy/apis/onnx/passes/__init__.py | 4 + mmdeploy/apis/onnx/passes/optimize_onnx.py | 23 + mmdeploy/apis/onnxruntime/__init__.py | 4 + mmdeploy/apis/openvino/__init__.py | 17 + mmdeploy/apis/openvino/utils.py | 70 + mmdeploy/apis/pplnn/__init__.py | 11 + mmdeploy/apis/pytorch2onnx.py | 111 + mmdeploy/apis/pytorch2torchscript.py | 70 + mmdeploy/apis/rknn/__init__.py | 11 + mmdeploy/apis/sdk/__init__.py | 14 + mmdeploy/apis/snpe/__init__.py | 16 + mmdeploy/apis/tensorrt/__init__.py | 19 + mmdeploy/apis/torch_jit/__init__.py | 5 + mmdeploy/apis/torch_jit/trace.py | 123 + mmdeploy/apis/tvm/__init__.py | 12 + mmdeploy/apis/utils/__init__.py | 9 + mmdeploy/apis/utils/calibration.py | 90 + mmdeploy/apis/utils/utils.py | 104 + mmdeploy/apis/vacc/__init__.py | 13 + mmdeploy/apis/visualize.py | 96 + mmdeploy/backend/__init__.py | 1 + mmdeploy/backend/ascend/__init__.py | 14 + mmdeploy/backend/ascend/backend_manager.py | 91 + mmdeploy/backend/ascend/onnx2ascend.py | 81 + mmdeploy/backend/ascend/utils.py | 49 + mmdeploy/backend/ascend/wrapper.py | 593 ++++ mmdeploy/backend/base/__init__.py | 12 + mmdeploy/backend/base/backend_manager.py | 173 ++ .../backend/base/backend_wrapper_registry.py | 28 + mmdeploy/backend/base/base_wrapper.py | 71 + mmdeploy/backend/coreml/__init__.py | 15 + mmdeploy/backend/coreml/backend_manager.py | 123 + mmdeploy/backend/coreml/ops.py | 97 + mmdeploy/backend/coreml/torchscript2coreml.py | 120 + mmdeploy/backend/coreml/wrapper.py | 67 + mmdeploy/backend/ncnn/__init__.py | 26 + mmdeploy/backend/ncnn/backend_manager.py | 145 + mmdeploy/backend/ncnn/init_plugins.py | 49 + mmdeploy/backend/ncnn/onnx2ncnn.py | 72 + mmdeploy/backend/ncnn/quant.py | 58 + mmdeploy/backend/ncnn/wrapper.py | 146 + mmdeploy/backend/onnxruntime/__init__.py | 17 + .../backend/onnxruntime/backend_manager.py | 156 + mmdeploy/backend/onnxruntime/init_plugins.py | 30 + mmdeploy/backend/onnxruntime/wrapper.py | 126 + mmdeploy/backend/openvino/__init__.py | 16 + mmdeploy/backend/openvino/backend_manager.py | 101 + mmdeploy/backend/openvino/onnx2openvino.py | 119 + mmdeploy/backend/openvino/utils.py | 45 + mmdeploy/backend/openvino/wrapper.py | 151 + mmdeploy/backend/pplnn/__init__.py | 13 + mmdeploy/backend/pplnn/backend_manager.py | 108 + mmdeploy/backend/pplnn/onnx2pplnn.py | 53 + mmdeploy/backend/pplnn/utils.py | 132 + mmdeploy/backend/pplnn/wrapper.py | 99 + mmdeploy/backend/rknn/__init__.py | 12 + mmdeploy/backend/rknn/backend_manager.py | 150 + mmdeploy/backend/rknn/onnx2rknn.py | 105 + mmdeploy/backend/rknn/wrapper.py | 81 + mmdeploy/backend/sdk/__init__.py | 16 + mmdeploy/backend/sdk/backend_manager.py | 83 + mmdeploy/backend/sdk/export_info.py | 370 +++ mmdeploy/backend/sdk/tracer.py | 153 + mmdeploy/backend/sdk/wrapper.py | 25 + mmdeploy/backend/snpe/__init__.py | 17 + mmdeploy/backend/snpe/backend_manager.py | 99 + mmdeploy/backend/snpe/init_plugins.py | 11 + mmdeploy/backend/snpe/onnx2dlc.py | 78 + mmdeploy/backend/snpe/wrapper.py | 250 ++ mmdeploy/backend/tensorrt/__init__.py | 24 + mmdeploy/backend/tensorrt/backend_manager.py | 138 + mmdeploy/backend/tensorrt/calib_utils.py | 128 + mmdeploy/backend/tensorrt/init_plugins.py | 39 + mmdeploy/backend/tensorrt/onnx2tensorrt.py | 88 + mmdeploy/backend/tensorrt/torch_allocator.py | 62 + mmdeploy/backend/tensorrt/utils.py | 270 ++ mmdeploy/backend/tensorrt/wrapper.py | 186 ++ mmdeploy/backend/torchscript/__init__.py | 15 + .../backend/torchscript/backend_manager.py | 104 + mmdeploy/backend/torchscript/init_plugins.py | 27 + mmdeploy/backend/torchscript/wrapper.py | 119 + mmdeploy/backend/tvm/__init__.py | 38 + mmdeploy/backend/tvm/backend_manager.py | 135 + mmdeploy/backend/tvm/onnx2tvm.py | 97 + mmdeploy/backend/tvm/quantize.py | 73 + mmdeploy/backend/tvm/tuner.py | 414 +++ mmdeploy/backend/tvm/wrapper.py | 119 + mmdeploy/backend/vacc/__init__.py | 18 + mmdeploy/backend/vacc/backend_manager.py | 144 + mmdeploy/backend/vacc/onnx2vacc.py | 105 + mmdeploy/backend/vacc/wrapper.py | 232 ++ mmdeploy/codebase/__init__.py | 40 + mmdeploy/codebase/base/__init__.py | 9 + mmdeploy/codebase/base/backend_model.py | 70 + mmdeploy/codebase/base/mmcodebase.py | 86 + mmdeploy/codebase/base/runner.py | 71 + mmdeploy/codebase/base/task.py | 412 +++ mmdeploy/codebase/mmaction/__init__.py | 3 + mmdeploy/codebase/mmaction/deploy/__init__.py | 6 + mmdeploy/codebase/mmaction/deploy/mmaction.py | 24 + .../mmaction/deploy/video_recognition.py | 332 ++ .../deploy/video_recognition_model.py | 149 + mmdeploy/codebase/mmaction/models/__init__.py | 3 + .../mmaction/models/recognizers/__init__.py | 3 + .../mmaction/models/recognizers/base.py | 36 + mmdeploy/codebase/mmagic/__init__.py | 4 + mmdeploy/codebase/mmagic/deploy/__init__.py | 5 + mmdeploy/codebase/mmagic/deploy/mmagic.py | 27 + .../mmagic/deploy/super_resolution.py | 357 +++ .../mmagic/deploy/super_resolution_model.py | 226 ++ mmdeploy/codebase/mmagic/models/__init__.py | 2 + .../mmagic/models/base_models/__init__.py | 2 + .../models/base_models/base_edit_model.py | 30 + mmdeploy/codebase/mmdet/__init__.py | 9 + mmdeploy/codebase/mmdet/deploy/__init__.py | 10 + .../mmdet/deploy/model_partition_cfg.py | 62 + .../codebase/mmdet/deploy/object_detection.py | 357 +++ .../mmdet/deploy/object_detection_model.py | 1122 +++++++ mmdeploy/codebase/mmdet/deploy/utils.py | 291 ++ mmdeploy/codebase/mmdet/models/__init__.py | 11 + mmdeploy/codebase/mmdet/models/backbones.py | 270 ++ .../mmdet/models/dense_heads/__init__.py | 15 + .../models/dense_heads/base_dense_head.py | 559 ++++ .../models/dense_heads/centernet_head.py | 44 + .../mmdet/models/dense_heads/condinst_head.py | 202 ++ .../mmdet/models/dense_heads/detr_head.py | 64 + .../mmdet/models/dense_heads/fovea_head.py | 108 + .../mmdet/models/dense_heads/gfl_head.py | 195 ++ .../models/dense_heads/reppoints_head.py | 192 ++ .../mmdet/models/dense_heads/rpn_head.py | 288 ++ .../mmdet/models/dense_heads/rtmdet_head.py | 225 ++ .../models/dense_heads/rtmdet_ins_head.py | 210 ++ .../mmdet/models/dense_heads/solo_head.py | 103 + .../mmdet/models/dense_heads/solov2_head.py | 140 + .../mmdet/models/dense_heads/yolo_head.py | 254 ++ .../mmdet/models/dense_heads/yolox_head.py | 246 ++ .../mmdet/models/detectors/__init__.py | 12 + .../mmdet/models/detectors/base_detr.py | 89 + .../mmdet/models/detectors/maskformer.py | 54 + .../detectors/panoptic_two_stage_segmentor.py | 65 + .../mmdet/models/detectors/single_stage.py | 85 + .../detectors/single_stage_instance_seg.py | 82 + .../mmdet/models/detectors/two_stage.py | 92 + .../codebase/mmdet/models/layers/__init__.py | 6 + .../mmdet/models/layers/matrix_nms.py | 103 + mmdeploy/codebase/mmdet/models/necks.py | 40 + .../mmdet/models/roi_heads/__init__.py | 7 + .../mmdet/models/roi_heads/bbox_head.py | 147 + .../models/roi_heads/cascade_roi_head.py | 142 + .../mmdet/models/roi_heads/fcn_mask_head.py | 139 + .../mmdet/models/roi_heads/htc_roi_head.py | 48 + .../roi_heads/single_level_roi_extractor.py | 354 +++ .../models/roi_heads/standard_roi_head.py | 125 + .../mmdet/models/seg_heads/__init__.py | 4 + .../models/seg_heads/base_semantic_head.py | 31 + .../mmdet/models/task_modules/__init__.py | 3 + .../models/task_modules/coders/__init__.py | 4 + .../coders/delta_xywh_bbox_coder.py | 230 ++ .../coders/distance_point_bbox_coder.py | 42 + .../task_modules/coders/tblr_bbox_coder.py | 72 + .../task_modules/prior_generators/__init__.py | 3 + .../task_modules/prior_generators/anchor.py | 118 + .../prior_generators/point_generator.py | 63 + mmdeploy/codebase/mmdet/models/transformer.py | 52 + .../codebase/mmdet/models/utils/__init__.py | 2 + .../mmdet/models/utils/gaussian_target.py | 20 + mmdeploy/codebase/mmdet/ops/__init__.py | 5 + .../codebase/mmdet/ops/detection_output.py | 72 + mmdeploy/codebase/mmdet/ops/prior_box.py | 83 + .../codebase/mmdet/structures/__init__.py | 2 + .../mmdet/structures/bbox/__init__.py | 2 + .../mmdet/structures/bbox/transforms.py | 43 + mmdeploy/codebase/mmdet3d/__init__.py | 4 + mmdeploy/codebase/mmdet3d/deploy/__init__.py | 11 + mmdeploy/codebase/mmdet3d/deploy/mmdet3d.py | 25 + .../codebase/mmdet3d/deploy/mono_detection.py | 208 ++ .../mmdet3d/deploy/mono_detection_model.py | 250 ++ .../mmdet3d/deploy/voxel_detection.py | 196 ++ .../mmdet3d/deploy/voxel_detection_model.py | 420 +++ mmdeploy/codebase/mmdet3d/models/__init__.py | 6 + mmdeploy/codebase/mmdet3d/models/base.py | 27 + .../codebase/mmdet3d/models/mvx_two_stage.py | 115 + .../codebase/mmdet3d/models/pillar_encode.py | 65 + .../codebase/mmdet3d/models/pillar_scatter.py | 35 + .../mmdet3d/models/single_stage_mono3d.py | 22 + mmdeploy/codebase/mmocr/__init__.py | 2 + mmdeploy/codebase/mmocr/deploy/__init__.py | 6 + mmdeploy/codebase/mmocr/deploy/mmocr.py | 31 + .../codebase/mmocr/deploy/text_detection.py | 318 ++ .../mmocr/deploy/text_detection_model.py | 273 ++ .../codebase/mmocr/deploy/text_recognition.py | 284 ++ .../mmocr/deploy/text_recognition_model.py | 174 ++ mmdeploy/codebase/mmocr/models/__init__.py | 3 + .../mmocr/models/text_detection/__init__.py | 5 + .../mmocr/models/text_detection/fpn_cat.py | 58 + .../mmocr/models/text_detection/heads.py | 57 + .../models/text_detection/mmdet_wrapper.py | 56 + .../single_stage_text_detector.py | 43 + .../mmocr/models/text_recognition/__init__.py | 11 + .../text_recognition/abi_language_decoder.py | 31 + .../models/text_recognition/base_decoder.py | 30 + .../models/text_recognition/crnn_decoder.py | 24 + .../encoder_decoder_recognizer.py | 36 + .../models/text_recognition/lstm_layer.py | 31 + .../models/text_recognition/nrtr_decoder.py | 36 + .../models/text_recognition/sar_decoder.py | 270 ++ .../models/text_recognition/sar_encoder.py | 65 + .../models/text_recognition/satrn_encoder.py | 42 + .../text_recognition/transformer_module.py | 44 + mmdeploy/codebase/mmocr/models/utils.py | 25 + mmdeploy/codebase/mmpose/__init__.py | 4 + mmdeploy/codebase/mmpose/codecs/__init__.py | 5 + .../codebase/mmpose/codecs/post_processing.py | 33 + mmdeploy/codebase/mmpose/deploy/__init__.py | 4 + .../codebase/mmpose/deploy/pose_detection.py | 380 +++ .../mmpose/deploy/pose_detection_model.py | 321 ++ mmdeploy/codebase/mmpose/models/__init__.py | 5 + .../codebase/mmpose/models/heads/__init__.py | 4 + .../codebase/mmpose/models/heads/mspn_head.py | 24 + .../codebase/mmpose/models/heads/rtmo_head.py | 100 + .../mmpose/models/heads/simcc_head.py | 28 + .../mmpose/models/heads/yolox_pose_head.py | 118 + .../mmpose/models/pose_estimators/__init__.py | 4 + .../mmpose/models/pose_estimators/base.py | 21 + .../codebase/mmpose/models/utils/__init__.py | 5 + .../mmpose/models/utils/rtmcc_block.py | 91 + mmdeploy/codebase/mmpretrain/__init__.py | 2 + .../codebase/mmpretrain/deploy/__init__.py | 4 + .../mmpretrain/deploy/classification.py | 360 +++ .../mmpretrain/deploy/classification_model.py | 248 ++ .../codebase/mmpretrain/models/__init__.py | 5 + .../mmpretrain/models/backbones/__init__.py | 2 + .../models/backbones/shufflenet_v2.py | 34 + .../mmpretrain/models/classifiers/__init__.py | 2 + .../mmpretrain/models/classifiers/base.py | 45 + .../mmpretrain/models/necks/__init__.py | 2 + .../codebase/mmpretrain/models/necks/gap.py | 26 + .../mmpretrain/models/utils/__init__.py | 2 + .../mmpretrain/models/utils/attention.py | 184 ++ mmdeploy/codebase/mmrazor/deploy/__init__.py | 4 + mmdeploy/codebase/mmrazor/deploy/mmrazor.py | 135 + mmdeploy/codebase/mmrotate/__init__.py | 2 + mmdeploy/codebase/mmrotate/deploy/__init__.py | 4 + .../mmrotate/deploy/rotated_detection.py | 367 +++ .../deploy/rotated_detection_model.py | 221 ++ mmdeploy/codebase/mmrotate/models/__init__.py | 4 + .../mmrotate/models/dense_heads/__init__.py | 3 + .../models/dense_heads/oriented_rpn_head.py | 184 ++ .../models/dense_heads/rotated_rtmdet_head.py | 119 + .../mmrotate/models/roi_heads/__init__.py | 4 + .../mmrotate/models/roi_heads/gv_bbox_head.py | 113 + .../models/roi_heads/gv_ratio_roi_head.py | 78 + .../models/roi_heads/roi_extractors.py | 96 + .../mmrotate/models/task_modules/__init__.py | 2 + .../mmrotate/models/task_modules/coders.py | 33 + .../codebase/mmrotate/structures/__init__.py | 2 + mmdeploy/codebase/mmrotate/structures/bbox.py | 46 + mmdeploy/codebase/mmseg/__init__.py | 2 + mmdeploy/codebase/mmseg/deploy/__init__.py | 4 + .../codebase/mmseg/deploy/segmentation.py | 326 ++ .../mmseg/deploy/segmentation_model.py | 234 ++ mmdeploy/codebase/mmseg/models/__init__.py | 4 + .../mmseg/models/decode_heads/__init__.py | 4 + .../mmseg/models/decode_heads/decode_head.py | 21 + .../mmseg/models/decode_heads/ema_head.py | 45 + .../mmseg/models/decode_heads/point_head.py | 38 + .../mmseg/models/segmentors/__init__.py | 4 + .../codebase/mmseg/models/segmentors/base.py | 69 + .../segmentors/cascade_encoder_decoder.py | 31 + .../models/segmentors/encoder_decoder.py | 27 + .../codebase/mmseg/models/utils/__init__.py | 2 + .../mmseg/models/utils/up_conv_block.py | 41 + mmdeploy/core/__init__.py | 3 + mmdeploy/core/optimizers/__init__.py | 11 + mmdeploy/core/optimizers/extractor.py | 63 + mmdeploy/core/optimizers/function_marker.py | 275 ++ mmdeploy/core/optimizers/optimize.py | 229 ++ mmdeploy/core/rewriters/__init__.py | 11 + mmdeploy/core/rewriters/function_rewriter.py | 291 ++ mmdeploy/core/rewriters/module_rewriter.py | 143 + mmdeploy/core/rewriters/rewriter_manager.py | 109 + mmdeploy/core/rewriters/rewriter_utils.py | 465 +++ mmdeploy/core/rewriters/symbolic_rewriter.py | 198 ++ mmdeploy/mmcv/__init__.py | 3 + mmdeploy/mmcv/cnn/__init__.py | 4 + mmdeploy/mmcv/cnn/transformer.py | 145 + mmdeploy/mmcv/ops/__init__.py | 18 + mmdeploy/mmcv/ops/deform_conv.py | 60 + mmdeploy/mmcv/ops/modulated_deform_conv.py | 47 + mmdeploy/mmcv/ops/multi_scale_deform_attn.py | 26 + mmdeploy/mmcv/ops/nms.py | 755 +++++ mmdeploy/mmcv/ops/nms_match.py | 209 ++ mmdeploy/mmcv/ops/nms_rotated.py | 331 ++ mmdeploy/mmcv/ops/point_sample.py | 68 + mmdeploy/mmcv/ops/roi_align.py | 129 + mmdeploy/mmcv/ops/roi_align_rotated.py | 51 + mmdeploy/mmcv/ops/transformer.py | 32 + mmdeploy/pytorch/__init__.py | 3 + mmdeploy/pytorch/functions/__init__.py | 26 + mmdeploy/pytorch/functions/adaptive_pool.py | 46 + mmdeploy/pytorch/functions/any.py | 19 + mmdeploy/pytorch/functions/atan2.py | 14 + mmdeploy/pytorch/functions/cat.py | 24 + mmdeploy/pytorch/functions/chunk.py | 47 + mmdeploy/pytorch/functions/clip.py | 28 + mmdeploy/pytorch/functions/copy.py | 17 + mmdeploy/pytorch/functions/expand.py | 17 + mmdeploy/pytorch/functions/flatten.py | 25 + mmdeploy/pytorch/functions/getattribute.py | 20 + mmdeploy/pytorch/functions/group_norm.py | 46 + mmdeploy/pytorch/functions/interpolate.py | 136 + mmdeploy/pytorch/functions/linear.py | 71 + mmdeploy/pytorch/functions/linspace.py | 21 + mmdeploy/pytorch/functions/masked_fill.py | 26 + mmdeploy/pytorch/functions/mod.py | 21 + .../functions/multi_head_attention_forward.py | 81 + mmdeploy/pytorch/functions/normalize.py | 66 + mmdeploy/pytorch/functions/pad.py | 78 + mmdeploy/pytorch/functions/repeat.py | 27 + mmdeploy/pytorch/functions/size.py | 43 + mmdeploy/pytorch/functions/tensor_getitem.py | 42 + mmdeploy/pytorch/functions/tensor_setitem.py | 81 + mmdeploy/pytorch/functions/topk.py | 94 + mmdeploy/pytorch/functions/triu.py | 19 + mmdeploy/pytorch/symbolics/__init__.py | 11 + mmdeploy/pytorch/symbolics/adaptive_pool.py | 13 + mmdeploy/pytorch/symbolics/gelu.py | 18 + mmdeploy/pytorch/symbolics/grid_sampler.py | 63 + mmdeploy/pytorch/symbolics/hardsigmoid.py | 12 + mmdeploy/pytorch/symbolics/instance_norm.py | 73 + mmdeploy/pytorch/symbolics/layer_norm.py | 70 + mmdeploy/pytorch/symbolics/linear.py | 44 + mmdeploy/pytorch/symbolics/lstm.py | 228 ++ mmdeploy/pytorch/symbolics/roll.py | 33 + mmdeploy/pytorch/symbolics/squeeze.py | 29 + mmdeploy/utils/__init__.py | 41 + mmdeploy/utils/config_utils.py | 479 +++ mmdeploy/utils/constants.py | 99 + mmdeploy/utils/dataset.py | 36 + mmdeploy/utils/device.py | 59 + mmdeploy/utils/env.py | 51 + mmdeploy/utils/logging.py | 79 + mmdeploy/utils/test.py | 512 +++ mmdeploy/utils/timer.py | 171 + mmdeploy/utils/utils.py | 128 + mmdeploy/version.py | 30 + 954 files changed, 96675 insertions(+) create mode 100644 csrc/mmdeploy/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/c/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/classifier.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/common.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/common.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/common_internal.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/detector.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/detector.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/executor.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/executor.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/executor_internal.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/handle.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/model.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/model.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pipeline.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pipeline.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pose_detector.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/restorer.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/segmentor.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/text_detector.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/text_detector.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.h create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.cpp create mode 100644 csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.h create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy.sln create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/.editorconfig create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Classifier.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Context.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Detector.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Device.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/DisposableObject.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Model.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/PoseDetector.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/PoseTracker.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Profiler.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Restorer.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/RotatedDetector.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Scheduler.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Segmentor.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/TextDetector.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/TextRecognizer.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/APIs/common.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/MMDeployCSharp.csproj create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/MMDeployCSharp.props create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/NativeAPIs/NativeMethods.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/NativeAPIs/NativeMethods_c_api.cs create mode 100644 csrc/mmdeploy/apis/csharp/MMDeploy/Properties/AssemblyInfo.cs create mode 100644 csrc/mmdeploy/apis/csharp/README.md create mode 100644 csrc/mmdeploy/apis/cxx/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/classifier.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/common.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/detector.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/pipeline.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/pose_detector.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/pose_tracker.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/restorer.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/rotated_detector.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/segmentor.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/text_detector.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/text_recognizer.hpp create mode 100644 csrc/mmdeploy/apis/cxx/mmdeploy/video_recognizer.hpp create mode 100644 csrc/mmdeploy/apis/java/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/java/README.md create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Classifier.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Context.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/DataType.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Detector.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Device.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/InstanceMask.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Mat.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Model.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/PixelFormat.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/PointF.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/PoseDetector.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/PoseTracker.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Profiler.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Rect.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Restorer.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/RotatedDetector.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Scheduler.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/Segmentor.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/TextDetector.java create mode 100644 csrc/mmdeploy/apis/java/mmdeploy/TextRecognizer.java create mode 100644 csrc/mmdeploy/apis/java/native/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/java/native/common.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Classifier.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Classifier.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Context.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Context.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Detector.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Detector.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Device.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Device.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Model.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Model.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_PoseDetector.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_PoseDetector.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_PoseTracker.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_PoseTracker.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Profiler.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Profiler.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Restorer.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Restorer.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_RotatedDetector.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_RotatedDetector.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Scheduler.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Scheduler.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Segmentor.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_Segmentor.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_TextDetector.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_TextDetector.h create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_TextRecognizer.cpp create mode 100644 csrc/mmdeploy/apis/java/native/mmdeploy_TextRecognizer.h create mode 100644 csrc/mmdeploy/apis/python/CMakeLists.txt create mode 100644 csrc/mmdeploy/apis/python/classifier.cpp create mode 100644 csrc/mmdeploy/apis/python/common.cpp create mode 100644 csrc/mmdeploy/apis/python/common.h create mode 100644 csrc/mmdeploy/apis/python/detector.cpp create mode 100644 csrc/mmdeploy/apis/python/executor.cpp create mode 100644 csrc/mmdeploy/apis/python/internal.cpp create mode 100644 csrc/mmdeploy/apis/python/pipeline.cpp create mode 100644 csrc/mmdeploy/apis/python/pose_detector.cpp create mode 100644 csrc/mmdeploy/apis/python/pose_tracker.cpp create mode 100644 csrc/mmdeploy/apis/python/restorer.cpp create mode 100644 csrc/mmdeploy/apis/python/rotated_detector.cpp create mode 100644 csrc/mmdeploy/apis/python/segmentor.cpp create mode 100644 csrc/mmdeploy/apis/python/text_detector.cpp create mode 100644 csrc/mmdeploy/apis/python/text_recognizer.cpp create mode 100644 csrc/mmdeploy/apis/python/video_recognizer.cpp create mode 100644 csrc/mmdeploy/archive/CMakeLists.txt create mode 100644 csrc/mmdeploy/archive/json_archive.h create mode 100644 csrc/mmdeploy/archive/value_archive.h create mode 100644 csrc/mmdeploy/backend_ops/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/common/modulated_deform_conv/common_cuda_helper.cuh create mode 100644 csrc/mmdeploy/backend_ops/common/modulated_deform_conv/modulated_deform_conv_cpu.h create mode 100644 csrc/mmdeploy/backend_ops/common/modulated_deform_conv/modulated_deform_conv_cuda.cuh create mode 100755 csrc/mmdeploy/backend_ops/ncnn/CMakeLists.txt create mode 100755 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/fuse_pass.cpp create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/fuse_pass.h create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/onnx.proto create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/onnx2ncnn.cpp create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/shape_inference.cpp create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/shape_inference.h create mode 100644 csrc/mmdeploy/backend_ops/ncnn/onnx2ncnn/utils.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/CMakeLists.txt create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/constantofshape/constantofshape.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/constantofshape/constantofshape.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/expand/expand.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/expand/expand.h create mode 100644 csrc/mmdeploy/backend_ops/ncnn/ops/gather/gather.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/gather/gather.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/ncnn_ops_definer.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/ncnn_ops_register.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/ncnn_ops_register.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/shape/shape.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/shape/shape.h create mode 100644 csrc/mmdeploy/backend_ops/ncnn/ops/tensorslice/tensorslice.cpp create mode 100755 csrc/mmdeploy/backend_ops/ncnn/ops/tensorslice/tensorslice.h create mode 100644 csrc/mmdeploy/backend_ops/ncnn/ops/topk/topk.cpp create mode 100644 csrc/mmdeploy/backend_ops/ncnn/ops/topk/topk.h create mode 100755 csrc/mmdeploy/backend_ops/ncnn/pyncnn_ext/CMakeLists.txt create mode 100755 csrc/mmdeploy/backend_ops/ncnn/pyncnn_ext/ncnn_ext.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/common/onnxruntime_register.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/common/onnxruntime_session_options_config_keys.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/common/ort_utils.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/common/ort_utils.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/grid_sample/grid_sample.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/grid_sample/grid_sample.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/modulated_deform_conv/modulated_deform_conv.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/nms_match/nms_match.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/nms_match/nms_match.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/nms_rotated/nms_rotated.h create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/onnxruntime_register.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/roi_align_rotated/roi_align_rotated.cpp create mode 100644 csrc/mmdeploy/backend_ops/onnxruntime/roi_align_rotated/roi_align_rotated.h create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/batched_nms/trt_batched_nms.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/batched_nms/trt_batched_nms.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/batched_rotated_nms/trt_batched_rotated_nms.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/batched_rotated_nms/trt_batched_rotated_nms.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/bicubic_interpolate/trt_bicubic_interpolate.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/bicubic_interpolate/trt_bicubic_interpolate.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/bicubic_interpolate/trt_bicubic_interpolate_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/bicubic_interpolate/trt_bicubic_interpolate_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/common_cuda_helper.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/nms/batched_nms_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/nms/cub_helper.h create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/nms/kernel.h create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/trt_plugin_base.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/trt_plugin_helper.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common/trt_serialize.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/allClassNMS.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/allClassRotatedNMS.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/batched_nms_kernel.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/gatherNMSOutputs.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/permuteData.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/sortScoresPerClass.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/nms/sortScoresPerImage.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/common_impl/trt_cuda_helper.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/deform_conv/trt_deform_conv.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/deform_conv/trt_deform_conv.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/deform_conv/trt_deform_conv_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/deform_conv/trt_deform_conv_kernel.cuh create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/deform_conv/trt_deform_conv_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/gather_topk/gather_topk.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/gather_topk/gather_topk.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/gather_topk/gather_topk_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/gather_topk/gather_topk_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_priors/trt_grid_priors.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_priors/trt_grid_priors.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_priors/trt_grid_priors_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_priors/trt_grid_priors_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_sampler/trt_grid_sampler.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_sampler/trt_grid_sampler.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_sampler/trt_grid_sampler_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/grid_sampler/trt_grid_sampler_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/instance_norm/trt_instance_norm.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/instance_norm/trt_instance_norm.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/modulated_deform_conv/trt_modulated_deform_conv.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/modulated_deform_conv/trt_modulated_deform_conv.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/modulated_deform_conv/trt_modulated_deform_conv_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/modulated_deform_conv/trt_modulated_deform_conv_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_roi_align/trt_multi_level_roi_align.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_roi_align/trt_multi_level_roi_align.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_roi_align/trt_multi_level_roi_align_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_roi_align/trt_multi_level_roi_align_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_rotated_roi_align/trt_multi_level_rotated_roi_align.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_rotated_roi_align/trt_multi_level_rotated_roi_align.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_rotated_roi_align/trt_multi_level_rotated_roi_align_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_level_rotated_roi_align/trt_multi_level_rotated_roi_align_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_scale_deform_attn/trt_ms_deform_attn.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_scale_deform_attn/trt_ms_deform_attn.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_scale_deform_attn/trt_ms_deform_attn_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_scale_deform_attn/trt_ms_deform_attn_kernel.cuh create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/multi_scale_deform_attn/trt_ms_deform_attn_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/roi_align/trt_roi_align.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/roi_align/trt_roi_align.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/roi_align/trt_roi_align_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/roi_align/trt_roi_align_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scaled_dot_product_attention/scaled_dot_product_attention.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scaled_dot_product_attention/scaled_dot_product_attention.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scaled_dot_product_attention/scaled_dot_product_attention_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scaled_dot_product_attention/scaled_dot_product_attention_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scatternd/trt_scatternd.cpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scatternd/trt_scatternd.hpp create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scatternd/trt_scatternd_kernel.cu create mode 100644 csrc/mmdeploy/backend_ops/tensorrt/scatternd/trt_scatternd_kernel.hpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/torchscript/ops/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/torchscript/ops/bind.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/ops/coreml_nms/coreml_nms_cpu.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/ops/modulated_deform_conv/modulated_deform_conv_cpu.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/ops/modulated_deform_conv/modulated_deform_conv_cuda.cu create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/CMakeLists.txt create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/bind.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/ir/subgraph_matcher.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/ir/subgraph_matcher.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/optimizer.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/optimizer.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/common_subgraph_elimination.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/common_subgraph_elimination.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/flatten_cls_head.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/flatten_cls_head.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/fuse_select_assign.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/fuse_select_assign.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/merge_shape_concate.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/merge_shape_concate.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/onnx_peephole.cpp create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/onnx_peephole.h create mode 100644 csrc/mmdeploy/backend_ops/torchscript/optimizer/passes/onnx/utils.h create mode 100644 csrc/mmdeploy/codebase/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/common.h create mode 100644 csrc/mmdeploy/codebase/mmaction/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmaction/base_head.cpp create mode 100644 csrc/mmdeploy/codebase/mmaction/format_shape.cpp create mode 100644 csrc/mmdeploy/codebase/mmaction/format_shape.h create mode 100644 csrc/mmdeploy/codebase/mmaction/mmaction.cpp create mode 100644 csrc/mmdeploy/codebase/mmaction/mmaction.h create mode 100644 csrc/mmdeploy/codebase/mmcls/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmcls/linear_cls.cpp create mode 100644 csrc/mmdeploy/codebase/mmcls/mmcls.cpp create mode 100644 csrc/mmdeploy/codebase/mmcls/mmcls.h create mode 100644 csrc/mmdeploy/codebase/mmcls/multi_label_linear_cls.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmdet/base_dense_head.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/base_dense_head.h create mode 100644 csrc/mmdeploy/codebase/mmdet/instance_segmentation.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/mmdet.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/mmdet.h create mode 100644 csrc/mmdeploy/codebase/mmdet/object_detection.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/object_detection.h create mode 100644 csrc/mmdeploy/codebase/mmdet/rtmdet_head.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/rtmdet_head.h create mode 100644 csrc/mmdeploy/codebase/mmdet/utils.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/utils.h create mode 100644 csrc/mmdeploy/codebase/mmdet/yolo_head.cpp create mode 100644 csrc/mmdeploy/codebase/mmdet/yolo_head.h create mode 100644 csrc/mmdeploy/codebase/mmedit/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmedit/mmedit.cpp create mode 100644 csrc/mmdeploy/codebase/mmedit/mmedit.h create mode 100644 csrc/mmdeploy/codebase/mmedit/restorer.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmocr/attention_convertor.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/base_convertor.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/base_convertor.h create mode 100644 csrc/mmdeploy/codebase/mmocr/contour_expand.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cpu/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmocr/cpu/dbnet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cpu/panet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cpu/psenet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/crnn.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/connected_component.cu create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/connected_component.h create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/dbnet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/panet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/psenet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/utils.cu create mode 100644 csrc/mmdeploy/codebase/mmocr/cuda/utils.h create mode 100644 csrc/mmdeploy/codebase/mmocr/dbnet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/dbnet.h create mode 100644 csrc/mmdeploy/codebase/mmocr/mmocr.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/mmocr.h create mode 100644 csrc/mmdeploy/codebase/mmocr/panet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/panet.h create mode 100644 csrc/mmdeploy/codebase/mmocr/pixel_group.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/psenet.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/psenet.h create mode 100644 csrc/mmdeploy/codebase/mmocr/rescale_to_height.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/resize_ocr.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/short_scale_aspect_jitter.cpp create mode 100644 csrc/mmdeploy/codebase/mmocr/warp.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmpose/keypoints_from_heatmap.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/keypoints_from_regression.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/mmpose.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/mmpose.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/common.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/pipeline.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/pose_tracker.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/pose_tracker.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/smoothing_filter.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/smoothing_filter.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/track.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/track.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/tracking_filter.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/tracking_filter.h create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/utils.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/pose_tracker/utils.h create mode 100644 csrc/mmdeploy/codebase/mmpose/simcc_label.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/topdown_affine.cpp create mode 100644 csrc/mmdeploy/codebase/mmpose/topdown_get_bbox_center_scale.cpp create mode 100644 csrc/mmdeploy/codebase/mmrotate/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmrotate/mmrotate.cpp create mode 100644 csrc/mmdeploy/codebase/mmrotate/mmrotate.h create mode 100644 csrc/mmdeploy/codebase/mmrotate/oriented_object_detection.cpp create mode 100644 csrc/mmdeploy/codebase/mmseg/CMakeLists.txt create mode 100644 csrc/mmdeploy/codebase/mmseg/mmseg.cpp create mode 100644 csrc/mmdeploy/codebase/mmseg/mmseg.h create mode 100644 csrc/mmdeploy/codebase/mmseg/segment.cpp create mode 100644 csrc/mmdeploy/core/CMakeLists.txt create mode 100644 csrc/mmdeploy/core/archive.h create mode 100644 csrc/mmdeploy/core/device.h create mode 100644 csrc/mmdeploy/core/device_impl.cpp create mode 100644 csrc/mmdeploy/core/device_impl.h create mode 100644 csrc/mmdeploy/core/graph.cpp create mode 100644 csrc/mmdeploy/core/graph.h create mode 100644 csrc/mmdeploy/core/logger.cpp create mode 100644 csrc/mmdeploy/core/logger.h create mode 100644 csrc/mmdeploy/core/macro.h create mode 100644 csrc/mmdeploy/core/mat.cpp create mode 100644 csrc/mmdeploy/core/mat.h create mode 100644 csrc/mmdeploy/core/model.cpp create mode 100644 csrc/mmdeploy/core/model.h create mode 100644 csrc/mmdeploy/core/model_impl.h create mode 100644 csrc/mmdeploy/core/module.cpp create mode 100644 csrc/mmdeploy/core/module.h create mode 100644 csrc/mmdeploy/core/mpl/detected.h create mode 100644 csrc/mmdeploy/core/mpl/iterator.h create mode 100644 csrc/mmdeploy/core/mpl/priority_tag.h create mode 100644 csrc/mmdeploy/core/mpl/span.h create mode 100644 csrc/mmdeploy/core/mpl/static_any.h create mode 100644 csrc/mmdeploy/core/mpl/structure.h create mode 100644 csrc/mmdeploy/core/mpl/type_traits.h create mode 100644 csrc/mmdeploy/core/net.cpp create mode 100644 csrc/mmdeploy/core/net.h create mode 100644 csrc/mmdeploy/core/operator.cpp create mode 100644 csrc/mmdeploy/core/operator.h create mode 100644 csrc/mmdeploy/core/profiler.cpp create mode 100644 csrc/mmdeploy/core/profiler.h create mode 100644 csrc/mmdeploy/core/registry.cpp create mode 100644 csrc/mmdeploy/core/registry.h create mode 100644 csrc/mmdeploy/core/serialization.h create mode 100644 csrc/mmdeploy/core/status_code.cpp create mode 100644 csrc/mmdeploy/core/status_code.h create mode 100644 csrc/mmdeploy/core/tensor.cpp create mode 100644 csrc/mmdeploy/core/tensor.h create mode 100644 csrc/mmdeploy/core/types.h create mode 100644 csrc/mmdeploy/core/utils/device_utils.cpp create mode 100644 csrc/mmdeploy/core/utils/device_utils.h create mode 100644 csrc/mmdeploy/core/utils/filesystem.h create mode 100644 csrc/mmdeploy/core/utils/formatter.cpp create mode 100644 csrc/mmdeploy/core/utils/formatter.h create mode 100644 csrc/mmdeploy/core/utils/source_location.h create mode 100644 csrc/mmdeploy/core/utils/stacktrace.cpp create mode 100644 csrc/mmdeploy/core/utils/stacktrace.h create mode 100644 csrc/mmdeploy/core/value.h create mode 100644 csrc/mmdeploy/device/CMakeLists.txt create mode 100644 csrc/mmdeploy/device/acl/CMakeLists.txt create mode 100644 csrc/mmdeploy/device/acl/acl_device.cpp create mode 100644 csrc/mmdeploy/device/cpu/CMakeLists.txt create mode 100644 csrc/mmdeploy/device/cpu/cpu_device.cpp create mode 100644 csrc/mmdeploy/device/cpu/cpu_device.h create mode 100644 csrc/mmdeploy/device/cuda/CMakeLists.txt create mode 100644 csrc/mmdeploy/device/cuda/buddy_allocator.h create mode 100644 csrc/mmdeploy/device/cuda/cuda_device.cpp create mode 100644 csrc/mmdeploy/device/cuda/cuda_device.h create mode 100644 csrc/mmdeploy/device/cuda/default_allocator.h create mode 100644 csrc/mmdeploy/device/cuda/linear_allocator.h create mode 100644 csrc/mmdeploy/device/device_allocator.h create mode 100644 csrc/mmdeploy/execution/CMakeLists.txt create mode 100644 csrc/mmdeploy/execution/bulk.h create mode 100644 csrc/mmdeploy/execution/closure.h create mode 100644 csrc/mmdeploy/execution/concepts.h create mode 100644 csrc/mmdeploy/execution/dynamic_batch.h create mode 100644 csrc/mmdeploy/execution/ensure_started.h create mode 100644 csrc/mmdeploy/execution/execute.h create mode 100644 csrc/mmdeploy/execution/execution.h create mode 100644 csrc/mmdeploy/execution/expand.h create mode 100644 csrc/mmdeploy/execution/just.h create mode 100644 csrc/mmdeploy/execution/let_value.h create mode 100644 csrc/mmdeploy/execution/on.h create mode 100644 csrc/mmdeploy/execution/run_loop.h create mode 100644 csrc/mmdeploy/execution/schedule_from.h create mode 100644 csrc/mmdeploy/execution/schedulers/dynamic_batch_scheduler.h create mode 100644 csrc/mmdeploy/execution/schedulers/inlined_scheduler.h create mode 100644 csrc/mmdeploy/execution/schedulers/intrusive_queue.h create mode 100644 csrc/mmdeploy/execution/schedulers/registry.h create mode 100644 csrc/mmdeploy/execution/schedulers/schedulers.cpp create mode 100644 csrc/mmdeploy/execution/schedulers/single_thread_context.h create mode 100644 csrc/mmdeploy/execution/schedulers/static_thread_pool.h create mode 100644 csrc/mmdeploy/execution/schedulers/timed_single_thread_context.h create mode 100644 csrc/mmdeploy/execution/split.h create mode 100644 csrc/mmdeploy/execution/start_detached.h create mode 100644 csrc/mmdeploy/execution/submit.h create mode 100644 csrc/mmdeploy/execution/sync_wait.h create mode 100644 csrc/mmdeploy/execution/tag_invoke.h create mode 100644 csrc/mmdeploy/execution/then.h create mode 100644 csrc/mmdeploy/execution/transfer.h create mode 100644 csrc/mmdeploy/execution/transfer_just.h create mode 100644 csrc/mmdeploy/execution/type_erased.h create mode 100644 csrc/mmdeploy/execution/type_traits.h create mode 100644 csrc/mmdeploy/execution/utility.h create mode 100644 csrc/mmdeploy/execution/when_all.h create mode 100644 csrc/mmdeploy/execution/when_all_value.h create mode 100644 csrc/mmdeploy/experimental/module_adapter.h create mode 100644 csrc/mmdeploy/graph/CMakeLists.txt create mode 100644 csrc/mmdeploy/graph/common.h create mode 100644 csrc/mmdeploy/graph/cond.cpp create mode 100644 csrc/mmdeploy/graph/cond.h create mode 100644 csrc/mmdeploy/graph/flattened.h create mode 100644 csrc/mmdeploy/graph/inference.cpp create mode 100644 csrc/mmdeploy/graph/inference.h create mode 100644 csrc/mmdeploy/graph/pipeline.cpp create mode 100644 csrc/mmdeploy/graph/pipeline.h create mode 100644 csrc/mmdeploy/graph/static_router.cpp create mode 100644 csrc/mmdeploy/graph/static_router.h create mode 100644 csrc/mmdeploy/graph/task.cpp create mode 100644 csrc/mmdeploy/graph/task.h create mode 100644 csrc/mmdeploy/model/CMakeLists.txt create mode 100644 csrc/mmdeploy/model/directory_model_impl.cpp create mode 100644 csrc/mmdeploy/model/zip_model_impl.cpp create mode 100644 csrc/mmdeploy/net/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/acl/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/acl/acl_net.cpp create mode 100644 csrc/mmdeploy/net/acl/acl_net.h create mode 100644 csrc/mmdeploy/net/coreml/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/coreml/coreml_net.h create mode 100644 csrc/mmdeploy/net/coreml/coreml_net.mm create mode 100644 csrc/mmdeploy/net/ncnn/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/ncnn/ncnn_net.cpp create mode 100644 csrc/mmdeploy/net/ncnn/ncnn_net.h create mode 100644 csrc/mmdeploy/net/net_module.cpp create mode 100644 csrc/mmdeploy/net/net_module.h create mode 100644 csrc/mmdeploy/net/openvino/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/openvino/openvino_net.cpp create mode 100644 csrc/mmdeploy/net/openvino/openvino_net.h create mode 100644 csrc/mmdeploy/net/ort/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/ort/ort_net.cpp create mode 100644 csrc/mmdeploy/net/ort/ort_net.h create mode 100644 csrc/mmdeploy/net/ppl/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/ppl/ppl_net.cpp create mode 100644 csrc/mmdeploy/net/ppl/ppl_net.h create mode 100644 csrc/mmdeploy/net/rknn/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/rknn/rknn_net.cpp create mode 100644 csrc/mmdeploy/net/rknn/rknn_net.h create mode 100644 csrc/mmdeploy/net/snpe/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/snpe/snpe_net.cpp create mode 100644 csrc/mmdeploy/net/snpe/snpe_net.h create mode 100644 csrc/mmdeploy/net/torchscript/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/torchscript/torch_net.cpp create mode 100644 csrc/mmdeploy/net/torchscript/torch_net.h create mode 100644 csrc/mmdeploy/net/trt/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/trt/trt_net.cpp create mode 100644 csrc/mmdeploy/net/trt/trt_net.h create mode 100644 csrc/mmdeploy/net/tvm/CMakeLists.txt create mode 100644 csrc/mmdeploy/net/tvm/tvm_net.cpp create mode 100644 csrc/mmdeploy/net/tvm/tvm_net.h create mode 100644 csrc/mmdeploy/operation/CMakeLists.txt create mode 100644 csrc/mmdeploy/operation/cpu/CMakeLists.txt create mode 100644 csrc/mmdeploy/operation/cpu/crop.cpp create mode 100644 csrc/mmdeploy/operation/cpu/crop_resize_pad.cpp create mode 100644 csrc/mmdeploy/operation/cpu/cvtcolor.cpp create mode 100644 csrc/mmdeploy/operation/cpu/flip.cpp create mode 100644 csrc/mmdeploy/operation/cpu/hwc2chw.cpp create mode 100644 csrc/mmdeploy/operation/cpu/normalize.cpp create mode 100644 csrc/mmdeploy/operation/cpu/pad.cpp create mode 100644 csrc/mmdeploy/operation/cpu/permute.cpp create mode 100644 csrc/mmdeploy/operation/cpu/resize.cpp create mode 100644 csrc/mmdeploy/operation/cpu/to_float.cpp create mode 100644 csrc/mmdeploy/operation/cpu/warp_affine.cpp create mode 100644 csrc/mmdeploy/operation/cuda/CMakeLists.txt create mode 100644 csrc/mmdeploy/operation/cuda/cast.cu create mode 100644 csrc/mmdeploy/operation/cuda/crop.cpp create mode 100644 csrc/mmdeploy/operation/cuda/crop.cu create mode 100644 csrc/mmdeploy/operation/cuda/crop_resize_pad.cpp create mode 100644 csrc/mmdeploy/operation/cuda/cvtcolor.cpp create mode 100644 csrc/mmdeploy/operation/cuda/flip.cpp create mode 100644 csrc/mmdeploy/operation/cuda/hwc2chw.cpp create mode 100644 csrc/mmdeploy/operation/cuda/normalize.cpp create mode 100644 csrc/mmdeploy/operation/cuda/normalize.cu create mode 100644 csrc/mmdeploy/operation/cuda/pad.cpp create mode 100644 csrc/mmdeploy/operation/cuda/permute.cpp create mode 100644 csrc/mmdeploy/operation/cuda/permute.cu create mode 100644 csrc/mmdeploy/operation/cuda/permute.h create mode 100644 csrc/mmdeploy/operation/cuda/resize.cpp create mode 100644 csrc/mmdeploy/operation/cuda/to_float.cpp create mode 100644 csrc/mmdeploy/operation/cuda/transpose.cu create mode 100644 csrc/mmdeploy/operation/cuda/warp_affine.cpp create mode 100644 csrc/mmdeploy/operation/dummy/CMakeLists.txt create mode 100644 csrc/mmdeploy/operation/dummy/operations.cpp create mode 100644 csrc/mmdeploy/operation/managed.h create mode 100644 csrc/mmdeploy/operation/operation.cpp create mode 100644 csrc/mmdeploy/operation/operation.h create mode 100644 csrc/mmdeploy/operation/vision.cpp create mode 100644 csrc/mmdeploy/operation/vision.h create mode 100644 csrc/mmdeploy/preprocess/CMakeLists.txt create mode 100644 csrc/mmdeploy/preprocess/elena/CMakeLists.txt create mode 100644 csrc/mmdeploy/preprocess/elena/cpu_kernel/.gitkeep create mode 100644 csrc/mmdeploy/preprocess/elena/cuda_kernel/.gitkeep create mode 100644 csrc/mmdeploy/preprocess/elena/elena_registry.cpp create mode 100644 csrc/mmdeploy/preprocess/elena/elena_registry.h create mode 100644 csrc/mmdeploy/preprocess/elena/fused.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/CMakeLists.txt create mode 100644 csrc/mmdeploy/preprocess/transform/center_crop.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/collect.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/compose.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/default_format_bundle.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/image2tensor.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/letter_resize.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/lift.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/load.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/normalize.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/pad.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/resize.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/ten_crop.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/three_crop.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/tracer.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/tracer.h create mode 100644 csrc/mmdeploy/preprocess/transform/transform.cpp create mode 100644 csrc/mmdeploy/preprocess/transform/transform.h create mode 100644 csrc/mmdeploy/preprocess/transform_module.cpp create mode 100644 csrc/mmdeploy/utils/CMakeLists.txt create mode 100644 csrc/mmdeploy/utils/dlpack/CMakeLists.txt create mode 100644 csrc/mmdeploy/utils/dlpack/dlpack_utils.cpp create mode 100644 csrc/mmdeploy/utils/dlpack/dlpack_utils.h create mode 100644 csrc/mmdeploy/utils/opencv/CMakeLists.txt create mode 100644 csrc/mmdeploy/utils/opencv/opencv_utils.cpp create mode 100644 csrc/mmdeploy/utils/opencv/opencv_utils.h create mode 100644 mmdeploy/__init__.py create mode 100644 mmdeploy/apis/__init__.py create mode 100644 mmdeploy/apis/ascend/__init__.py create mode 100644 mmdeploy/apis/calibration.py create mode 100644 mmdeploy/apis/core/__init__.py create mode 100644 mmdeploy/apis/core/pipeline_manager.py create mode 100644 mmdeploy/apis/coreml/__init__.py create mode 100644 mmdeploy/apis/extract_model.py create mode 100644 mmdeploy/apis/inference.py create mode 100644 mmdeploy/apis/ncnn/__init__.py create mode 100644 mmdeploy/apis/onnx/__init__.py create mode 100644 mmdeploy/apis/onnx/export.py create mode 100644 mmdeploy/apis/onnx/optimizer.py create mode 100644 mmdeploy/apis/onnx/partition.py create mode 100644 mmdeploy/apis/onnx/passes/__init__.py create mode 100644 mmdeploy/apis/onnx/passes/optimize_onnx.py create mode 100644 mmdeploy/apis/onnxruntime/__init__.py create mode 100644 mmdeploy/apis/openvino/__init__.py create mode 100644 mmdeploy/apis/openvino/utils.py create mode 100644 mmdeploy/apis/pplnn/__init__.py create mode 100644 mmdeploy/apis/pytorch2onnx.py create mode 100644 mmdeploy/apis/pytorch2torchscript.py create mode 100644 mmdeploy/apis/rknn/__init__.py create mode 100644 mmdeploy/apis/sdk/__init__.py create mode 100644 mmdeploy/apis/snpe/__init__.py create mode 100644 mmdeploy/apis/tensorrt/__init__.py create mode 100644 mmdeploy/apis/torch_jit/__init__.py create mode 100644 mmdeploy/apis/torch_jit/trace.py create mode 100644 mmdeploy/apis/tvm/__init__.py create mode 100644 mmdeploy/apis/utils/__init__.py create mode 100644 mmdeploy/apis/utils/calibration.py create mode 100644 mmdeploy/apis/utils/utils.py create mode 100644 mmdeploy/apis/vacc/__init__.py create mode 100644 mmdeploy/apis/visualize.py create mode 100644 mmdeploy/backend/__init__.py create mode 100644 mmdeploy/backend/ascend/__init__.py create mode 100644 mmdeploy/backend/ascend/backend_manager.py create mode 100644 mmdeploy/backend/ascend/onnx2ascend.py create mode 100644 mmdeploy/backend/ascend/utils.py create mode 100644 mmdeploy/backend/ascend/wrapper.py create mode 100644 mmdeploy/backend/base/__init__.py create mode 100644 mmdeploy/backend/base/backend_manager.py create mode 100644 mmdeploy/backend/base/backend_wrapper_registry.py create mode 100644 mmdeploy/backend/base/base_wrapper.py create mode 100644 mmdeploy/backend/coreml/__init__.py create mode 100644 mmdeploy/backend/coreml/backend_manager.py create mode 100644 mmdeploy/backend/coreml/ops.py create mode 100644 mmdeploy/backend/coreml/torchscript2coreml.py create mode 100644 mmdeploy/backend/coreml/wrapper.py create mode 100644 mmdeploy/backend/ncnn/__init__.py create mode 100644 mmdeploy/backend/ncnn/backend_manager.py create mode 100644 mmdeploy/backend/ncnn/init_plugins.py create mode 100644 mmdeploy/backend/ncnn/onnx2ncnn.py create mode 100644 mmdeploy/backend/ncnn/quant.py create mode 100644 mmdeploy/backend/ncnn/wrapper.py create mode 100644 mmdeploy/backend/onnxruntime/__init__.py create mode 100644 mmdeploy/backend/onnxruntime/backend_manager.py create mode 100644 mmdeploy/backend/onnxruntime/init_plugins.py create mode 100644 mmdeploy/backend/onnxruntime/wrapper.py create mode 100644 mmdeploy/backend/openvino/__init__.py create mode 100644 mmdeploy/backend/openvino/backend_manager.py create mode 100644 mmdeploy/backend/openvino/onnx2openvino.py create mode 100644 mmdeploy/backend/openvino/utils.py create mode 100644 mmdeploy/backend/openvino/wrapper.py create mode 100644 mmdeploy/backend/pplnn/__init__.py create mode 100644 mmdeploy/backend/pplnn/backend_manager.py create mode 100644 mmdeploy/backend/pplnn/onnx2pplnn.py create mode 100644 mmdeploy/backend/pplnn/utils.py create mode 100644 mmdeploy/backend/pplnn/wrapper.py create mode 100644 mmdeploy/backend/rknn/__init__.py create mode 100644 mmdeploy/backend/rknn/backend_manager.py create mode 100644 mmdeploy/backend/rknn/onnx2rknn.py create mode 100644 mmdeploy/backend/rknn/wrapper.py create mode 100644 mmdeploy/backend/sdk/__init__.py create mode 100644 mmdeploy/backend/sdk/backend_manager.py create mode 100644 mmdeploy/backend/sdk/export_info.py create mode 100644 mmdeploy/backend/sdk/tracer.py create mode 100644 mmdeploy/backend/sdk/wrapper.py create mode 100644 mmdeploy/backend/snpe/__init__.py create mode 100644 mmdeploy/backend/snpe/backend_manager.py create mode 100644 mmdeploy/backend/snpe/init_plugins.py create mode 100644 mmdeploy/backend/snpe/onnx2dlc.py create mode 100644 mmdeploy/backend/snpe/wrapper.py create mode 100644 mmdeploy/backend/tensorrt/__init__.py create mode 100644 mmdeploy/backend/tensorrt/backend_manager.py create mode 100644 mmdeploy/backend/tensorrt/calib_utils.py create mode 100644 mmdeploy/backend/tensorrt/init_plugins.py create mode 100644 mmdeploy/backend/tensorrt/onnx2tensorrt.py create mode 100644 mmdeploy/backend/tensorrt/torch_allocator.py create mode 100644 mmdeploy/backend/tensorrt/utils.py create mode 100644 mmdeploy/backend/tensorrt/wrapper.py create mode 100644 mmdeploy/backend/torchscript/__init__.py create mode 100644 mmdeploy/backend/torchscript/backend_manager.py create mode 100644 mmdeploy/backend/torchscript/init_plugins.py create mode 100644 mmdeploy/backend/torchscript/wrapper.py create mode 100644 mmdeploy/backend/tvm/__init__.py create mode 100644 mmdeploy/backend/tvm/backend_manager.py create mode 100644 mmdeploy/backend/tvm/onnx2tvm.py create mode 100644 mmdeploy/backend/tvm/quantize.py create mode 100644 mmdeploy/backend/tvm/tuner.py create mode 100644 mmdeploy/backend/tvm/wrapper.py create mode 100644 mmdeploy/backend/vacc/__init__.py create mode 100644 mmdeploy/backend/vacc/backend_manager.py create mode 100644 mmdeploy/backend/vacc/onnx2vacc.py create mode 100644 mmdeploy/backend/vacc/wrapper.py create mode 100644 mmdeploy/codebase/__init__.py create mode 100644 mmdeploy/codebase/base/__init__.py create mode 100644 mmdeploy/codebase/base/backend_model.py create mode 100644 mmdeploy/codebase/base/mmcodebase.py create mode 100644 mmdeploy/codebase/base/runner.py create mode 100644 mmdeploy/codebase/base/task.py create mode 100644 mmdeploy/codebase/mmaction/__init__.py create mode 100644 mmdeploy/codebase/mmaction/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmaction/deploy/mmaction.py create mode 100644 mmdeploy/codebase/mmaction/deploy/video_recognition.py create mode 100644 mmdeploy/codebase/mmaction/deploy/video_recognition_model.py create mode 100644 mmdeploy/codebase/mmaction/models/__init__.py create mode 100644 mmdeploy/codebase/mmaction/models/recognizers/__init__.py create mode 100644 mmdeploy/codebase/mmaction/models/recognizers/base.py create mode 100644 mmdeploy/codebase/mmagic/__init__.py create mode 100644 mmdeploy/codebase/mmagic/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmagic/deploy/mmagic.py create mode 100644 mmdeploy/codebase/mmagic/deploy/super_resolution.py create mode 100644 mmdeploy/codebase/mmagic/deploy/super_resolution_model.py create mode 100644 mmdeploy/codebase/mmagic/models/__init__.py create mode 100644 mmdeploy/codebase/mmagic/models/base_models/__init__.py create mode 100644 mmdeploy/codebase/mmagic/models/base_models/base_edit_model.py create mode 100644 mmdeploy/codebase/mmdet/__init__.py create mode 100644 mmdeploy/codebase/mmdet/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmdet/deploy/model_partition_cfg.py create mode 100644 mmdeploy/codebase/mmdet/deploy/object_detection.py create mode 100644 mmdeploy/codebase/mmdet/deploy/object_detection_model.py create mode 100644 mmdeploy/codebase/mmdet/deploy/utils.py create mode 100644 mmdeploy/codebase/mmdet/models/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/backbones.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/centernet_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/condinst_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/detr_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/fovea_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/gfl_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/reppoints_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/rpn_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/rtmdet_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/rtmdet_ins_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/solo_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/solov2_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/yolo_head.py create mode 100644 mmdeploy/codebase/mmdet/models/dense_heads/yolox_head.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/base_detr.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/maskformer.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/panoptic_two_stage_segmentor.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/single_stage.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/single_stage_instance_seg.py create mode 100644 mmdeploy/codebase/mmdet/models/detectors/two_stage.py create mode 100644 mmdeploy/codebase/mmdet/models/layers/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/layers/matrix_nms.py create mode 100644 mmdeploy/codebase/mmdet/models/necks.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/bbox_head.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/cascade_roi_head.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/fcn_mask_head.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/htc_roi_head.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/single_level_roi_extractor.py create mode 100644 mmdeploy/codebase/mmdet/models/roi_heads/standard_roi_head.py create mode 100644 mmdeploy/codebase/mmdet/models/seg_heads/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/seg_heads/base_semantic_head.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/coders/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/coders/delta_xywh_bbox_coder.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/coders/distance_point_bbox_coder.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/coders/tblr_bbox_coder.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/prior_generators/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/prior_generators/anchor.py create mode 100644 mmdeploy/codebase/mmdet/models/task_modules/prior_generators/point_generator.py create mode 100644 mmdeploy/codebase/mmdet/models/transformer.py create mode 100644 mmdeploy/codebase/mmdet/models/utils/__init__.py create mode 100644 mmdeploy/codebase/mmdet/models/utils/gaussian_target.py create mode 100644 mmdeploy/codebase/mmdet/ops/__init__.py create mode 100644 mmdeploy/codebase/mmdet/ops/detection_output.py create mode 100644 mmdeploy/codebase/mmdet/ops/prior_box.py create mode 100644 mmdeploy/codebase/mmdet/structures/__init__.py create mode 100644 mmdeploy/codebase/mmdet/structures/bbox/__init__.py create mode 100644 mmdeploy/codebase/mmdet/structures/bbox/transforms.py create mode 100644 mmdeploy/codebase/mmdet3d/__init__.py create mode 100644 mmdeploy/codebase/mmdet3d/deploy/__init__.py create mode 100755 mmdeploy/codebase/mmdet3d/deploy/mmdet3d.py create mode 100644 mmdeploy/codebase/mmdet3d/deploy/mono_detection.py create mode 100644 mmdeploy/codebase/mmdet3d/deploy/mono_detection_model.py create mode 100644 mmdeploy/codebase/mmdet3d/deploy/voxel_detection.py create mode 100644 mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py create mode 100644 mmdeploy/codebase/mmdet3d/models/__init__.py create mode 100644 mmdeploy/codebase/mmdet3d/models/base.py create mode 100644 mmdeploy/codebase/mmdet3d/models/mvx_two_stage.py create mode 100644 mmdeploy/codebase/mmdet3d/models/pillar_encode.py create mode 100644 mmdeploy/codebase/mmdet3d/models/pillar_scatter.py create mode 100755 mmdeploy/codebase/mmdet3d/models/single_stage_mono3d.py create mode 100644 mmdeploy/codebase/mmocr/__init__.py create mode 100644 mmdeploy/codebase/mmocr/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmocr/deploy/mmocr.py create mode 100644 mmdeploy/codebase/mmocr/deploy/text_detection.py create mode 100644 mmdeploy/codebase/mmocr/deploy/text_detection_model.py create mode 100644 mmdeploy/codebase/mmocr/deploy/text_recognition.py create mode 100644 mmdeploy/codebase/mmocr/deploy/text_recognition_model.py create mode 100644 mmdeploy/codebase/mmocr/models/__init__.py create mode 100644 mmdeploy/codebase/mmocr/models/text_detection/__init__.py create mode 100644 mmdeploy/codebase/mmocr/models/text_detection/fpn_cat.py create mode 100644 mmdeploy/codebase/mmocr/models/text_detection/heads.py create mode 100644 mmdeploy/codebase/mmocr/models/text_detection/mmdet_wrapper.py create mode 100644 mmdeploy/codebase/mmocr/models/text_detection/single_stage_text_detector.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/__init__.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/abi_language_decoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/base_decoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/crnn_decoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/encoder_decoder_recognizer.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/lstm_layer.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/nrtr_decoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/sar_decoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/sar_encoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/satrn_encoder.py create mode 100644 mmdeploy/codebase/mmocr/models/text_recognition/transformer_module.py create mode 100644 mmdeploy/codebase/mmocr/models/utils.py create mode 100644 mmdeploy/codebase/mmpose/__init__.py create mode 100644 mmdeploy/codebase/mmpose/codecs/__init__.py create mode 100644 mmdeploy/codebase/mmpose/codecs/post_processing.py create mode 100644 mmdeploy/codebase/mmpose/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmpose/deploy/pose_detection.py create mode 100644 mmdeploy/codebase/mmpose/deploy/pose_detection_model.py create mode 100644 mmdeploy/codebase/mmpose/models/__init__.py create mode 100644 mmdeploy/codebase/mmpose/models/heads/__init__.py create mode 100644 mmdeploy/codebase/mmpose/models/heads/mspn_head.py create mode 100644 mmdeploy/codebase/mmpose/models/heads/rtmo_head.py create mode 100644 mmdeploy/codebase/mmpose/models/heads/simcc_head.py create mode 100644 mmdeploy/codebase/mmpose/models/heads/yolox_pose_head.py create mode 100644 mmdeploy/codebase/mmpose/models/pose_estimators/__init__.py create mode 100644 mmdeploy/codebase/mmpose/models/pose_estimators/base.py create mode 100644 mmdeploy/codebase/mmpose/models/utils/__init__.py create mode 100644 mmdeploy/codebase/mmpose/models/utils/rtmcc_block.py create mode 100644 mmdeploy/codebase/mmpretrain/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/deploy/classification.py create mode 100644 mmdeploy/codebase/mmpretrain/deploy/classification_model.py create mode 100644 mmdeploy/codebase/mmpretrain/models/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/models/backbones/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/models/backbones/shufflenet_v2.py create mode 100644 mmdeploy/codebase/mmpretrain/models/classifiers/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/models/classifiers/base.py create mode 100644 mmdeploy/codebase/mmpretrain/models/necks/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/models/necks/gap.py create mode 100644 mmdeploy/codebase/mmpretrain/models/utils/__init__.py create mode 100644 mmdeploy/codebase/mmpretrain/models/utils/attention.py create mode 100644 mmdeploy/codebase/mmrazor/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmrazor/deploy/mmrazor.py create mode 100644 mmdeploy/codebase/mmrotate/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/deploy/rotated_detection.py create mode 100644 mmdeploy/codebase/mmrotate/deploy/rotated_detection_model.py create mode 100644 mmdeploy/codebase/mmrotate/models/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/models/dense_heads/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/models/dense_heads/oriented_rpn_head.py create mode 100644 mmdeploy/codebase/mmrotate/models/dense_heads/rotated_rtmdet_head.py create mode 100644 mmdeploy/codebase/mmrotate/models/roi_heads/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/models/roi_heads/gv_bbox_head.py create mode 100644 mmdeploy/codebase/mmrotate/models/roi_heads/gv_ratio_roi_head.py create mode 100644 mmdeploy/codebase/mmrotate/models/roi_heads/roi_extractors.py create mode 100644 mmdeploy/codebase/mmrotate/models/task_modules/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/models/task_modules/coders.py create mode 100644 mmdeploy/codebase/mmrotate/structures/__init__.py create mode 100644 mmdeploy/codebase/mmrotate/structures/bbox.py create mode 100644 mmdeploy/codebase/mmseg/__init__.py create mode 100644 mmdeploy/codebase/mmseg/deploy/__init__.py create mode 100644 mmdeploy/codebase/mmseg/deploy/segmentation.py create mode 100644 mmdeploy/codebase/mmseg/deploy/segmentation_model.py create mode 100644 mmdeploy/codebase/mmseg/models/__init__.py create mode 100644 mmdeploy/codebase/mmseg/models/decode_heads/__init__.py create mode 100644 mmdeploy/codebase/mmseg/models/decode_heads/decode_head.py create mode 100644 mmdeploy/codebase/mmseg/models/decode_heads/ema_head.py create mode 100644 mmdeploy/codebase/mmseg/models/decode_heads/point_head.py create mode 100644 mmdeploy/codebase/mmseg/models/segmentors/__init__.py create mode 100644 mmdeploy/codebase/mmseg/models/segmentors/base.py create mode 100644 mmdeploy/codebase/mmseg/models/segmentors/cascade_encoder_decoder.py create mode 100644 mmdeploy/codebase/mmseg/models/segmentors/encoder_decoder.py create mode 100644 mmdeploy/codebase/mmseg/models/utils/__init__.py create mode 100644 mmdeploy/codebase/mmseg/models/utils/up_conv_block.py create mode 100644 mmdeploy/core/__init__.py create mode 100644 mmdeploy/core/optimizers/__init__.py create mode 100644 mmdeploy/core/optimizers/extractor.py create mode 100644 mmdeploy/core/optimizers/function_marker.py create mode 100644 mmdeploy/core/optimizers/optimize.py create mode 100644 mmdeploy/core/rewriters/__init__.py create mode 100644 mmdeploy/core/rewriters/function_rewriter.py create mode 100644 mmdeploy/core/rewriters/module_rewriter.py create mode 100644 mmdeploy/core/rewriters/rewriter_manager.py create mode 100644 mmdeploy/core/rewriters/rewriter_utils.py create mode 100644 mmdeploy/core/rewriters/symbolic_rewriter.py create mode 100644 mmdeploy/mmcv/__init__.py create mode 100644 mmdeploy/mmcv/cnn/__init__.py create mode 100644 mmdeploy/mmcv/cnn/transformer.py create mode 100644 mmdeploy/mmcv/ops/__init__.py create mode 100644 mmdeploy/mmcv/ops/deform_conv.py create mode 100644 mmdeploy/mmcv/ops/modulated_deform_conv.py create mode 100644 mmdeploy/mmcv/ops/multi_scale_deform_attn.py create mode 100644 mmdeploy/mmcv/ops/nms.py create mode 100644 mmdeploy/mmcv/ops/nms_match.py create mode 100644 mmdeploy/mmcv/ops/nms_rotated.py create mode 100644 mmdeploy/mmcv/ops/point_sample.py create mode 100644 mmdeploy/mmcv/ops/roi_align.py create mode 100644 mmdeploy/mmcv/ops/roi_align_rotated.py create mode 100644 mmdeploy/mmcv/ops/transformer.py create mode 100644 mmdeploy/pytorch/__init__.py create mode 100644 mmdeploy/pytorch/functions/__init__.py create mode 100644 mmdeploy/pytorch/functions/adaptive_pool.py create mode 100644 mmdeploy/pytorch/functions/any.py create mode 100644 mmdeploy/pytorch/functions/atan2.py create mode 100644 mmdeploy/pytorch/functions/cat.py create mode 100644 mmdeploy/pytorch/functions/chunk.py create mode 100644 mmdeploy/pytorch/functions/clip.py create mode 100644 mmdeploy/pytorch/functions/copy.py create mode 100644 mmdeploy/pytorch/functions/expand.py create mode 100644 mmdeploy/pytorch/functions/flatten.py create mode 100644 mmdeploy/pytorch/functions/getattribute.py create mode 100644 mmdeploy/pytorch/functions/group_norm.py create mode 100644 mmdeploy/pytorch/functions/interpolate.py create mode 100644 mmdeploy/pytorch/functions/linear.py create mode 100644 mmdeploy/pytorch/functions/linspace.py create mode 100644 mmdeploy/pytorch/functions/masked_fill.py create mode 100644 mmdeploy/pytorch/functions/mod.py create mode 100644 mmdeploy/pytorch/functions/multi_head_attention_forward.py create mode 100644 mmdeploy/pytorch/functions/normalize.py create mode 100644 mmdeploy/pytorch/functions/pad.py create mode 100644 mmdeploy/pytorch/functions/repeat.py create mode 100644 mmdeploy/pytorch/functions/size.py create mode 100644 mmdeploy/pytorch/functions/tensor_getitem.py create mode 100644 mmdeploy/pytorch/functions/tensor_setitem.py create mode 100644 mmdeploy/pytorch/functions/topk.py create mode 100644 mmdeploy/pytorch/functions/triu.py create mode 100644 mmdeploy/pytorch/symbolics/__init__.py create mode 100644 mmdeploy/pytorch/symbolics/adaptive_pool.py create mode 100644 mmdeploy/pytorch/symbolics/gelu.py create mode 100644 mmdeploy/pytorch/symbolics/grid_sampler.py create mode 100644 mmdeploy/pytorch/symbolics/hardsigmoid.py create mode 100644 mmdeploy/pytorch/symbolics/instance_norm.py create mode 100644 mmdeploy/pytorch/symbolics/layer_norm.py create mode 100644 mmdeploy/pytorch/symbolics/linear.py create mode 100644 mmdeploy/pytorch/symbolics/lstm.py create mode 100644 mmdeploy/pytorch/symbolics/roll.py create mode 100644 mmdeploy/pytorch/symbolics/squeeze.py create mode 100644 mmdeploy/utils/__init__.py create mode 100644 mmdeploy/utils/config_utils.py create mode 100644 mmdeploy/utils/constants.py create mode 100644 mmdeploy/utils/dataset.py create mode 100644 mmdeploy/utils/device.py create mode 100644 mmdeploy/utils/env.py create mode 100644 mmdeploy/utils/logging.py create mode 100644 mmdeploy/utils/test.py create mode 100644 mmdeploy/utils/timer.py create mode 100644 mmdeploy/utils/utils.py create mode 100644 mmdeploy/version.py diff --git a/csrc/mmdeploy/CMakeLists.txt b/csrc/mmdeploy/CMakeLists.txt new file mode 100644 index 0000000..6bfbd3a --- /dev/null +++ b/csrc/mmdeploy/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +add_subdirectory(backend_ops) + +if (MMDEPLOY_BUILD_SDK) + # include OpenCV for SDK modules since many of them depends on it + include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake) + + add_subdirectory(core) + add_subdirectory(execution) + add_subdirectory(utils) + add_subdirectory(archive) + add_subdirectory(device) + add_subdirectory(graph) + add_subdirectory(model) + add_subdirectory(operation) + add_subdirectory(preprocess) + add_subdirectory(net) + add_subdirectory(codebase) + add_subdirectory(apis) +endif () diff --git a/csrc/mmdeploy/apis/CMakeLists.txt b/csrc/mmdeploy/apis/CMakeLists.txt new file mode 100644 index 0000000..1ab877b --- /dev/null +++ b/csrc/mmdeploy/apis/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +add_subdirectory(c) +add_subdirectory(cxx) +add_subdirectory(java) + +# add python subdir conditionally since it's designed to work as +# a standalone project also +if (MMDEPLOY_BUILD_SDK_PYTHON_API) + add_subdirectory(python) +endif () diff --git a/csrc/mmdeploy/apis/c/CMakeLists.txt b/csrc/mmdeploy/apis/c/CMakeLists.txt new file mode 100644 index 0000000..f08fa8c --- /dev/null +++ b/csrc/mmdeploy/apis/c/CMakeLists.txt @@ -0,0 +1,86 @@ +# Copyright (c) OpenMMLab. All rights reserved. + +project(capis) +include(${CMAKE_SOURCE_DIR}/cmake/MMDeploy.cmake) + +set(CAPI_OBJS) + +macro(add_object name) + add_library(${name} OBJECT ${ARGN}) + set_target_properties(${name} PROPERTIES POSITION_INDEPENDENT_CODE 1) + target_compile_definitions(${name} PRIVATE -DMMDEPLOY_API_EXPORTS=1) + if (NOT MSVC) + target_compile_options(${name} PRIVATE $<$:-fvisibility=hidden>) + endif () + target_link_libraries(${name} PRIVATE mmdeploy::core) + target_include_directories(${name} PUBLIC + $ + $) + set(CAPI_OBJS ${CAPI_OBJS} ${name}) + mmdeploy_export(${name}) +endmacro() + +set(COMMON_LIST + common + model + executor + pipeline) + +set(TASK_LIST ${MMDEPLOY_TASKS}) + +foreach (TASK ${COMMON_LIST}) + set(TARGET_NAME mmdeploy_${TASK}) + set(OBJECT_NAME mmdeploy_${TASK}_obj) + add_object(${OBJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${TASK}.cpp) + mmdeploy_add_library(${TARGET_NAME}) + target_link_libraries(${TARGET_NAME} PRIVATE ${OBJECT_NAME}) + target_include_directories(${TARGET_NAME} PUBLIC + $ + $) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${TASK}.h + DESTINATION include/mmdeploy) +endforeach () + +target_link_libraries(mmdeploy_executor PUBLIC + mmdeploy_execution mmdeploy_common) +target_link_libraries(mmdeploy_pipeline PUBLIC + mmdeploy_executor mmdeploy_model mmdeploy_common) + +foreach (TASK ${TASK_LIST}) + set(TARGET_NAME mmdeploy_${TASK}) + set(OBJECT_NAME mmdeploy_${TASK}_obj) + add_object(${OBJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${TASK}.cpp) + mmdeploy_add_library(${TARGET_NAME}) + target_link_libraries(${TARGET_NAME} PRIVATE ${OBJECT_NAME} + mmdeploy_pipeline) + target_include_directories(${TARGET_NAME} PUBLIC + $ + $) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${TASK}.h + DESTINATION include/mmdeploy) +endforeach () + +install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp + FILES_MATCHING + PATTERN "*.cpp" + PATTERN "CMakeLists.txt" + ) + +if (MMDEPLOY_BUILD_SDK_CSHARP_API OR MMDEPLOY_BUILD_SDK_MONOLITHIC) + add_library(mmdeploy SHARED) + mmdeploy_load_static(mmdeploy MMDeployStaticModules) + mmdeploy_load_dynamic(mmdeploy MMDeployDynamicModules) + target_link_libraries(mmdeploy PRIVATE ${CAPI_OBJS} mmdeploy_execution) + target_include_directories(mmdeploy PUBLIC + $ + $) + set(MMDEPLOY_VERSION ${MMDEPLOY_VERSION_MAJOR} + .${MMDEPLOY_VERSION_MINOR} + .${MMDEPLOY_VERSION_PATCH}) + string(REPLACE ";" "" MMDEPLOY_VERSION ${MMDEPLOY_VERSION}) + set_target_properties(mmdeploy PROPERTIES + VERSION ${MMDEPLOY_VERSION} + SOVERSION ${MMDEPLOY_VERSION_MAJOR}) + mmdeploy_add_rpath(mmdeploy) + mmdeploy_export_impl(mmdeploy) +endif () diff --git a/csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp b/csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp new file mode 100644 index 0000000..3eec4ef --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/classifier.cpp @@ -0,0 +1,133 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/classifier.h" + +#include + +#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 "mmdeploy/handle.h" +#include "mmdeploy/pipeline.h" + +using namespace mmdeploy; +using namespace std; + +int mmdeploy_classifier_create(mmdeploy_model_t model, const char* device_name, int device_id, + mmdeploy_classifier_t* classifier) { + mmdeploy_context_t context{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_classifier_create_v2(model, context, classifier); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_classifier_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_classifier_t* classifier) { + mmdeploy_model_t model{}; + + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_classifier_create(model, device_name, device_id, classifier); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_classifier_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_classifier_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, + mmdeploy_value_t* value) { + return mmdeploy_common_create_input(mats, mat_count, value); +} + +int mmdeploy_classifier_apply(mmdeploy_classifier_t classifier, const mmdeploy_mat_t* mats, + int mat_count, mmdeploy_classification_t** results, + int** result_count) { + wrapped input; + if (auto ec = mmdeploy_classifier_create_input(mats, mat_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_classifier_apply_v2(classifier, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_classifier_get_result(output, results, result_count)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_classifier_apply_v2(mmdeploy_classifier_t classifier, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)classifier, input, output); +} + +int mmdeploy_classifier_apply_async(mmdeploy_classifier_t classifier, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)classifier, input, output); +} + +int mmdeploy_classifier_get_result(mmdeploy_value_t output, mmdeploy_classification_t** results, + int** result_count) { + if (!output || !results || !result_count) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value& value = Cast(output)->front(); + + auto classify_outputs = from_value>(value); + + vector _result_count; + _result_count.reserve(classify_outputs.size()); + + for (const auto& cls_output : classify_outputs) { + _result_count.push_back((int)cls_output.size()); + } + + auto total = std::accumulate(begin(_result_count), end(_result_count), 0); + + std::unique_ptr result_count_data(new int[_result_count.size()]{}); + std::copy(_result_count.begin(), _result_count.end(), result_count_data.get()); + + std::unique_ptr result_data( + new mmdeploy_classification_t[total]{}); + auto result_ptr = result_data.get(); + for (const auto& cls_output : classify_outputs) { + for (const auto& label : cls_output) { + result_ptr->label_id = label.label_id; + result_ptr->score = label.score; + ++result_ptr; + } + } + + *result_count = result_count_data.release(); + *results = result_data.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; +} + +void mmdeploy_classifier_release_result(mmdeploy_classification_t* results, const int* result_count, + int count) { + delete[] results; + delete[] result_count; +} + +void mmdeploy_classifier_destroy(mmdeploy_classifier_t classifier) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)classifier); +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/classifier.h b/csrc/mmdeploy/apis/c/mmdeploy/classifier.h new file mode 100644 index 0000000..54e9d02 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/classifier.h @@ -0,0 +1,139 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file classifier.h + * @brief Interface to MMClassification task + */ + +#ifndef MMDEPLOY_CLASSIFIER_H +#define MMDEPLOY_CLASSIFIER_H + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_classification_t { + int label_id; + float score; +} mmdeploy_classification_t; + +typedef struct mmdeploy_classifier* mmdeploy_classifier_t; + +/** + * @brief Create classifier's handle + * @param[in] model an instance of mmclassification sdk model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] classifier instance of a classifier, which must be destroyed + * by \ref mmdeploy_classifier_destroy + * @return status of creating classifier's handle + */ +MMDEPLOY_API int mmdeploy_classifier_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_classifier_t* classifier); + +/** + * @brief Create classifier's handle + * @param[in] model_path path of mmclassification sdk model exported by mmdeploy model converter + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] classifier instance of a classifier, which must be destroyed + * by \ref mmdeploy_classifier_destroy + * @return status of creating classifier's handle + */ +MMDEPLOY_API int mmdeploy_classifier_create_by_path(const char* model_path, const char* device_name, + int device_id, + mmdeploy_classifier_t* classifier); + +/** + * @brief Use classifier created by \ref mmdeploy_classifier_create_by_path to get label + * information of each image in a batch + * @param[in] classifier classifier's handle created by \ref mmdeploy_classifier_create_by_path + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] results a linear buffer to save classification results of each + * image, which must be freed by \ref mmdeploy_classifier_release_result + * @param[out] result_count a linear buffer with length being \p mat_count to save the number of + * classification results of each image. It must be released by \ref + * mmdeploy_classifier_release_result + * @return status of inference + */ +MMDEPLOY_API int mmdeploy_classifier_apply(mmdeploy_classifier_t classifier, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_classification_t** results, int** result_count); + +/** + * @brief Release the inference result buffer created \ref mmdeploy_classifier_apply + * @param[in] results classification results buffer + * @param[in] result_count \p results size buffer + * @param[in] count length of \p result_count + */ +MMDEPLOY_API void mmdeploy_classifier_release_result(mmdeploy_classification_t* results, + const int* result_count, int count); + +/** + * @brief Destroy classifier's handle + * @param[in] classifier classifier's handle created by \ref mmdeploy_classifier_create_by_path + */ +MMDEPLOY_API void mmdeploy_classifier_destroy(mmdeploy_classifier_t classifier); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +/** + * @brief Same as \ref mmdeploy_classifier_create, but allows to control execution context of tasks + * via context + */ +MMDEPLOY_API int mmdeploy_classifier_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_classifier_t* classifier); + +/** + * @brief Pack classifier inputs into mmdeploy_value_t + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] value the packed value + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_classifier_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* value); + +/** + * @brief Same as \ref mmdeploy_classifier_apply, but input and output are packed in \ref + * mmdeploy_value_t. + */ +MMDEPLOY_API int mmdeploy_classifier_apply_v2(mmdeploy_classifier_t classifier, + mmdeploy_value_t input, mmdeploy_value_t* output); + +/** + * @brief Apply classifier asynchronously + * @param[in] classifier handle of the classifier + * @param[in] input input sender that will be consumed by the operation + * @param[out] output output sender + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_classifier_apply_async(mmdeploy_classifier_t classifier, + mmdeploy_sender_t input, + mmdeploy_sender_t* output); + +/** + * + * @param[in] output output obtained by applying a classifier + * @param[out] results a linear buffer containing classification results of each image, released by + * \ref mmdeploy_classifier_release_result + * @param[out] result_count a linear buffer containing the number of results for each input image, + * released by \ref mmdeploy_classifier_release_result + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_classifier_get_result(mmdeploy_value_t output, + mmdeploy_classification_t** results, + int** result_count); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_CLASSIFIER_H diff --git a/csrc/mmdeploy/apis/c/mmdeploy/common.cpp b/csrc/mmdeploy/apis/c/mmdeploy/common.cpp new file mode 100644 index 0000000..e00cc3f --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/common.cpp @@ -0,0 +1,115 @@ +#include "mmdeploy/common.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) { + return nullptr; + } + return Guard([&] { return Take(Value(*Cast(value))); }); +} + +void mmdeploy_value_destroy(mmdeploy_value_t value) { delete Cast(value); } + +int mmdeploy_context_create(mmdeploy_context_t* context) { + *context = (mmdeploy_context_t) new Value; + return 0; +} + +int mmdeploy_context_create_by_device(const char* device_name, int device_id, + mmdeploy_context_t* context) { + mmdeploy_device_t device{}; + int ec = MMDEPLOY_SUCCESS; + mmdeploy_context_t _context{}; + ec = mmdeploy_context_create(&_context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_device_create(device_name, device_id, &device); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_context_add(_context, MMDEPLOY_TYPE_DEVICE, nullptr, device); + mmdeploy_device_destroy(device); + if (ec == MMDEPLOY_SUCCESS) { + *context = _context; + } + return ec; +} + +void mmdeploy_context_destroy(mmdeploy_context_t context) { delete Cast(context); } + +int mmdeploy_common_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* value) { + if (mat_count && mats == nullptr) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + auto input = std::make_unique(Value{Value::kArray}); + for (int i = 0; i < mat_count; ++i) { + input->front().push_back({{"ori_img", Cast(mats[i])}}); + } + *value = Cast(input.release()); + } catch (const std::exception& e) { + MMDEPLOY_ERROR("unhandled exception: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_device_create(const char* device_name, int device_id, mmdeploy_device_t* device) { + Device tmp(device_name, device_id); + if (tmp.platform_id() == -1) { + MMDEPLOY_ERROR("Device \"{}\" not found", device_name); + return MMDEPLOY_E_INVALID_ARG; + } + *device = (mmdeploy_device_t) new Device(tmp); + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_device_destroy(mmdeploy_device_t device) { delete (Device*)device; } + +int mmdeploy_profiler_create(const char* path, mmdeploy_profiler_t* profiler) { + *profiler = (mmdeploy_profiler_t) new profiler::Profiler(path); + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_profiler_destroy(mmdeploy_profiler_t profiler) { + if (profiler) { + auto p = (profiler::Profiler*)profiler; + p->Release(); + delete p; + } +} + +int mmdeploy_context_add(mmdeploy_context_t context, mmdeploy_context_type_t type, const char* name, + const void* object) { + auto& ctx = *Cast(context); + switch (type) { + case MMDEPLOY_TYPE_DEVICE: { + const auto& device = *(Device*)object; + ctx["device"] = device; + ctx["stream"] = Stream(device); + break; + } + case MMDEPLOY_TYPE_SCHEDULER: + ctx["scheduler"][name] = *Cast((const mmdeploy_scheduler_t)object); + break; + case MMDEPLOY_TYPE_MODEL: + ctx["model"][name] = *Cast((const mmdeploy_model_t)object); + break; + case MMDEPLOY_TYPE_PROFILER: { + const auto& profiler = *(profiler::Profiler*)object; + profiler::Scope* root(profiler.scope()); + ctx["scope"] = root; + break; + } + default: + return MMDEPLOY_E_NOT_SUPPORTED; + } + return 0; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/common.h b/csrc/mmdeploy/apis/c/mmdeploy/common.h new file mode 100644 index 0000000..c665134 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/common.h @@ -0,0 +1,192 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_COMMON_H +#define MMDEPLOY_COMMON_H + +#include // NOLINT + +#ifndef MMDEPLOY_EXPORT +#ifdef _MSC_VER +#define MMDEPLOY_EXPORT __declspec(dllexport) +#else +#define MMDEPLOY_EXPORT __attribute__((visibility("default"))) +#endif +#endif + +#ifndef MMDEPLOY_API +#ifdef MMDEPLOY_API_EXPORTS +#define MMDEPLOY_API MMDEPLOY_EXPORT +#else +#define MMDEPLOY_API +#endif +#endif + +// clang-format off + +typedef enum mmdeploy_pixel_format_t{ + MMDEPLOY_PIXEL_FORMAT_BGR, + MMDEPLOY_PIXEL_FORMAT_RGB, + MMDEPLOY_PIXEL_FORMAT_GRAYSCALE, + MMDEPLOY_PIXEL_FORMAT_NV12, + MMDEPLOY_PIXEL_FORMAT_NV21, + MMDEPLOY_PIXEL_FORMAT_BGRA, + MMDEPLOY_PIXEL_FORMAT_COUNT +} mmdeploy_pixel_format_t; + +typedef enum mmdeploy_data_type_t{ + MMDEPLOY_DATA_TYPE_FLOAT, + MMDEPLOY_DATA_TYPE_HALF, + MMDEPLOY_DATA_TYPE_UINT8, + MMDEPLOY_DATA_TYPE_INT32, + MMDEPLOY_DATA_TYPE_COUNT +} mmdeploy_data_type_t; + +typedef enum mmdeploy_status_t { + MMDEPLOY_SUCCESS = 0, + MMDEPLOY_E_INVALID_ARG = 1, + MMDEPLOY_E_NOT_SUPPORTED = 2, + MMDEPLOY_E_OUT_OF_RANGE = 3, + MMDEPLOY_E_OUT_OF_MEMORY = 4, + MMDEPLOY_E_FILE_NOT_EXIST = 5, + MMDEPLOY_E_FAIL = 6, + MMDEPLOY_STATUS_COUNT = 7 +} mmdeploy_status_t; + +// clang-format on + +typedef struct mmdeploy_device* mmdeploy_device_t; + +typedef struct mmdeploy_profiler* mmdeploy_profiler_t; + +typedef struct mmdeploy_mat_t { + uint8_t* data; + int height; + int width; + int channel; + mmdeploy_pixel_format_t format; + mmdeploy_data_type_t type; + mmdeploy_device_t device; +} mmdeploy_mat_t; + +typedef struct mmdeploy_rect_t { + float left; + float top; + float right; + float bottom; +} mmdeploy_rect_t; + +typedef struct mmdeploy_point_t { + float x; + float y; +} mmdeploy_point_t; + +typedef struct mmdeploy_value* mmdeploy_value_t; + +typedef struct mmdeploy_context* mmdeploy_context_t; + +typedef enum mmdeploy_context_type_t { + MMDEPLOY_TYPE_DEVICE = 0, + MMDEPLOY_TYPE_STREAM = 1, + MMDEPLOY_TYPE_MODEL = 2, + MMDEPLOY_TYPE_SCHEDULER = 3, + MMDEPLOY_TYPE_MAT = 4, + MMDEPLOY_TYPE_PROFILER = 5, +} mmdeploy_context_type_t; + +#if __cplusplus +extern "C" { +#endif + +/** + * Copy value + * @param value + * @return + */ +MMDEPLOY_API mmdeploy_value_t mmdeploy_value_copy(mmdeploy_value_t value); + +/** + * Destroy value + * @param value + */ +MMDEPLOY_API void mmdeploy_value_destroy(mmdeploy_value_t value); + +/** + * Create device handle + * @param device_name + * @param device_id + * @param device + * @return + */ +MMDEPLOY_API int mmdeploy_device_create(const char* device_name, int device_id, + mmdeploy_device_t* device); + +/** + * Destroy device handle + * @param device + */ +MMDEPLOY_API void mmdeploy_device_destroy(mmdeploy_device_t device); + +/** + * Create profiler + * @param path path to save the profile data + * @param profiler handle for profiler, should be added to context and deleted by + * mmdeploy_profiler_destroy + * @return status of create + */ +MMDEPLOY_API int mmdeploy_profiler_create(const char* path, mmdeploy_profiler_t* profiler); + +/** + * Destroy profiler handle + * @param profiler handle for profiler, profile data will be written to disk after this call + */ +MMDEPLOY_API void mmdeploy_profiler_destroy(mmdeploy_profiler_t profiler); + +/** + * Create context + * @param context + * @return + */ +MMDEPLOY_API int mmdeploy_context_create(mmdeploy_context_t* context); + +/** + * Create context + * @param device_name + * @param device_id + * @param context + * @return + */ +MMDEPLOY_API int mmdeploy_context_create_by_device(const char* device_name, int device_id, + mmdeploy_context_t* context); + +/** + * Destroy context + * @param context + */ +MMDEPLOY_API void mmdeploy_context_destroy(mmdeploy_context_t context); + +/** + * Add context object + * @param context + * @param type + * @param name + * @param object + * @return + */ +MMDEPLOY_API int mmdeploy_context_add(mmdeploy_context_t context, mmdeploy_context_type_t type, + const char* name, const void* object); + +/** + * Create input value from array of mats + * @param mats + * @param mat_count + * @param value + * @return + */ +MMDEPLOY_API int mmdeploy_common_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* value); + +#if __cplusplus +} +#endif + +#endif // MMDEPLOY_COMMON_H diff --git a/csrc/mmdeploy/apis/c/mmdeploy/common_internal.h b/csrc/mmdeploy/apis/c/mmdeploy/common_internal.h new file mode 100644 index 0000000..a1ddecb --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/common_internal.h @@ -0,0 +1,105 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_CSRC_APIS_C_COMMON_INTERNAL_H_ +#define MMDEPLOY_CSRC_APIS_C_COMMON_INTERNAL_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/core/mat.h" +#include "mmdeploy/core/value.h" +#include "mmdeploy/handle.h" +#include "mmdeploy/model.h" +#include "mmdeploy/pipeline.h" + +using namespace mmdeploy; + +namespace { + +inline mmdeploy_value_t Cast(Value* s) { return reinterpret_cast(s); } + +inline Value* Cast(mmdeploy_value_t s) { return reinterpret_cast(s); } + +inline Value Take(mmdeploy_value_t v) { + auto value = std::move(*Cast(v)); + mmdeploy_value_destroy(v); + return value; +} + +inline Value* Cast(mmdeploy_context_t c) { return reinterpret_cast(c); } + +inline mmdeploy_value_t Take(Value v) { + return Cast(new Value(std::move(v))); // NOLINT +} + +inline mmdeploy_pipeline_t Cast(AsyncHandle* pipeline) { + return reinterpret_cast(pipeline); +} + +inline AsyncHandle* Cast(mmdeploy_pipeline_t pipeline) { + return reinterpret_cast(pipeline); +} + +inline mmdeploy_model_t Cast(Model* model) { return reinterpret_cast(model); } + +inline Model* Cast(mmdeploy_model_t model) { return reinterpret_cast(model); } + +inline Mat Cast(const mmdeploy_mat_t& mat) { + return Mat{mat.height, mat.width, PixelFormat(mat.format), + DataType(mat.type), mat.data, mat.device ? *(const Device*)mat.device : Device{0}}; +} + +template +std::invoke_result_t Guard(F f) { + try { + return f(); + } catch (const std::exception& e) { + MMDEPLOY_ERROR("unhandled exception: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return nullptr; +} + +template +class wrapped {}; + +template +class wrapped> { + public: + wrapped() noexcept : v_(nullptr) {} + explicit wrapped(T v) noexcept : v_(v) {} + + void reset() { + if (v_) { + delete Cast(v_); + v_ = nullptr; + } + } + + ~wrapped() { reset(); } + + wrapped(const wrapped&) = delete; + wrapped& operator=(const wrapped&) = delete; + + wrapped(wrapped&& other) noexcept : v_(other.release()) {} + wrapped& operator=(wrapped&& other) noexcept { + reset(); + v_ = other.release(); + return *this; + } + + T release() noexcept { return std::exchange(v_, nullptr); } + + auto operator*() { return Cast(v_); } + auto operator-> () { return Cast(v_); } + + T* ptr() noexcept { return &v_; } + + operator T() const noexcept { return v_; } // NOLINT + + private: + T v_; +}; + +} // namespace + +#endif // MMDEPLOY_CSRC_APIS_C_COMMON_INTERNAL_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/detector.cpp b/csrc/mmdeploy/apis/c/mmdeploy/detector.cpp new file mode 100644 index 0000000..aadf92f --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/detector.cpp @@ -0,0 +1,149 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/detector.h" + +#include +#include + +#include "mmdeploy/apis/c/mmdeploy/common_internal.h" +#include "mmdeploy/apis/c/mmdeploy/model.h" +#include "mmdeploy/apis/c/mmdeploy/pipeline.h" +#include "mmdeploy/archive/value_archive.h" +#include "mmdeploy/codebase/mmdet/mmdet.h" +#include "mmdeploy/core/device.h" +#include "mmdeploy/core/model.h" +#include "mmdeploy/core/mpl/structure.h" +#include "mmdeploy/core/utils/formatter.h" +#include "mmdeploy/core/value.h" + +using namespace std; +using namespace mmdeploy; + +using ResultType = mmdeploy::Structure, // + std::deque, // + std::vector>; // + +int mmdeploy_detector_create(mmdeploy_model_t model, const char* device_name, int device_id, + mmdeploy_detector_t* detector) { + mmdeploy_context_t context{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_detector_create_v2(model, context, detector); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_detector_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, + mmdeploy_detector_t* detector) { + mmdeploy_model_t model{}; + + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_detector_create(model, device_name, device_id, detector); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* input) { + return mmdeploy_common_create_input(mats, mat_count, input); +} + +int mmdeploy_detector_apply(mmdeploy_detector_t detector, const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_detection_t** results, int** result_count) { + wrapped input; + if (auto ec = mmdeploy_detector_create_input(mats, mat_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_detector_apply_v2(detector, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_detector_get_result(output, results, result_count)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_detector_apply_v2(mmdeploy_detector_t detector, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_detector_apply_async(mmdeploy_detector_t detector, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_detector_get_result(mmdeploy_value_t output, mmdeploy_detection_t** results, + int** result_count) { + if (!output || !results || !result_count) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value& value = Cast(output)->front(); + auto detector_outputs = from_value>(value); + + vector _result_count(detector_outputs.size()); + size_t total = 0; + for (size_t i = 0; i < detector_outputs.size(); ++i) { + _result_count[i] = static_cast(detector_outputs[i].size()); + total += detector_outputs[i].size(); + } + + ResultType r({total, 1, 1, 1}); + auto [result_data, result_count_vec, masks, buffers] = r.pointers(); + + auto result_ptr = result_data; + + for (const auto& det_output : detector_outputs) { + for (const auto& detection : det_output) { + result_ptr->label_id = detection.label_id; + result_ptr->score = detection.score; + const auto& bbox = detection.bbox; + result_ptr->bbox = {bbox[0], bbox[1], bbox[2], bbox[3]}; + auto mask_byte_size = detection.mask.byte_size(); + if (mask_byte_size) { + auto& mask = detection.mask; + result_ptr->mask = &masks->emplace_back(); + buffers->push_back(mask.buffer()); + result_ptr->mask->data = mask.data(); + result_ptr->mask->width = mask.width(); + result_ptr->mask->height = mask.height(); + } + ++result_ptr; + } + } + + *result_count_vec = std::move(_result_count); + *result_count = result_count_vec->data(); + *results = result_data; + r.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; +} + +void mmdeploy_detector_release_result(mmdeploy_detection_t* results, const int* result_count, + int count) { + auto num_dets = std::accumulate(result_count, result_count + count, 0); + ResultType deleter({static_cast(num_dets), 1, 1, 1}, results); +} + +void mmdeploy_detector_destroy(mmdeploy_detector_t detector) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)detector); +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/detector.h b/csrc/mmdeploy/apis/c/mmdeploy/detector.h new file mode 100644 index 0000000..5c5ba2f --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/detector.h @@ -0,0 +1,139 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file detector.h + * @brief Interface to MMDetection task + */ + +#ifndef MMDEPLOY_DETECTOR_H +#define MMDEPLOY_DETECTOR_H + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_instance_mask_t { + char* data; + int height; + int width; +} mmdeploy_instance_mask_t; + +typedef struct mmdeploy_detection_t { + int label_id; + float score; + mmdeploy_rect_t bbox; + mmdeploy_instance_mask_t* mask; +} mmdeploy_detection_t; + +typedef struct mmdeploy_detector* mmdeploy_detector_t; + +/** + * @brief Create detector's handle + * @param[in] model an instance of mmdetection sdk model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector instance of a detector + * @return status of creating detector's handle + */ +MMDEPLOY_API int mmdeploy_detector_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_detector_t* detector); + +/** + * @brief Create detector's handle + * @param[in] model_path path of mmdetection sdk model exported by mmdeploy model converter + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector instance of a detector + * @return status of creating detector's handle + */ +MMDEPLOY_API int mmdeploy_detector_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_detector_t* detector); + +/** + * @brief Apply detector to batch images and get their inference results + * @param[in] detector detector's handle created by \ref mmdeploy_detector_create_by_path + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] results a linear buffer to save detection results of each image. It must be released + * by \ref mmdeploy_detector_release_result + * @param[out] result_count a linear buffer with length being \p mat_count to save the number of + * detection results of each image. And it must be released by \ref + * mmdeploy_detector_release_result + * @return status of inference + */ +MMDEPLOY_API int mmdeploy_detector_apply(mmdeploy_detector_t detector, const mmdeploy_mat_t* mats, + int mat_count, mmdeploy_detection_t** results, + int** result_count); + +/** @brief Release the inference result buffer created by \ref mmdeploy_detector_apply + * @param[in] results detection results buffer + * @param[in] result_count \p results size buffer + * @param[in] count length of \p result_count + */ +MMDEPLOY_API void mmdeploy_detector_release_result(mmdeploy_detection_t* results, + const int* result_count, int count); + +/** + * @brief Destroy detector's handle + * @param[in] detector detector's handle created by \ref mmdeploy_detector_create_by_path + */ +MMDEPLOY_API void mmdeploy_detector_destroy(mmdeploy_detector_t detector); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +/** + * @brief Same as \ref mmdeploy_detector_create, but allows to control execution context of tasks + * via context + */ +MMDEPLOY_API int mmdeploy_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_detector_t* detector); + +/** + * @brief Pack detector inputs into mmdeploy_value_t + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @return the created value + */ +MMDEPLOY_API int mmdeploy_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* input); + +/** + * @brief Same as \ref mmdeploy_detector_apply, but input and output are packed in \ref + * mmdeploy_value_t. + */ +MMDEPLOY_API int mmdeploy_detector_apply_v2(mmdeploy_detector_t detector, mmdeploy_value_t input, + mmdeploy_value_t* output); + +/** + * @brief Apply detector asynchronously + * @param[in] detector handle to the detector + * @param[in] input input sender + * @return output sender + */ +MMDEPLOY_API int mmdeploy_detector_apply_async(mmdeploy_detector_t detector, + mmdeploy_sender_t input, mmdeploy_sender_t* output); + +/** + * @brief Unpack detector output from a mmdeploy_value_t + * @param[in] output output obtained by applying a detector + * @param[out] results a linear buffer to save detection results of each image. It must be released + * by \ref mmdeploy_detector_release_result + * @param[out] result_count a linear buffer with length number of input images to save the number of + * detection results of each image. Must be released by \ref + * mmdeploy_detector_release_result + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_detector_get_result(mmdeploy_value_t output, + mmdeploy_detection_t** results, int** result_count); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_DETECTOR_H diff --git a/csrc/mmdeploy/apis/c/mmdeploy/executor.cpp b/csrc/mmdeploy/apis/c/mmdeploy/executor.cpp new file mode 100644 index 0000000..2fdfb90 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/executor.cpp @@ -0,0 +1,207 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/executor.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; + +namespace { + +mmdeploy_scheduler_t CreateScheduler(const char* type, const Value& config = Value()) { + try { + auto creator = gRegistry().Get(type); + if (!creator) { + MMDEPLOY_ERROR("Creator for {} not found. Available schedulers: {}", type, + gRegistry().List()); + return nullptr; + } + return Cast(new SchedulerType(creator->Create(config))); + } catch (const std::exception& e) { + MMDEPLOY_ERROR("failed to create Scheduler: {} ({}), config: {}", type, e.what(), config); + return nullptr; + } +} + +} // namespace + +mmdeploy_sender_t mmdeploy_sender_copy(mmdeploy_sender_t input) { + if (!input) { + return nullptr; + } + return Take(SenderType(*Cast(input))); +} + +int mmdeploy_sender_destroy(mmdeploy_sender_t sender) { + delete Cast(sender); + return 0; +} + +mmdeploy_scheduler_t mmdeploy_executor_inline() { return CreateScheduler("Inline"); } + +mmdeploy_scheduler_t mmdeploy_executor_system_pool() { + // create a thread pool context and hold its shared handle + static auto scheduler = *Cast(CreateScheduler("ThreadPool")); + // return a copy of the handle to the thread pool + return Cast(new SchedulerType(scheduler)); +} + +mmdeploy_scheduler_t mmdeploy_executor_create_thread_pool(int num_threads) { + return CreateScheduler("ThreadPool", {{"num_threads", num_threads}}); +} + +mmdeploy_scheduler_t mmdeploy_executor_create_thread() { return CreateScheduler("SingleThread"); } + +mmdeploy_scheduler_t mmdeploy_executor_dynamic_batch(mmdeploy_scheduler_t scheduler, + int max_batch_size, int timeout) { + if (!scheduler) { + return nullptr; + } + return CreateScheduler( + "DynamicBatch", + {{"scheduler", *Cast(scheduler)}, {"max_batch_size", max_batch_size}, {"timeout", timeout}}); +} + +int mmdeploy_scheduler_destroy(mmdeploy_scheduler_t scheduler) { + delete Cast(scheduler); + return 0; +} + +mmdeploy_sender_t mmdeploy_executor_just(mmdeploy_value_t value) { + if (value) { + return Guard([&] { return Take(Just(*Cast(value))); }); + } else { + return Take(Just(Value())); + } +} + +mmdeploy_sender_t mmdeploy_executor_schedule(mmdeploy_scheduler_t scheduler) { + if (!scheduler) { + return nullptr; + } + return Guard([&] { return Take(Then(Schedule(*Cast(scheduler)), [] { return Value(); })); }); +} + +mmdeploy_sender_t mmdeploy_executor_transfer_just(mmdeploy_scheduler_t scheduler, + mmdeploy_value_t value) { + if (!scheduler || !value) { + return nullptr; + } + return Guard([&] { return Take(TransferJust(*Cast(scheduler), *Cast(value))); }); +} + +mmdeploy_sender_t mmdeploy_executor_transfer(mmdeploy_sender_t input, + mmdeploy_scheduler_t scheduler) { + if (!input || !scheduler) { + return nullptr; + } + return Guard([&] { return Take(Transfer(Take(input), *Cast(scheduler))); }); +} + +mmdeploy_sender_t mmdeploy_executor_on(mmdeploy_scheduler_t scheduler, mmdeploy_sender_t input) { + if (!scheduler || !input) { + return nullptr; + } + return Guard([&] { return Take(On(*Cast(scheduler), Take(input))); }); +} + +mmdeploy_sender_t mmdeploy_executor_then(mmdeploy_sender_t input, mmdeploy_then_fn_t fn, + void* context) { + if (!input || !fn) { + return nullptr; + } + return Guard([&] { + return Take(Then(Take(input), [fn, context](Value args) { + auto out = Cast(fn(Take(std::move(args)), context)); + Value ret(std::move(*out)); + delete out; + return ret; + })); + }); +} + +mmdeploy_sender_t mmdeploy_executor_let_value(mmdeploy_sender_t input, mmdeploy_let_value_fn_t fn, + void* context) { + if (!input || !fn) { + return nullptr; + } + return Guard([&] { + return Take(LetValue(Take(input), [fn, context](Value& args) { + auto out = Cast(fn(Cast(&args), context)); + SenderType ret(std::move(*out)); + delete out; + return ret; + })); + }); +} + +mmdeploy_sender_t mmdeploy_executor_split(mmdeploy_sender_t input) { + if (!input) { + return nullptr; + } + return Guard([&] { return Take(Split(Take(input))); }); +} + +mmdeploy_sender_t mmdeploy_executor_when_all(mmdeploy_sender_t inputs[], int32_t n) { + if (!inputs) { + return nullptr; + } + return Guard([&] { + std::vector senders; + senders.reserve(n); + for (int i = 0; i < n; ++i) { + senders.emplace_back(Take(inputs[i])); + } + return Take( + Then(WhenAll(std::move(senders)), [](Value::Array&& v) { return Value(std::move(v)); })); + }); +} + +mmdeploy_sender_t mmdeploy_executor_ensure_started(mmdeploy_sender_t input) { + if (!input) { + return nullptr; + } + return Guard([&] { return Take(EnsureStarted(Take(input))); }); +} + +int mmdeploy_executor_start_detached(mmdeploy_sender_t input) { + if (!input) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + StartDetached(Take(input)); + return 0; + } catch (...) { + } + return MMDEPLOY_E_FAIL; +} + +mmdeploy_value_t mmdeploy_executor_sync_wait(mmdeploy_sender_t input) { + if (!input) { + return nullptr; + } + return Guard([&] { return Take(std::get(SyncWait(Take(input)))); }); +} + +int mmdeploy_executor_sync_wait_v2(mmdeploy_sender_t sender, mmdeploy_value_t* value) { + if (!sender) { + return MMDEPLOY_E_INVALID_ARG; + } + auto result = mmdeploy_executor_sync_wait(sender); + if (!result) { + return MMDEPLOY_E_FAIL; + } + if (value) { + *value = result; + } else { + mmdeploy_value_destroy(result); + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_executor_execute(mmdeploy_scheduler_t scheduler, void (*fn)(void*), void* context) { + Execute(*Cast(scheduler), [fn, context] { fn(context); }); +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/executor.h b/csrc/mmdeploy/apis/c/mmdeploy/executor.h new file mode 100644 index 0000000..a2c8ffa --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/executor.h @@ -0,0 +1,141 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_CSRC_APIS_C_EXECUTOR_H_ +#define MMDEPLOY_CSRC_APIS_C_EXECUTOR_H_ + +#include "mmdeploy/common.h" + +#if __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Experimental asynchronous APIs */ + +typedef mmdeploy_value_t (*mmdeploy_then_fn_t)(mmdeploy_value_t, void*); + +typedef mmdeploy_value_t (*mmdeploy_then_fn_v2_t)(mmdeploy_value_t*, void*); + +typedef int (*mmdeploy_then_fn_v3_t)(mmdeploy_value_t* input, mmdeploy_value_t* output, void*); + +struct mmdeploy_sender; +struct mmdeploy_scheduler; + +typedef struct mmdeploy_sender* mmdeploy_sender_t; +typedef struct mmdeploy_scheduler* mmdeploy_scheduler_t; + +typedef mmdeploy_sender_t (*mmdeploy_let_value_fn_t)(mmdeploy_value_t, void*); + +/////////////////////////////////////////////////////////////////////////////// +// Scheduler +/////////////////////////////////////////////////////////////////////////////// +MMDEPLOY_API mmdeploy_scheduler_t mmdeploy_executor_inline(); + +MMDEPLOY_API mmdeploy_scheduler_t mmdeploy_executor_system_pool(); + +/** + * Create a thread pool with the given number of worker threads + * @param[in] num_threads + * @return the handle to the created thread pool + */ +MMDEPLOY_API mmdeploy_scheduler_t mmdeploy_executor_create_thread_pool(int num_threads); + +MMDEPLOY_API mmdeploy_scheduler_t mmdeploy_executor_create_thread(); + +MMDEPLOY_API mmdeploy_scheduler_t mmdeploy_executor_dynamic_batch(mmdeploy_scheduler_t scheduler, + int max_batch_size, int timeout); + +MMDEPLOY_API int mmdeploy_scheduler_destroy(mmdeploy_scheduler_t scheduler); + +/////////////////////////////////////////////////////////////////////////////// +// Utilities +/////////////////////////////////////////////////////////////////////////////// + +/** + * @brief Create a copy of a copyable sender. Only senders created by \ref mmdeploy_executor_split + * is copyable for now. + * @param[in] input copyable sender, + * @return the sender created, or nullptr if the sender is not copyable + */ +MMDEPLOY_API mmdeploy_sender_t mmdeploy_sender_copy(mmdeploy_sender_t input); + +/** + * @brief Destroy a sender, notice that all sender adapters will consume input senders, only unused + * senders should be destroyed using this function. + * @param[in] input + */ +MMDEPLOY_API int mmdeploy_sender_destroy(mmdeploy_sender_t sender); + +/////////////////////////////////////////////////////////////////////////////// +// Sender factories +/////////////////////////////////////////////////////////////////////////////// + +/** + * @brief Create a sender that sends the provided value + * @param[in] value + * @return created sender + */ +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_just(mmdeploy_value_t value); + +/** + * @brief + * @param[in] scheduler + * @return the sender created + */ +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_schedule(mmdeploy_scheduler_t scheduler); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_transfer_just(mmdeploy_scheduler_t scheduler, + mmdeploy_value_t value); + +/////////////////////////////////////////////////////////////////////////////// +// Sender adapters +/////////////////////////////////////////////////////////////////////////////// + +/** + * Transfer the execution to the execution agent of the provided scheduler + * @param[in] input + * @param[in] scheduler + * @return the sender created + */ +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_transfer(mmdeploy_sender_t input, + mmdeploy_scheduler_t scheduler); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_on(mmdeploy_scheduler_t scheduler, + mmdeploy_sender_t input); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_then(mmdeploy_sender_t input, + mmdeploy_then_fn_t fn, void* context); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_let_value(mmdeploy_sender_t input, + mmdeploy_let_value_fn_t fn, + void* context); + +/** + * Convert the input sender into a sender that is copyable via \ref mmdeploy_sender_copy. Notice + * that this function doesn't make the sender multi-shot, it just return a sender that is copyable. + * @param[in] input + * @return the sender that is copyable + */ +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_split(mmdeploy_sender_t input); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_when_all(mmdeploy_sender_t inputs[], int32_t n); + +MMDEPLOY_API mmdeploy_sender_t mmdeploy_executor_ensure_started(mmdeploy_sender_t input); + +/////////////////////////////////////////////////////////////////////////////// +// Sender consumers +/////////////////////////////////////////////////////////////////////////////// +MMDEPLOY_API int mmdeploy_executor_start_detached(mmdeploy_sender_t input); + +MMDEPLOY_API mmdeploy_value_t mmdeploy_executor_sync_wait(mmdeploy_sender_t input); + +MMDEPLOY_API int mmdeploy_executor_sync_wait_v2(mmdeploy_sender_t input, mmdeploy_value_t* output); + +MMDEPLOY_API void mmdeploy_executor_execute(mmdeploy_scheduler_t scheduler, void (*fn)(void*), + void* context); + +#if __cplusplus +} +#endif + +#endif // MMDEPLOY_CSRC_APIS_C_EXECUTOR_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/executor_internal.h b/csrc/mmdeploy/apis/c/mmdeploy/executor_internal.h new file mode 100644 index 0000000..95f39fe --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/executor_internal.h @@ -0,0 +1,41 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_CSRC_APIS_C_EXECUTOR_INTERNAL_H_ +#define MMDEPLOY_CSRC_APIS_C_EXECUTOR_INTERNAL_H_ + +#include "mmdeploy/execution/schedulers/registry.h" +#include "mmdeploy/executor.h" + +using namespace mmdeploy; + +using SenderType = TypeErasedSender; +using SchedulerType = TypeErasedScheduler; + +namespace { + +inline SchedulerType* Cast(mmdeploy_scheduler_t s) { return reinterpret_cast(s); } + +inline mmdeploy_scheduler_t Cast(SchedulerType* s) { + return reinterpret_cast(s); +} + +inline SenderType* Cast(mmdeploy_sender_t s) { return reinterpret_cast(s); } + +inline mmdeploy_sender_t Cast(SenderType* s) { return reinterpret_cast(s); } + +inline SenderType Take(mmdeploy_sender_t s) { + auto sender = std::move(*Cast(s)); + mmdeploy_sender_destroy(s); + return sender; +} + +inline mmdeploy_sender_t Take(SenderType s) { return Cast(new SenderType(std::move(s))); } + +template , int> = 0> +inline mmdeploy_sender_t Take(T& s) { + return Take(SenderType(std::move(s))); +} + +} // namespace + +#endif // MMDEPLOY_CSRC_APIS_C_EXECUTOR_INTERNAL_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/handle.h b/csrc/mmdeploy/apis/c/mmdeploy/handle.h new file mode 100644 index 0000000..006ddaa --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/handle.h @@ -0,0 +1,53 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_SRC_APIS_C_HANDLE_H_ +#define MMDEPLOY_SRC_APIS_C_HANDLE_H_ + +#include + +#include "mmdeploy/core/device.h" +#include "mmdeploy/core/graph.h" +#include "mmdeploy/core/value.h" +#include "mmdeploy/graph/common.h" +#include "mmdeploy/graph/static_router.h" + +namespace mmdeploy { + +using namespace framework; + +namespace { + +class AsyncHandle { + public: + AsyncHandle(const char* device_name, int device_id, Value config) + : AsyncHandle(SetContext(std::move(config), device_name, device_id)) {} + + explicit AsyncHandle(const Value& config) { + if (auto builder = graph::Builder::CreateFromConfig(config).value()) { + node_ = builder->Build().value(); + } else { + MMDEPLOY_ERROR("failed to find creator for node"); + throw_exception(eEntryNotFound); + } + } + + graph::Sender Process(graph::Sender input) { + return node_->Process(std::move(input)); + } + + private: + static Value SetContext(Value config, const char* device_name, int device_id) { + Device device(device_name, device_id); + Stream stream(device); + config["context"].update({{"device", device}, {"stream", stream}}); + return config; + } + + std::unique_ptr node_; +}; + +} // namespace + +} // namespace mmdeploy + +#endif // MMDEPLOY_SRC_APIS_C_HANDLE_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/model.cpp b/csrc/mmdeploy/apis/c/mmdeploy/model.cpp new file mode 100644 index 0000000..6d202bc --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/model.cpp @@ -0,0 +1,41 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +// clang-format off +#include "mmdeploy/model.h" + +#include + +#include "mmdeploy/common_internal.h" +#include "mmdeploy/core/logger.h" +#include "mmdeploy/core/model.h" +// clang-format on + +using namespace mmdeploy; + +int mmdeploy_model_create_by_path(const char* path, mmdeploy_model_t* model) { + try { + auto ptr = std::make_unique(path); + *model = reinterpret_cast(ptr.release()); + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("failed to create model: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_E_FAIL; +} + +int mmdeploy_model_create(const void* buffer, int size, mmdeploy_model_t* model) { + try { + auto ptr = std::make_unique(buffer, size); + *model = reinterpret_cast(ptr.release()); + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("failed to create model: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_E_FAIL; +} + +void mmdeploy_model_destroy(mmdeploy_model_t model) { delete reinterpret_cast(model); } diff --git a/csrc/mmdeploy/apis/c/mmdeploy/model.h b/csrc/mmdeploy/apis/c/mmdeploy/model.h new file mode 100644 index 0000000..394d290 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/model.h @@ -0,0 +1,47 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file model.h + * @brief Interface to MMDeploy SDK Model + */ + +#ifndef MMDEPLOY_SRC_APIS_C_MODEL_H_ +#define MMDEPLOY_SRC_APIS_C_MODEL_H_ + +#include "mmdeploy/common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_model* mmdeploy_model_t; + +/** + * @brief Create SDK Model instance from given model path + * @param[in] path model path + * @param[out] model sdk model instance that must be destroyed by \ref mmdeploy_model_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_model_create_by_path(const char* path, mmdeploy_model_t* model); + +/** + * @brief Create SDK Model instance from memory + * @param[in] buffer a linear buffer contains the model information + * @param[in] size size of \p buffer in bytes + * @param[out] model sdk model instance that must be destroyed by \ref mmdeploy_model_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_model_create(const void* buffer, int size, mmdeploy_model_t* model); + +/** + * @brief Destroy model instance + * @param[in] model sdk model instance created by \ref mmdeploy_model_create_by_path or \ref + * mmdeploy_model_create + */ +MMDEPLOY_API void mmdeploy_model_destroy(mmdeploy_model_t model); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SRC_APIS_C_MODEL_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pipeline.cpp b/csrc/mmdeploy/apis/c/mmdeploy/pipeline.cpp new file mode 100644 index 0000000..a9a0280 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pipeline.cpp @@ -0,0 +1,78 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/pipeline.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) { + try { + auto _config = *Cast(config); + if (context) { + if (!_config.contains("context")) { + _config["context"] = Value::Object(); + } + update(_config["context"].object(), Cast(context)->object(), 2); + } + auto _handle = std::make_unique(std::move(_config)); + *pipeline = Cast(_handle.release()); + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("exception caught: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + 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) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + auto h = Cast(pipeline); + *output = Take(h->Process(Take(input))); + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("exception caught: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_E_FAIL; +} + +void mmdeploy_pipeline_destroy(mmdeploy_pipeline_t pipeline) { + if (pipeline != nullptr) { + delete Cast(pipeline); + } +} + +int mmdeploy_pipeline_apply(mmdeploy_pipeline_t pipeline, mmdeploy_value_t input, + mmdeploy_value_t* output) { + auto input_sender = mmdeploy_executor_just(input); + if (!input_sender) { + return MMDEPLOY_E_FAIL; + } + mmdeploy_sender_t output_sender{}; + if (auto ec = mmdeploy_pipeline_apply_async(pipeline, input_sender, &output_sender)) { + return ec; + } + auto _output = mmdeploy_executor_sync_wait(output_sender); + if (!_output) { + return MMDEPLOY_E_FAIL; + } + *output = _output; + return MMDEPLOY_SUCCESS; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pipeline.h b/csrc/mmdeploy/apis/c/mmdeploy/pipeline.h new file mode 100644 index 0000000..55ccf1e --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pipeline.h @@ -0,0 +1,69 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#ifndef MMDEPLOY_CSRC_APIS_C_PIPELINE_H_ +#define MMDEPLOY_CSRC_APIS_C_PIPELINE_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Experimental pipeline APIs */ + +typedef struct mmdeploy_pipeline* mmdeploy_pipeline_t; + +/** + * Create pipeline + * @param config + * @param context + * @param pipeline + * @return + */ +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 + * @param[in] pipeline handle of the pipeline + * @param[in] input input value + * @param[out] output output value + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_pipeline_apply(mmdeploy_pipeline_t pipeline, mmdeploy_value_t input, + mmdeploy_value_t* output); + +/** + * Apply pipeline asynchronously + * @param pipeline handle of the pipeline + * @param input input sender that will be consumed by the operation + * @param output output sender + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_pipeline_apply_async(mmdeploy_pipeline_t pipeline, + mmdeploy_sender_t input, mmdeploy_sender_t* output); + +/** + * @brief destroy pipeline + * @param[in] pipeline + */ +MMDEPLOY_API void mmdeploy_pipeline_destroy(mmdeploy_pipeline_t pipeline); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_CSRC_APIS_C_PIPELINE_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.cpp b/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.cpp new file mode 100644 index 0000000..46f9921 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.cpp @@ -0,0 +1,179 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/pose_detector.h" + +#include + +#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 "mmdeploy/handle.h" +#include "mmdeploy/pipeline.h" + +using namespace std; +using namespace mmdeploy; + +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{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_pose_detector_create_v2(model, context, detector); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_pose_detector_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_pose_detector_t* detector) { + mmdeploy_model_t model{}; + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_pose_detector_create(model, device_name, device_id, detector); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_pose_detector_apply(mmdeploy_pose_detector_t detector, const mmdeploy_mat_t* mats, + int mat_count, mmdeploy_pose_detection_t** results) { + return mmdeploy_pose_detector_apply_bbox(detector, mats, mat_count, nullptr, nullptr, results); +} + +int mmdeploy_pose_detector_apply_bbox(mmdeploy_pose_detector_t detector, const mmdeploy_mat_t* mats, + int mat_count, const mmdeploy_rect_t* bboxes, + const int* bbox_count, mmdeploy_pose_detection_t** results) { + wrapped input; + if (auto ec = + mmdeploy_pose_detector_create_input(mats, mat_count, bboxes, bbox_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_pose_detector_apply_v2(detector, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_pose_detector_get_result(output, results)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_pose_detector_release_result(mmdeploy_pose_detection_t* results, int count) { + if (results == nullptr) { + return; + } + for (int i = 0; i < count; ++i) { + delete[] results[i].point; + delete[] results[i].score; + } + delete[] results; +} + +void mmdeploy_pose_detector_destroy(mmdeploy_pose_detector_t detector) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)detector); +} + +int mmdeploy_pose_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_pose_detector_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, + const mmdeploy_rect_t* bboxes, const int* bbox_count, + mmdeploy_value_t* value) { + if (mat_count && mats == nullptr) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value::Array input_images; + + auto add_bbox = [&](const Mat& img, const mmdeploy_rect_t* bbox) { + Value::Array b; + if (bbox) { + float width = bbox->right - bbox->left + 1; + float height = bbox->bottom - bbox->top + 1; + b = {bbox->left, bbox->top, width, height, 1.0}; + } else { + b = {0, 0, img.width(), img.height(), 1.0}; + } + input_images.push_back({{"ori_img", img}, {"bbox", std::move(b)}}); + }; + + for (int i = 0; i < mat_count; ++i) { + auto _mat = Cast(mats[i]); + if (bboxes && bbox_count) { + for (int j = 0; j < bbox_count[i]; ++j) { + add_bbox(_mat, bboxes++); + } + } else { // inference whole image + add_bbox(_mat, nullptr); + } + } + + *value = Take(Value{std::move(input_images)}); + 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_detector_apply_v2(mmdeploy_pose_detector_t detector, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_pose_detector_apply_async(mmdeploy_pose_detector_t detector, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_pose_detector_get_result(mmdeploy_value_t output, + mmdeploy_pose_detection_t** results) { + if (!output || !results) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + std::vector detections; + from_value(Cast(output)->front(), detections); + + size_t count = detections.size(); + + auto deleter = [&](mmdeploy_pose_detection_t* p) { + mmdeploy_pose_detector_release_result(p, static_cast(count)); + }; + + std::unique_ptr _results( + new mmdeploy_pose_detection_t[count]{}, deleter); + + size_t result_idx = 0; + for (const auto& bbox_result : detections) { + auto& res = _results[result_idx++]; + auto size = bbox_result.key_points.size(); + + res.point = new mmdeploy_point_t[size]; + res.score = new float[size]; + res.length = static_cast(size); + + for (int k = 0; k < size; k++) { + res.point[k].x = bbox_result.key_points[k].bbox[0]; + res.point[k].y = bbox_result.key_points[k].bbox[1]; + res.score[k] = bbox_result.key_points[k].score; + } + } + + *results = _results.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; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h b/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h new file mode 100644 index 0000000..ff0987c --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pose_detector.h @@ -0,0 +1,126 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file pose_detector.h + * @brief Interface to MMPose task + */ + +#ifndef MMDEPLOY_SRC_APIS_C_POSE_DETECTOR_H_ +#define MMDEPLOY_SRC_APIS_C_POSE_DETECTOR_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_pose_detection_t { + mmdeploy_point_t* point; ///< keypoint + float* score; ///< keypoint score + int length; ///< number of keypoint +} mmdeploy_pose_detection_t; + +typedef struct mmdeploy_pose_detector* mmdeploy_pose_detector_t; + +/** + * @brief Create a pose detector instance + * @param[in] model an instance of mmpose model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector handle of the created pose detector, which must be destroyed + * by \ref mmdeploy_pose_detector_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_pose_detector_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_pose_detector_t* detector); + +/** + * @brief Create a pose detector instance + * @param[in] model_path path to pose detection model + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector handle of the created pose detector, which must be destroyed + * by \ref mmdeploy_pose_detector_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_pose_detector_create_by_path(const char* model_path, + const char* device_name, int device_id, + mmdeploy_pose_detector_t* detector); + +/** + * @brief Apply pose detector to a batch of images with full image roi + * @param[in] detector pose detector's handle created by \ref + * mmdeploy_pose_detector_create_by_path + * @param[in] images a batch of images + * @param[in] count number of images in the batch + * @param[out] results a linear buffer contains the pose result, must be release + * by \ref mmdeploy_pose_detector_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_pose_detector_apply(mmdeploy_pose_detector_t detector, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_pose_detection_t** results); + +/** + * @brief Apply pose detector to a batch of images supplied with bboxes(roi) + * @param[in] detector pose detector's handle created by \ref + * mmdeploy_pose_detector_create_by_path + * @param[in] images a batch of images + * @param[in] image_count number of images in the batch + * @param[in] bboxes bounding boxes(roi) detected by mmdet + * @param[in] bbox_count number of bboxes of each \p images, must be same length as \p images + * @param[out] results a linear buffer contains the pose result, which has the same length as \p + * bboxes, must be release by \ref mmdeploy_pose_detector_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_pose_detector_apply_bbox(mmdeploy_pose_detector_t detector, + const mmdeploy_mat_t* mats, int mat_count, + const mmdeploy_rect_t* bboxes, + const int* bbox_count, + mmdeploy_pose_detection_t** results); + +/** @brief Release result buffer returned by \ref mmdeploy_pose_detector_apply or \ref + * mmdeploy_pose_detector_apply_bbox + * @param[in] results result buffer by pose detector + * @param[in] count length of \p result + */ +MMDEPLOY_API void mmdeploy_pose_detector_release_result(mmdeploy_pose_detection_t* results, + int count); + +/** + * @brief destroy pose_detector + * @param[in] detector handle of pose_detector created by \ref + * mmdeploy_pose_detector_create_by_path or \ref mmdeploy_pose_detector_create + */ +MMDEPLOY_API void mmdeploy_pose_detector_destroy(mmdeploy_pose_detector_t detector); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +MMDEPLOY_API int mmdeploy_pose_detector_create_v2(mmdeploy_model_t model, + mmdeploy_context_t context, + mmdeploy_pose_detector_t* detector); + +MMDEPLOY_API int mmdeploy_pose_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + const mmdeploy_rect_t* bboxes, + const int* bbox_count, + mmdeploy_value_t* value); + +MMDEPLOY_API int mmdeploy_pose_detector_apply_v2(mmdeploy_pose_detector_t detector, + mmdeploy_value_t input, mmdeploy_value_t* output); + +MMDEPLOY_API int mmdeploy_pose_detector_apply_async(mmdeploy_pose_detector_t detector, + mmdeploy_sender_t input, + mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_pose_detector_get_result(mmdeploy_value_t output, + mmdeploy_pose_detection_t** results); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SRC_APIS_C_POSE_DETECTOR_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.cpp b/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.cpp new file mode 100644 index 0000000..113b520 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.cpp @@ -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(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().Create("pose_tracker::Create", Value()).value(); + *state = reinterpret_cast(new Value( + create_fn->Process({const_cast(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(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(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, + std::vector>; + +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 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(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 input; + if (auto ec = + mmdeploy_pose_tracker_create_input(states, frames, use_detect, count, input.ptr())) { + return ec; + } + wrapped 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(total), 1, 1}, results); +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h b/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h new file mode 100644 index 0000000..4b27fba --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h @@ -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 diff --git a/csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp b/csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp new file mode 100644 index 0000000..9ca2ca6 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/restorer.cpp @@ -0,0 +1,121 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/restorer.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 "mmdeploy/executor_internal.h" +#include "mmdeploy/handle.h" +#include "mmdeploy/pipeline.h" + +using namespace mmdeploy; + +using ResultType = mmdeploy::Structure; + +int mmdeploy_restorer_create(mmdeploy_model_t model, const char* device_name, int device_id, + mmdeploy_restorer_t* restorer) { + mmdeploy_context_t context{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_restorer_create_v2(model, context, restorer); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_restorer_create_by_path(const char* model_path, const char* device_name, int device_id, + mmdeploy_restorer_t* restorer) { + mmdeploy_model_t model{}; + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_restorer_create(model, device_name, device_id, restorer); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_restorer_apply(mmdeploy_restorer_t restorer, const mmdeploy_mat_t* images, int count, + mmdeploy_mat_t** results) { + wrapped input; + if (auto ec = mmdeploy_restorer_create_input(images, count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_restorer_apply_v2(restorer, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_restorer_get_result(output, results)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_restorer_release_result(mmdeploy_mat_t* results, int count) { + ResultType deleter{static_cast(count), results}; +} + +void mmdeploy_restorer_destroy(mmdeploy_restorer_t restorer) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)restorer); +} + +int mmdeploy_restorer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_restorer_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, + mmdeploy_value_t* value) { + return mmdeploy_common_create_input(mats, mat_count, value); +} + +int mmdeploy_restorer_apply_v2(mmdeploy_restorer_t restorer, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)restorer, input, output); +} + +int mmdeploy_restorer_apply_async(mmdeploy_restorer_t restorer, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)restorer, input, output); +} + +int mmdeploy_restorer_get_result(mmdeploy_value_t output, mmdeploy_mat_t** results) { + if (!output || !results) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + const Value& value = Cast(output)->front(); + + auto restorer_output = from_value>(value); + auto count = restorer_output.size(); + + ResultType r(count); + auto [_results, buffers] = r.pointers(); + + for (int i = 0; i < count; ++i) { + auto upscale = restorer_output[i]; + auto& res = _results[i]; + res.data = upscale.data(); + buffers[i] = upscale.buffer(); + res.format = (mmdeploy_pixel_format_t)upscale.pixel_format(); + res.height = upscale.height(); + res.width = upscale.width(); + res.channel = upscale.channel(); + res.type = (mmdeploy_data_type_t)upscale.type(); + } + + *results = _results; + r.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; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/restorer.h b/csrc/mmdeploy/apis/c/mmdeploy/restorer.h new file mode 100644 index 0000000..9ab5298 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/restorer.h @@ -0,0 +1,91 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file restorer.h + * @brief Interface to MMEditing image restoration task + */ + +#ifndef MMDEPLOY_SRC_APIS_C_RESTORER_H_ +#define MMDEPLOY_SRC_APIS_C_RESTORER_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_restorer* mmdeploy_restorer_t; + +/** + * @brief Create a restorer instance + * @param[in] model an instance of image restoration model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] restorer handle of the created restorer, which must be destroyed + * by \ref mmdeploy_restorer_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_restorer_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_restorer_t* restorer); + +/** + * @brief Create a restorer instance + * @param[in] model_path path to image restoration model + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] restorer handle of the created restorer, which must be destroyed + * by \ref mmdeploy_restorer_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_restorer_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_restorer_t* restorer); + +/** + * @brief Apply restorer to a batch of images + * @param[in] restorer restorer's handle created by \ref mmdeploy_restorer_create_by_path + * @param[in] images a batch of images + * @param[in] count number of images in the batch + * @param[out] results a linear buffer contains the restored images, must be release + * by \ref mmdeploy_restorer_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_restorer_apply(mmdeploy_restorer_t restorer, const mmdeploy_mat_t* images, + int count, mmdeploy_mat_t** results); + +/** @brief Release result buffer returned by \ref mmdeploy_restorer_apply + * @param[in] results result buffer by restorer + * @param[in] count length of \p result + */ +MMDEPLOY_API void mmdeploy_restorer_release_result(mmdeploy_mat_t* results, int count); + +/** + * @brief destroy restorer + * @param[in] restorer handle of restorer created by \ref mmdeploy_restorer_create_by_path + */ +MMDEPLOY_API void mmdeploy_restorer_destroy(mmdeploy_restorer_t restorer); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +MMDEPLOY_API int mmdeploy_restorer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_restorer_t* restorer); + +MMDEPLOY_API int mmdeploy_restorer_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* value); + +MMDEPLOY_API int mmdeploy_restorer_apply_v2(mmdeploy_restorer_t restorer, mmdeploy_value_t input, + mmdeploy_value_t* output); + +MMDEPLOY_API int mmdeploy_restorer_apply_async(mmdeploy_restorer_t restorer, + mmdeploy_sender_t input, mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_restorer_get_result(mmdeploy_value_t output, mmdeploy_mat_t** results); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SRC_APIS_C_RESTORER_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.cpp b/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.cpp new file mode 100644 index 0000000..d2172c5 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.cpp @@ -0,0 +1,138 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/rotated_detector.h" + +#include + +#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 "mmdeploy/handle.h" +#include "mmdeploy/pipeline.h" + +using namespace std; +using namespace mmdeploy; + +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{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_rotated_detector_create_v2(model, context, detector); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_rotated_detector_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_rotated_detector_t* detector) { + mmdeploy_model_t model{}; + + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_rotated_detector_create(model, device_name, device_id, detector); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_rotated_detector_apply(mmdeploy_rotated_detector_t detector, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_rotated_detection_t** results, int** result_count) { + wrapped input; + if (auto ec = mmdeploy_rotated_detector_create_input(mats, mat_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_rotated_detector_apply_v2(detector, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_rotated_detector_get_result(output, results, result_count)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_rotated_detector_release_result(mmdeploy_rotated_detection_t* results, + const int* result_count) { + delete[] results; + delete[] result_count; +} + +void mmdeploy_rotated_detector_destroy(mmdeploy_rotated_detector_t detector) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)detector); +} + +int mmdeploy_rotated_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_rotated_detector_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, + mmdeploy_value_t* input) { + return mmdeploy_common_create_input(mats, mat_count, input); +} + +int mmdeploy_rotated_detector_apply_v2(mmdeploy_rotated_detector_t detector, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_rotated_detector_apply_async(mmdeploy_rotated_detector_t detector, + mmdeploy_sender_t input, mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_rotated_detector_get_result(mmdeploy_value_t output, + mmdeploy_rotated_detection_t** results, + int** result_count) { + if (!output || !results || !result_count) { + return MMDEPLOY_E_INVALID_ARG; + } + + try { + Value& value = Cast(output)->front(); + auto detector_outputs = from_value>(value); + + vector _result_count; + _result_count.reserve(detector_outputs.size()); + for (const auto& det_output : detector_outputs) { + _result_count.push_back((int)det_output.detections.size()); + } + + auto total = std::accumulate(_result_count.begin(), _result_count.end(), 0); + + std::unique_ptr result_count_data(new int[_result_count.size()]{}); + std::copy(_result_count.begin(), _result_count.end(), result_count_data.get()); + + std::unique_ptr result_data( + new mmdeploy_rotated_detection_t[total]{}); + auto result_ptr = result_data.get(); + + for (const auto& det_output : detector_outputs) { + for (const auto& detection : det_output.detections) { + result_ptr->label_id = detection.label_id; + result_ptr->score = detection.score; + const auto& rbbox = detection.rbbox; + for (int i = 0; i < 5; i++) { + result_ptr->rbbox[i] = rbbox[i]; + } + ++result_ptr; + } + } + + *result_count = result_count_data.release(); + *results = result_data.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; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.h b/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.h new file mode 100644 index 0000000..35125a7 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/rotated_detector.h @@ -0,0 +1,140 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file rotated_detector.h + * @brief Interface to MMRotate task + */ + +#ifndef MMDEPLOY_SRC_APIS_C_ROTATED_DETECTOR_H_ +#define MMDEPLOY_SRC_APIS_C_ROTATED_DETECTOR_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_rotated_detection_t { + int label_id; + float score; + float rbbox[5]; // cx, cy, w, h, angle +} mmdeploy_rotated_detection_t; + +typedef struct mmdeploy_rotated_detector* mmdeploy_rotated_detector_t; + +/** + * @brief Create rotated detector's handle + * @param[in] model an instance of mmrotate sdk model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector instance of a rotated detector + * @return status of creating rotated detector's handle + */ +MMDEPLOY_API int mmdeploy_rotated_detector_create(mmdeploy_model_t model, const char* device_name, + int device_id, + mmdeploy_rotated_detector_t* detector); + +/** + * @brief Create rotated detector's handle + * @param[in] model_path path of mmrotate sdk model exported by mmdeploy model converter + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector instance of a rotated detector + * @return status of creating rotated detector's handle + */ +MMDEPLOY_API int mmdeploy_rotated_detector_create_by_path(const char* model_path, + const char* device_name, int device_id, + mmdeploy_rotated_detector_t* detector); + +/** + * @brief Apply rotated detector to batch images and get their inference results + * @param[in] detector rotated detector's handle created by \ref + * mmdeploy_rotated_detector_create_by_path + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] results a linear buffer to save detection results of each image. It must be released + * by \ref mmdeploy_rotated_detector_release_result + * @param[out] result_count a linear buffer with length being \p mat_count to save the number of + * detection results of each image. And it must be released by \ref + * mmdeploy_rotated_detector_release_result + * @return status of inference + */ +MMDEPLOY_API int mmdeploy_rotated_detector_apply(mmdeploy_rotated_detector_t detector, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_rotated_detection_t** results, + int** result_count); + +/** @brief Release the inference result buffer created by \ref mmdeploy_rotated_detector_apply + * @param[in] results rotated detection results buffer + * @param[in] result_count \p results size buffer + */ +MMDEPLOY_API void mmdeploy_rotated_detector_release_result(mmdeploy_rotated_detection_t* results, + const int* result_count); + +/** + * @brief Destroy rotated detector's handle + * @param[in] detector rotated detector's handle created by \ref + * mmdeploy_rotated_detector_create_by_path or by \ref mmdeploy_rotated_detector_create + */ +MMDEPLOY_API void mmdeploy_rotated_detector_destroy(mmdeploy_rotated_detector_t detector); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +/** + * @brief Same as \ref mmdeploy_detector_create, but allows to control execution context of tasks + * via context + */ +MMDEPLOY_API int mmdeploy_rotated_detector_create_v2(mmdeploy_model_t model, + mmdeploy_context_t context, + mmdeploy_rotated_detector_t* detector); + +/** + * @brief Pack rotated detector inputs into mmdeploy_value_t + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @return the created value + */ +MMDEPLOY_API int mmdeploy_rotated_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* input); + +/** + * @brief Same as \ref mmdeploy_rotated_detector_apply, but input and output are packed in \ref + * mmdeploy_value_t. + */ +MMDEPLOY_API int mmdeploy_rotated_detector_apply_v2(mmdeploy_rotated_detector_t detector, + mmdeploy_value_t input, + mmdeploy_value_t* output); + +/** + * @brief Apply rotated detector asynchronously + * @param[in] detector handle to the detector + * @param[in] input input sender + * @return output sender + */ +MMDEPLOY_API int mmdeploy_rotated_detector_apply_async(mmdeploy_rotated_detector_t detector, + mmdeploy_sender_t input, + mmdeploy_sender_t* output); + +/** + * @brief Unpack rotated detector output from a mmdeploy_value_t + * @param[in] output output obtained by applying a detector + * @param[out] results a linear buffer to save detection results of each image. It must be released + * by \ref mmdeploy_detector_release_result + * @param[out] result_count a linear buffer with length number of input images to save the number of + * detection results of each image. Must be released by \ref + * mmdeploy_detector_release_result + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_rotated_detector_get_result(mmdeploy_value_t output, + mmdeploy_rotated_detection_t** results, + int** result_count); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SRC_APIS_C_ROTATED_DETECTOR_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp b/csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp new file mode 100644 index 0000000..c982df3 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp @@ -0,0 +1,128 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/segmentor.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 "mmdeploy/handle.h" +#include "mmdeploy/pipeline.h" + +using namespace std; +using namespace mmdeploy; + +using ResultType = mmdeploy::Structure; + +int mmdeploy_segmentor_create(mmdeploy_model_t model, const char* device_name, int device_id, + mmdeploy_segmentor_t* segmentor) { + mmdeploy_context_t context{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_segmentor_create_v2(model, context, segmentor); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_segmentor_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_segmentor_t* segmentor) { + mmdeploy_model_t model{}; + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_segmentor_create(model, device_name, device_id, segmentor); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_segmentor_apply(mmdeploy_segmentor_t segmentor, const mmdeploy_mat_t* mats, + int mat_count, mmdeploy_segmentation_t** results) { + wrapped input; + if (auto ec = mmdeploy_segmentor_create_input(mats, mat_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_segmentor_apply_v2(segmentor, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_segmentor_get_result(output, results)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_segmentor_release_result(mmdeploy_segmentation_t* results, int count) { + ResultType deleter(static_cast(count), results); +} + +void mmdeploy_segmentor_destroy(mmdeploy_segmentor_t segmentor) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)segmentor); +} + +int mmdeploy_segmentor_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_segmentor_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, + mmdeploy_value_t* value) { + return mmdeploy_common_create_input(mats, mat_count, value); +} + +int mmdeploy_segmentor_apply_v2(mmdeploy_segmentor_t segmentor, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)segmentor, input, output); +} + +int mmdeploy_segmentor_apply_async(mmdeploy_segmentor_t segmentor, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)segmentor, input, output); +} + +int mmdeploy_segmentor_get_result(mmdeploy_value_t output, mmdeploy_segmentation_t** results) { + try { + const auto& value = Cast(output)->front(); + size_t image_count = value.size(); + + ResultType r(image_count); + auto [results_data, buffers] = r.pointers(); + + auto results_ptr = results_data; + + for (auto i = 0; i < image_count; ++i, ++results_ptr) { + auto& output_item = value[i]; + MMDEPLOY_DEBUG("the {}-th item in output: {}", i, output_item); + auto segmentor_output = from_value(output_item); + results_ptr->height = segmentor_output.height; + results_ptr->width = segmentor_output.width; + results_ptr->classes = segmentor_output.classes; + auto& mask = segmentor_output.mask; + auto& score = segmentor_output.score; + results_ptr->mask = nullptr; + results_ptr->score = nullptr; + if (mask.shape().size()) { + results_ptr->mask = mask.data(); + buffers[i] = mask.buffer(); + } else { + results_ptr->score = score.data(); + buffers[i] = score.buffer(); + } + } + + *results = results_data; + r.release(); + + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("exception caught: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_E_FAIL; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/segmentor.h b/csrc/mmdeploy/apis/c/mmdeploy/segmentor.h new file mode 100644 index 0000000..65bcfd0 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/segmentor.h @@ -0,0 +1,106 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file segmentor.h + * @brief Interface to MMSegmentation task + */ + +#ifndef MMDEPLOY_SEGMENTOR_H +#define MMDEPLOY_SEGMENTOR_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), 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; + +/** + * @brief Create segmentor's handle + * @param[in] model an instance of mmsegmentation sdk model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] segmentor instance of a segmentor, which must be destroyed + * by \ref mmdeploy_segmentor_destroy + * @return status of creating segmentor's handle + */ +MMDEPLOY_API int mmdeploy_segmentor_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_segmentor_t* segmentor); + +/** + * @brief Create segmentor's handle + * @param[in] model_path path of mmsegmentation sdk model exported by mmdeploy model converter + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] segmentor instance of a segmentor, which must be destroyed + * by \ref mmdeploy_segmentor_destroy + * @return status of creating segmentor's handle + */ +MMDEPLOY_API int mmdeploy_segmentor_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_segmentor_t* segmentor); + +/** + * @brief Apply segmentor to batch images and get their inference results + * @param[in] segmentor segmentor's handle created by \ref mmdeploy_segmentor_create_by_path or \ref + * mmdeploy_segmentor_create + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] results a linear buffer of length \p mat_count to save segmentation result of each + * image. It must be released by \ref mmdeploy_segmentor_release_result + * @return status of inference + */ +MMDEPLOY_API int mmdeploy_segmentor_apply(mmdeploy_segmentor_t segmentor, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_segmentation_t** results); + +/** + * @brief Release result buffer returned by \ref mmdeploy_segmentor_apply + * @param[in] results result buffer + * @param[in] count length of \p results + */ +MMDEPLOY_API void mmdeploy_segmentor_release_result(mmdeploy_segmentation_t* results, int count); + +/** + * @brief Destroy segmentor's handle + * @param[in] segmentor segmentor's handle created by \ref mmdeploy_segmentor_create_by_path + */ +MMDEPLOY_API void mmdeploy_segmentor_destroy(mmdeploy_segmentor_t segmentor); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +MMDEPLOY_API int mmdeploy_segmentor_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_segmentor_t* segmentor); + +MMDEPLOY_API int mmdeploy_segmentor_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* value); + +MMDEPLOY_API int mmdeploy_segmentor_apply_v2(mmdeploy_segmentor_t segmentor, mmdeploy_value_t input, + mmdeploy_value_t* output); + +MMDEPLOY_API int mmdeploy_segmentor_apply_async(mmdeploy_segmentor_t segmentor, + mmdeploy_sender_t input, mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_segmentor_get_result(mmdeploy_value_t output, + mmdeploy_segmentation_t** results); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SEGMENTOR_H diff --git a/csrc/mmdeploy/apis/c/mmdeploy/text_detector.cpp b/csrc/mmdeploy/apis/c/mmdeploy/text_detector.cpp new file mode 100644 index 0000000..576af07 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/text_detector.cpp @@ -0,0 +1,189 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/text_detector.h" + +#include + +#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 "mmdeploy/executor_internal.h" +#include "mmdeploy/model.h" +#include "mmdeploy/pipeline.h" + +using namespace std; +using namespace mmdeploy; + +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{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_text_detector_create_v2(model, context, detector); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_text_detector_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_text_detector_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, + int device_id, mmdeploy_text_detector_t* detector) { + mmdeploy_model_t model{}; + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_text_detector_create(model, device_name, device_id, detector); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_text_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* input) { + return mmdeploy_common_create_input(mats, mat_count, input); +} + +int mmdeploy_text_detector_apply(mmdeploy_text_detector_t detector, const mmdeploy_mat_t* mats, + int mat_count, mmdeploy_text_detection_t** results, + int** result_count) { + wrapped input; + if (auto ec = mmdeploy_text_detector_create_input(mats, mat_count, input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_text_detector_apply_v2(detector, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_text_detector_get_result(output, results, result_count)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_text_detector_apply_v2(mmdeploy_text_detector_t detector, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_text_detector_apply_async(mmdeploy_text_detector_t detector, mmdeploy_sender_t input, + mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)detector, input, output); +} + +int mmdeploy_text_detector_get_result(mmdeploy_value_t output, mmdeploy_text_detection_t** results, + int** result_count) { + if (!output || !results || !result_count) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value& value = reinterpret_cast(output)->front(); + auto detector_outputs = from_value>(value); + + vector _result_count; + _result_count.reserve(detector_outputs.size()); + for (const auto& det_output : detector_outputs) { + _result_count.push_back((int)det_output.size()); + } + + auto total = std::accumulate(_result_count.begin(), _result_count.end(), 0); + + std::unique_ptr result_count_data(new int[_result_count.size()]{}); + std::copy(_result_count.begin(), _result_count.end(), result_count_data.get()); + + std::unique_ptr result_data( + new mmdeploy_text_detection_t[total]{}); + auto result_ptr = result_data.get(); + + for (const auto& det_output : detector_outputs) { + for (auto i = 0; i < det_output.size(); ++i, ++result_ptr) { + result_ptr->score = det_output[i].score; + auto& bbox = det_output[i].bbox; + for (auto j = 0; j < bbox.size(); j += 2) { + result_ptr->bbox[j / 2].x = bbox[j]; + result_ptr->bbox[j / 2].y = bbox[j + 1]; + } + } + } + + *result_count = result_count_data.release(); + *results = result_data.release(); + + return MMDEPLOY_SUCCESS; + + } catch (const std::exception& e) { + MMDEPLOY_ERROR("unhandled exception: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return 0; +} + +void mmdeploy_text_detector_release_result(mmdeploy_text_detection_t* results, + const int* result_count, int count) { + delete[] results; + delete[] result_count; +} + +void mmdeploy_text_detector_destroy(mmdeploy_text_detector_t detector) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)detector); +} + +int mmdeploy_text_detector_apply_async_v2(mmdeploy_text_detector_t detector, + const mmdeploy_mat_t* imgs, int img_count, + mmdeploy_text_detector_continue_t cont, void* context, + mmdeploy_sender_t* output) { + mmdeploy_sender_t result_sender{}; + if (auto ec = mmdeploy_text_detector_apply_async_v3(detector, imgs, img_count, &result_sender)) { + return ec; + } + if (auto ec = mmdeploy_text_detector_continue_async(result_sender, cont, context, output)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_text_detector_apply_async_v3(mmdeploy_text_detector_t detector, + const mmdeploy_mat_t* imgs, int img_count, + mmdeploy_sender_t* output) { + wrapped input_val; + if (auto ec = mmdeploy_text_detector_create_input(imgs, img_count, input_val.ptr())) { + return ec; + } + mmdeploy_sender_t input_sndr = mmdeploy_executor_just(input_val); + if (auto ec = mmdeploy_text_detector_apply_async(detector, input_sndr, output)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_text_detector_continue_async(mmdeploy_sender_t input, + mmdeploy_text_detector_continue_t cont, void* context, + mmdeploy_sender_t* output) { + auto sender = Guard([&] { + return Take( + LetValue(Take(input), [fn = cont, context](Value& value) -> TypeErasedSender { + mmdeploy_text_detection_t* results{}; + int* result_count{}; + if (auto ec = mmdeploy_text_detector_get_result(Cast(&value), &results, &result_count)) { + return Just(Value()); + } + value = nullptr; + mmdeploy_sender_t output{}; + if (auto ec = fn(results, result_count, context, &output); ec || !output) { + return Just(Value()); + } + return Take(output); + })); + }); + if (sender) { + *output = sender; + return MMDEPLOY_SUCCESS; + } + return MMDEPLOY_E_FAIL; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/text_detector.h b/csrc/mmdeploy/apis/c/mmdeploy/text_detector.h new file mode 100644 index 0000000..a3c38dc --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/text_detector.h @@ -0,0 +1,156 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file text_detector.h + * @brief Interface to MMOCR text detection task + */ + +#ifndef MMDEPLOY_TEXT_DETECTOR_H +#define MMDEPLOY_TEXT_DETECTOR_H + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_text_detection_t { + mmdeploy_point_t bbox[4]; ///< a text bounding box of which the vertex are in clock-wise + float score; +} mmdeploy_text_detection_t; + +typedef struct mmdeploy_text_detector* mmdeploy_text_detector_t; + +/** + * @brief Create text-detector's handle + * @param[in] model an instance of mmocr text detection model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] detector instance of a text-detector, which must be destroyed + * by \ref mmdeploy_text_detector_destroy + * @return status of creating text-detector's handle + */ +MMDEPLOY_API int mmdeploy_text_detector_create(mmdeploy_model_t model, const char* device_name, + int device_id, mmdeploy_text_detector_t* detector); + +/** + * @brief Create text-detector's handle + * @param[in] model_path path to text detection model + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device + * @param[out] detector instance of a text-detector, which must be destroyed + * by \ref mmdeploy_text_detector_destroy + * @return status of creating text-detector's handle + */ +MMDEPLOY_API int mmdeploy_text_detector_create_by_path(const char* model_path, + const char* device_name, int device_id, + mmdeploy_text_detector_t* detector); + +/** + * @brief Apply text-detector to batch images and get their inference results + * @param[in] detector text-detector's handle created by \ref mmdeploy_text_detector_create_by_path + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @param[out] results a linear buffer to save text detection results of each + * image. It must be released by calling \ref mmdeploy_text_detector_release_result + * @param[out] result_count a linear buffer of length \p mat_count to save the number of detection + * results of each image. It must be released by \ref mmdeploy_detector_release_result + * @return status of inference + */ +MMDEPLOY_API int mmdeploy_text_detector_apply(mmdeploy_text_detector_t detector, + const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_text_detection_t** results, + int** result_count); + +/** @brief Release the inference result buffer returned by \ref mmdeploy_text_detector_apply + * @param[in] results text detection result buffer + * @param[in] result_count \p results size buffer + * @param[in] count the length of buffer \p result_count + */ +MMDEPLOY_API void mmdeploy_text_detector_release_result(mmdeploy_text_detection_t* results, + const int* result_count, int count); + +/** + * @brief Destroy text-detector's handle + * @param[in] detector text-detector's handle created by \ref mmdeploy_text_detector_create_by_path + * or \ref mmdeploy_text_detector_create + */ +MMDEPLOY_API void mmdeploy_text_detector_destroy(mmdeploy_text_detector_t detector); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +/** + * @brief Same as \ref mmdeploy_text_detector_create, but allows to control execution context of + * tasks via context + */ +MMDEPLOY_API int mmdeploy_text_detector_create_v2(mmdeploy_model_t model, + mmdeploy_context_t context, + mmdeploy_text_detector_t* detector); + +/** + * @brief Pack text-detector inputs into mmdeploy_value_t + * @param[in] mats a batch of images + * @param[in] mat_count number of images in the batch + * @return the created value + */ +MMDEPLOY_API int mmdeploy_text_detector_create_input(const mmdeploy_mat_t* mats, int mat_count, + mmdeploy_value_t* input); + +/** + * @brief Same as \ref mmdeploy_text_detector_apply, but input and output are packed in \ref + * mmdeploy_value_t. + */ +MMDEPLOY_API int mmdeploy_text_detector_apply_v2(mmdeploy_text_detector_t detector, + mmdeploy_value_t input, mmdeploy_value_t* output); + +/** + * @brief Apply text-detector asynchronously + * @param[in] detector handle to the detector + * @param[in] input input sender that will be consumed by the operation + * @return output sender + */ +MMDEPLOY_API int mmdeploy_text_detector_apply_async(mmdeploy_text_detector_t detector, + mmdeploy_sender_t input, + mmdeploy_sender_t* output); + +/** + * @brief Unpack detector output from a mmdeploy_value_t + * @param[in] output output sender returned by applying a detector + * @param[out] results a linear buffer to save detection results of each image. It must be + * released by \ref mmdeploy_text_detector_release_result + * @param[out] result_count a linear buffer with length number of input images to save the + * number of detection results of each image. Must be released by \ref + * mmdeploy_text_detector_release_result + * @return status of the operation + */ +MMDEPLOY_API +int mmdeploy_text_detector_get_result(mmdeploy_value_t output, mmdeploy_text_detection_t** results, + int** result_count); + +typedef int (*mmdeploy_text_detector_continue_t)(mmdeploy_text_detection_t* results, + int* result_count, void* context, + mmdeploy_sender_t* output); + +// MMDEPLOY_API int mmdeploy_text_detector_apply_async_v2(mm_handle_t handle, const mm_mat_t* imgs, +// int img_count, +// mmdeploy_text_detector_continuation_t +// cont, void* context, mmdeploy_sender_t* +// output); + +MMDEPLOY_API int mmdeploy_text_detector_apply_async_v3(mmdeploy_text_detector_t detector, + const mmdeploy_mat_t* imgs, int img_count, + mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_text_detector_continue_async(mmdeploy_sender_t input, + mmdeploy_text_detector_continue_t cont, + void* context, mmdeploy_sender_t* output); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_TEXT_DETECTOR_H diff --git a/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.cpp b/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.cpp new file mode 100644 index 0000000..3c8cfbb --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.cpp @@ -0,0 +1,252 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/text_recognizer.h" + +#include + +#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 "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", {"imgs", "bboxes"}}, + { + "tasks", { + { + {"type", "Task"}, + {"module", "WarpBbox"}, + {"input", {"imgs", "bboxes"}}, + {"output", "patches"}, + }, + { + {"type", "Inference"}, + {"input", "patches"}, + {"output", "texts"}, + {"params", {{"model", model}}}, + } + } + }, + {"output", "texts"}, + }; + // clang-format on +} + +} // namespace + +int mmdeploy_text_recognizer_create(mmdeploy_model_t model, const char* device_name, int device_id, + mmdeploy_text_recognizer_t* recognizer) { + mmdeploy_context_t context{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_text_recognizer_create_v2(model, context, recognizer); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_text_recognizer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_text_recognizer_t* recognizer) { + auto config = config_template(*Cast(model)); + return mmdeploy_pipeline_create_v3(Cast(&config), context, (mmdeploy_pipeline_t*)recognizer); +} + +int mmdeploy_text_recognizer_create_by_path(const char* model_path, const char* device_name, + int device_id, mmdeploy_text_recognizer_t* recognizer) { + mmdeploy_model_t model{}; + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_text_recognizer_create(model, device_name, device_id, recognizer); + mmdeploy_model_destroy(model); + return ec; +} + +int mmdeploy_text_recognizer_apply(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* images, int count, + mmdeploy_text_recognition_t** results) { + return mmdeploy_text_recognizer_apply_bbox(recognizer, images, count, nullptr, nullptr, results); +} + +int mmdeploy_text_recognizer_create_input(const mmdeploy_mat_t* images, int image_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, mmdeploy_value_t* output) { + if (image_count && images == nullptr) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value::Array input_images; + Value::Array input_bboxes; + + auto add_bbox = [&](Mat img, const mmdeploy_text_detection_t* det) { + if (det) { + const auto& b = det->bbox; + Value::Array bbox{b[0].x, b[0].y, b[1].x, b[1].y, b[2].x, b[2].y, b[3].x, b[3].y}; + input_bboxes.push_back({{"bbox", std::move(bbox)}}); + } else { + input_bboxes.push_back(nullptr); + } + input_images.push_back({{"ori_img", img}}); + }; + + for (int i = 0; i < image_count; ++i) { + auto _mat = Cast(images[i]); + if (bboxes && bbox_count) { + for (int j = 0; j < bbox_count[i]; ++j) { + add_bbox(_mat, bboxes++); + } + } else { // inference with whole image + add_bbox(_mat, nullptr); + } + } + + *output = Take(Value{std::move(input_images), std::move(input_bboxes)}); + return MMDEPLOY_SUCCESS; + } catch (const std::exception& e) { + MMDEPLOY_ERROR("exception caught: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_E_FAIL; +} + +int mmdeploy_text_recognizer_apply_bbox(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* images, int image_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, + mmdeploy_text_recognition_t** results) { + wrapped input; + if (auto ec = mmdeploy_text_recognizer_create_input(images, image_count, bboxes, bbox_count, + input.ptr())) { + return ec; + } + wrapped output; + if (auto ec = mmdeploy_text_recognizer_apply_v2(recognizer, input, output.ptr())) { + return ec; + } + if (auto ec = mmdeploy_text_recognizer_get_result(output, results)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_text_recognizer_apply_v2(mmdeploy_text_recognizer_t recognizer, mmdeploy_value_t input, + mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)recognizer, input, output); +} + +int mmdeploy_text_recognizer_apply_async(mmdeploy_text_recognizer_t recognizer, + mmdeploy_sender_t input, mmdeploy_sender_t* output) { + return mmdeploy_pipeline_apply_async((mmdeploy_pipeline_t)recognizer, input, output); +} + +MMDEPLOY_API int mmdeploy_text_recognizer_get_result(mmdeploy_value_t output, + mmdeploy_text_recognition_t** results) { + if (!output || !results) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + std::vector recognitions; + from_value(Cast(output)->front(), recognitions); + + size_t count = recognitions.size(); + + auto deleter = [&](mmdeploy_text_recognition_t* p) { + mmdeploy_text_recognizer_release_result(p, static_cast(count)); + }; + + std::unique_ptr _results( + new mmdeploy_text_recognition_t[count]{}, deleter); + + size_t result_idx = 0; + for (const auto& bbox_result : recognitions) { + auto& res = _results[result_idx++]; + + auto& score = bbox_result.score; + res.length = static_cast(score.size()); + + res.score = new float[score.size()]; + std::copy_n(score.data(), score.size(), res.score); + + auto text = bbox_result.text; + res.text = new char[text.length() + 1]; + std::copy_n(text.data(), text.length() + 1, res.text); + } + + *results = _results.release(); + } catch (const std::exception& e) { + MMDEPLOY_ERROR("exception caught: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_text_recognizer_release_result(mmdeploy_text_recognition_t* results, int count) { + for (int i = 0; i < count; ++i) { + delete[] results[i].score; + delete[] results[i].text; + } + delete[] results; +} + +void mmdeploy_text_recognizer_destroy(mmdeploy_text_recognizer_t recognizer) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)recognizer); +} + +int mmdeploy_text_recognizer_apply_async_v3(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* imgs, int img_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, mmdeploy_sender_t* output) { + wrapped input_val; + if (auto ec = mmdeploy_text_recognizer_create_input(imgs, img_count, bboxes, bbox_count, + input_val.ptr())) { + return ec; + } + mmdeploy_sender_t input_sndr = mmdeploy_executor_just(input_val); + if (auto ec = mmdeploy_text_recognizer_apply_async(recognizer, input_sndr, output)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_text_recognizer_continue_async(mmdeploy_sender_t input, + mmdeploy_text_recognizer_continue_t cont, void* context, + mmdeploy_sender_t* output) { + auto sender = Guard([&] { + return Take( + LetValue(Take(input), [fn = cont, context](Value& value) -> TypeErasedSender { + mmdeploy_text_recognition_t* results{}; + if (auto ec = mmdeploy_text_recognizer_get_result(Cast(&value), &results)) { + return Just(Value()); + } + value = nullptr; + mmdeploy_sender_t output{}; + if (auto ec = fn(results, context, &output); ec || !output) { + return Just(Value()); + } + return Take(output); + })); + }); + if (sender) { + *output = sender; + return MMDEPLOY_SUCCESS; + } + return MMDEPLOY_E_FAIL; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.h b/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.h new file mode 100644 index 0000000..6c18928 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/text_recognizer.h @@ -0,0 +1,164 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file text_recognizer.h + * @brief Interface to MMOCR text recognition task + */ + +#ifndef MMDEPLOY_SRC_APIS_C_TEXT_RECOGNIZER_H_ +#define MMDEPLOY_SRC_APIS_C_TEXT_RECOGNIZER_H_ + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/text_detector.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_text_recognition_t { + char* text; + float* score; + int length; +} mmdeploy_text_recognition_t; + +typedef struct mmdeploy_text_recognizer* mmdeploy_text_recognizer_t; + +/** + * @brief Create a text recognizer instance + * @param[in] model an instance of mmocr text recognition model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] recognizer handle of the created text recognizer, which must be destroyed + * by \ref mmdeploy_text_recognizer_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_text_recognizer_create(mmdeploy_model_t model, const char* device_name, + int device_id, + mmdeploy_text_recognizer_t* recognizer); + +/** + * @brief Create a text recognizer instance + * @param[in] model_path path to text recognition model + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] recognizer handle of the created text recognizer, which must be destroyed + * by \ref mmdeploy_text_recognizer_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_text_recognizer_create_by_path(const char* model_path, + const char* device_name, int device_id, + mmdeploy_text_recognizer_t* recognizer); + +/** + * @brief Apply text recognizer to a batch of text images + * @param[in] recognizer text recognizer's handle created by \ref + * mmdeploy_text_recognizer_create_by_path + * @param[in] images a batch of text images + * @param[in] count number of images in the batch + * @param[out] results a linear buffer contains the recognized text, must be release + * by \ref mmdeploy_text_recognizer_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_text_recognizer_apply(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* images, int count, + mmdeploy_text_recognition_t** results); + +/** + * @brief Apply text recognizer to a batch of images supplied with text bboxes + * @param[in] recognizer text recognizer's handle created by \ref + * mmdeploy_text_recognizer_create_by_path + * @param[in] images a batch of text images + * @param[in] image_count number of images in the batch + * @param[in] bboxes bounding boxes detected by text detector + * @param[in] bbox_count number of bboxes of each \p images, must be same length as \p images + * @param[out] results a linear buffer contains the recognized text, which has the same length as \p + * bboxes, must be release by \ref mmdeploy_text_recognizer_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_text_recognizer_apply_bbox(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* images, int image_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, + mmdeploy_text_recognition_t** results); + +/** @brief Release result buffer returned by \ref mmdeploy_text_recognizer_apply or \ref + * mmdeploy_text_recognizer_apply_bbox + * @param[in] results result buffer by text recognizer + * @param[in] count length of \p result + */ +MMDEPLOY_API void mmdeploy_text_recognizer_release_result(mmdeploy_text_recognition_t* results, + int count); + +/** + * @brief destroy text recognizer + * @param[in] recognizer handle of text recognizer created by \ref + * mmdeploy_text_recognizer_create_by_path or \ref mmdeploy_text_recognizer_create + */ +MMDEPLOY_API void mmdeploy_text_recognizer_destroy(mmdeploy_text_recognizer_t recognizer); + +/****************************************************************************** + * Experimental asynchronous APIs */ + +/** + * @brief Same as \ref mmdeploy_text_recognizer_create, but allows to control execution context of + * tasks via context + */ +MMDEPLOY_API int mmdeploy_text_recognizer_create_v2(mmdeploy_model_t model, + mmdeploy_context_t context, + mmdeploy_text_recognizer_t* recognizer); + +/** + * @brief Pack text-recognizer inputs into mmdeploy_value_t + * @param[in] images a batch of images + * @param[in] image_count number of images in the batch + * @param[in] bboxes bounding boxes detected by text detector + * @param[in] bbox_count number of bboxes of each \p images, must be same length as \p images + * @return value created + */ +MMDEPLOY_API int mmdeploy_text_recognizer_create_input(const mmdeploy_mat_t* images, + int image_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, + mmdeploy_value_t* output); + +MMDEPLOY_API int mmdeploy_text_recognizer_apply_v2(mmdeploy_text_recognizer_t recognizer, + mmdeploy_value_t input, + mmdeploy_value_t* output); + +/** + * @brief Same as \ref mmdeploy_text_recognizer_apply_bbox, but input and output are packed in \ref + * mmdeploy_value_t. + */ +MMDEPLOY_API int mmdeploy_text_recognizer_apply_async(mmdeploy_text_recognizer_t recognizer, + mmdeploy_sender_t input, + mmdeploy_sender_t* output); + +typedef int (*mmdeploy_text_recognizer_continue_t)(mmdeploy_text_recognition_t* results, + void* context, mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_text_recognizer_apply_async_v3(mmdeploy_text_recognizer_t recognizer, + const mmdeploy_mat_t* imgs, int img_count, + const mmdeploy_text_detection_t* bboxes, + const int* bbox_count, + mmdeploy_sender_t* output); + +MMDEPLOY_API int mmdeploy_text_recognizer_continue_async(mmdeploy_sender_t input, + mmdeploy_text_recognizer_continue_t cont, + void* context, mmdeploy_sender_t* output); + +/** + * @brief Unpack text-recognizer output from a mmdeploy_value_t + * @param[in] output + * @param[out] results + * @return status of the operation + */ +MMDEPLOY_API int mmdeploy_text_recognizer_get_result(mmdeploy_value_t output, + mmdeploy_text_recognition_t** results); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_SRC_APIS_C_TEXT_RECOGNIZER_H_ diff --git a/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.cpp b/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.cpp new file mode 100644 index 0000000..de71e57 --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.cpp @@ -0,0 +1,165 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +#include "mmdeploy/video_recognizer.h" + +#include +#include + +#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 "mmdeploy/executor_internal.h" +#include "mmdeploy/model.h" +#include "mmdeploy/pipeline.h" + +using namespace mmdeploy; + +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{}; + auto ec = mmdeploy_context_create_by_device(device_name, device_id, &context); + if (ec != MMDEPLOY_SUCCESS) { + return ec; + } + ec = mmdeploy_video_recognizer_create_v2(model, context, recognizer); + mmdeploy_context_destroy(context); + return ec; +} + +int mmdeploy_video_recognizer_create_by_path(const char* model_path, const char* device_name, + int device_id, + mmdeploy_video_recognizer_t* recognizer) { + mmdeploy_model_t model{}; + + if (auto ec = mmdeploy_model_create_by_path(model_path, &model)) { + return ec; + } + auto ec = mmdeploy_video_recognizer_create(model, device_name, device_id, recognizer); + mmdeploy_model_destroy(model); + return ec; +} +int mmdeploy_video_recognizer_apply(mmdeploy_video_recognizer_t recognizer, + const mmdeploy_mat_t* images, + const mmdeploy_video_sample_info_t* video_info, int video_count, + mmdeploy_video_recognition_t** results, int** result_count) { + wrapped input; + if (auto ec = + mmdeploy_video_recognizer_create_input(images, video_info, video_count, input.ptr())) { + return ec; + } + + wrapped output; + if (auto ec = mmdeploy_video_recognizer_apply_v2(recognizer, input, output.ptr())) { + return ec; + } + + if (auto ec = mmdeploy_video_recognizer_get_result(output, results, result_count)) { + return ec; + } + return MMDEPLOY_SUCCESS; +} + +void mmdeploy_video_recognizer_release_result(mmdeploy_video_recognition_t* results, + int* result_count, int video_count) { + delete[] results; + delete[] result_count; +} + +void mmdeploy_video_recognizer_destroy(mmdeploy_video_recognizer_t recognizer) { + mmdeploy_pipeline_destroy((mmdeploy_pipeline_t)recognizer); +} + +int mmdeploy_video_recognizer_create_v2(mmdeploy_model_t model, mmdeploy_context_t context, + mmdeploy_video_recognizer_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, + const mmdeploy_video_sample_info_t* video_info, + int video_count, mmdeploy_value_t* value) { + if (video_count && (images == nullptr || video_info == nullptr)) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + auto input = std::make_unique(Value{Value::kArray}); + auto sample = std::make_unique(Value::kArray); + for (int i = 0; i < video_count; ++i) { + int clip_len = video_info[i].clip_len; + int num_clips = video_info[i].num_clips; + int n_mat = clip_len * num_clips; + for (int j = 0; j < n_mat; j++) { + mmdeploy::Mat _mat{images[j].height, + images[j].width, + PixelFormat(images[j].format), + DataType(images[j].type), + images[j].data, + images[j].device ? *(const Device*)(images[j].device) : Device{0}}; + sample->push_back({{"ori_img", _mat}, {"clip_len", clip_len}, {"num_clips", num_clips}}); + } + input->front().push_back(std::move(*sample.release())); + } + *value = Cast(input.release()); + } catch (const std::exception& e) { + MMDEPLOY_ERROR("unhandled exception: {}", e.what()); + } catch (...) { + MMDEPLOY_ERROR("unknown exception caught"); + } + return MMDEPLOY_SUCCESS; +} + +int mmdeploy_video_recognizer_apply_v2(mmdeploy_video_recognizer_t recognizer, + mmdeploy_value_t input, mmdeploy_value_t* output) { + return mmdeploy_pipeline_apply((mmdeploy_pipeline_t)recognizer, input, output); +} + +int mmdeploy_video_recognizer_get_result(mmdeploy_value_t output, + mmdeploy_video_recognition_t** results, + int** result_count) { + if (!output || !results || !result_count) { + return MMDEPLOY_E_INVALID_ARG; + } + try { + Value& value = Cast(output)->front(); + + auto classify_outputs = from_value>(value); + + std::vector _result_count; + _result_count.reserve(classify_outputs.size()); + + for (const auto& cls_output : classify_outputs) { + _result_count.push_back((int)cls_output.size()); + } + + auto total = std::accumulate(begin(_result_count), end(_result_count), 0); + + std::unique_ptr result_count_data(new int[_result_count.size()]{}); + std::copy(_result_count.begin(), _result_count.end(), result_count_data.get()); + + std::unique_ptr result_data( + new mmdeploy_video_recognition_t[total]{}); + auto result_ptr = result_data.get(); + for (const auto& cls_output : classify_outputs) { + for (const auto& label : cls_output) { + result_ptr->label_id = label.label_id; + result_ptr->score = label.score; + ++result_ptr; + } + } + + *result_count = result_count_data.release(); + *results = result_data.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; +} diff --git a/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.h b/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.h new file mode 100644 index 0000000..e98b2bd --- /dev/null +++ b/csrc/mmdeploy/apis/c/mmdeploy/video_recognizer.h @@ -0,0 +1,139 @@ +// Copyright (c) OpenMMLab. All rights reserved. + +/** + * @file video_recognizer.h + * @brief Interface to MMACTION video recognition task + */ + +#ifndef MMDEPLOY_VIDEO_RECOGNIZER_H +#define MMDEPLOY_VIDEO_RECOGNIZER_H + +#include "mmdeploy/common.h" +#include "mmdeploy/executor.h" +#include "mmdeploy/model.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct mmdeploy_video_recognition_t { + int label_id; + float score; +} mmdeploy_video_recognition_t; + +typedef struct mmdeploy_video_sample_info_t { + int clip_len; + int num_clips; +} mmdeploy_video_sample_info_t; + +typedef struct mmdeploy_video_recognizer* mmdeploy_video_recognizer_t; + +/** + * @brief Create video recognizer's handle + * @param[in] model an instance of mmaction sdk model created by + * \ref mmdeploy_model_create_by_path or \ref mmdeploy_model_create in \ref model.h + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] recognizer handle of the created video recognizer, which must be destroyed + * by \ref mmdeploy_video_recognizer_destroy + * @return status of creating video recognizer's handle + */ +MMDEPLOY_API int mmdeploy_video_recognizer_create(mmdeploy_model_t model, const char* device_name, + int device_id, + mmdeploy_video_recognizer_t* recognizer); + +/** + * @brief Create a video recognizer instance + * @param[in] model_path path to video recognition model + * @param[in] device_name name of device, such as "cpu", "cuda", etc. + * @param[in] device_id id of device. + * @param[out] recognizer handle of the created video recognizer, which must be destroyed + * by \ref mmdeploy_video_recognizer_destroy + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_video_recognizer_create_by_path(const char* model_path, + const char* device_name, int device_id, + mmdeploy_video_recognizer_t* recognizer); + +/** + * @brief Apply video recognizer to a batch of videos + * @param[in] recognizer video recognizer's handle created by \ref + * mmdeploy_video_recognizer_create_by_path + * @param[in] images a batch of videos + * @param[in] video_info video information of each video + * @param[in] video_count number of videos + * @param[out] results a linear buffer contains the recognized video, must be release + * by \ref mmdeploy_video_recognizer_release_result + * @param[out] result_count a linear buffer with length being \p video_count to save the number of + * recognition results of each video. It must be released by \ref + * mmdeploy_video_recognizer_release_result + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_video_recognizer_apply(mmdeploy_video_recognizer_t recognizer, + const mmdeploy_mat_t* images, + const mmdeploy_video_sample_info_t* video_info, + int video_count, + mmdeploy_video_recognition_t** results, + int** result_count); + +/** @brief Release result buffer returned by \ref mmdeploy_video_recognizer_apply + * @param[in] results result buffer by video recognizer + * @param[in] result_count \p results size buffer + * @param[in] video_count length of \p result_count + */ +MMDEPLOY_API void mmdeploy_video_recognizer_release_result(mmdeploy_video_recognition_t* results, + int* result_count, int video_count); + +/** + * @brief destroy video recognizer + * @param[in] recognizer handle of video recognizer created by \ref + * mmdeploy_video_recognizer_create_by_path or \ref mmdeploy_video_recognizer_create + */ +MMDEPLOY_API void mmdeploy_video_recognizer_destroy(mmdeploy_video_recognizer_t recognizer); + +/** + * @brief Same as \ref mmdeploy_video_recognizer_create, but allows to control execution context of + * tasks via context + */ +MMDEPLOY_API int mmdeploy_video_recognizer_create_v2(mmdeploy_model_t model, + mmdeploy_context_t context, + mmdeploy_video_recognizer_t* recognizer); + +/** + * @brief Pack video recognizer inputs into mmdeploy_value_t + * @param[in] images a batch of videos + * @param[in] video_info video information of each video + * @param[in] video_count number of videos in the batch + * @param[out] value created value + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_video_recognizer_create_input( + const mmdeploy_mat_t* images, const mmdeploy_video_sample_info_t* video_info, int video_count, + mmdeploy_value_t* value); + +/** + * @brief Apply video recognizer to a batch of videos + * @param[in] input packed input + * @param[out] output inference output + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_video_recognizer_apply_v2(mmdeploy_video_recognizer_t recognizer, + mmdeploy_value_t input, + mmdeploy_value_t* output); + +/** + * @brief Apply video recognizer to a batch of videos + * @param[in] output inference output + * @param[out] results structured output + * @param[out] result_count number of each videos + * @return status code of the operation + */ +MMDEPLOY_API int mmdeploy_video_recognizer_get_result(mmdeploy_value_t output, + mmdeploy_video_recognition_t** results, + int** result_count); + +#ifdef __cplusplus +} +#endif + +#endif // MMDEPLOY_VIDEO_RECOGNIZER_H diff --git a/csrc/mmdeploy/apis/csharp/MMDeploy.sln b/csrc/mmdeploy/apis/csharp/MMDeploy.sln new file mode 100644 index 0000000..72cbead --- /dev/null +++ b/csrc/mmdeploy/apis/csharp/MMDeploy.sln @@ -0,0 +1,50 @@ + +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\MMDeployCSharp.csproj", "{3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}" +EndProject + +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|x64.ActiveCfg = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|x64.Build.0 = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|x86.ActiveCfg = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Debug|x86.Build.0 = Debug|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|Any CPU.Build.0 = Release|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|x64.ActiveCfg = Release|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|x64.Build.0 = Release|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|x86.ActiveCfg = Release|Any CPU + {3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}.Release|x86.Build.0 = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|x64.ActiveCfg = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|x64.Build.0 = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|x86.ActiveCfg = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Debug|x86.Build.0 = Debug|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|Any CPU.Build.0 = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|x64.ActiveCfg = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|x64.Build.0 = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|x86.ActiveCfg = Release|Any CPU + {661A4295-68CF-41C6-85B8-B11748113A6F}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5E63FEFB-A55D-4BEB-83B8-7D0E5A59EBF7} + EndGlobalSection +EndGlobal diff --git a/csrc/mmdeploy/apis/csharp/MMDeploy/.editorconfig b/csrc/mmdeploy/apis/csharp/MMDeploy/.editorconfig new file mode 100644 index 0000000..2a76901 --- /dev/null +++ b/csrc/mmdeploy/apis/csharp/MMDeploy/.editorconfig @@ -0,0 +1,110 @@ +[*.cs] +csharp_style_var_for_built_in_types=true:silent +csharp_style_var_when_type_is_apparent=true:silent +csharp_style_var_elsewhere=true:silent + +## +## StyleCop.Analyzers +## + +# Using directive should appear within a namespace declaration +dotnet_diagnostic.SA1200.severity = None + +# XML comment analysis is disabled due to project configuration +dotnet_diagnostic.SA0001.severity = None + +# The file header is missing or not located at the Top of the file +dotnet_diagnostic.SA1633.severity = None + +# Use string.Empty for empty strings +dotnet_diagnostic.SA1122.severity = None + +# Variable '_' should begin with lower-case letter +dotnet_diagnostic.SA1312.severity = None + +# Parameter '_' should begin with lower-case letter +dotnet_diagnostic.SA1313.severity = None + +# Elements should be documented +dotnet_diagnostic.SA1600.severity = None + +# Prefix local calls with this +dotnet_diagnostic.SA1101.severity = None + +# 'public' members should come before 'private' members +dotnet_diagnostic.SA1202.severity = None + +# Comments should contain text +dotnet_diagnostic.SA1120.severity = None + +# Constant fields should appear before non-constant fields +dotnet_diagnostic.SA1203.severity = None + +# Field '_blah' should not begin with an underscore +dotnet_diagnostic.SA1309.severity = None + +# Use trailing comma in multi-line initializers +dotnet_diagnostic.SA1413.severity = None + +# A method should not follow a class +dotnet_diagnostic.SA1201.severity = None + +# Elements should be separated by blank line +dotnet_diagnostic.SA1516.severity = None + +# The parameter spans multiple lines +dotnet_diagnostic.SA1118.severity = None + +# Static members should appear before non-static members +dotnet_diagnostic.SA1204.severity = None + +# Put constructor initializers on their own line +dotnet_diagnostic.SA1128.severity = None + +# Opening braces should not be preceded by blank line +dotnet_diagnostic.SA1509.severity = None + +# The parameter should begin on the line after the previous parameter +dotnet_diagnostic.SA1115.severity = None + +# File name should match first type name +dotnet_diagnostic.SA1649.severity = None + +# File may only contain a single type +dotnet_diagnostic.SA1402.severity = None + +# Enumeration items should be documented +dotnet_diagnostic.SA1602.severity = None + +# Element should not be on a single line +dotnet_diagnostic.SA1502.severity = None + +# Closing parenthesis should not be preceded by a space +dotnet_diagnostic.SA1009.severity = None + +# Closing parenthesis should be on line of last parameter +dotnet_diagnostic.SA1111.severity = None + +# Braces should not be ommitted +dotnet_diagnostic.SA1503.severity = None + +# The name of a C# element does not begin with an upper-case letter +# dotnet_diagnostic.SA1300.severity = None + +# The name of a public or internal field in C# does not begin with an upper-case letter +# dotnet_diagnostic.SA1307.severity = None + +# The code uses one of the basic C# types, but does not use the built-in alias for the type +# dotnet_diagnostic.SA1121.severity = None + +# Two or more attributes appeared within the same set of square brackets. +dotnet_diagnostic.SA1133.severity = None + +# The C# code contains a region. +dotnet_diagnostic.SA1124.severity = None + +# The parameters to a C# method or indexer call or declaration span across multiple lines, but the first parameter does not start on the line after the opening bracket. +dotnet_diagnostic.SA1116.severity = None + +# The parameters to a C# method or indexer call or declaration are not all on the same line or each on a separate line. +dotnet_diagnostic.SA1117.severity = None diff --git a/csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Classifier.cs b/csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Classifier.cs new file mode 100644 index 0000000..9a2e4d1 --- /dev/null +++ b/csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Classifier.cs @@ -0,0 +1,134 @@ +using System.Collections.Generic; + +namespace MMDeploy +{ + /// + /// Single classification result of a picture. + /// A picture may contains multiple reuslts. + /// + public struct Label + { + /// + /// Id. + /// + public int Id; + + /// + /// Score. + /// + public float Score; + + /// + /// Initializes a new instance of the struct. + /// + /// id. + /// score. + public Label(int id, float score) + { + Id = id; + Score = score; + } + } + + /// + /// Output of Classifier. + /// + public struct ClassifierOutput + { + /// + /// Classification results for single image. + /// + public List