Skip to content

what is error of train.cache? #13610

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

Open
1 task done
hitbuyi opened this issue May 27, 2025 · 4 comments
Open
1 task done

what is error of train.cache? #13610

hitbuyi opened this issue May 27, 2025 · 4 comments
Labels
detect Object Detection issues, PR's question Further information is requested

Comments

@hitbuyi
Copy link

hitbuyi commented May 27, 2025

Search before asking

Question

mydata
├── dataSet
├── images
├── labels
└── label_xml

where dataSet includes trainval.txt,val.txt, image is png image, label includes txt lablefiles
contents of train.txt

D:\Yolo\v5\myData\images\20250526101429_00001.png
D:\Yolo\v5\myData\images\20250526101429_00002.png
...

data cfg ymal is

path: D:\Yolo\v5\mydata  # Replace with your actual path to mydata folde
train: dataSet\train.txt  # 
val: dataSet\val.txt  #
# Classes
nc: 6  # number of classes
names: [ 'car', 'truck', 'pedestrian', 'bus', 'person', 'incense']  # class names,car,truck,pedestrian,bus,person,incense

an error happen

Exception has occurred: AssertionError:
�[34m�[1mtrain: �[0mNo labels found in D:\Yolo\v5\myData\dataSet\train.cache, can not start training. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data
  File "D:\Yolo\v5\yolov5\utils\dataloaders.py", line 611, in __init__
    assert nf > 0 or not augment, f"{prefix}No labels found in {cache_path}, can not start training. {HELP_URL}"
  File "D:\Yolo\v5\yolov5\utils\dataloaders.py", line 184, in create_dataloader
    dataset = LoadImagesAndLabels(
  File "D:\Yolo\v5\yolov5\train.py", line 285, in train
    train_loader, dataset = create_dataloader(
  File "D:\Yolo\v5\yolov5\train.py", line 688, in main
    train(opt.hyp, opt, device, callbacks)
  File "D:\Yolo\v5\yolov5\train.py", line 986, in <module>
    main(opt)
AssertionError: �[34m�[1mtrain: �[0mNo labels found in D:\Yolo\v5\myData\dataSet\train.cache, can not start training. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data

what is train.cache? how to avoid this problem?

Additional

No response

@hitbuyi hitbuyi added the question Further information is requested label May 27, 2025
@UltralyticsAssistant UltralyticsAssistant added the detect Object Detection issues, PR's label May 27, 2025
@UltralyticsAssistant
Copy link
Member

👋 Hello @hitbuyi, thank you for reaching out and providing detailed information about your dataset and error! This is an automated response to assist you as quickly as possible. An Ultralytics engineer will review your issue and provide further help soon 😊.

To get started with YOLOv5 🚀, please refer to our ⭐️ Tutorials for step-by-step guides, including Custom Data Training, which can help you set up your dataset and directory structure properly.

If this is a 🐛 Bug Report, please provide a minimum reproducible example (MRE) so we can help you debug more efficiently.

If this is a custom training ❓ Question, try to include as much information as possible (such as dataset samples, config files, and logs), and review our Tips for Best Training Results to ensure your setup aligns with recommended practices.

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 can be run in 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.

🔎 Please provide an MRE if you believe this is a bug, and check your label files and dataset structure according to our Custom Training Tutorial. Thank you for your patience!

@pderrenger
Copy link
Member

The train.cache file is automatically generated by YOLOv5 to cache dataset information for faster loading. The error indicates that no valid labels were found for your training images.

Looking at your configuration, the issue is likely with your dataset structure and paths. Your YAML points to dataSet\train.txt which should contain relative paths to images, but you're using absolute paths. Try updating your train.txt to use relative paths from the dataset root:

images/20250526101429_00001.png
images/20250526101429_00002.png

Also ensure that for each image file you have a corresponding label file with the same name but .txt extension in the labels folder (e.g., labels/20250526101429_00001.txt). Delete any existing .cache files and retrain to regenerate them with the corrected paths.

@hitbuyi
Copy link
Author

hitbuyi commented May 28, 2025

The train.cache file is automatically generated by YOLOv5 to cache dataset information for faster loading. The error indicates that no valid labels were found for your training images.

Looking at your configuration, the issue is likely with your dataset structure and paths. Your YAML points to dataSet\train.txt which should contain relative paths to images, but you're using absolute paths. Try updating your train.txt to use relative paths from the dataset root:

images/20250526101429_00001.png
images/20250526101429_00002.png

Also ensure that for each image file you have a corresponding label file with the same name but .txt extension in the labels folder (e.g., labels/20250526101429_00001.txt). Delete any existing .cache files and retrain to regenerate them with the corrected paths.

Thanks for reply. I will have a try. /images/, /labels/ are mandatory in the code, but there are no descriptions in your documents.

@pderrenger
Copy link
Member

You're absolutely right that the documentation could be clearer about the required folder structure. The YOLOv5 codebase expects images and labels to be in separate folders named images and labels respectively, with matching filenames. This convention allows the dataloader to automatically find corresponding label files for each image. Thanks for pointing out this documentation gap - it's valuable feedback for improving the train custom data tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detect Object Detection issues, PR's question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants