yolov5半自动标注

yolov5手动标注太累,可以先标注一部分图片,训练个模型出来,然后在用模型推理图片,把结果保存起来,转为labelme格式,在微调
代码:

import os
import json
import cv2
import base64

version = '4.5.13'
flags = {}

for file in os.listdir('data/'):
    if 'png' in file:
        dic = {}
        dic['version'] = version
        dic['flags'] = flags
        dic['shapes'] = []
        #print(file)  1090.png
        #print('data/{}'.format(file)) data/1090.png
        #print(file.split('.')[0]) 1090

        img = cv2.imread('data/{}'.format(file))
        imageHeight, imageWidth, _ = img.shape
        with open('data/{}.txt'.format(file.split('.')[0])) as f:
            #print('data/{}.txt'.format(file.split('.')[0])) data/1090.txt
            datas = f.readlines()
            for data in datas:
                #print(data)  #1 0.8191 0.203355 0.130203334 0.17
                shape = {}
                #print(int(data[:2]))
                #print(int(data[:2]) == 2)
                if str(data[:2]) == '0 ':
                    print("000000")
                    shape['label'] = '0'
                    data = data.strip().split(' ')
                    x = float(data[1]) * imageWidth
                    y = float(data[2]) * imageHeight
                    w = float(data[3]) * imageWidth
                    h = float(data[4]) * imageHeight
                    x1 = x - w / 2
                    y1 = y - h / 2
                    x2 = x1 + w
                    y2 = y1 + h
                    shape['points'] = [[x1, y1], [x2, y2]]
                    shape['shape_type'] = 'rectangle'
                    shape['flags'] = {}
                    dic['shapes'].append(shape)
                if str(data[:2]) == '1 ':
                    print("111111")
                    shape['label'] = '1'
                    data = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值