当前位置: 首页 > news >正文

PaddleClas学习3——使用PPLCNet模型对车辆朝向进行识别(c++)

使用PPLCNet模型对车辆朝向进行识别

  • 1 准备环境
  • 2 准备模型
    • 2.1 模型导出
    • 2.2 修改配置文件
  • 3 编译
    • 3.1 使用CMake生成项目文件
    • 3.2 编译
    • 3.3 执行
    • 3.4 添加后处理程序
      • 3.4.1 postprocess.h
      • 3.4.2 postprocess.cpp
      • 3.4.3 在cls.h中添加函数声明
      • 3.4.4 在cls.cpp中添加函数定义
      • 3.4.5 在main.cpp中调用
  • 4 模型预测
    • 4.1 测试结果
    • 4.2 与python预测结果对比

1 准备环境

参考上一篇:Windows PaddleSeg c++部署

2 准备模型

2.1 模型导出

对上一篇 使用PPLCNet模型对车辆朝向进行识别 训练得到模型进行转换。将该模型转为 inference 模型只需运行如下命令:

python tools\export_model.py -c .\ppcls\configs\PULC\vehicle_attribute\PPLCNet_x1_0.yaml -o Global.pretrained_model=output/PPLCNet_x1_0/best_model -o Global.save_inference_dir=./deploy/models/class_vehicle_attribute_infer

训练得到的模型
图2.1 训练得到的模型
在这里插入图片描述
图2.2 导出的模型

2.2 修改配置文件

deploy/configs/PULC/vehicle_attribute/inference_vehicle_attribute.yaml
修改Global下的infer_imgsinference_model_dir

Global:infer_imgs: "./images/PULC/vehicle_attribute/0002_c002_00030670_0.jpg"inference_model_dir: "./models/class_vehicle_attribute_infer"batch_size: 1use_gpu: Trueenable_mkldnn: Truecpu_num_threads: 10#benchmark: Falseenable_benchmark: Falseuse_fp16: Falseir_optim: Trueuse_tensorrt: Falsegpu_mem: 8000enable_profile: False

3 编译

工程整体目录结构如下:

G:/paddle/c++├── paddle_inference
G:/paddle├── PaddleClas-release-2.5

3.1 使用CMake生成项目文件

在这里插入图片描述

3.2 编译

用Visual Studio 2022打开cpp\build\clas_system.sln,将编译模式设置为Release,点击生成->生成解决方案,在cpp\build\Release文件夹内生成clas_system.exe

3.3 执行

进入到build/Release目录下,将准备的模型和图片放到clas_system.exe同级目录,build/Release目录结构如下:

Release
├──clas_system.exe                # 可执行文件
├──images         				  # 测试图片├── PULC├── vehicle_attribute├── 0002_c002_00030670_0.jpg
├──configs         				  # 配置文件├── PULC├── vehicle_attribute├── inference_vehicle_attribute.yaml
├──models      					  # 推理用到的模型├── class_vehicle_attribute_infer├── inference.pdmodel          # 预测模型的拓扑结构文件├── inference.pdiparams        # 预测模型的权重文件└── inference.pdiparams.info   # 参数额外信息,一般无需关注
├──*.dll                          # dll文件

3.4 添加后处理程序

3.4.1 postprocess.h

// postprocess.h
#include <iostream>
#include <vector>namespace PaddleClas {class VehicleAttribute {public:float color_threshold = 0.5;float type_threshold = 0.5;float direction_threshold = 0.5;std::vector<std::string> color_list = { "yellow", "orange", "green", "gray", "red", "blue", "white","golden", "brown", "black" };std::vector<std::string> type_list = { "sedan", "suv", "van", "hatchback", "mpv", "pickup", "bus","truck", "estate" };std::vector<std::string> direction_list = { "forward", "sideward", "backward" };std::string run(std::vector<float>& pred_data);};
}

3.4.2 postprocess.cpp

// postprocess.cpp#include "include/postprocess.h"
#include <string>
namespace PaddleClas {std::string VehicleAttribute::run(std::vector<float>& pred_data) {int color_num = 10;int type_num = 9;int direction_num = 3;int index_color = std::distance(&pred_data[0], std::max_element(&pred_data[0
http://www.lryc.cn/news/255370.html

相关文章:

  • 学习记录---kubernetes中备份和恢复etcd
  • 使用单例模式+观察者模式实现参数配置实时更新
  • 区块链实验室(28) - 拜占庭节点劫持区块链仿真
  • 聊聊AsyncHttpClient的ChannelPool
  • [MySQL] MySQL复合查询(多表查询、子查询)
  • [架构之路-256]:目标系统 - 设计方法 - 软件工程 - 软件设计 - 架构设计 - 软件系统不同层次的复用与软件系统向越来越复杂的方向聚合
  • C++初学教程三
  • 雷达点云数据.pcd格式转.bin格式
  • Fiddler抓包测试
  • 视频处理关键知识
  • LeetCode435. Non-overlapping Intervals
  • ffmpeg 实现多视频轨录制到同一个文件
  • vue3中子组件调用父组件的方法
  • 使用OkHttp上传本地图片及参数
  • 无公网IP环境如何SSH远程连接Deepin操作系统
  • 不会代码(零基础)学语音开发(语音控制板载双继电器)
  • 在imx6ull中加入ov5640模块
  • Kafka中的auto-offset-reset配置
  • TCP/IP_整理起因
  • CG-0A 电子水尺水导电测量原理应用于道路积水监测
  • openEuler JDK21 部署 Zookeeper 集群
  • 前端——html拖拽原理
  • JVM 执行引擎篇
  • js中数组对象去重的方法
  • 【送书活动四期】被GitHub 要求强制开启 2FA 双重身份验证,我该怎么办?
  • GO设计模式——13、享元模式(结构型)
  • Linux 网络协议
  • 【C语言】7-32 刮刮彩票 分数 20
  • 交叉验证以及scikit-learn实现
  • css实现头部占一定高度,内容区占剩余高度可滚动