七、yolov8图像标注和模型训练(目标检测)

环境配置方法:点这里

环境配置完毕后,需要进行标注工作和训练任务,以下分两个部分进行。

图片标注

1、按照以下的格式,将图片放入images中。(不限制文件夹路径)

2、然后下载labelme标注工具,链接;如果没有下载到或者没有积分,可以联系我发给你。labelme标注工具的使用可以参考:链接

3、目标检测的话,需要选择创建rectangle。然后就可以直接画矩形框。

3、然后我们把图片分成两个标签进行标注,一种是bad,一种是good。

jsons转txt格式

python 复制代码
import json
import os




def convert(img_size, box):
    dw = 1. / (img_size[0])
    dh = 1. / (img_size[1])
    x = (box[0] + box[2]) / 2.0 - 1
    y = (box[1] + box[3]) / 2.0 - 1
    w = box[2] - box[0]
    h = box[3] - box[1]
    x = abs(x * dw)
    w = abs(w * dw)
    y = abs(y * dh)
    h = abs(h * dh)
    return (x, y, w, h)


def decode_json(json_floder_path, json_name, txt_floder_path, classes):
    txt_name = txt_floder_path + '\\' + json_name[0:-5] + '.txt'
    txt_file = open(txt_name, 'w')

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

    img_w = data['imageWidth']
    img_h = data['imageHeight']

    for i in data['shapes']:

        label_name = i['label']
        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])

            bb = (x1, y1, x2, y2)
            bbox = convert((img_w, img_h), bb)
            txt_file.write(str(classes[label_name]) + " " + " ".join([str(a) for a in bbox]) + '\n')

print('json to txt over!')


if __name__ == "__main__":

    json_floder_path = 'E:\\WDX\\CODE\\python\\TOOL\\FPC\\jsons'
    txt_floder_path = 'E:\\WDX\\CODE\\python\\TOOL\\FPC\\labels'
    classes = {'bad': 0, 'good': 1}  # 多少类就写多少
    json_names = os.listdir(json_floder_path)
    for json_name in json_names:
        decode_json(json_floder_path, json_name, txt_floder_path, classes)

模型训练

1、在datasets文件夹下创建文件夹FPC-det,将images文件夹和labels文件夹放在其中。

2、然后在下面文件夹中增加ymal文件(可复制其他的,改一下里面路径就可以)

3、在detect文件夹下找到train文件,打开修改以下内容。

4、另外找到default.ymal文件,修改epochs,batch和workers根据显卡,自己调整。

5、然后右击train.py文件,运行。

6、训练完成,会生成best.pt;至此,检测模型训练完成

相关推荐
沃达德软件2 天前
智慧无人机图像识别分析技术
人工智能·目标检测·计算机视觉·目标跟踪·视觉检测·无人机
William一直在路上2 天前
把轻量化 YOLO 模型部署到你的手机上
yolo·智能手机
迪菲赫尔曼2 天前
【基础篇 11】把官方源码放到服务器:版本、解压层级和安装位置,一次弄清楚
运维·服务器·开发语言·人工智能·python·yolo·目标检测
迪菲赫尔曼2 天前
【基础篇 12】把环境与源码接起来:检查 GPU,再安装服务器上的项目
运维·服务器·开发语言·人工智能·python·yolo·目标检测
yyk333243 天前
YOLOv4算法
人工智能·yolo·目标跟踪
陈嘿萌3 天前
ACM MM 2026|告别密集交互!ProtoHGF-Net:基于原型超图的RGBT目标检测新范式
图像处理·人工智能·深度学习·目标检测·计算机视觉·学术研究与理论基础
pjj198543 天前
YOLO 目标检测算法系列梳理:从 V1 到 V5 的原理演进
算法·yolo·目标检测
爱吃火鸡面呀3 天前
YOLOv2、YOLOv3、YOLOv4、YOLOv5 全面对比与总结
yolo
微尘hjx3 天前
【ByteTrack 04】多轨迹算法ByteTrack改进点
算法·yolo·目标检测·目标跟踪·bytetrack·ultralytics·车跟踪
fl1768314 天前
工业玻璃不同形状类别玻璃检测数据集VOC+YOLO格式1012张4类别
人工智能·yolo·机器学习