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

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.lryc.cn/news/2381720.html

相关文章:

  • 【论文#目标检测】End-to-End Object Detection with Transformers
  • C++:迭代器
  • MongoDB数据库深度解析:架构、特性与应用场景
  • 【强化学习】深度强化学习 - Deep Q-Network(DQN)算法
  • git 修改一个老commit,再把修改应用到所有后续的 commit
  • docker compose 启动指定的 service
  • Elasticsearch 深入分析三种分页查询【Elasticsearch 深度分页】
  • DAY29 超大力王爱学Python
  • Ubuntu 远程桌面配置指南
  • 【Python装饰器深度解析】从语法糖到元编程实战
  • 推扫式高光谱相机VIX-N230重磅发布——开启精准成像新时代
  • Parsec解决PnP连接失败的问题
  • 面试题:详细分析Arraylist 与 LinkedList 的异同
  • 软件I2C
  • 通过实例讲解螺旋模型
  • Brooks Polycold快速循环水蒸气冷冻泵客户使用手含电路图,适用于真空室应用
  • winfrom中创建webapi
  • unity XCharts插件生成曲线图在UICanvas中
  • Pichome 开源网盘程序index.php 文件读取漏洞(CVE-2025-1743)
  • 关于在Unity项目中使用Post Processing插件打包到web端出现的问题
  • Prompt Tuning:高效微调大模型的新利器
  • OpenCV 第6课 图像处理之几何变换(重映射)
  • C++初阶-vector的底层
  • 获取文件夹下所有文件的名称
  • C语言指针深入详解(五):回调函数、qsort函数
  • 数据结构进阶:AVL树与红黑树
  • 容器化-K8s-镜像仓库使用和应用
  • 基于Spring Boot + Vue的教师工作量管理系统设计与实现
  • 预先学习:构建智能系统的 “未雨绸缪” 之道
  • 完善网络安全等级保护,企业需注意: