国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題

這篇具有很好參考價(jià)值的文章主要介紹了一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

YOLOv5 訓(xùn)練找不到標(biāo)簽, No labels found in /path/train.cache 問(wèn)題的解決方法(親測(cè)可用)

?? 網(wǎng)上絕大部分教程所述解決方法都不靠譜,也沒(méi)有分析問(wèn)題發(fā)生的原因,本文徹底解決了YOLOv5訓(xùn)練時(shí)找不到標(biāo)簽,出現(xiàn) No labels found in /path/train.cache 的問(wèn)題!希望通過(guò)本文,在配置環(huán)境的過(guò)程中,為各位解決一些不必要的麻煩。——?? Sylvan Ding

版本 系統(tǒng)
YOLOv5 v6.1 Linux

出現(xiàn) No labels found 的原因主要有兩點(diǎn),一方面是因?yàn)榫W(wǎng)上下載的數(shù)據(jù)集只提供了其專屬的標(biāo)簽格式,需要轉(zhuǎn)換成YOLOv5格式的標(biāo)簽;另一方面則是因?yàn)轫?xiàng)目目錄的組織問(wèn)題。本文重點(diǎn)探討后者,即由項(xiàng)目目錄的組織問(wèn)題而引起的找不到標(biāo)簽的問(wèn)題,這類問(wèn)題網(wǎng)上的解答較少。

標(biāo)簽格式有誤

網(wǎng)上下載的數(shù)據(jù)集大多數(shù)只提供 VOC 格式的 .xml 標(biāo)記文件,存放于 annotations 文件夾中,或是其他格式的標(biāo)記文件。此時(shí),就應(yīng)當(dāng)先編寫程序,將標(biāo)簽轉(zhuǎn)換成YOLOv5所需格式。

YOLOv5標(biāo)簽格式說(shuō)明

After using a tool like Roboflow Annotate to label your images, export your labels to YOLO format, with one *.txt file per image (if no objects in image, no *.txt file is required). The *.txt file specifications are:

  • One row per object
  • Each row is class x_center y_center width height format.
  • Box coordinates must be in normalized xywh format (from 0 - 1). If your boxes are in pixels, divide x_center and width by image width, and y_center and height by image height.
  • Class numbers are zero-indexed (start from 0).

一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題

一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題

convert VOC to YOLOv5

VOC到Y(jié)OLOv5格式轉(zhuǎn)換,可以參考yolov5/data/VOC.yaml中,36行convert_label(),其中convert_box()提供了坐標(biāo)轉(zhuǎn)換功能。

def convert_label(path, lb_path, year, image_id):
    def convert_box(size, box):
        dw, dh = 1. / size[0], 1. / size[1]
        x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2]
        return x * dw, y * dh, w * dw, h * dh

    in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml')
    out_file = open(lb_path, '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'):
        cls = obj.find('name').text
        if cls in yaml['names'] and not int(obj.find('difficult').text) == 1:
            xmlbox = obj.find('bndbox')
            bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')])
            cls_id = yaml['names'].index(cls)  # class id
            out_file.write(" ".join([str(a) for a in (cls_id, *bb)]) + '\n')

注:convert_box(size, box), bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ('xmin', 'xmax', 'ymin', 'ymax')])

?? 具體實(shí)現(xiàn)細(xì)節(jié)可以參考其他博主的文章,這類文章比較多。

其他格式轉(zhuǎn)換成YOLOv5

對(duì)其他不同格式的標(biāo)記文件,需要手動(dòng)編寫程序以轉(zhuǎn)換成YOLOv5格式標(biāo)記。

yolov5/utils/general.py中的一些函數(shù)也許能給您提供一些啟發(fā),如xyxy2xywh(), xywh2xyxy()… 他們負(fù)責(zé)坐標(biāo)格式的轉(zhuǎn)換。

項(xiàng)目目錄的結(jié)構(gòu)有誤

在得到正確的標(biāo)簽格式后,仍出現(xiàn)No labels found錯(cuò)誤,這時(shí)考慮項(xiàng)目目錄組織結(jié)構(gòu)出現(xiàn)錯(cuò)誤。

正確的目錄結(jié)構(gòu)

coco

?? 先放結(jié)論,以COCO為例,正確的目錄結(jié)構(gòu)應(yīng)當(dāng)為:

# path example
../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label
# yolov5/data/coco.yaml
path: ../datasets/coco  # dataset root dir
train: train2017.txt  # train images (relative to 'path')
val: val2017.txt  # val images
test: test-dev2017.txt

一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題

  • datasets文件夾和yolov5文件夾同級(jí),datasets下建立各個(gè)數(shù)據(jù)集文件。以coco為例,images文件夾直接存放所有圖片數(shù)據(jù)labels文件夾直接存放圖片對(duì)應(yīng)的*.txt標(biāo)記文件。

    .
    ├── images
    │   ├── 20151127_114556.jpg
    │   ├── 20151127_114946.jpg
    │   └── 20151127_115133.jpg
    ├── labels
    │   ├── 20151127_114556.txt
    │   ├── 20151127_114946.txt
    │   └── 20151127_115133.txt
    
  • 注意,imageslabels文件夾的命名均不能改成別的!原因稍后再說(shuō)。

  • train2017.txt, val2017.txt,test-dev2017.txt中存放訓(xùn)練集、驗(yàn)證集、測(cè)試集的圖片文件路徑,其內(nèi)容如下所示:

    ./images/20151127_114556.jpg
    ./images/20151127_114946.jpg
    ./images/20151127_115133.jpg
    
