小菜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

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、跑一阵子就提示内存不足 out of memory
减小batch_size
2、跑一阵子提示
WARNING: non-finite loss, ending training tensor([nan, nan, 0., nan], device=‘cuda:0’)
在这里插入图片描述

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

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

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值