栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

极市打榜平台使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

极市打榜平台使用

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/726219.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号