当前位置:   article > 正文

小菜YOLOV3训练手记_yolov3不需要写明标签路径吗

yolov3不需要写明标签路径吗

地址:https://github.com/ultralytics/yolov3
官方指导网址:https://github.com/ultralytics/yolov3/wiki/Train-Custom-Data
1、安装环境
最好新建一个anaconda3环境
python:3.7
pytorch:1.5.0
GPU:2080TI
2、图片和标签路径
按这样的方式放图片和标签,images和labels是必须有的,其它可以改,但要保持一致

../coco/images/train2017/000000109622.jpg  # image
../coco/labels/train2017/000000109622.txt  # label
  • 1
  • 2

3、制作归一化标签数据
在这里插入图片描述
标签归一化数据制作代码:
代码要自己修改,我的是修改过的

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
import cv2
import numpy as np
from os.path import join

ocr_train = 'ocr_train'

classes = ["x_bill"]  # 类别自己修改,要和XX.names里的类别一样


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_name,image_zuobiao):
    img = cv2.imread('./data/images/' + image_name)
    img = np.array(img)
    h,w = img.shape[0:2]
    list = image_zuobiao.split(' ')
    minx,maxx,miny,maxy = [list[0],list[2],list[1],list[3]]
    b = [float(minx),float(maxx),float(miny),float(maxy)]
    bb = convert((w, h), b)
    with open('./data/labels/' + image_name.split('.')[0] + '.txt','a',encoding='utf-8') as f:
        f.write('0' + " " + " ".join([str(a) for a in bb]) + '\n')


wd = getcwd()
print(wd)
if not os.path.exists('data/labels/'):
    os.makedirs('data/labels/')
image_ids = open('./data/train_labels.csv').read().strip().split('\n')
for image_id in image_ids:
    if 'ID' in image_id:
        continue
    image_name = image_id.split(',')[0]
    image_zuobiao = image_id.split(',')[1]
    convert_annotation(image_name,image_zuobiao)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

目前遇到的问题
1、跑一阵子就提示内存不足 out of memory
减小batch_size
2、跑一阵子提示
WARNING: non-finite loss, ending training tensor([nan, nan, 0., nan], device=‘cuda:0’)
在这里插入图片描述

不知道原因是什么,先记录一下
补充:后面测试发现,用其它数据没出现这样的问题,可能是我的数据有问题吧

我建了一个QQ群,1080729300,大家一起来讨论吧!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/860393
推荐阅读
  

闽ICP备14008679号