Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error: "no labels found in val set, can not compute metrics without labels" #8791

Closed
1 task done
GxTeo opened this issue Jul 30, 2022 · 23 comments · Fixed by #8806
Closed
1 task done

Validation error: "no labels found in val set, can not compute metrics without labels" #8791

GxTeo opened this issue Jul 30, 2022 · 23 comments · Fixed by #8806
Labels
question Further information is requested

Comments

@GxTeo
Copy link

GxTeo commented Jul 30, 2022

Search before asking

Question

I have checked my annotations and train & validation sets. Everything seems to be fine but I have been getting this warning whenever I want to train my model
image

Additional

No response

@GxTeo GxTeo added the question Further information is requested label Jul 30, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 30, 2022

👋 Hello @GxTeo, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

glenn-jocher commented Jul 30, 2022

@GxTeo 👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. Your dataset has no validation labels or is incorrectly formatted an no validation labels can be found.

Please see our Train Custom Data tutorial for full documentation on dataset setup and all steps required to start training your first model. A few excerpts from the tutorial:

1.1 Create dataset.yaml

COCO128 is an example small tutorial dataset composed of the first 128 images in COCO train2017. These same 128 images are used for both training and validation to verify our training pipeline is capable of overfitting. data/coco128.yaml, shown below, is the dataset config file that defines 1) the dataset root directory path and relative paths to train / val / test image directories (or *.txt files with image paths), 2) the number of classes nc and 3) a list of class names:

# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
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)

# Classes
nc: 80  # number of classes
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
         'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
         'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
         'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
         'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
         'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
         'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
         'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
         'hair drier', 'toothbrush' ]  # class names

1.2 Create Labels

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).

Image Labels

The label file corresponding to the above image contains 2 persons (class 0) and a tie (class 27):

1.3 Organize Directories

Organize your train and val images and labels according to the example below. YOLOv5 assumes /coco128 is inside a /datasets directory next to the /yolov5 directory. YOLOv5 locates labels automatically for each image by replacing the last instance of /images/ in each image path with /labels/. For example:

../datasets/coco128/images/im0.jpg  # image
../datasets/coco128/labels/im0.txt  # label

Good luck 🍀 and let us know if you have any other questions!

@FranciosoDonato
Copy link

FranciosoDonato commented Jul 30, 2022

Hi, i have the same error. This morning no problem, but in this afternoon i found this warning and i have't change nothing. I use RoboFlow for create my dataset and i export it in my code.
from roboflow import Roboflow
rf = Roboflow(api_key="<key>")
project = rf.workspace("computer-vision-ppbyu").project("rice-detection-mnpf6")
dataset = project.version(30).download("yolov5")
!python train.py --batch 64 --epochs 20 --data '/content/yolov5/dataset/data.yaml' --weights yolov5s.pt

I follow all the tutorial but the warning persists. Cause this error my metric are not visualized correctly.

@glenn-jocher
Copy link
Member

@FranciosoDonato got it. You might want to raise the issue with the Roboflow team, there may be a dataset issue as the command works correctly with the default datasets, i.e.

!python train.py --batch 64 --epochs 20 --data coco128.yaml --weights yolov5s.pt

@GxTeo
Copy link
Author

GxTeo commented Jul 31, 2022

I have tried the same dataset with no changes to the labels folder using google colab and had no error so its unlikely an annotation format problem. Any other possible reasons why I might have such errors?

@glenn-jocher
Copy link
Member

@GxTeo I'll take another look at this. This message was recently introduced in #8782

@glenn-jocher
Copy link
Member

@GxTeo yes it looks like the labels count is not considered if no detections are found, i.e.:

 python val.py --imgsz 32 --conf 0.001
 python val.py --imgsz 32 --conf 0.999

I'll work on a fix.

glenn-jocher added a commit that referenced this issue Jul 31, 2022
Resolves #8791

Bug first introduced in #8782
glenn-jocher added a commit that referenced this issue Jul 31, 2022
Resolves #8791

Bug first introduced in #8782
@glenn-jocher
Copy link
Member

@GxTeo good news 😃! Your original issue may now be fixed ✅ in PR #8806. To receive this update:

  • Gitgit pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
  • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
  • Notebooks – View updated notebooks Open In Colab Open In Kaggle
  • Dockersudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

@GxTeo
Copy link
Author

GxTeo commented Aug 1, 2022

@glenn-jocher Hi, thank you so much! It works perfectly now!

@RonaldYuren
Copy link

RonaldYuren commented Aug 16, 2022

Hi I have some question about the similar question.
image

I didn't find the place to add labels' path, I am trying to run the yolov7 custom_dataset
from https://github.com/akashAD98/yolov7_custom_data_trainig

but the train.txt and valid.txt I only put my images' path;
Are there any place I need to add my own labels?

@GxTeo
Copy link
Author

GxTeo commented Aug 16, 2022

@RonaldYuren In Yolov5, i am sure the data yaml source file directly indicates the path to your images. There is no train.txt or val.txt file needed for the paths of images which is used in Yolov4 and Yolov7. Perhaps you can screenshot and share your yaml source file here?

@RonaldYuren
Copy link

I have pass the the question about the path, I am wondering that what the detect.py will do and how to use detect.py ?
I think that detect.py is similar for v5 & v7 right??

@glenn-jocher
Copy link
Member

@RonaldYuren detect.py Usage examples are shown right in the file:

yolov5/detect.py

Lines 1 to 26 in 6728dad

# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
"""
Run inference on images, videos, directories, streams, etc.
Usage - sources:
$ python path/to/detect.py --weights yolov5s.pt --source 0 # webcam
img.jpg # image
vid.mp4 # video
path/ # directory
path/*.jpg # glob
'https://youtu.be/Zgi9g1ksQHc' # YouTube
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
Usage - formats:
$ python path/to/detect.py --weights yolov5s.pt # PyTorch
yolov5s.torchscript # TorchScript
yolov5s.onnx # ONNX Runtime or OpenCV DNN with --dnn
yolov5s.xml # OpenVINO
yolov5s.engine # TensorRT
yolov5s.mlmodel # CoreML (macOS-only)
yolov5s_saved_model # TensorFlow SavedModel
yolov5s.pb # TensorFlow GraphDef
yolov5s.tflite # TensorFlow Lite
yolov5s_edgetpu.tflite # TensorFlow Edge TPU
"""

ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this issue Sep 8, 2022
@Ahmadreza1365
Copy link

Ahmadreza1365 commented Dec 1, 2022

I have similar issue with yolov7. I read all the comments above, but I couldn't resolve it. The labels show 0.

1

@Linkhdaiong
Copy link

询问前搜索

  • 我搜索了 YOLOv5 问题和讨论,没有发现类似的问题

问题

我已经检查了我的注释和训练与验证集。一切似乎都很好,但是每当我想训练我的模型时,我都会收到此警告 image

附加

无响应
您好!您是怎么解决的呢,我的问题跟你一样,也重新下载了源码,还是没有val.label

@glenn-jocher
Copy link
Member

@Linkhdaiong 您好!感谢您的提问!对于您遇到的问题,可能是由于在验证集中没有找到标签导致的。

警告消息是提示没有在验证集中找到标签,因此无法计算指标。在使用YOLOv5时,验证集需要包含有标签的数据,以便进行精度评估和模型性能分析。

请确保您的验证集中的每个图像都有对应的标签文件,并且标签文件的格式正确。标签文件通常是以相同名称但不同扩展名(如.jpg和.txt)命名的文件,其中.txt文件包含了相应图像的目标物体的边界框和类别信息。

如果您确认标签文件存在并且格式正确,但仍然出现此问题,请检查文件的路径和命名是否正确。确保将数据集的标签文件路径正确指定到代码中。

