采坑:
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文件,并执行

import os
import randomtrainval_percent = 0.1
train_percent = 0.9
xmlfilepath = 'data/Annotations'
txtsavepath = 'data/ImageSets'
total_xml = os.listdir(xmlfilepath)num = len(total_xml)
list = range(num)
tv = int(num * trainval_percent)
tr = int(tv * train_percent)
trainval = random.sample(list, tv)
train = random.sample(trainval, tr)ftrainval = open('data/ImageSets/trainval.txt', 'w')
ftest = open('data/ImageSets/test.txt', 'w')
ftrain = open('data/ImageSets/train.txt', 'w')
fval = open('data/ImageSets/val.txt', 'w')for i in list:name = total_xml[i][:-4] + '\n'if i in trainval:ftrainval.write(name)if i in train:ftest.write(name)else:fval.write(name)else:ftrain.write(name)ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

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: /home/zyc/anaconda3/envs/yolov3-master/data/train.txt
val: /home/zyc/anaconda3/envs/yolov3-master/data/val.txt
test: /home/zyc/anaconda3/envs/yolov3-master/data/test.txt  # number of classes
nc: 1# class names
names: [ 'RBC' ]

最后在train.py

YOLOV3 --BUG---No labels in D:\yolov5\train_data\train.cache. Can not train without labels.相关推荐

  1. 训练yolov7报错AssertionError: train: No labels in XX\train.cache. Can not train without labels

    原因:自己的数据集文件夹和dataset中的数据集名称不同. 代码中要求的文件名是Images和Labels,可能自己命名的是image和label 参考:https://code84.com/381 ...

  2. 解决YOLOv5训练自己的数据集出现No labels in path\train.cache问题

    不知道是第几次训练了,最开始跑也出现了这个问题,当时怎么解决的时隔了几个月又完全忘了,还好翻看了几个博客后回忆了起来 我自己的数据集的格式是VOC格式,如下图 若没有对数据集进行划分,则使用makeT ...

  3. AssertionError: train: No labels found in ****\train.cache报错

    解决方法:看了很作解决方案,包括更改dataloder.py文件. 最终将自己的数据集中存放图片的文件夹改名为images,存放标签的文件夹改名为labels问题得以解决.

  4. 解决yolov5不能使用 tensorboard --logdir=runs/train的问题

    ValueError: Duplicate plugins for name projector 这是 报错类型 解决这个的方法就是删除一个文件 找到你自己的环境,然后找lib文件夹,然后找文件夹si ...

  5. win10+cpu+yolov5实现安全帽绝缘鞋绝缘手套等的检测

    学习目标: win10+cpu+yolov5实现安全帽绝缘鞋绝缘手套等的检测 学习内容: 搭建 yolov5环境 找到合适的数据集训练 跑跑看看效果 一.搭建yolov5环境: 参考win10部署yo ...

  6. yolov5训练voc数据集

    1.数据集 下载好voc数据集,以2007为例,把数据集(VOCtrainval_06-Nov-2007和VOCtest_06-Nov-2007)都解压同一个文件夹里,记住解压后的图片是从000001 ...

  7. 训练自己的yolo v5模型出现AssertionError: train: No labels(已解决,亲测有效)

    问题描述:利用yolo v5代码训练自己的数据时出现AssertionError: train: No labels in autodl-tmp/PyQt5-YOLOv5-5.0/VOC2007/da ...

  8. yolov5 c++ 识别工件

    记录一下训练yolov5识别工件,并用c++调用模型的过程 操作系统:Ubuntu18.04 训练过程 准备数据 使用网站https://app.roboflow.com/cv-rbynj进行数据标注 ...

  9. 【深度学习】【Python】【Widerface数据集】 转VOC格式,VOC 转YOLOv5格式,YOLOv5训练WiderFace数据集,检查yolo labels对不对

    文章目录 Widerface数据集转VOC格式 VOC 转YOLO格式 数据集的imageslisttxt YOLOv5训练 检查yolo labels对不对 并行训练 Widerface数据集转VO ...

最新文章

  1. 80个招聘求职网站整理,不管招聘or求职,看这个就够了!
  2. (gnome-ssh-askpass:609): Gtk-WARNING **: cannot open display:
  3. MongoDB操作(.net)
  4. 点击图片放大,再点击缩小的代码段
  5. linux命令0424
  6. 阿里资深技术专家:如何快速成长为技术大牛?
  7. 25岁男生要有多少存款才能让女友满意?
  8. 堆和栈的区别(经典干货)
  9. yum安装jdk1.8
  10. 樊昌信 通信原理第七版 第九章思考题
  11. 6-2 递归方法:汉诺塔问题 (10 分)
  12. 计算机设备图形符号,常用一次设备的图形符号和文字符号
  13. AltiumDesigner之Logo制作
  14. 14考虑电动汽车可调度潜力的充电站两阶段市场投标策略
  15. 产品经理如何自学入门?
  16. boost库的安装和使用
  17. xxl-job(大众点评-许雪里)
  18. 1.1.1.1校园网_高一数学上册必修1第一章知识点:1.1.1集合的含义与表示
  19. OSChina 周四乱弹 ——金毛如何实现部门自助化管理案例图
  20. 正弦波和方波发生器的设计

热门文章

  1. boost::regex模块实现config_info 来打印正则表达式库配置信息的测试程序
  2. boost::mpl模块实现count相关的测试程序
  3. boost::math模块非有限环回的基本测试
  4. boost::math::arcsine用法的测试程序
  5. boost::log模块实现loging到 syslog 服务器的示例
  6. boost::hana::remove_at用法的测试程序
  7. Boost:计算一些tail统计数据,插入数据,更新数据
  8. ITK:按标量乘以图像
  9. DCMTK:类DcmOther64bitVeryLong的测试程序
  10. DCMTK:将DICOM文件的内容转换为XML格式