coco128

如果你想用coco128的文件組織形式:

# yolov5/data/coco128.yaml
path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

datasets目錄結(jié)構(gòu)應(yīng)當(dāng)為:

coco128
├── images
│   ├── test
│   │   └── 20151127_115133.jpg
│   └── train2017
│       └── 20151127_114556.jpg
└── labels
    ├── test
    │   └── 20151127_115133.txt
    └── train2017
        └── 20151127_114556.txt
  • 注意,imageslabels文件夾的命名均不能改成別的!
  • imageslabels文件夾內(nèi),創(chuàng)建相互對(duì)應(yīng)的文件夾用來(lái)存放訓(xùn)練集、驗(yàn)證集、測(cè)試集,文件夾名字要一致,沒(méi)有要求,但需要在coco128.yaml中設(shè)置。

錯(cuò)誤原因探究

yolov5/utils/datasets.py 391行 img2label_paths(img_paths) 定義了圖片路徑到標(biāo)簽路徑的映射,447行 self.label_files = img2label_paths(self.im_files) # labels 調(diào)用 img2label_paths() 以生成 label_files.

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

YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/.

即YOLOv5會(huì)自動(dòng)將圖片路徑../datasets/coco128/images/*.jpg更改為../datasets/coco128/labels/*.txt,以尋找labels路徑!

如何解決問(wèn)題?

在上述 label_files 賦值后,打印 label_files,我們就能得到標(biāo)記的路徑,再根據(jù)打印出的路徑修改自己項(xiàng)目的文件路徑,方能解決一切問(wèn)題!

一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題

參考文獻(xiàn)

Cannot find labels in train.cache custom dataset COCO #6158文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-453232.html

到了這里,關(guān)于一文徹底解決YOLOv5訓(xùn)練找不到標(biāo)簽問(wèn)題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 解決YOLOv5訓(xùn)練自己的數(shù)據(jù)集出現(xiàn)No labels in path\train.cache問(wèn)題

    解決YOLOv5訓(xùn)練自己的數(shù)據(jù)集出現(xiàn)No labels in path\train.cache問(wèn)題

    不知道是第幾次訓(xùn)練了,最開(kāi)始跑也出現(xiàn)了這個(gè)問(wèn)題,當(dāng)時(shí)怎么解決的時(shí)隔了幾個(gè)月又完全忘了,還好翻看了幾個(gè)博客后回憶了起來(lái) 我自己的數(shù)據(jù)集的格式是VOC格式,如下圖 ?若沒(méi)有對(duì)數(shù)據(jù)集進(jìn)行劃分,則使用makeTXT.py對(duì)數(shù)據(jù)集進(jìn)行劃分,若數(shù)據(jù)集已經(jīng)劃分,則可忽略這一步

    2024年02月12日
    瀏覽(43)
  • YOLOv5訓(xùn)練過(guò)程中遇到該問(wèn)題的解決方法ValueError: The requested array has an inhomogeneous shape after 1 dimensions

    YOLOv5訓(xùn)練過(guò)程中遇到該問(wèn)題的解決方法ValueError: The requested array has an inhomogeneous shape after 1 dimensions

    YOLOv5訓(xùn)練時(shí)遇到問(wèn)題ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions.可以參考以下解決方案 問(wèn)題分析: 數(shù)組append時(shí)前后數(shù)組的shape不一致,當(dāng)時(shí)我在自己遇到問(wèn)題時(shí)也沒(méi)有找到解決方法,最后發(fā)現(xiàn)是訓(xùn)練集中有一個(gè)圖片名字太長(zhǎng)導(dǎo)致

    2024年02月11日
    瀏覽(22)
  • YOLOV5 訓(xùn)練好模型測(cè)試時(shí)出現(xiàn)問(wèn)題:AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘的解決方法

    YOLOV5 訓(xùn)練好模型測(cè)試時(shí)出現(xiàn)問(wèn)題:AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘的解決方法

    在使用YOLOV5 訓(xùn)練好模型測(cè)試時(shí)出現(xiàn)問(wèn)題:AttributeError: ‘Upsample’ object has no attribute \\\'recompute_scale_factor’的快速解決方法。 解決方法一: 有些博主說(shuō)降低torchhe和torchvision版本,比如上圖所示我的torch版本1.11.0 torchvision版本0.10.2,torch版本降低到版本1.9.1,torchvision版本降低到版

    2024年02月12日
    瀏覽(25)
  • yolov5訓(xùn)練自己的數(shù)據(jù)集問(wèn)題排除

    D:ProgramDataAnaconda3envsyolov5python.exe D:/yxt/yolov5-master/train.py Traceback (most recent call last): ? File \\\"D:ProgramDataAnaconda3envsyolov5libsite-packagesgit__init__.py\\\", line 140, in module ? ? refresh() ? File \\\"D:ProgramDataAnaconda3envsyolov5libsite-packagesgit__init__.py\\\", line 127, in refresh ? ? if not Git.refresh(p

    2024年04月11日
    瀏覽(96)
  • yolov5繼續(xù)訓(xùn)練的方法,沒(méi)解決sad

    yolov5繼續(xù)訓(xùn)練的方法,沒(méi)解決sad

    目錄 嘗試1--唯一運(yùn)行成功的 嘗試2 嘗試3 嘗試4--希望最大 嘗試5 后續(xù)成功! 前提 :雖然成功訓(xùn)練完了,但是想到以后萬(wàn)一訓(xùn)練輪數(shù)太少?zèng)]收斂,怎么在已經(jīng)訓(xùn)練好的模型基礎(chǔ)上繼續(xù)進(jìn)行多輪epoch的訓(xùn)練?;蛘哂?xùn)練著突然中斷,之前訓(xùn)練的豈不是功虧一簣。 起因 :在kaggle上訓(xùn)

    2024年02月05日
    瀏覽(15)
  • YOLOv5訓(xùn)練速度慢的一些解決方法

    YOLOv5訓(xùn)練速度慢的一些解決方法

    ? ? 博主電腦配置是AMD R5 3600,Nvidia RTX3060 12G,16G 3200MHz內(nèi)存,訓(xùn)練數(shù)據(jù)集是自建數(shù)據(jù)集,大約1200張圖片,3個(gè)檢測(cè)目標(biāo)。 ? ? 訓(xùn)練YOLOv5-5.0版本的模型參數(shù)設(shè)置,模型是yolov5s,epoch 150(如果想要更好的mAP@0.5:0.95指標(biāo)可以設(shè)置的更大,博主這個(gè)收斂的太快了就沒(méi)設(shè)太多),bat

    2024年01月16日
    瀏覽(27)
  • 【YOLOv5】一些網(wǎng)上找不到答案的報(bào)錯(cuò)解決方案

    【YOLOv5】一些網(wǎng)上找不到答案的報(bào)錯(cuò)解決方案

    目錄 AssertionError: Label class 4 exceeds nc=4 in /xxxxxx解決方法 原因 解決方法:(以我的情況為例) RuntimeError: result type Float can‘t be cast to the desired output type long int 原因 解決方法 ImportError: libgthread-2.0.so.0: cannot open shared object file: tensorboard :No dashboards are active for the current data set. 問(wèn)題

    2024年02月12日
    瀏覽(25)
  • YOLOV5訓(xùn)練時(shí)P、R、mAP等值均為0的問(wèn)題

    當(dāng)YOLOv5的訓(xùn)練P、R、mAP等指標(biāo)為0時(shí),通常有以下一些原因: 數(shù)據(jù)集質(zhì)量不佳:檢查數(shù)據(jù)集中是否存在較大的類別不平衡或者太多的噪聲。可能需要重新清理數(shù)據(jù)集以確保標(biāo)簽正確且具有可解釋性。 學(xué)習(xí)率過(guò)高或過(guò)低:首先嘗試將學(xué)習(xí)率降低到一個(gè)更合適的水平,并考慮使用

    2024年02月04日
    瀏覽(15)
  • 【Yolov5+Deepsort】訓(xùn)練自己的數(shù)據(jù)集(3)| 目標(biāo)檢測(cè)&追蹤 | 軌跡繪制 | 報(bào)錯(cuò)分析&解決

    【Yolov5+Deepsort】訓(xùn)練自己的數(shù)據(jù)集(3)| 目標(biāo)檢測(cè)&追蹤 | 軌跡繪制 | 報(bào)錯(cuò)分析&解決

    ??前言: 本篇是關(guān)于 如何使用YoloV5+Deepsort訓(xùn)練自己的數(shù)據(jù)集 ,從而實(shí)現(xiàn)目標(biāo)檢測(cè)與目標(biāo)追蹤,并繪制出物體的運(yùn)動(dòng)軌跡。本章講解的為第三部分內(nèi)容:數(shù)據(jù)集的制作、Deepsort模型的訓(xùn)練以及動(dòng)物運(yùn)動(dòng)軌跡的繪制。本文中用到的數(shù)據(jù)集均為自采,實(shí)驗(yàn)動(dòng)物為斑馬魚。 ??環(huán)境

    2024年02月10日
    瀏覽(26)
  • 訓(xùn)練yolov5的那些事之解決:AssertionError: Label class x exceeds nc=x in data/yolov5.yaml. Possible class label

    Yolov5報(bào)錯(cuò): AssertionError: Label class x exceeds nc=x in data/yolov5.yaml. Possible class labels are 0-x-1 File “C:Users1Desktop水表識(shí)別YOLO5yolov5-mastertrain.py”, line 175, in train assert mlc nc, ‘Label class %g exceeds nc=%g in %s. Possible class labels are 0-%g’ % (mlc, nc, opt.data, nc - 1) 找到train文件的175行: 改成這樣

    2024年02月11日
    瀏覽(162)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包