FastDeploy:PaddleSeg C++部署方式(一)

news/2024/11/23 3:20:58/

     

1.FastDeploy介绍

⚡️FastDeploy是一款全场景易用灵活极致高效的AI推理部署工具, 支持云边端部署。提供超过 🔥160+ TextVision, Speech跨模态模型📦开箱即用的部署体验,并实现🔚端到端的推理性能优化,满足开发者多场景、多硬件、多平台的产业部署需求。

        使用FastDeploy可以简单高效的在X86 CPU、NVIDIA GPU、飞腾CPU、ARM CPU、Intel GPU、昆仑、昇腾、瑞芯微、晶晨、算能等10+款硬件上对PaddleSeg语义分割模型进行快速部署,并且支持Paddle Inference、Paddle Lite、TensorRT、OpenVINO、ONNXRuntime、RKNPU2、SOPHGO等多种推理后端。

2. 通过FastDeploy C++ 部署PaddleSeg模型

支持CpuInfer、GpuInfer、TrtInfer三种推理模式

// Copyright (c) 2022 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.#include "fastdeploy/vision.h"#ifdef WIN32
const char sep = '\\';
#else
const char sep = '/';
#endifvoid CpuInfer(const std::string& model_dir, const std::string& image_file) {auto model_file = model_dir + sep + "model.pdmodel";auto params_file = model_dir + sep + "model.pdiparams";auto config_file = model_dir + sep + "deploy.yaml";auto option = fastdeploy::RuntimeOption();option.UseCpu();auto model = fastdeploy::vision::segmentation::PaddleSegModel(model_file, params_file, config_file, option);if (!model.Initialized()) {std::cerr << "Failed to initialize." << std::endl;return;}auto im = cv::imread(image_file);fastdeploy::vision::SegmentationResult res;if (!model.Predict(im, &res)) {std::cerr << "Failed to predict." << std::endl;return;}std::cout << res.Str() << std::endl;auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5);cv::imwrite("vis_result.jpg", vis_im);std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}void GpuInfer(const std::string& model_dir, const std::string& image_file) {auto model_file = model_dir + sep + "model.pdmodel";auto params_file = model_dir + sep + "model.pdiparams";auto config_file = model_dir + sep + "deploy.yaml";auto option = fastdeploy::RuntimeOption();option.UseGpu();auto model = fastdeploy::vision::segmentation::PaddleSegModel(model_file, params_file, config_file, option);if (!model.Initialized()) {std::cerr << "Failed to initialize." << std::endl;return;}auto im = cv::imread(image_file);fastdeploy::vision::SegmentationResult res;if (!model.Predict(im, &res)) {std::cerr << "Failed to predict." << std::endl;return;}std::cout << res.Str() << std::endl;auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5);cv::imwrite("vis_result.jpg", vis_im);std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}void TrtInfer(const std::string& model_dir, const std::string& image_file) {auto model_file = model_dir + sep + "model.pdmodel";auto params_file = model_dir + sep + "model.pdiparams";auto config_file = model_dir + sep + "deploy.yaml";auto option = fastdeploy::RuntimeOption();option.UseGpu();option.UseTrtBackend();// If use original Tensorrt, not Paddle-TensorRT,// comment the following two linesoption.EnablePaddleToTrt();option.EnablePaddleTrtCollectShape();option.SetTrtInputShape("x", {1, 3, 256, 256}, {1, 3, 1024, 1024},{1, 3, 2048, 2048});auto model = fastdeploy::vision::segmentation::PaddleSegModel(model_file, params_file, config_file, option);if (!model.Initialized()) {std::cerr << "Failed to initialize." << std::endl;return;}auto im = cv::imread(image_file);fastdeploy::vision::SegmentationResult res;if (!model.Predict(im, &res)) {std::cerr << "Failed to predict." << std::endl;return;}std::cout << res.Str() << std::endl;auto vis_im = fastdeploy::vision::VisSegmentation(im, res, 0.5);cv::imwrite("vis_result.jpg", vis_im);std::cout << "Visualized result saved in ./vis_result.jpg" << std::endl;
}int main(int argc, char* argv[]) {std::string model_dir = "model\\PP_LiteSeg_B_STDC2_cityscapes_without_argmax_infer";std::string image_file = "model\\cityscapes_demo.png";// CpuInfer(argv[1], argv[2]);GpuInfer(model_dir, image_file);//  TrtInfer(argv[1], argv[2]);return 0;
}

