只要总结一些出现的错误

一、

出现

 Scanning 'datasets/Helmet/train_list.cache' images and labels... 0 found, 71 missing, 0 empty, 0 co

同时最后还出现

No labels in datasets/Helmet/images/train.cache. Can not train without labels.

这是指根据指定的地址找不到labels文件,也就是.txt文件。

标签本来是.xml格式,但yolo模型需要的是txt格式,所以读取的时候文件需要是txt格式,否则也会读取错误。用vco2yolo这个脚本能实现转换。地址不对最好改地址,程序不好改,地址好改。

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
import random
from shutil import copyfileclasses = ["gas"]
# classes=["ball"]TRAIN_RATIO = 70def clear_hidden_files(path):dir_list = os.listdir(path)for i in dir_list:abspath = os.path.join(os.path.abspath(path), i)if os.path.isfile(abspath):if i.startswith("._"):os.remove(abspath)else:clear_hidden_files(abspath)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('VOCdevkit/VOC2007/Annotations/%s.xml' % image_id)out_file = open('VOCdevkit/VOC2007/YOLOLabels/%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: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')in_file.close()out_file.close()wd = os.getcwd()
wd = os.getcwd()
data_base_dir = os.path.join(wd, "VOCdevkit/")
if not os.path.isdir(data_base_dir):os.mkdir(data_base_dir)
work_sapce_dir = os.path.join(data_base_dir, "VOC2007/")
if not os.path.isdir(work_sapce_dir):os.mkdir(work_sapce_dir)
annotation_dir = os.path.join(work_sapce_dir, "Annotations/")
if not os.path.isdir(annotation_dir):os.mkdir(annotation_dir)
clear_hidden_files(annotation_dir)
image_dir = os.path.join(work_sapce_dir, "JPEGImages/")
if not os.path.isdir(image_dir):os.mkdir(image_dir)
clear_hidden_files(image_dir)
yolo_labels_dir = os.path.join(work_sapce_dir, "YOLOLabels/")
if not os.path.isdir(yolo_labels_dir):os.mkdir(yolo_labels_dir)
clear_hidden_files(yolo_labels_dir)
yolov5_images_dir = os.path.join(data_base_dir, "images/")
if not os.path.isdir(yolov5_images_dir):os.mkdir(yolov5_images_dir)
clear_hidden_files(yolov5_images_dir)
yolov5_labels_dir = os.path.join(data_base_dir, "labels/")
if not os.path.isdir(yolov5_labels_dir):os.mkdir(yolov5_labels_dir)
clear_hidden_files(yolov5_labels_dir)
yolov5_images_train_dir = os.path.join(yolov5_images_dir, "train/")
if not os.path.isdir(yolov5_images_train_dir):os.mkdir(yolov5_images_train_dir)
clear_hidden_files(yolov5_images_train_dir)
yolov5_images_test_dir = os.path.join(yolov5_images_dir, "val/")
if not os.path.isdir(yolov5_images_test_dir):os.mkdir(yolov5_images_test_dir)
clear_hidden_files(yolov5_images_test_dir)
yolov5_labels_train_dir = os.path.join(yolov5_labels_dir, "train/")
if not os.path.isdir(yolov5_labels_train_dir):os.mkdir(yolov5_labels_train_dir)
clear_hidden_files(yolov5_labels_train_dir)
yolov5_labels_test_dir = os.path.join(yolov5_labels_dir, "val/")
if not os.path.isdir(yolov5_labels_test_dir):os.mkdir(yolov5_labels_test_dir)
clear_hidden_files(yolov5_labels_test_dir)train_file = open(os.path.join(wd, "yolov7_train.txt"), 'w')
test_file = open(os.path.join(wd, "yolov7_val.txt"), 'w')
train_file.close()
test_file.close()
train_file = open(os.path.join(wd, "yolov7_train.txt"), 'a')
test_file = open(os.path.join(wd, "yolov7_val.txt"), 'a')
list_imgs = os.listdir(image_dir)  # list image files
prob = random.randint(1, 100)
print("Probability: %d" % prob)
for i in range(0, len(list_imgs)):path = os.path.join(image_dir, list_imgs[i])if os.path.isfile(path):image_path = image_dir + list_imgs[i]voc_path = list_imgs[i](nameWithoutExtention, extention) = os.path.splitext(os.path.basename(image_path))(voc_nameWithoutExtention, voc_extention) = os.path.splitext(os.path.basename(voc_path))annotation_name = nameWithoutExtention + '.xml'annotation_path = os.path.join(annotation_dir, annotation_name)label_name = nameWithoutExtention + '.txt'label_path = os.path.join(yolo_labels_dir, label_name)prob = random.randint(1, 100)print("Probability: %d" % prob)if (prob < TRAIN_RATIO):  # train datasetif os.path.exists(annotation_path):train_file.write(image_path + '\n')convert_annotation(nameWithoutExtention)  # convert labelcopyfile(image_path, yolov5_images_train_dir + voc_path)copyfile(label_path, yolov5_labels_train_dir + label_name)else:  # test datasetif os.path.exists(annotation_path):test_file.write(image_path + '\n')convert_annotation(nameWithoutExtention)  # convert labelcopyfile(image_path, yolov5_images_test_dir + voc_path)copyfile(label_path, yolov5_labels_test_dir + label_name)
train_file.close()
test_file.close()

若就是txt格式,则在yolov7-main/utils/datasets.py文件中搜索(ctrl+f)sa,sb可以找到这句话

def img2label_paths(img_paths):# Define label paths as a function of image pathssa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep  # /images/, /labels/ substringsreturn ['txt'.join(x.replace(sa, sb, 1).rsplit(x.split('.')[-1], 1)) for x in img_paths]

这句代码就是在已知images时怎么生成TXT的地址,意思就是把images地址中的‘images’换成'labels'进行搜索,可以根据自己的数据集制作方法修改这段代码,让他能顺利找到labels的地址。

yolov7训练自己的数据集相关推荐

  1. YOLOv7训练自己的数据集(超详细)

       目录 一.准备深度学习环境 二. 准备自己的数据集 1.创建数据集 2.转换数据格式 3.配置文件 三.模型训练 1.下载预训练模型 2.训练 四.模型测试 五.模型推理 YOLOv7训练自己的 ...

  2. 利用yolov7训练自己的数据集; yolov7的安装与使用 ; yolov7源码解读

    *免责声明: 1\此方法仅提供参考 2\搬了其他博主的操作方法,以贴上路径. 3* 场景一:Anconda环境基本操作 场景二:yolov7的使用 场景三:yolov7训练自己的数据集 场景四:实用工 ...

  3. 目标检测算法——YOLOv7训练自己的数据集(保姆级教程)

    >>>深度学习Tricks,第一时间送达<<< 目录 YOLOv7训练自己的数据集(保姆级教程): 一.YOLOv7源代码下载 二.安装深度学习环境 三.准备自己的 ...

  4. YOLOv7训练自己的数据集(口罩检测)

    YOLOv7训练自己的数据集(口罩检测) 前言 前提条件 实验环境 项目结构 制作自己的数据集 数据集目录结构 训练自己的数据集 VOC格式数据集转换成YOLO格式数据集 修改cfg配置 新建一个my ...

  5. YOLO | 用YOLOv7训练自己的数据集(超详细版)

    一.环境设置 本文环境设置:Ubuntu (docker) pytorch-gpu 1.远程Ubuntu新建一个新的docker 容器 以下命令是创建一个名称为torch_yolo的gpu容器.如果没 ...

  6. win10 安装yolov7 训练自己的数据集

    1.安装 https://www.pudn.com/news/62ddf431864d5c73acfb1a09.html 下载yolov7源码 yolov7 修改requirements.txt 修改 ...

  7. YOLOV7训练TT100K交通标识符数据集

       <临江仙>                                                         作者:缠中说禅                 浊水倾波三 ...

  8. 使用YOLOV7训练BDD100K数据集(数据格式转化+训练全流程)

    目录 1. 前言 1.1 BDD100K数据集详细介绍(此节可跳过) 1.2 BDD100K数据集简要介绍 1.3 下载必要文件 2. bdd100k转yolo数据集格式 2.1 为什么要转格式 2. ...

  9. YOLOv7训练自己的VOC数据集

    YOLOv7源码:https://github.com/WongKinYiu/yolov7 本文是对YOLOV7训练自己的yolo数据集的扩展,具体训练等步骤不再详细赘述,遇到看不懂的请移步YOLOV ...

  10. yolov7_obb在WIN10下训练自己的数据集

    首先获取这位大神的GitHub代码:yolov7_obb+TensorRT+WIN10_Mrs.Gril的博客-CSDN博客 一.配置环境,为了方便大家尽量少的遇到配置问题,下面给出我的环境. 我的C ...

最新文章

  1. CF888G Xor-MST (01字典树+MST)
  2. java nio 强制关闭_netty 处理远程主机强制关闭一个连接
  3. 计算机社团活动丰富多彩,描写社团丰富多彩的句子
  4. 3.5 定向搜索的误差分析
  5. PNG文件格式具体解释
  6. 强连通分量(tarjan求强连通分量)
  7. 解决NuGet加载或下载资源慢的问题
  8. mongodb和mysql创建表_mongodb入门命令-创建表数据(二)
  9. 大疆2018网申之机器学习算法工程师笔试题B卷
  10. IT软件下载地址大全
  11. 屏幕小于6英寸的手机_2019小屏手机有哪些 8款6英寸以下小屏全面屏手机推荐 (全文)...
  12. LinkIQ 福禄克全新的以太网电缆,网络和PoE测试仪LIQ-100 LIQ-KIT
  13. kali下使用phpstudy
  14. Linux学习(1)-常用快捷键、文件管理和查询 阅读目录
  15. 讯飞免费获取时长操作步骤
  16. 高德地图--SDK集成--定位功能 地图定位搜索
  17. avue中地图使用实现地图的联动_7.1地图组件
  18. `Algorithm-Solution` `LeetCode` 6305. 二进制矩阵中翻转最多一次使路径不连通
  19. win10下docker搭建fastDFS
  20. 将任意一个对象中的所有String类型的成员变量所对应的字符串内容中的“a“改为“b“(封装成一个方法)

热门文章

  1. 数理统计复习笔记九——正态性检验
  2. ppt手动放映怎么设置_PPT如何设置幻灯片自动播放免除手动一张一张的点击
  3. easypoi 批量导出_浅谈easypoi快速实现excel批量导入
  4. 阿里 酷家乐:实习生面试
  5. 微信小程序实现退款,Java版。
  6. 2020最新教师资格证《中学综合素质》必考知识点大全
  7. 反射中的SetValue和GetValue
  8. Java之Joda工具包处理时间的7点总结分享
  9. python如何输出整数_如何根据Python中的输入输出整数和浮点值?
  10. 修改+首选+dns服务器地址,首选dns服务器地址怎么设置