深度学习部署:FastDeploy部署教程(CSharp版本)

本文详细介绍了FastDeploy的C#部署教程,涉及C++SDK配置、C#项目创建、目标检测和语义分割示例,展示了如何使用FastDeploy在C#环境中进行AI推理和模型部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FastDeploy部署教程(CSharp版本)

1. FastDeploy介绍

FastDeploy是一款全场景易用灵活极致高效的AI推理部署工具, 支持云边端部署。提供超过 🔥160+ TextVisionSpeech跨模态模型📦开箱即用的部署体验,并实现🔚端到端的推理性能优化。包括 物体检测字符识别(OCR)人脸人像扣图多目标跟踪系统NLPStable Diffusion文图生成TTS 等几十种任务场景,满足开发者多场景、多硬件、多平台的产业部署需求。

在这里插入图片描述

2. FastDeploy 部署(C++)

参考:

FastDeploy 安装教程

3. FastDeploy 部署(CSharp)

FastDeploy C# SDK的接口实现,为用户需要C# API的场景提供解决方案。

3.1 FastDeploy 源码编译

  1. CMAKE_CONFIGURATION_TYPES属性设置为Release

  2. 请不要勾选WITH_GPUENABLE_TRT_BACKEND

  3. 开启

    ENABLE_ORT_BACKEND=ON
    ENABLE_PADDLE_BACKEND=ON 
    ENABLE_OPENVINO_BACKEND=ON 
    ENABLE_VISION=ON 
    ENABLE_TEXT=ON 
    WITH_CAPI=ON 
    WITH_CSHARPAPI=ON 
    
  4. 指定CMAKE_INSTALL_PREFIX 安装路径

  5. 生成fastdeploy.sln解决方案文件选择Release版本,生成编译,点击"INSTALL"->右键点击"生成"将编译好的SDK安装到先前指定的目录步骤⑤。

    在这里插入图片描述

3.2 创建CSharp项目

  1. 在项目引用中添加–>fastdeploy_csharp;

  2. nuget 包添加OpenCvSharp、OpenCvSharp.Extensions等包

  3. 在debug\relese项目文件夹中添加Fastdeploy的动态链接库;

fastdeploy_init.bat install %cd% D:\workSpace\Paddle\deploy\FastDeplyCsharp\FastDeplyCsharp\bin\x64\Debug
  1. 结果预览

在这里插入图片描述

在这里插入图片描述

3.3 源代码

//目标检测
public  void fastdeployDetInfer(string image_path)
{
    string model_dir = "D://workSpace//Paddle//models//ppyoloe_crn_l_300e_coco";

    string model_file = model_dir + "\\" + "model.pdmodel";
    string params_file = model_dir + "\\" + "model.pdiparams";
    string config_file = model_dir + "\\" + "infer_cfg.yml";
    RuntimeOption runtimeoption = new RuntimeOption();
    int device_option = 0;
    if (device_option == 0)
    {
        runtimeoption.UseCpu();
    }
    else
    {
        runtimeoption.UseGpu();
    }
    fastdeploy.vision.detection.PPYOLOE model = new fastdeploy.vision.detection.PPYOLOE(model_file, params_file, config_file, runtimeoption, ModelFormat.PADDLE);
    if (!model.Initialized())
    {
        Console.WriteLine("Failed to initialize.\n");
    }
    Mat image = Cv2.ImRead(image_path);
    fastdeploy.vision.DetectionResult res = model.Predict(image);
    //Console.WriteLine(res.ToString());
    Mat res_img = fastdeploy.vision.Visualize.VisDetection(image, res, 0.5f, 1, 0.5f);
    InferPictureBox.Image = res_img.ToBitmap();
}
// 语义分割
public void fastdeplySegInfer(string image_path)
{
    string model_dir = "D://workSpace//Paddle//models//PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer";

    string model_file = model_dir + "\\" + "model.pdmodel";
    string params_file = model_dir + "\\" + "model.pdiparams";
    string config_file = model_dir + "\\" + "deploy.yaml";
    RuntimeOption runtimeoption = new RuntimeOption();
    runtimeoption.UseCpu();


    fastdeploy.vision.segmentation.PaddleSegModel model = new fastdeploy.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtimeoption, ModelFormat.PADDLE);

    if (!model.Initialized())
    {
        Console.WriteLine("Failed to initialize.\n");
    }
    Mat image = Cv2.ImRead(image_path);

    fastdeploy.vision.SegmentationResult res = model.Predict(image);


    Console.WriteLine(res.ToString());
    Mat res_img = fastdeploy.vision.Visualize.VisSegmentation(image, res, 0.5f);
    InferPictureBox.Image = res_img.ToBitmap();
}
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

热衷技术的尼古拉斯

您的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值