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

下载paddlepaddle3.0.0

下载paddleclas 2.6.0

实验: 运行前输入:

export FLAGS_enable_pir_api=0

python 复制代码
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模型

python 复制代码
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
python 复制代码
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)
相关推荐
满怀冰雪4 天前
15-Paddle 高层 API 入门:paddle.Model 的训练与评估流程
人工智能·python·深度学习·机器学习·paddle
molihuan9 天前
最新 Paddle-Lite Android平台编译
android·ocr·paddle·推理·端侧·paddle lite
满怀冰雪11 天前
08-Paddle 神经网络层入门:Linear、激活函数与 Sequential
神经网络·机器学习·paddle
蓝创工坊Blue Foundry12 天前
PaddleOCR 本地部署教程:小模型 OCR 如何完成字段提取到 Excel
pdf·自动化·ocr·excel·paddlepaddle·paddle
满怀冰雪12 天前
09-使用 paddle.nn 构建第一个多层感知机
python·深度学习·神经网络·paddle
蓝创工坊Blue Foundry13 天前
个人藏书太多怎么整理?用 OCR 字段提取汇总成电子书目
pdf·ocr·excel·文心一言·paddlepaddle·paddle
山石满棠15 天前
基于python313环境构建paddle-ocr镜像
ocr·paddle
蓝创工坊Blue Foundry17 天前
PDF 批量提取指定内容到 Excel:按字段整理多个 PDF 的方法
pdf·ocr·excel·文心一言·paddlepaddle·paddle
满怀冰雪18 天前
04-Paddle Tensor 基础:形状、数据类型、广播与索引
python·深度学习·神经网络·paddle
梦远青城18 天前
Docker 部署python的paddle进行OCR文字识别身份证
python·docker·ocr·paddle·身份证识别