YOLOV3 --BUG---No labels in D:\yolov5\train_data\train.cache. Can not train without labels.
生活随笔
收集整理的這篇文章主要介紹了
YOLOV3 --BUG---No labels in D:\yolov5\train_data\train.cache. Can not train without labels.
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
采坑:
No labels in D:\yolov5\train_data\train.cache. Can not train without labels.
參考:https://blog.csdn.net/qq_44787464/article/details/99736670
解決辦法:
STEP1:
一定要按照這個順序:
新建Annotations(存放voc格式的xml)
新建JPEGImages(存放訓練的圖片)
新建ImageSets ,labels (這兩個文件為空)
將JPEGImages的圖片復制到images中
STEP2:
在工程的根目錄下添加makeTxt.py文件,并執行
?
STEP3:
在工程根目錄下新建voc_label.py,并執行(注意!!!里面的標簽名要改成自己訓練標簽,否則labels里面的txt文件為空)
import xml.etree.ElementTree as ET import pickle import os from os import listdir, getcwd from os.path import joinsets = ['train', 'test','val']################################這里修改為自己的標簽名############### classes = ["RBC"]#我們只是檢測細胞,因此只有一個類別def convert(size, box):dw = 1. / size[0]dh = 1. / size[1]x = (box[0] + box[1]) / 2.0y = (box[2] + box[3]) / 2.0w = box[1] - box[0]h = box[3] - box[2]x = x * dww = w * dwy = y * dhh = h * dhreturn (x, y, w, h)def convert_annotation(image_id):in_file = open('data/Annotations/%s.xml' % (image_id))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').textcls = obj.find('name').textif cls not in classes or int(difficult) == 1:continuecls_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)).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()?
得到labels的具體內容以及data目錄下的train.txt,test.txt,val.txt
STEP4:
創建自己yaml文件,在data目錄下:
RBC.yaml
最后在train.py
?
?
?
?
總結
以上是生活随笔為你收集整理的YOLOV3 --BUG---No labels in D:\yolov5\train_data\train.cache. Can not train without labels.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 朝朝宝只能存入5万吗
- 下一篇: 网络WIFI摄像机方案主控芯片最全介绍