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)
相关推荐
Cyan_RA98 天前
如何利用 Paddle-OCR 丝滑进行复杂版面 PDF 的批量化OCR处理?
java·linux·python·ocr·conda·paddle·surya
Daydream.V12 天前
PaddleOCR入门到实战教程
paddle·paddleocr·paddleocr安装·paddleocr实战
AI数据皮皮侠17 天前
基于XGBoost+LSTM+SARIMA模型的非线性时间序列预测(Paddle)
人工智能·lstm·paddle
开开心心_Every20 天前
文字转语音无字数限,对接微软接口比付费爽
运维·服务器·人工智能·edge·pdf·paddle·segmentfault
xuedeyumu23 天前
Paddle ocr基本识别
ocr·paddle
skywalk81631 个月前
训推一体化的AI飞桨套件:paddlex初探,还是不太顺利
开发语言·paddle
房开民1 个月前
paddle 文本检测识别模型转为onnx
开发语言·r语言·paddle
房开民1 个月前
基于paddle模型 文本识别
paddle
彭祥.1 个月前
基于PaddleSeg与YOLO的自动标注工具
yolo·paddle
Qt学视觉2 个月前
AI2-Paddle环境搭建
c++·人工智能·python·opencv·paddle