希望这些提示能对您有所帮助!如果您有任何其他问题或者需要进一步的帮助,请随时告诉我们。我们很乐意帮助您解决问题!

@Miarviolin
Copy link

hi , I have the same error
image
and this how my files look
image
thanks inadvance

@MeatyAri
Copy link

MeatyAri commented Sep 6, 2023

For those encountering the same error, like me and @Linkhdaiong, that displays the message:
WARNING no labels found in detect set, can not compute metrics without labels

Here's a solution: Organize your label files in a structure similar to your image directories. For instance, if you have a train/validation split like me:
image
Make sure to create corresponding train/validation split directories for your labels as well.

A helpful tip: You can simply copy all the label files to both directories. YOLO will use only the ones it needs, so there's no need to worry about duplicating files.

@glenn-jocher
Copy link
Member

Hi @MeatyAri, thank you for bringing this issue to our attention. I understand that you and @Linkhdaiong are encountering the same error message, "WARNING no labels found in detect set, can not compute metrics without labels."

To resolve this issue, please ensure that your label files are organized in a structure similar to your image directories. This means creating corresponding train/validation split directories for your labels. You can refer to the provided image for an example structure.

A useful tip is to copy all the label files to both directories. YOLOv5 will only use the necessary label files, so there is no need to worry about duplicating files.

I hope this solution helps resolve the issue for you. Please let us know if you need any further assistance.

@Andres-San
Copy link

Andres-San commented Mar 18, 2024

Hi There,

After "loosing" a few hours, I figured that it was not a path issue, moreover it was a format issue:

  • Format of my label files, was not correct. I had not the format "class x_center y_center width height" as specified here

  • If you are using google Collab, when uploadind to .txt files to GDrive, they are converted to .gdocs, so you must prevent this from happening (settings in drive)

When I resolved both those issues, it run well for me.

For anyone wondering, I labeled my photos using labelme, and then used labelme2yolo to get the yolo format. Problem was that labelme2yolo has the default output format to polygon, so I changed it to bbox and problem solved regarding the yolo format.

I guess the warning was pretty missleading, instead for "labels not found" it should be something more like "wrong format"

Hope it helps somebody, Best!

P.S: Before all of this, make sure you have your paths right (no labels path required in your .yaml, only images, and label path will mimic the image path )
P.S2: My final clue was that in the error message, at some point it says "no label found in :{PATH}" and that PATH was exactly the correct Path, so then I started digging.

@glenn-jocher
Copy link
Member

@Andres-San hi There,

Thank you so much for sharing your findings and solutions! 🙌 It's super helpful for the community.

To summarize and add a bit:

  • Always ensure label files follow the "class x_center y_center width height" format as per Ultralytics Yolo format guidelines.
  • When using Google Colab and Google Drive, be mindful of file conversions (like .txt to .gdocs). Adjusting Drive settings can prevent this.
  • Tools like labelme are great, but converting formats (e.g., with labelme2yolo) requires careful attention to details like output folders. Switching from 'polygon' to 'bbox' for YOLO format is a key step.
  • A "wrong format" error indicator would indeed be more precise than a general "labels not found" message. Your suggestion is noted for improvement! 📝
  • Lastly, confirming the path is crucial, as the correct path can still result in errors if the format or file standards aren't met.

Your PS notes perfectly highlight the importance of verifying paths and the format. Your journey and solution will definitely assist others facing similar issues.

Best regards and happy coding!

@Bakhtawar378
Copy link

i was facing the same problem and it turned out that my "images" folder was "Images" and labels folder was "Labels"... i just changed the case for I and L and the problem was solved

@glenn-jocher
Copy link
Member

@Bakhtawar378 hi there! 😊

Great to hear you've resolved the issue! Indeed, the case sensitivity in file or folder names can lead to such problems. It's always good to double-check the file & folder names match exactly what the code expects. Happy coding, and feel free to reach out if you encounter any more issues. Keep up the great work! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants