ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.73k stars 16.12k forks source link

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

Closed GxTeo closed 2 years ago

GxTeo commented 2 years ago

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

github-actions[bot] commented 2 years ago

👋 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 commented 2 years ago

@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:

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

@GxTeo I'll take another look at this. This message was recently introduced in https://github.com/ultralytics/yolov5/pull/8782

glenn-jocher commented 2 years ago

@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 commented 2 years ago

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

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 commented 2 years ago

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

RonaldYuren commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

@RonaldYuren detect.py Usage examples are shown right in the file: https://github.com/ultralytics/yolov5/blob/6728dad76df8d62ed3c08e39c224a773d20582a0/detect.py#L1-L26

Ahmadreza1365 commented 1 year ago

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

1

Linkhdaiong commented 1 year ago

询问前搜索

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

问题

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

附加

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

glenn-jocher commented 1 year ago

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

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

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

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

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

Miarviolin commented 1 year ago

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

MeatyAri commented 1 year ago

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 commented 1 year ago

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 commented 6 months ago

Hi There,

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

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 commented 6 months ago

@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:

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 commented 5 months ago

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 commented 5 months ago

@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! 👍