ONNX 模型库
返回模型

说明文档

模型概述

该模型是在伊朗车牌数据集上微调的 YOLOv8 medium 的 ONNX 版本。YOLOv8 旨在通过在感兴趣的对象周围生成边界框并预测其相关的类别概率,来高效地检测图像中的对象。

如何使用

使用 ONNX Runtime 进行推理

import onnxruntime as rt
sess = rt.InferenceSession(\"path_to_model.onnx\")

# 查看模型输入和输出详情
input_name = sess.get_inputs()[0].name
print(\"输入名称:\", input_name)
input_shape = sess.get_inputs()[0].shape
print(\"输入形状:\", input_shape)
input_type = sess.get_inputs()[0].type
print(\"输入类型:\", input_type)

output_name = sess.get_outputs()[0].name
print(\"输出名称:\", output_name)
output_shape = sess.get_outputs()[0].shape
print(\"输出形状:\", output_shape)
output_type = sess.get_outputs()[0].type
print(\"输出类型:\", output_type)

预处理

  1. 加载图像:使用 cv2.imread() 加载图像。
  2. 调整大小:将输入图像调整为 224x224 分辨率。
  3. 归一化:通过除以 255 将像素值缩放到 [0, 1] 范围。
  4. 转置:将图像数组更改为通道优先格式 (C, H, W)
  5. 转换:将图像转换为 float32 NumPy 数组并添加批次维度。
import cv2
import numpy as np

# 预处理输入图像
image_path = \"/path_to_image.png\"
input_image = cv2.imread(image_path)
resized_image = cv2.resize(input_image, (224, 224))
scaled_image = resized_image / 255.0
transposed_image = scaled_image.transpose((2, 0, 1))
prep_image = np.array(transposed_image, dtype='float32')[None, :]

推理

预处理完成后,在准备好的图像上运行模型。

# 运行推理
output_probabilities = sess.run([output_name], {input_name: prep_image})

后处理

提取边界框详情:

  • 识别概率最高的边界框。
  • 提取坐标(x, y, width, height)和相关概率。
# 提取边界框信息
most_prob_idx = output_probabilities[0][0][4].argmax()
x, y, width, height, prob = output_probabilities[0][0][:, most_prob_idx]
print(x, y, width, height, prob)

shalchianmh/Iran_license_plate_detection_YOLOv8m_onnx

作者 shalchianmh

object-detection ultralytics
↓ 0 ♥ 2

创建时间: 2024-10-03 10:35:21+00:00

更新时间: 2024-10-03 11:07:59+00:00

在 Hugging Face 上查看

文件 (4)

.gitattributes
README.md
model.onnx ONNX
model_nms.onnx ONNX