极市打榜平台使用

1 克隆yolov5代码

git clone https://gitee.com/monkeycc/yolov5.git

可以去gitee找代码

2 相关文件

split.py

# _*_ coding:utf-8 _*_
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir , getcwd
from os.path import join
import glob
import sys

classes = {"front_head":0,"side_head":1,"back_head":2,"hand":3,"mobile_phone":4,"person_on_phone":5}
 
def convert(size, box):
 
    dw = 1.0/size[0]
    dh = 1.0/size[1]
    x = (box[0]+box[1])/2.0
    y = (box[2]+box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    x = min(x,1.0)
    w = min(w,1.0)
    y = min(y,1.0)
    h = min(h,1.0)
    return (x,y,w,h)
 
def convert_annotation(path):
    in_file = open(path.replace('.xml','.xml'),encoding="utf-8")
    out_file = open(path.replace('.xml','.txt'),'w')
    tree = ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)
    
    if w == 0 or h == 0:
        print(1)
        return
 
 
    for obj in root.iter('object'):
        name = obj.find('name').text
        cls_id = classes[name]
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
             float(xmlbox.find('ymax').text))
        bb = convert((w,h), b)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')

files = glob.glob('./trainval/*.xml')
 
if __name__ == '__main__':
 
    for file in files:
        convert_annotation(file)

run.sh

cd /project/train/src_repo

cp -r /home/data/720 ./trainval
python split.py && python path.py
cd yolov5
python train.py --batch-size 16 --epochs 500 --data ./data/buy.yaml --hyp ./data/hyps/hyp.scratch.yaml --weight ./yolov5.pt --img 480 --project /project/train/models/ --cfg ./models/yolov5s.yaml

path.py

from glob import glob
from random import randint
files = glob('/projrct/train/src_repo/trainval/*.txt')

train = open('train.txt','w')
val = open('val.txt','w')
for i in files:
    num = randint(1,10)
    name = i.replace('.txt','jpg')
    if num < 8:
        train.write(name + '\n')
    else:
        val.write(name + '\n')

train.close()
val.close()

buy.yaml

# train and val datasets
train: ../train.txt
val: ../val.txt

# number of classes
nc: 6

# classes name
names: ["front_head","side_head","back_head","hand","mobile_phone","person_on_phone"]

3 安装所需要的包

cd yolov5
pip install --index-url https://pypi.douban.com/simple -r requirements.txt

4 运行

bash run.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值
>