[C# api] add c sharp api for fastdeploy (#1246)

* add c sharp api for fastdeploy

* update accroding to c apis

* add cmakelist for c sharp api

* add cmakelists for c sharp

* fix cmakelists

* fix cmakelists

* add c sharp api for fastdeploy

* add ppyoloe demo

* add ppyoloe demo

* modify demo namespace code

* add readme

* fix format

* format code

* fix doc

---------

Co-authored-by: heliqi <1101791222@qq.com>
This commit is contained in:
chenjian
2023-02-15 14:27:31 +08:00
committed by GitHub
parent e12091f343
commit f43ff32752
15 changed files with 1600 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace fastdeploy {
public enum ModelFormat {
AUTOREC, ///< Auto recognize the model format by model file name
PADDLE, ///< Model with paddlepaddle format
ONNX, ///< Model with ONNX format
RKNN, ///< Model with RKNN format
TORCHSCRIPT, ///< Model with TorchScript format
SOPHGO, ///< Model with SOPHGO format
}
public enum rknpu2_CpuName {
RK356X = 0, /* run on RK356X. */
RK3588 = 1, /* default,run on RK3588. */
UNDEFINED,
}
public enum rknpu2_CoreMask {
RKNN_NPU_CORE_AUTO = 0, //< default, run on NPU core randomly.
RKNN_NPU_CORE_0 = 1, //< run on NPU core 0.
RKNN_NPU_CORE_1 = 2, //< run on NPU core 1.
RKNN_NPU_CORE_2 = 4, //< run on NPU core 2.
RKNN_NPU_CORE_0_1 =
RKNN_NPU_CORE_0 | RKNN_NPU_CORE_1, //< run on NPU core 1 and core 2.
RKNN_NPU_CORE_0_1_2 =
RKNN_NPU_CORE_0_1 | RKNN_NPU_CORE_2, //< run on NPU core 1 and core 2.
RKNN_NPU_CORE_UNDEFINED,
}
public enum LitePowerMode {
LITE_POWER_HIGH = 0, ///< Use Lite Backend with high power mode
LITE_POWER_LOW = 1, ///< Use Lite Backend with low power mode
LITE_POWER_FULL = 2, ///< Use Lite Backend with full power mode
LITE_POWER_NO_BIND = 3, ///< Use Lite Backend with no bind power mode
LITE_POWER_RAND_HIGH = 4, ///< Use Lite Backend with rand high mode
LITE_POWER_RAND_LOW = 5 ///< Use Lite Backend with rand low power mode
}
}

View File

@@ -0,0 +1,541 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace fastdeploy {
public class RuntimeOption {
public RuntimeOption() {
fd_runtime_option_wrapper = FD_C_CreateRuntimeOptionWrapper();
}
~RuntimeOption() {
FD_C_DestroyRuntimeOptionWrapper(fd_runtime_option_wrapper);
}
public void SetModelPath(string model_path, string params_path = "",
ModelFormat format = ModelFormat.PADDLE) {
FD_C_RuntimeOptionWrapperSetModelPath(fd_runtime_option_wrapper, model_path,
params_path, format);
}
public void SetModelBuffer(string model_buffer, string params_buffer = "",
ModelFormat format = ModelFormat.PADDLE) {
FD_C_RuntimeOptionWrapperSetModelBuffer(
fd_runtime_option_wrapper, model_buffer, params_buffer, format);
}
public void UseCpu() {
FD_C_RuntimeOptionWrapperUseCpu(fd_runtime_option_wrapper);
}
public void UseGpu(int gpu_id = 0) {
FD_C_RuntimeOptionWrapperUseGpu(fd_runtime_option_wrapper, gpu_id);
}
public void
UseRKNPU2(rknpu2_CpuName rknpu2_name = rknpu2_CpuName.RK3588,
rknpu2_CoreMask rknpu2_core = rknpu2_CoreMask.RKNN_NPU_CORE_0) {
FD_C_RuntimeOptionWrapperUseRKNPU2(fd_runtime_option_wrapper, rknpu2_name,
rknpu2_core);
}
public void UseTimVX() {
FD_C_RuntimeOptionWrapperUseTimVX(fd_runtime_option_wrapper);
}
public void UseAscend() {
FD_C_RuntimeOptionWrapperUseAscend(fd_runtime_option_wrapper);
}
public void
UseKunlunXin(int kunlunxin_id = 0, int l3_workspace_size = 0xfffc00,
bool locked = false, bool autotune = true,
string autotune_file = "", string precision = "int16",
bool adaptive_seqlen = false, bool enable_multi_stream = false) {
FD_C_RuntimeOptionWrapperUseKunlunXin(
fd_runtime_option_wrapper, kunlunxin_id, l3_workspace_size, locked,
autotune, autotune_file, precision, adaptive_seqlen,
enable_multi_stream);
}
public void UseSophgo() {
FD_C_RuntimeOptionWrapperUseSophgo(fd_runtime_option_wrapper);
}
public void SetExternalStream(IntPtr external_stream) {
FD_C_RuntimeOptionWrapperSetExternalStream(fd_runtime_option_wrapper,
external_stream);
}
public void SetCpuThreadNum(int thread_num) {
FD_C_RuntimeOptionWrapperSetCpuThreadNum(fd_runtime_option_wrapper,
thread_num);
}
public void SetOrtGraphOptLevel(int level = -1) {
FD_C_RuntimeOptionWrapperSetOrtGraphOptLevel(fd_runtime_option_wrapper,
level);
}
public void UsePaddleBackend() {
FD_C_RuntimeOptionWrapperUsePaddleBackend(fd_runtime_option_wrapper);
}
public void UsePaddleInferBackend() {
FD_C_RuntimeOptionWrapperUsePaddleInferBackend(fd_runtime_option_wrapper);
}
public void UseOrtBackend() {
FD_C_RuntimeOptionWrapperUseOrtBackend(fd_runtime_option_wrapper);
}
public void UseSophgoBackend() {
FD_C_RuntimeOptionWrapperUseSophgoBackend(fd_runtime_option_wrapper);
}
public void UseTrtBackend() {
FD_C_RuntimeOptionWrapperUseTrtBackend(fd_runtime_option_wrapper);
}
public void UsePorosBackend() {
FD_C_RuntimeOptionWrapperUsePorosBackend(fd_runtime_option_wrapper);
}
public void UseOpenVINOBackend() {
FD_C_RuntimeOptionWrapperUseOpenVINOBackend(fd_runtime_option_wrapper);
}
public void UseLiteBackend() {
FD_C_RuntimeOptionWrapperUseLiteBackend(fd_runtime_option_wrapper);
}
public void UsePaddleLiteBackend() {
FD_C_RuntimeOptionWrapperUsePaddleLiteBackend(fd_runtime_option_wrapper);
}
public void SetPaddleMKLDNN(bool pd_mkldnn = true) {
FD_C_RuntimeOptionWrapperSetPaddleMKLDNN(fd_runtime_option_wrapper,
pd_mkldnn);
}
public void EnablePaddleToTrt() {
FD_C_RuntimeOptionWrapperEnablePaddleToTrt(fd_runtime_option_wrapper);
}
public void DeletePaddleBackendPass(string delete_pass_name) {
FD_C_RuntimeOptionWrapperDeletePaddleBackendPass(fd_runtime_option_wrapper,
delete_pass_name);
}
public void EnablePaddleLogInfo() {
FD_C_RuntimeOptionWrapperEnablePaddleLogInfo(fd_runtime_option_wrapper);
}
public void DisablePaddleLogInfo() {
FD_C_RuntimeOptionWrapperDisablePaddleLogInfo(fd_runtime_option_wrapper);
}
public void SetPaddleMKLDNNCacheSize(int size) {
FD_C_RuntimeOptionWrapperSetPaddleMKLDNNCacheSize(fd_runtime_option_wrapper,
size);
}
public void SetOpenVINODevice(string name = "CPU") {
FD_C_RuntimeOptionWrapperSetOpenVINODevice(fd_runtime_option_wrapper, name);
}
public void SetLiteOptimizedModelDir(string optimized_model_dir) {
FD_C_RuntimeOptionWrapperSetLiteOptimizedModelDir(fd_runtime_option_wrapper,
optimized_model_dir);
}
public void SetLiteSubgraphPartitionPath(
string nnadapter_subgraph_partition_config_path) {
FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionPath(
fd_runtime_option_wrapper, nnadapter_subgraph_partition_config_path);
}
public void SetLiteSubgraphPartitionConfigBuffer(
string nnadapter_subgraph_partition_config_buffer) {
FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionConfigBuffer(
fd_runtime_option_wrapper, nnadapter_subgraph_partition_config_buffer);
}
public void SetLiteContextProperties(string nnadapter_context_properties) {
FD_C_RuntimeOptionWrapperSetLiteContextProperties(
fd_runtime_option_wrapper, nnadapter_context_properties);
}
public void SetLiteModelCacheDir(string nnadapter_model_cache_dir) {
FD_C_RuntimeOptionWrapperSetLiteModelCacheDir(fd_runtime_option_wrapper,
nnadapter_model_cache_dir);
}
public void SetLiteMixedPrecisionQuantizationConfigPath(
string nnadapter_mixed_precision_quantization_config_path) {
FD_C_RuntimeOptionWrapperSetLiteMixedPrecisionQuantizationConfigPath(
fd_runtime_option_wrapper,
nnadapter_mixed_precision_quantization_config_path);
}
public void EnableLiteFP16() {
FD_C_RuntimeOptionWrapperEnableLiteFP16(fd_runtime_option_wrapper);
}
public void DisableLiteFP16() {
FD_C_RuntimeOptionWrapperDisableLiteFP16(fd_runtime_option_wrapper);
}
public void EnableLiteInt8() {
FD_C_RuntimeOptionWrapperEnableLiteInt8(fd_runtime_option_wrapper);
}
public void DisableLiteInt8() {
FD_C_RuntimeOptionWrapperDisableLiteInt8(fd_runtime_option_wrapper);
}
public void SetLitePowerMode(LitePowerMode mode) {
FD_C_RuntimeOptionWrapperSetLitePowerMode(fd_runtime_option_wrapper, mode);
}
public void EnableTrtFP16() {
FD_C_RuntimeOptionWrapperEnableTrtFP16(fd_runtime_option_wrapper);
}
public void DisableTrtFP16() {
FD_C_RuntimeOptionWrapperDisableTrtFP16(fd_runtime_option_wrapper);
}
public void SetTrtCacheFile(string cache_file_path) {
FD_C_RuntimeOptionWrapperSetTrtCacheFile(fd_runtime_option_wrapper,
cache_file_path);
}
public void EnablePinnedMemory() {
FD_C_RuntimeOptionWrapperEnablePinnedMemory(fd_runtime_option_wrapper);
}
public void DisablePinnedMemory() {
FD_C_RuntimeOptionWrapperDisablePinnedMemory(fd_runtime_option_wrapper);
}
public void EnablePaddleTrtCollectShape() {
FD_C_RuntimeOptionWrapperEnablePaddleTrtCollectShape(
fd_runtime_option_wrapper);
}
public void DisablePaddleTrtCollectShape() {
FD_C_RuntimeOptionWrapperDisablePaddleTrtCollectShape(
fd_runtime_option_wrapper);
}
public void SetOpenVINOStreams(int num_streams) {
FD_C_RuntimeOptionWrapperSetOpenVINOStreams(fd_runtime_option_wrapper,
num_streams);
}
public void UseIpu(int device_num = 1, int micro_batch_size = 1,
bool enable_pipelining = false, int batches_per_step = 1) {
FD_C_RuntimeOptionWrapperUseIpu(fd_runtime_option_wrapper, device_num,
micro_batch_size, enable_pipelining,
batches_per_step);
}
public IntPtr GetWrapperPtr() { return fd_runtime_option_wrapper; }
// Below are underlying C api
private IntPtr fd_runtime_option_wrapper;
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_CreateRuntimeOptionWrapper")]
private static extern IntPtr FD_C_CreateRuntimeOptionWrapper();
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_DestroyRuntimeOptionWrapper")]
private static extern void
FD_C_DestroyRuntimeOptionWrapper(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetModelPath")]
private static extern void
FD_C_RuntimeOptionWrapperSetModelPath(IntPtr fd_runtime_option_wrapper,
string model_path, string params_path,
ModelFormat format);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetModelBuffer")]
private static extern void FD_C_RuntimeOptionWrapperSetModelBuffer(
IntPtr fd_runtime_option_wrapper, string model_buffer,
string params_buffer, ModelFormat format);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_RuntimeOptionWrapperUseCpu")]
private static extern void
FD_C_RuntimeOptionWrapperUseCpu(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_RuntimeOptionWrapperUseGpu")]
private static extern void
FD_C_RuntimeOptionWrapperUseGpu(IntPtr fd_runtime_option_wrapper, int gpu_id);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseRKNPU2")]
private static extern void
FD_C_RuntimeOptionWrapperUseRKNPU2(IntPtr fd_runtime_option_wrapper,
rknpu2_CpuName rknpu2_name,
rknpu2_CoreMask rknpu2_core);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseTimVX")]
private static extern void
FD_C_RuntimeOptionWrapperUseTimVX(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseAscend")]
private static extern void
FD_C_RuntimeOptionWrapperUseAscend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseKunlunXin")]
private static extern void FD_C_RuntimeOptionWrapperUseKunlunXin(
IntPtr fd_runtime_option_wrapper, int kunlunxin_id, int l3_workspace_size,
bool locked, bool autotune, string autotune_file, string precision,
bool adaptive_seqlen, bool enable_multi_stream);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseSophgo")]
private static extern void
FD_C_RuntimeOptionWrapperUseSophgo(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetExternalStream")]
private static extern void
FD_C_RuntimeOptionWrapperSetExternalStream(IntPtr fd_runtime_option_wrapper,
IntPtr external_stream);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetCpuThreadNum")]
private static extern void
FD_C_RuntimeOptionWrapperSetCpuThreadNum(IntPtr fd_runtime_option_wrapper,
int thread_num);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetOrtGraphOptLevel")]
private static extern void
FD_C_RuntimeOptionWrapperSetOrtGraphOptLevel(IntPtr fd_runtime_option_wrapper,
int level);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUsePaddleBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUsePaddleBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUsePaddleInferBackend")]
private static extern void FD_C_RuntimeOptionWrapperUsePaddleInferBackend(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseOrtBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUseOrtBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseSophgoBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUseSophgoBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseTrtBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUseTrtBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUsePorosBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUsePorosBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseOpenVINOBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUseOpenVINOBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUseLiteBackend")]
private static extern void
FD_C_RuntimeOptionWrapperUseLiteBackend(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperUsePaddleLiteBackend")]
private static extern void FD_C_RuntimeOptionWrapperUsePaddleLiteBackend(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetPaddleMKLDNN")]
private static extern void
FD_C_RuntimeOptionWrapperSetPaddleMKLDNN(IntPtr fd_runtime_option_wrapper,
bool pd_mkldnn);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnablePaddleToTrt")]
private static extern void
FD_C_RuntimeOptionWrapperEnablePaddleToTrt(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDeletePaddleBackendPass")]
private static extern void FD_C_RuntimeOptionWrapperDeletePaddleBackendPass(
IntPtr fd_runtime_option_wrapper, string delete_pass_name);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnablePaddleLogInfo")]
private static extern void FD_C_RuntimeOptionWrapperEnablePaddleLogInfo(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDisablePaddleLogInfo")]
private static extern void FD_C_RuntimeOptionWrapperDisablePaddleLogInfo(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetPaddleMKLDNNCacheSize")]
private static extern void FD_C_RuntimeOptionWrapperSetPaddleMKLDNNCacheSize(
IntPtr fd_runtime_option_wrapper, int size);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetOpenVINODevice")]
private static extern void
FD_C_RuntimeOptionWrapperSetOpenVINODevice(IntPtr fd_runtime_option_wrapper,
string name);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetLiteOptimizedModelDir")]
private static extern void FD_C_RuntimeOptionWrapperSetLiteOptimizedModelDir(
IntPtr fd_runtime_option_wrapper, string optimized_model_dir);
[DllImport("fastdeploy.dll",
EntryPoint =
"FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionPath")]
private static extern void
FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionPath(
IntPtr fd_runtime_option_wrapper,
string nnadapter_subgraph_partition_config_path);
[DllImport(
"fastdeploy.dll",
EntryPoint =
"FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionConfigBuffer")]
private static extern void
FD_C_RuntimeOptionWrapperSetLiteSubgraphPartitionConfigBuffer(
IntPtr fd_runtime_option_wrapper,
string nnadapter_subgraph_partition_config_buffer);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetLiteContextProperties")]
private static extern void FD_C_RuntimeOptionWrapperSetLiteContextProperties(
IntPtr fd_runtime_option_wrapper, string nnadapter_context_properties);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetLiteModelCacheDir")]
private static extern void FD_C_RuntimeOptionWrapperSetLiteModelCacheDir(
IntPtr fd_runtime_option_wrapper, string nnadapter_model_cache_dir);
[DllImport(
"fastdeploy.dll",
EntryPoint =
"FD_C_RuntimeOptionWrapperSetLiteMixedPrecisionQuantizationConfigPath")]
private static extern void
FD_C_RuntimeOptionWrapperSetLiteMixedPrecisionQuantizationConfigPath(
IntPtr fd_runtime_option_wrapper,
string nnadapter_mixed_precision_quantization_config_path);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnableLiteFP16")]
private static extern void
FD_C_RuntimeOptionWrapperEnableLiteFP16(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDisableLiteFP16")]
private static extern void
FD_C_RuntimeOptionWrapperDisableLiteFP16(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnableLiteInt8")]
private static extern void
FD_C_RuntimeOptionWrapperEnableLiteInt8(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDisableLiteInt8")]
private static extern void
FD_C_RuntimeOptionWrapperDisableLiteInt8(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetLitePowerMode")]
private static extern void
FD_C_RuntimeOptionWrapperSetLitePowerMode(IntPtr fd_runtime_option_wrapper,
LitePowerMode mode);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnableTrtFP16")]
private static extern void
FD_C_RuntimeOptionWrapperEnableTrtFP16(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDisableTrtFP16")]
private static extern void
FD_C_RuntimeOptionWrapperDisableTrtFP16(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetTrtCacheFile")]
private static extern void
FD_C_RuntimeOptionWrapperSetTrtCacheFile(IntPtr fd_runtime_option_wrapper,
string cache_file_path);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperEnablePinnedMemory")]
private static extern void
FD_C_RuntimeOptionWrapperEnablePinnedMemory(IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperDisablePinnedMemory")]
private static extern void FD_C_RuntimeOptionWrapperDisablePinnedMemory(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint =
"FD_C_RuntimeOptionWrapperEnablePaddleTrtCollectShape")]
private static extern void
FD_C_RuntimeOptionWrapperEnablePaddleTrtCollectShape(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint =
"FD_C_RuntimeOptionWrapperDisablePaddleTrtCollectShape")]
private static extern void
FD_C_RuntimeOptionWrapperDisablePaddleTrtCollectShape(
IntPtr fd_runtime_option_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_RuntimeOptionWrapperSetOpenVINOStreams")]
private static extern void
FD_C_RuntimeOptionWrapperSetOpenVINOStreams(IntPtr fd_runtime_option_wrapper,
int num_streams);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_RuntimeOptionWrapperUseIpu")]
private static extern void
FD_C_RuntimeOptionWrapperUseIpu(IntPtr fd_runtime_option_wrapper,
int device_num, int micro_batch_size,
bool enable_pipelining, int batches_per_step);
}
}

View File

@@ -0,0 +1,125 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
using fastdeploy.vision;
namespace fastdeploy {
namespace types_internal_c {
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArrayUint8 {
public nuint size;
public IntPtr data; // byte[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArrayInt32 {
public nuint size;
public IntPtr data; // int[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArraySize {
public nuint size;
public IntPtr data; // nuint[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArrayInt64 {
public nuint size;
public IntPtr data; // long[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArrayFloat {
public nuint size;
public IntPtr data; // float[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_Cstr {
public nuint size;
public string data;
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimArrayCstr {
public nuint size;
public IntPtr data; // FD_Cstr[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_TwoDimArraySize {
public nuint size;
public IntPtr data; // FD_OneDimArraySize[]
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_TwoDimArrayFloat {
public nuint size;
public IntPtr data; // FD_OneDimArrayFloat[]
}
public enum FD_ResultType {
UNKNOWN_RESULT,
CLASSIFY,
DETECTION,
SEGMENTATION,
OCR,
MOT,
FACE_DETECTION,
FACE_ALIGNMENT,
FACE_RECOGNITION,
MATTING,
MASK,
KEYPOINT_DETECTION,
HEADPOSE
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_ClassifyResult {
public FD_OneDimArrayInt32 label_ids;
public FD_OneDimArrayFloat scores;
public FD_ResultType type;
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_Mask {
public FD_OneDimArrayUint8 data;
public FD_OneDimArrayInt64 shape;
public FD_ResultType type;
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_OneDimMask {
public nint size;
public IntPtr data; // FD_Mask*
}
[StructLayout(LayoutKind.Sequential)]
public struct FD_DetectionResult {
public FD_TwoDimArrayFloat boxes;
public FD_OneDimArrayFloat scores;
public FD_OneDimArrayInt32 label_ids;
public FD_OneDimMask masks;
[MarshalAs(UnmanagedType.U1)]
public bool contain_masks;
public FD_ResultType type;
}
}
}

View File

@@ -0,0 +1,100 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using OpenCvSharp;
using fastdeploy.types_internal_c;
namespace fastdeploy {
namespace vision {
namespace classification {
class PaddleClasModel {
public PaddleClasModel(string model_file, string params_file,
string config_file, RuntimeOption custom_option = null,
ModelFormat model_format = ModelFormat.PADDLE) {
if (custom_option == null) {
custom_option = new RuntimeOption();
}
fd_paddleclas_model_wrapper = FD_C_CreatePaddleClasModelWrapper(
model_file, params_file, config_file, custom_option.GetWrapperPtr(),
model_format);
}
~PaddleClasModel() {
FD_C_DestroyPaddleClasModelWrapper(fd_paddleclas_model_wrapper);
}
public ClassifyResult Predict(Mat img) {
IntPtr fd_classify_result_wrapper_ptr = FD_C_CreateClassifyResultWrapper();
FD_C_PaddleClasModelWrapperPredict(
fd_paddleclas_model_wrapper, img.CvPtr,
fd_classify_result_wrapper_ptr); // predict
IntPtr fd_classify_result_ptr = FD_C_ClassifyResultWrapperGetData(
fd_classify_result_wrapper_ptr); // get result from wrapper
FD_ClassifyResult fd_classify_result =
(FD_ClassifyResult)Marshal.PtrToStructure(fd_classify_result_ptr,
typeof(FD_ClassifyResult));
ClassifyResult classify_result =
ConvertResult.ConvertCResultToClassifyResult(fd_classify_result);
FD_C_DestroyClassifyResultWrapper(
fd_classify_result_wrapper_ptr); // free fd_classify_result_wrapper_ptr
FD_C_DestroyClassifyResult(
fd_classify_result_ptr); // free fd_classify_result_ptr
return classify_result;
}
// below are underlying C api
private IntPtr fd_paddleclas_model_wrapper;
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_CreatePaddleClasModelWrapper")]
private static extern IntPtr FD_C_CreatePaddleClasModelWrapper(
string model_file, string params_file, string config_file,
IntPtr fd_runtime_option_wrapper, ModelFormat model_format);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_DestroyPaddleClasModelWrapper")]
private static extern void
FD_C_DestroyPaddleClasModelWrapper(IntPtr fd_paddleclas_model_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_PaddleClasModelWrapperPredict")]
private static extern bool
FD_C_PaddleClasModelWrapperPredict(IntPtr fd_paddleclas_model_wrapper,
IntPtr img,
IntPtr fd_classify_result_wrapper);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_CreateClassifyResultWrapper")]
private static extern IntPtr FD_C_CreateClassifyResultWrapper();
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_DestroyClassifyResultWrapper")]
private static extern void
FD_C_DestroyClassifyResultWrapper(IntPtr fd_classify_result_wrapper);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_DestroyClassifyResult")]
private static extern void
FD_C_DestroyClassifyResult(IntPtr fd_classify_result);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_ClassifyResultWrapperGetData")]
private static extern IntPtr
FD_C_ClassifyResultWrapperGetData(IntPtr fd_classify_result_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_CreateClassifyResultWrapperFromData")]
private static extern IntPtr
FD_C_CreateClassifyResultWrapperFromData(IntPtr fd_classify_result);
}
}
}
}

View File

@@ -0,0 +1,94 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using OpenCvSharp;
using fastdeploy.types_internal_c;
namespace fastdeploy {
namespace vision {
namespace detection {
public class PPYOLOE {
public PPYOLOE(string model_file, string params_file, string config_file,
RuntimeOption custom_option = null,
ModelFormat model_format = ModelFormat.PADDLE) {
if (custom_option == null) {
custom_option = new RuntimeOption();
}
fd_ppyoloe_wrapper =
FD_C_CreatesPPYOLOEWrapper(model_file, params_file, config_file,
custom_option.GetWrapperPtr(), model_format);
}
~PPYOLOE() { FD_C_DestroyPPYOLOEWrapper(fd_ppyoloe_wrapper); }
public DetectionResult Predict(Mat img) {
IntPtr fd_detection_result_wrapper_ptr =
FD_C_CreateDetectionResultWrapper();
FD_C_PPYOLOEWrapperPredict(fd_ppyoloe_wrapper, img.CvPtr,
fd_detection_result_wrapper_ptr); // predict
IntPtr fd_detection_result_ptr = FD_C_DetectionResultWrapperGetData(
fd_detection_result_wrapper_ptr); // get result from wrapper
FD_DetectionResult fd_detection_result =
(FD_DetectionResult)Marshal.PtrToStructure(fd_detection_result_ptr,
typeof(FD_DetectionResult));
DetectionResult detection_result =
ConvertResult.ConvertCResultToDetectionResult(fd_detection_result);
FD_C_DestroyDetectionResultWrapper(
fd_detection_result_wrapper_ptr); // free fd_detection_result_wrapper_ptr
FD_C_DestroyDetectionResult(
fd_detection_result_ptr); // free fd_detection_result_ptr
return detection_result;
}
// below are underlying C api
private IntPtr fd_ppyoloe_wrapper;
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_CreatesPPYOLOEWrapper")]
private static extern IntPtr FD_C_CreatesPPYOLOEWrapper(
string model_file, string params_file, string config_file,
IntPtr fd_runtime_option_wrapper, ModelFormat model_format);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_DestroyPPYOLOEWrapper")]
private static extern void
FD_C_DestroyPPYOLOEWrapper(IntPtr fd_ppyoloe_wrapper);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_PPYOLOEWrapperPredict")]
private static extern bool
FD_C_PPYOLOEWrapperPredict(IntPtr fd_ppyoloe_wrapper, IntPtr img,
IntPtr fd_detection_result_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_CreateDetectionResultWrapper")]
private static extern IntPtr FD_C_CreateDetectionResultWrapper();
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_DestroyDetectionResultWrapper")]
private static extern void
FD_C_DestroyDetectionResultWrapper(IntPtr fd_detection_result_wrapper);
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_DestroyDetectionResult")]
private static extern void
FD_C_DestroyDetectionResult(IntPtr fd_detection_result);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_DetectionResultWrapperGetData")]
private static extern IntPtr
FD_C_DetectionResultWrapperGetData(IntPtr fd_detection_result_wrapper);
[DllImport("fastdeploy.dll",
EntryPoint = "FD_C_CreateDetectionResultWrapperFromData")]
private static extern IntPtr
FD_C_CreateDetectionResultWrapperFromData(IntPtr fd_detection_result);
}
}
}
}

View File

@@ -0,0 +1,272 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using fastdeploy.types_internal_c;
namespace fastdeploy {
namespace vision {
public enum ResultType {
UNKNOWN_RESULT,
CLASSIFY,
DETECTION,
SEGMENTATION,
OCR,
MOT,
FACE_DETECTION,
FACE_ALIGNMENT,
FACE_RECOGNITION,
MATTING,
MASK,
KEYPOINT_DETECTION,
HEADPOSE
}
public struct Mask {
public List<byte> data;
public List<long> shape;
public ResultType type;
public Mask() {
this.data = new List<byte>();
this.shape = new List<long>();
this.type = ResultType.MASK;
}
}
public struct ClassifyResult {
public List<int> label_ids;
public List<float> scores;
public ResultType type;
public ClassifyResult() {
this.label_ids = new List<int>();
this.scores = new List<float>();
this.type = ResultType.CLASSIFY;
}
}
public struct DetectionResult {
public List<float[]> boxes;
public List<float> scores;
public List<int> label_ids;
public List<Mask> masks;
public bool contain_masks;
public ResultType type;
public DetectionResult() {
this.boxes = new List<float[]>();
this.scores = new List<float>();
this.label_ids = new List<int>();
this.masks = new List<Mask>();
this.contain_masks = false;
this.type = ResultType.DETECTION;
}
}
public class ConvertResult {
public static FD_ClassifyResult
ConvertClassifyResultToCResult(ClassifyResult classify_result) {
FD_ClassifyResult fd_classify_result = new FD_ClassifyResult();
// copy label_ids
// Create a managed array
fd_classify_result.label_ids.size = (uint)classify_result.label_ids.Count;
int[] label_ids = new int[fd_classify_result.label_ids.size];
// Copy data from Link to Array
classify_result.label_ids.CopyTo(label_ids);
// Copy data to unmanaged memory
int size = Marshal.SizeOf(label_ids[0]) * label_ids.Length;
fd_classify_result.label_ids.data = Marshal.AllocHGlobal(size);
Marshal.Copy(label_ids, 0, fd_classify_result.label_ids.data,
label_ids.Length);
// copy scores
// Create a managed array
fd_classify_result.scores.size = (uint)classify_result.scores.Count;
float[] scores = new float[fd_classify_result.scores.size];
// Copy data from Link to Array
classify_result.scores.CopyTo(scores);
// Copy data to unmanaged memory
size = Marshal.SizeOf(scores[0]) * scores.Length;
fd_classify_result.scores.data = Marshal.AllocHGlobal(size);
Marshal.Copy(scores, 0, fd_classify_result.scores.data, scores.Length);
fd_classify_result.type = (FD_ResultType)classify_result.type;
return fd_classify_result;
}
public static ClassifyResult
ConvertCResultToClassifyResult(FD_ClassifyResult fd_classify_result) {
ClassifyResult classify_result = new ClassifyResult();
// copy label_ids
int[] label_ids = new int[fd_classify_result.label_ids.size];
Marshal.Copy(fd_classify_result.label_ids.data, label_ids, 0,
label_ids.Length);
classify_result.label_ids = new List<int>(label_ids);
// copy scores
float[] scores = new float[fd_classify_result.scores.size];
Marshal.Copy(fd_classify_result.scores.data, scores, 0, scores.Length);
classify_result.scores = new List<float>(scores);
classify_result.type = (ResultType)fd_classify_result.type;
return classify_result;
}
public static FD_DetectionResult
ConvertDetectionResultToCResult(DetectionResult detection_result) {
FD_DetectionResult fd_detection_result = new FD_DetectionResult();
// copy boxes
int boxes_coordinate_dim = 4;
int size;
fd_detection_result.boxes.size = (uint)detection_result.boxes.Count;
FD_OneDimArraySize[] boxes =
new FD_OneDimArraySize[fd_detection_result.boxes.size];
// Copy each box
for (int i = 0; i < (int)fd_detection_result.boxes.size; i++) {
boxes[i].size = (uint)detection_result.boxes[i].Length;
float[] boxes_i = new float[boxes_coordinate_dim];
detection_result.boxes[i].CopyTo(boxes_i, 0);
size = Marshal.SizeOf(boxes_i[0]) * boxes_i.Length;
boxes[i].data = Marshal.AllocHGlobal(size);
Marshal.Copy(boxes_i, 0, boxes[i].data, boxes_i.Length);
}
// Copy data to unmanaged memory
size = Marshal.SizeOf(boxes[0]) * boxes.Length;
fd_detection_result.boxes.data = Marshal.AllocHGlobal(size);
for (int i = 0; i < boxes.Length; i++) {
Marshal.StructureToPtr(
boxes[i],
fd_detection_result.boxes.data + i * Marshal.SizeOf(boxes[0]), true);
}
// copy scores
fd_detection_result.scores.size = (uint)detection_result.scores.Count;
float[] scores = new float[fd_detection_result.scores.size];
// Copy data from Link to Array
detection_result.scores.CopyTo(scores);
// Copy data to unmanaged memory
size = Marshal.SizeOf(scores[0]) * scores.Length;
fd_detection_result.scores.data = Marshal.AllocHGlobal(size);
Marshal.Copy(scores, 0, fd_detection_result.scores.data, scores.Length);
// copy label_ids
fd_detection_result.label_ids.size = (uint)detection_result.label_ids.Count;
int[] label_ids = new int[fd_detection_result.label_ids.size];
// Copy data from Link to Array
detection_result.label_ids.CopyTo(label_ids);
// Copy data to unmanaged memory
size = Marshal.SizeOf(label_ids[0]) * label_ids.Length;
fd_detection_result.label_ids.data = Marshal.AllocHGlobal(size);
Marshal.Copy(label_ids, 0, fd_detection_result.label_ids.data,
label_ids.Length);
// copy masks
fd_detection_result.masks.size = detection_result.masks.Count;
FD_Mask[] masks = new FD_Mask[fd_detection_result.masks.size];
// copy each mask
for (int i = 0; i < (int)fd_detection_result.masks.size; i++) {
// copy data in mask
masks[i].data.size = (uint)detection_result.masks[i].data.Count;
byte[] masks_data_i = new byte[masks[i].data.size];
detection_result.masks[i].data.CopyTo(masks_data_i);
size = Marshal.SizeOf(masks_data_i[0]) * masks_data_i.Length;
masks[i].data.data = Marshal.AllocHGlobal(size);
Marshal.Copy(masks_data_i, 0, masks[i].data.data, masks_data_i.Length);
// copy shape in mask
masks[i].shape.size = (uint)detection_result.masks[i].shape.Count;
long[] masks_shape_i = new long[masks[i].shape.size];
detection_result.masks[i].shape.CopyTo(masks_shape_i);
size = Marshal.SizeOf(masks_shape_i[0]) * masks_shape_i.Length;
masks[i].shape.data = Marshal.AllocHGlobal(size);
Marshal.Copy(masks_shape_i, 0, masks[i].shape.data, masks_shape_i.Length);
// copy type
masks[i].type = (FD_ResultType)detection_result.masks[i].type;
}
if (fd_detection_result.masks.size != 0) {
size = Marshal.SizeOf(masks[0]) * masks.Length;
fd_detection_result.masks.data = Marshal.AllocHGlobal(size);
for (int i = 0; i < masks.Length; i++) {
Marshal.StructureToPtr(masks[i],
fd_detection_result.masks.data +
i * Marshal.SizeOf(masks[0]),
true);
}
}
fd_detection_result.contain_masks = detection_result.contain_masks;
fd_detection_result.type = (FD_ResultType)detection_result.type;
return fd_detection_result;
}
public static DetectionResult
ConvertCResultToDetectionResult(FD_DetectionResult fd_detection_result) {
DetectionResult detection_result = new DetectionResult();
// copy boxes
detection_result.boxes = new List<float[]>();
FD_OneDimArraySize[] boxes =
new FD_OneDimArraySize[fd_detection_result.boxes.size];
Console.WriteLine(fd_detection_result.boxes.size);
for (int i = 0; i < (int)fd_detection_result.boxes.size; i++) {
boxes[i] = (FD_OneDimArraySize)Marshal.PtrToStructure(
fd_detection_result.boxes.data + i * Marshal.SizeOf(boxes[0]),
typeof(FD_OneDimArraySize));
float[] box_i = new float[boxes[i].size];
Marshal.Copy(boxes[i].data, box_i, 0, box_i.Length);
detection_result.boxes.Add(box_i);
}
// copy scores
float[] scores = new float[fd_detection_result.scores.size];
Marshal.Copy(fd_detection_result.scores.data, scores, 0, scores.Length);
detection_result.scores = new List<float>(scores);
// copy label_ids
int[] label_ids = new int[fd_detection_result.label_ids.size];
Marshal.Copy(fd_detection_result.label_ids.data, label_ids, 0,
label_ids.Length);
detection_result.label_ids = new List<int>(label_ids);
// copy masks
detection_result.masks = new List<Mask>();
FD_Mask[] fd_masks = new FD_Mask[fd_detection_result.masks.size];
for (int i = 0; i < (int)fd_detection_result.masks.size; i++) {
fd_masks[i] = (FD_Mask)Marshal.PtrToStructure(
fd_detection_result.masks.data + i * Marshal.SizeOf(fd_masks[0]),
typeof(FD_Mask));
Mask mask_i = new Mask();
byte[] mask_i_data = new byte[fd_masks[i].data.size];
Marshal.Copy(fd_masks[i].data.data, mask_i_data, 0, mask_i_data.Length);
long[] mask_i_shape = new long[fd_masks[i].shape.size];
Marshal.Copy(fd_masks[i].shape.data, mask_i_shape, 0,
mask_i_shape.Length);
mask_i.type = (ResultType)fd_masks[i].type;
detection_result.masks.Add(mask_i);
}
detection_result.contain_masks = fd_detection_result.contain_masks;
detection_result.type = (ResultType)fd_detection_result.type;
return detection_result;
}
}
}
}

View File

@@ -0,0 +1,45 @@
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using OpenCvSharp;
using fastdeploy.types_internal_c;
namespace fastdeploy {
namespace vision {
public class Visualize {
public static Mat VisDetection(Mat im, DetectionResult detection_result,
float score_threshold = 0.0f,
int line_size = 1, float font_size = 0.5f) {
FD_DetectionResult fd_detection_result =
ConvertResult.ConvertDetectionResultToCResult(detection_result);
IntPtr result_ptr =
FD_C_VisDetection(im.CvPtr, ref fd_detection_result, score_threshold,
line_size, font_size);
return new Mat(result_ptr);
}
[DllImport("fastdeploy.dll", EntryPoint = "FD_C_VisDetection")]
private static extern IntPtr
FD_C_VisDetection(IntPtr im, ref FD_DetectionResult fd_detection_result,
float score_threshold, int line_size, float font_size);
}
}
}