ultralytics / yolov5

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

All labels empty in {cache_path}/train.cache, can not start training. #12700

Closed sebabrzovic closed 7 months ago

sebabrzovic commented 9 months ago

Search before asking

Question

Hello! Im having trouble trying to train with yolov5: I have my folders ordered in this manner:

train_data/ -logos.yaml images/ train/ -image1.png -image2.png val/ -image3.png -image4.png labels/ train/ -image1.txt -image2.txt val/ -image3.txt -image4.txt yolov5/

Now my logos.yaml is:

path: ../train_data train: images/train val: images/val
names: 0: first_object 1: 2nd_object

The problem is when i run this code : python train.py --img 640 --epochs 3 --data ../train_data/logos.yaml --weights yolov5m.pt --cache ram i get the same error:

Transferred 475/481 items from yolov5m.pt optimizer: SGD(lr=0.01) with parameter groups 79 weight(decay=0.0), 82 weight(decay=0.0005), 82 bias train: Scanning C:\Users\sebab\Documents\Seba\DCC\SEMESTRE_9\PRACTICA\train_data\labels\train... 1294 images, 14234 backgrounds, 0 corrupt: 100%|██████████| 14234/14234 [ train: New cache created: {train_data_path}\train_data\labels\train.cache Traceback (most recent call last): File "{yolo_path}\yolov5\train.py", line 836, in main(opt) File "{yolo_path}\yolov5\train.py", line 616, in main train(opt.hyp, opt, device, callbacks) File "{yolo_path}\yolov5\train.py", line 248, in train train_loader, dataset = create_dataloader( File "{yolo_path}\yolov5\utils\dataloaders.py", line 177, in create_dataloader dataset = LoadImagesAndLabels( File "{yolo_path}\yolov5\utils\dataloaders.py", line 574, in init assert nl > 0 or not augment, f"{prefix} All labels empty in {cache_path}, can not start training. {HELP_URL}" AssertionError: train: All labels empty in {train_data_path}\train_data\labels\train.cache, can not start training. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

I've tried running the code withouth the cache but it gives me the same error,

Additional

I've tried everything down to the obviouse, I've tried rewriting my roots, checking my labels, checking whether i have the proper requeriments, tryinh from the begining in another directory, and nothing works. with any help i'd be grateful.

github-actions[bot] commented 9 months ago

👋 Hello @sebabrzovic, 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 a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. 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

YOLOv5 CI

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

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
glenn-jocher commented 9 months ago

@sebabrzovic hello!

It seems like there might be an issue with your label files or their paths. Here are a few steps to troubleshoot this problem:

  1. Check Label Files: Ensure that your label .txt files are not empty and formatted correctly. Each line in a label file should represent one object and follow the format: <class> <x_center> <y_center> <width> <height>, with values normalized between 0 and 1.

  2. Paths in YAML: Verify that the paths in your logos.yaml file are correct relative to the directory from which you're running the train.py script.

  3. No Background Labels: The error message indicates a large number of backgrounds (14234) and no labels. Ensure that your dataset does not contain label files with only the class 'background' or no objects.

  4. Clear Cache: If you've made changes to your dataset or labels, clear the cache by deleting {train_data_path}\train_data\labels\train.cache before running the training again.

  5. Check Images and Labels Alignment: Make sure that for every image in the images/train/ directory, there is a corresponding label file in labels/train/ with the exact same filename (except for the file extension).

  6. Permissions: Ensure that you have read/write permissions for the directories and files involved in the training process.

If you've checked all the above and the issue persists, consider sharing a snippet of your label file content for further assistance. Remember, the community is here to help!

sebabrzovic commented 9 months ago

@glenn-jocher Hey, thanks for your answer, today i checked all the posibilities, I doubled check my images, the labels, the backgrounds, and unfortunately none of them worked. Here is an image of how i have my files ordered and how i have my logos.yaml image

Is there anything that I'm missing?

glenn-jocher commented 9 months ago

@sebabrzovic, thanks for the update and for checking those items.

From the information provided, it seems like your file structure and logos.yaml appear to be correct. However, since the image you're trying to show isn't visible here, I can't confirm the exact setup.

Here are a few more things to consider:

  1. Label File Content: Open a few .txt label files and ensure they contain the correct object annotations. If they are empty or incorrectly formatted, the training process will not detect any labels.

  2. File Naming: Confirm that the image files and label files have the exact same base filenames. For example, image1.png should have a corresponding label file named image1.txt.

  3. YAML Content: Double-check the logos.yaml content for any typos or formatting issues. The path should be correct relative to where you're running the script, and the train and val should correctly point to the image folders.

  4. Dataset Integrity: Use the val.py script with the --task val option to validate your dataset without training. This can help identify issues with the dataset.

  5. Verbose Output: Run the training with the --verbose flag to get more detailed output, which might help pinpoint the issue.

If you've gone through all these steps and the problem persists, you might want to share the content of one of your label files here for further inspection. Please ensure there's no sensitive information in the content you share.

amira-essawy commented 9 months ago

@glenn-jocher I have a similar error:

Transferred 343/349 items from yolov5n.pt AMP: checks passed ✅ optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.0005), 60 bias train: Scanning /home/aessawy/workspace/amiras/new/datasets/CV3/labels/train... 0 images, 21713 backgrounds, 0 corrupt: 100%|██████████| 21713/21713 [02:19< train: WARNING ⚠️ No labels found in /home/aessawy/workspace/amiras/new/datasets/CV3/labels/train.cache. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data train: WARNING ⚠️ Cache directory /home/aessawy/workspace/amiras/new/datasets/CV3/labels is not writeable: [Errno 2] No such file or directory: '/home/aessawy/workspace/amiras/new/datasets/CV3/labels/train.cache.npy' Traceback (most recent call last): File "train.py", line 836, in main(opt) File "train.py", line 616, in main train(opt.hyp, opt, device, callbacks) File "train.py", line 248, in train train_loader, dataset = create_dataloader( File "/home/aessawy/workspace/amiras/new/yolov5/utils/dataloaders.py", line 177, in create_dataloader dataset = LoadImagesAndLabels( File "/home/aessawy/workspace/amiras/new/yolov5/utils/dataloaders.py", line 568, in init assert nf > 0 or not augment, f"{prefix}No labels found in {cache_path}, can not start training. {HELP_URL}" AssertionError: train: No labels found in /home/aessawy/workspace/amiras/new/datasets/CV3/labels/train.cache, can not start training. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

I did the check steps you mentioned but the problem is still exist.

glenn-jocher commented 9 months ago

@amira-essawy, it looks like there are a couple of issues highlighted in the error message:

  1. No Labels Found: The scan reports 0 images and a large number of backgrounds, which indicates that it did not find any valid image-label pairs. Ensure that your image files in the images/train directory have corresponding label files with the same base name in the labels/train directory.

  2. Write Permission: The warning about the cache directory not being writable suggests a file system permission issue. Make sure that the user running the train.py script has the necessary permissions to read from and write to the /home/aessawy/workspace/amiras/new/datasets/CV3/labels directory.

Here's what you can do next:

If you've tried all the above and the issue still exists, please share the content of your dataset YAML file and a snippet from one of your label .txt files for further assistance. Remember to exclude any sensitive information.

github-actions[bot] commented 8 months ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