windows下使用yolov3-tiny训练数据

配置环境

在这里插入图片描述

  1. 查看电脑GPU版本
    在这里插入图片描述
  2. 安装pytorch对应cuda 10.1
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.doubanio.com/simple --user

在这里插入图片描述
3. 配置训练数据
使用voc格式

数据集来自安全帽数据
4. 训练代码
链接
5. 训练数据配置先运行makeTxt.py,再运行voc_label.py(原作者voc_label.py处理安全帽数据爆GBK错误,这是修改后的源码)

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
 
sets = ['train', 'test','val']
 
classes = ["hat","person"]
 
 
def convert(size, box):
    dw = 1. / size[0]
    dh = 1. / 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
    return (x, y, w, h)
 
 
def convert_annotation(image_id):
    in_file = open('data/Annotations/%s.xml' % (image_id),encoding = 'UTF-8')
    out_file = open('data/labels/%s.txt' % (image_id), '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)
 
    for obj in root.iter('object'):
        difficult = obj.find('difficult').text
        cls = obj.find('name').text
        if cls not in classes or int(difficult) == 1:
            continue
        cls_id = classes.index(cls)
        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')
 
 
wd = getcwd()
print(wd)
for image_set in sets:
    if not os.path.exists('data/labels/'):
        os.makedirs('data/labels/')
    image_ids = open('data/ImageSets/%s.txt' % (image_set),encoding = 'UTF-8').read().strip().split()
    list_file = open('data/%s.txt' % (image_set), 'w')
    for image_id in image_ids:
        list_file.write('data/images/%s.jpg\n' % (image_id))
        convert_annotation(image_id)
    list_file.close()

  1. 删除原训练数据无关文件
    在这里插入图片描述
  2. 运行训练命令(原作者命令有错,更改如下)
python train.py --data data/rbc.data --cfg cfg/yolov3-tiny.cfg --epochs 100

运行出错缺啥库就安装啥。

  1. 网吧CUDA内存报错。。。。发现cfg没改。
CUDA out of memory. Tried to allocate 1.15 GiB (GPU 0; 5.00 GiB total capaci

在这里插入图片描述
在这里插入图片描述

  1. 1 epoch
    在这里插入图片描述
    在这里插入图片描述
  2. 测试samples
python detect.py --data-cfg data/rbc.data --cfg cfg/yolov3-tiny.cfg --weights weights/best.pt

跑了一遍,效果能看见,结果不太好,网费有点贵,就不跑了。
在这里插入图片描述

工具包

需要将JPEGImages的图片复制到一份到images,为节省内存我删了。
网吧专用代码包
在这里插入图片描述

本次体验花费网费

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智能视界探索者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值