赞
踩
地址: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,大家一起来讨论吧!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。