推理结果可视化:

 3.待打包上传整个工程


http://www.ppmy.cn/news/45763.html

相关文章

iot-Scada免费Scada组态软件系列教程4-二次开发与版本部署

iot-Scada免费Scada组态软件系列教程 系列文章目录 iot-Scada免费Scada组态软件系列教程1-初识iot-Scada iot-Scada免费Scada组态软件系列教程2-架构设计 iot-Scada免费Scada组态软件系列教程3-各模块详细介绍 iot-Scada免费Scada组态软件系列教程4-二次开发与版本部署 前言…

LeetCode 1147. 段式回文

LeetCode 1147. 段式回文 难度&#xff1a; h a r d \color{red}{hard} hard 题目描述 你会得到一个字符串 t e x t text text 。你应该把它分成 k k k 个子字符串 ( s u b t e x t 1 , s u b t e x t 2 &#xff0c; … &#xff0c; s u b t e x t k ) (subtext1, subte…

【打卡】图像检索与重复图像识别1,2

Part4 图像检索与匹配 背景介绍 随着互联网上的图像数量不断增长&#xff0c;图像检索和匹配技术已成为许多视觉搜索引擎的核心技术&#xff0c;能够提高搜索结果的准确性和覆盖范围。图像检索和匹配是计算机视觉领域的重要研究方向之一&#xff0c;其主要目的是从大规模的图…

【一起啃书】《机器学习》第四章决策树

第四章 决策树 4.1 基本流程 决策树是一类常见的机器学习方法&#xff0c;是基于树结构来进行决策的&#xff0c;通过对训练样本的分析来确定划分属性&#xff0c;来模拟人类决策过程。 一般的&#xff0c;一棵决策树包含一个根结点、若干个内部结点和若干个叶结点&#xff0c;…

MSVC Debug 与 Release 库

CMake Debug后缀 set_target_properties(liba PROPERTIES DEBUG_POSTFIX "d") 或者 set(CMAKE_DEBUG_POSTFIX "d") 这样生成的库或者exe程序名会多一个d字符。如下链接 vc 运行时库 通过/MD、/MT 可以改变MSVC运行库&#xff0c; /MD代表使用动态运行时…

低代码/无代码平台在软件开发中的应用

随着技术的不断发展&#xff0c;软件开发也在不断地进步。低代码/无代码平台已经成为软件开发的一个新的趋势。在这篇文章中&#xff0c;我们将深入探讨低代码/无代码平台在软件开发中的应用&#xff0c;包括它们的优势、如何选择合适的平台以及如何使用这些平台来开发高质量的…

ubuntu快速安装VMware Tools(全屏用的)

VMware Tools实现主机和虚拟机的文件共享。 第一步 打开VMware Workstation,启动ubuntu系统。 点击主界面的&#xff08;虚拟机&#xff09;——点击&#xff08;安装VMware Tools&#xff09;。 弹出提示框点击是——等待自动下载完成。 第二步 将安装包复制到桌面&#x…

临床决策曲线分析如何影响预测模型的使用和评价

目前&#xff0c;临床决策曲线分析&#xff08;clinical decision curve analysis, DCA&#xff09;在业界已经被超过1500文献使用&#xff0c;也被多个主流的临床杂志所推荐&#xff0c;更被写进了临床预测模型撰写标准&#xff08;TRIPOD&#xff09;中&#xff0c;但是许多预…