Yolov8和Yolov10的差异以及后处理实现

Yolo模型可分为4个维度的概念

模型版本、数据集、模型变体(Variants)、动态/静态模型。

Yolo各模型版本进展历史

Yolov(2015年华盛顿大学的 Joseph Redmon 和 Ali Farhadi 发布)

Yolov2(2016年Joseph Redmon发布)

Yolov3(2018年Joseph Redmon发布)

Yolov4(2020年Alexey Bochkovskiy发布)

Yolov5(2018年Glen Jocher发布)

Yolov6(2022年美团团队发布)

Yolov7(2022年WongKinYiu发布)

Yolov8(2023年Ultralytics发布)

Yolov9(2023年发布)

Yolov10(2024年清华大学团队发布)

其中Yolov10是刚刚2024年5月底才刚发布的,其中v10实现了一个无NMS的架构,具有一致的双重分配,显著减少了后处理时间,并改善了整体延迟,让后处理变得更简单很多。

数据集(用于训练)

COCO(Common Objects in Context)

COCO旨在鼓励对各种对象类别的研究,通常用于对计算机视觉模型进行基准测试。
COCO 包含 330K 张图像,其中 200K 张图像带有对象检测、分割和字幕任务的注释。
该数据集仅包含80 个 对象类别,包括汽车、自行车和动物、雨伞、手提包和运动器材等常见对象。
用途主要是拿来比较各种AI模型的优劣的,不适合实际商业用途。
COCO数据集下载地址:https://cocodataset.org/#download

OIV7(Open Image V7 )

Open Image V7 是 Google 倡导的多功能、广泛的数据集。它旨在推动计算机视觉领域的研究,拥有大量标注有大量数据的图像900万张,在边界框标注的 190 万张图像中,支持涵盖 600 个 对象类别,包含的 1600 万个边界框。这些边界框主要由专家手工绘制,确保高精度。数据集总体积有561GB。
数据集下载地址:https://storage.googleapis.com/openimages/web/download_v7.html

注:目前Yolov8有Open Image V7和COCO两种数据集已经有别人训练好了的权重文件。
而Yolov10因为是刚出来只找到COCO一种数据集训练好的权重文件,也就是说Yolov10只能识别80种 物体,除非我们自己去训练。

模型变体(Variants)

下面只列出来我有尝试过导出了的:
YOLOv8-N / YOLOv10-N:适用于资源极其受限的环境的纳米版本。
YOLOv8-S / YOLOv10-S:平衡速度和准确度的小型版本。
YOLOv8-M / YOLOv10-M:适用于通用用途的中型版本。
YOLOv10-B:平衡版本,宽度增加,准确度更高。
YOLOv8-L / YOLOv10-L:大型版本,以增加计算资源为代价,实现更高的准确度。
YOLOv8-X / YOLOv10-X:超大型版本,可实现最大准确度和性能。
注:v10有6种,v8只有5种。
v8和v10的coco数据集分别占体积大小见下截图:

动态/静态模型

模型支持导出成静态模型和动态模型,静态模型是[1,3,640,640],要求宽高符合32对齐。

动态模型则没有要求,其中v8的动态模型会随着输入尺寸不同,输出的尺寸会跟着变化。

而v10输入尺寸无论怎样,输出的尺寸都是固定的[1,300,6]。

我已将动态静态两种处理方式都融合在一份代码上,根据加载后的模型推理后的输出长度是否等于1800来判断是否是v10,均可在其内部进行处理。

Demo截图

Yolov8的后处理代码:

复制代码
std::vector<YoloResult> filterYolov8Detections(
    float* inputs, float confidence_threshold,
    int num_channels, int num_anchors, int num_labels,
    int infer_img_width, int infer_img_height
    )
{
    std::vector<YoloResult> detections;
    cv::Mat output =
        cv::Mat((int)num_channels, (int)num_anchors,
                CV_32F, inputs).t();

    for (int i = 0; i < num_anchors; i++) {
        auto  row_ptr    = output.row(i).ptr<float>();
        auto  bboxes_ptr = row_ptr;
        auto  scores_ptr = row_ptr + 4;
        auto  max_s_ptr  = std::max_element(scores_ptr, scores_ptr + num_labels);
        float score      = *max_s_ptr;
        if (score > confidence_threshold) {
            float x = *bboxes_ptr++;
            float y = *bboxes_ptr++;
            float w = *bboxes_ptr++;
            float h = *bboxes_ptr;

            float x0 = std::clamp((x - 0.5f * w), 0.f, (float)infer_img_width);
            float y0 = std::clamp((y - 0.5f * h), 0.f, (float)infer_img_height);
            float x1 = std::clamp((x + 0.5f * w), 0.f, (float)infer_img_width);
            float y1 = std::clamp((y + 0.5f * h), 0.f, (float)infer_img_height);

            cv::Rect_<float> bbox;
            bbox.x      = x0;
            bbox.y      = y0;
            bbox.width  = x1 - x0;
            bbox.height = y1 - y0;
            YoloResult object;
            object.object_id = max_s_ptr - scores_ptr;
            object.score = score;
            object.box = bbox;
            detections.emplace_back(object);
        }
    }
    return detections;
}

Yolov10的后处理代码:

复制代码
std::vector<YoloResult> filterYolov10Detections(
    const std::vector<float> &inputs, float confidence_threshold)
{
    std::vector<YoloResult> detections;
    const int num_detections = inputs.size() / 6;
    for (int i = 0; i < num_detections; ++i)
    {
        float left = inputs[i * 6 + 0];
        float top = inputs[i * 6 + 1];
        float right = inputs[i * 6 + 2];
        float bottom = inputs[i * 6 + 3];
        float confidence = inputs[i * 6 + 4];
        int class_id = inputs[i * 6 + 5];

        if (confidence >= confidence_threshold)
        {
            cv::Rect_<float> bbox;
            bbox.x = left;
            bbox.y = top;
            bbox.width = right - left;
            bbox.height = bottom - top;
            detections.push_back({class_id, confidence, bbox});
        }
    }
    return detections;
}
相关推荐
美酒没故事°12 小时前
Open WebUI安装指南。搭建自己的自托管 AI 平台
人工智能·windows·ai
鸿乃江边鸟12 小时前
Nanobot 从onboard启动命令来看个人助理Agent的实现
人工智能·ai
本旺13 小时前
【Openclaw 】完美解决 Codex 认证失败
ai·codex·openclaw·小龙虾·gpt5.4
张張40813 小时前
(域格)环境搭建和编译
c语言·开发语言·python·ai
乐鑫科技 Espressif14 小时前
使用 MCP 服务器,把乐鑫文档接入 AI 工作流
人工智能·ai·esp32·乐鑫科技
语戚14 小时前
Stable Diffusion 入门:架构、空间与生成流程概览
人工智能·ai·stable diffusion·aigc·模型
俊哥V14 小时前
每日 AI 研究简报 · 2026-04-08
人工智能·ai
rrrjqy15 小时前
什么是RAG?
ai
Flittly15 小时前
【SpringAIAlibaba新手村系列】(15)MCP Client 调用本地服务
java·笔记·spring·ai·springboot
Flittly15 小时前
【SpringAIAlibaba新手村系列】(14)MCP 本地服务与工具集成
java·spring boot·笔记·spring·ai