惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Latest
Security Latest
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MyScale Blog
MyScale Blog
T
Tor Project blog
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
P
Privacy & Cybersecurity Law Blog
MongoDB | Blog
MongoDB | Blog
Simon Willison's Weblog
Simon Willison's Weblog
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
小众软件
小众软件
G
GRAHAM CLULEY
P
Privacy International News Feed
AWS News Blog
AWS News Blog
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
人人都是产品经理
人人都是产品经理
S
Schneier on Security
Scott Helme
Scott Helme
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
E
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
U
Unit 42
The Register - Security
The Register - Security
S
Securelist
Martin Fowler
Martin Fowler
Project Zero
Project Zero
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog

博客园 - 夕西行

显卡、cuda、pytorch版本确定与安装 conda的安装与使用 conda虚拟环境中的pip、No module named问题、missing the 'build_editable' hook和PEP660 mmyolo与官方yolo,在背景数据集上的注意事项 跨平台的文件夹映射cifs WinSCP复制时报 Received SSH2_MSG_CHANNEL_DATA for nonexistent channel 0 CMakeLists.txt之include、lib labelImg安装、改软件后打包成exe、改软件功能 Jetson插网线后启动慢 mmyolo安装 QString有中文空格时 VS2015下载 Qt5.15.2在线安装 向串口发送数据的方式 编译Arm Qt5.14.2(在Arm上本地编译) Qt5.14.2下载 VS2022编译运行VS2015的项目 二进制字面量、字节序、串口发送、转16进制时符号扩展问题 QString的toStdString().c_str()坑
mmyolo数据集、训练
夕西行 · 2025-05-28 · via 博客园 - 夕西行

请先阅读此博客MMYOLO 自定义数据集从标注到部署保姆级教程_mmyolo 从零-CSDN博客

1、转coco样式的数据集

labelImg工具标注yolo后,将结果按照如下方式放置:

    └── $ROOT_PATH
        ├── classes.txt
        ├── labels
        │    ├── a.txt
        │    ├── b.txt
        │    └── ...
        ├── images
        │    ├── a.jpg
        │    ├── b.png
        │    └── ...
        └── ...

然后转coco数据集

    └── $ROOT_PATH
        ├── annotations
        │    ├── result.json
        │    └── ...
        ├── classes.txt
        ├── labels
        │    ├── a.txt
        │    ├── b.txt
        │    └── ...
        ├── images
        │    ├── a.jpg
        │    ├── b.png
        │    └── ...
        └── ...

进入到clone到本地的mmyolo目录,找到tools/dataset_converters/yolo2coco.py,此文件有瑕疵,添加黄色代码。

    # convert x,y,w,h to x1,y1,x2,y2
    x1 = (x - w / 2) * image_width
    y1 = (y - h / 2) * image_height
    x2 = (x + w / 2) * image_width
    y2 = (y + h / 2) * image_height

    #可能因精度误差超出图像边界
    x1 = max(0., x1)
    y1 = max(0., y1)
    x2 = min(x2, image_width)
    y2 = min(y2, image_height)

在mmyolo目录里打开终端,进入自己的虚拟环境后,转coco,注意自己的样本路径

python tools/dataset_converters/yolo2coco.py ~/datasets/yolo/

会得到 annotations/result.json 目录和文件

2、划分数据集

python tools/misc/coco_split.py --json ~/datasets/yolo/annotations/result.json --out-dir ~/datasets/yolo/annotations/ --ratios 0.8 0.2 --shuffle --seed 10

得到下图两个json文件

经验证,数据集会根据每个类别进行划分,而不是全局划分,因此不必担心某个类别样本少导致验证集里为0。验证代码如下:

import json
import os.path
from collections import defaultdict

def count_classes(json_file):
    with open(json_file) as f:
        data = json.load(f)
    class_counts = defaultdict(int)
    for ann in data['annotations']:
        class_counts[ann['category_id']] += 1
    return class_counts

if __name__=='__main__':
    train_counts = count_classes(os.path.expanduser('~/datasets/yolo_caiSe160/annotations/trainval.json'))
    val_counts = count_classes(os.path.expanduser('~/datasets/yolo_caiSe160/annotations/test.json'))
    print("Train class counts:", train_counts)
    print("Val class counts:", val_counts)

 可以看到几乎每个类别按4:1划分的。

3、配置文件。用于模型参数的py文件

参考15 分钟上手 MMYOLO 目标检测 — MMYOLO 0.6.0 文档

我放到了自己新建的yolov8_12目录里

 

4、训练

python tools/train.py configs/yolov8_12/yolov8_12.py

如果报“CUBLAS_WORKSPACE_CONFIG=:4096:8”之类的错误,先执行

export CUBLAS_WORKSPACE_CONFIG=:4096:8

 临时设置(仅当前终端会话有效)

训练得到的pth 在~/mmyolo/work_dirs/yolov8_12/里