YOLO系列,从V1~V10,持续更新(Pytorch实现)

关于YOLOV1

本文主要偏向代码实战,详细的算法原理着墨不多

主要创新:

实现了实时的目标检测

附上YOLOV1论文地址:
https://arxiv.org/abs/1506.02640
关于数据

首先要了解该网络架构的输入和输出,以及网络是如何进行训练的。这里主要讲一下数据集的格式以及使用labelme制作数据集(当然还有其他更好的工具,这里只做参考)

如果已经安装了python,使用以下命令直接安装labelme工具,没安python的先安python

bash 复制代码
pip install labelme

之后在cmd中输入labelme,然后回车就能看到labelme的前端UI界面了

(ps:在启动labelme时也可以指定很多参数,比如 --flags可以启动时指定有哪些类别,具体不在赘述,感兴趣的读者自行搜索)

bash 复制代码
labelme --flags F:\python\yolo系列\yolov1\flags.txt

之后OpenDir打开图片所在的文件夹路径,然后鼠标右键Create Rectangle夸夸框就完事了,之后会save为json格式的文件。(把自动保存打开的话会保存到图片的路径下如图:随便标了十五张)

如何你有仔细看过YOLOV1的论文会发现json根本不是我们训练所需要的格式,json多了很多无用的信息,甚至Rectangle也只标记了左上和右下两个点。别慌,我们用脚本转化一下:

python 复制代码
import json
import os


def convert(img_size, box):
    x1 = box[0]
    y1 = box[1]
    x2 = box[2]
    y2 = box[3]

    center_x = (x1 + x2) * 0.5 / img_size[0]
    center_y = (y1 + y2) * 0.5 / img_size[1]
    w = abs((x2 - x1)) * 1.0 / img_size[0]
    h = abs((y2 - y1)) * 1.0 / img_size[1]

    return (center_x, center_y, w, h)


def decode_json(jsonfloder_path, json_name):
    txt_name = jsonfloder_path + json_name[0:-5] + '.txt'
    txt_file = open(txt_name, 'w')  # te files

    json_path = os.path.join(json_folder_path, json_name)
    data = json.load(open(json_path, 'r'))

    img_w = data['imageWidth']  # json是一个字典的形式
    img_h = data['imageHeight']
    for i in data['shapes']:

        if (i['shape_type'] == 'rectangle'):

            x1 = int(i['points'][0][0])
            y1 = int(i['points'][0][1])
            x2 = int(i['points'][1][0])
            y2 = int(i['points'][1][1])
            if x1 < 0 or x2 < 0 or y1 < 0 or y2 < 0:
                continue
            else:
                bb = (x1, y1, x2, y2)
                bbox = convert((img_w, img_h), bb)

            ## 这里标签要对其
            if i['label'] == "person":
                 txt_file.write("0 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "plane":
                 txt_file.write("1 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "dog":
                 txt_file.write("2 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "cat":
                 txt_file.write("3 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "car":
                 txt_file.write("4 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "horse":
                 txt_file.write("5 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "can":
                 txt_file.write("6 " + " ".join([str(a) for a in bbox]) + '\n')
            elif i['label'] == "train":
                 txt_file.write("7 " + " ".join([str(a) for a in bbox]) + '\n')


if __name__ == "__main__":

    json_folder_path = r'F:\python\yolo系列\yolov1\images'        # json的path
    json_names = os.listdir(json_folder_path)  # file name
    for json_name in json_names:  # output all files
        print(json_name)
        if json_name[-5:] == '.json':  # just work for json files
            decode_json(json_folder_path, json_name)

不出意外的话会得到如下图所示的txt标签,这才是训练模型所需要的格式

相关推荐
美狐美颜SDK开放平台4 分钟前
直播APP集成美颜SDK,如何梳理第三方组件的数据权限?
开发语言·人工智能·深度学习·音视频·第三方美颜sdk
沉下心来学鲁班7 分钟前
具身智能进阶:让 MicroDuck 踩着高跷走路
人工智能·python·机器人
紧跟先前的步伐9 分钟前
Go AI Agent 实战 08|HTTP 模型 API 的工作原理与请求流程
人工智能·http·ai·golang
紧跟先前的步伐13 分钟前
Go AI Agent 实战 07|模型幻觉、能力边界与成本控制
大数据·人工智能·golang
dghongcheng16 分钟前
工业涂装数字化转型:从经验喷涂到数据驱动
人工智能·喷涂·喷漆设备·自动喷涂线·自动喷涂
liuyanqun-parbie17 分钟前
从零设计一个通用智能电话平台:FreeSWITCH + ESL + AI 实战架构
人工智能·架构
文慧的科技江湖18 分钟前
2026年10月21日智慧停车行业早报:番禺把单次封顶从132元砍到58元,同一天黄埔要往下挖59米只放200个车位——收费在往下走,车位在往深处长
人工智能·开源·智慧城市·智慧停车·城市管理·静态交通·停车saas
comedate21 分钟前
【AI】Jev API 接入实战:用 Python 调用 TypeSafe Jev 做结构化判断
人工智能·python·jev·typesafe·快速判断模型
workflower27 分钟前
无人机注册量与飞行量
大数据·网络·人工智能·云计算·汽车·无人机
鶴哥只手遮天27 分钟前
Spring AI Alibaba 深度技术系列-第 05 章 编译与执行引擎:CompiledGraph、GraphRunner与三段式 Executor
java·人工智能·开源