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

PaddleClas 车辆属性模型vehicle_attribute_model转onnx并部署

下载paddlepaddle3.0.0

下载paddleclas 2.6.0

实验:  运行前输入:

export FLAGS_enable_pir_api=0    

import paddleclas
model = paddleclas.PaddleClas(model_name="vehicle_attribute")
result = model.predict(input_data="/home/PaddleDetection-release-2.8.1/carimg/car.jpg")
print(next(result))

实验没问题后

 

替换成下载好的vehicle_attribute_model     inference模型

paddle2onnx --model_dir=./models/ResNet50_vd_infer/ \
--model_filename=inference.pdmodel \
--params_filename=inference.pdiparams \
--save_file=./models/ResNet50_vd_infer/inference.onnx \
--opset_version=10 \
--enable_onnx_checker=True

 

import onnxruntime as ort
import numpy as np
import torchvision.transforms as transforms
from PIL import Image
session = ort.InferenceSession("/home/inference.onnx")
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
img = Image.open("/home/car2.jpg").convert('RGB')  
preprocess = transforms.Compose([transforms.Resize((192, 256)),  transforms.ToTensor(),transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
input_tensor = preprocess(img)
input_batch = input_tensor.unsqueeze(0).numpy()  
result = session.run([output_name], {input_name: input_batch})
output = result[0][0]
color_map = {0: "yellow",1: "orange",2: "green",3: "gray",4: "red",5: "blue",6: "white",7: "golden",8: "brown",9:"black"
}
color_index = np.argmax(output[:10])  
color_prob = output[color_index]
output_dict = {"attributes": f"Color: ({color_map[color_index]}, prob: {color_prob})","output": output.tolist(),"filename": "/home/PaddleDetection-release-2.8.1/carimg/car.jpg"
}print(output_dict)

http://www.dtcms.com/a/192851.html

相关文章:

  • VirtualiSurg使用SenseGlove触觉手套开发XR手术培训体验
  • 「彻底卸载 Quay 容器仓库」:干净移除服务、镜像与配置的全流程指南
  • 使用GoLang版MySQLDiff对比表结构
  • OpenSSH 漏洞-SSH 服务器面临 MitM 攻击和拒绝服务攻击的风险
  • vue插槽的实例详解
  • 使用PEFT库将原始模型与LoRA权重合并
  • C++ asio网络编程(6)利用C11模拟伪闭包实现连接的安全回收
  • web3 前端常见错误类型以及错误捕获处理
  • WPS 调整多级编号
  • 【漫话机器学习系列】260.在前向神经网络中初始权重(Initializing Weights In Feedforward Neural Networks)
  • 驱动-Linux定时-timer_list
  • 嵌软面试每日一阅----通信协议篇(二)之TCP
  • ProceedingJoinPoint的认识
  • free void* 指令
  • 第九讲 | 模板进阶
  • manuskript开源程序是面向作家的开源工具
  • 游戏代码混淆的作用与应用分析
  • gRPC为什么高性能
  • RabbitMQ高级篇-MQ的可靠性
  • 2025-5-14Vue3快速上手
  • Git-学习笔记(粗略版)
  • 互联网大厂Java求职面试:构建高并发直播平台的架构设计与优化
  • pycharm中qthread中的run函数debug不上的问题
  • Ubnutu ADB 无法识别设备的解决方法
  • 第六章: SEO与交互指标 二
  • 解决Mawell1.29.2启动SQLException: You have an error in your SQL syntax问题
  • 黑马程序员C++2024版笔记 第0章 C++入门
  • SpringBoot应用启动过程
  • mybatis-plus配置逻辑删除
  • SEO双核驱动:关键词与长尾词优化