ultralytics / yolov5

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

AssertionError: train: No labels in VOCdevkit\images\train.cache. Can not train without labels. #8139

Closed hljulmf closed 2 years ago

hljulmf commented 2 years ago

Search before asking

YOLOv5 Component

Training

Bug

image image

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

github-actions[bot] commented 2 years ago

👋 Hello @hljulmf, 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.

Im-JimmyHu commented 2 years ago

you dataset looks like confusing,like voc, the cache created in the labels/ like this : image please convert voc format dataset to yolo format

glenn-jocher commented 2 years ago

@hljulmf 👋 Hello! Thanks for asking about YOLOv5 🚀 dataset formatting. To train correctly your data must be in YOLOv5 format. 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!

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv5 🚀 and Vision AI ⭐!

zhitkoalina commented 1 year ago

!chmod +w /content/gdrive/My\ Drive/{your path here}/data/labels solved it for me

glenn-jocher commented 1 year ago

@zhitkoalina glad to hear that the !chmod +w command fixed the issue you were experiencing with YOLOv5! For future reference, !chmod is a terminal command in Unix-based systems that changes the read, write, and execute permissions of files and directories. The +w flag grants write access to the specified file or directory.

In your case, it seems that adding write permissions to the /content/gdrive/My\ Drive/{your path here}/data/labels directory allowed YOLOv5 to write cache files to that location. This is useful to know if others run into a similar issue when using YOLOv5 with Google Drive.

Let me know if you have any other questions!

cvYouTian commented 1 year ago

emmm,I have encountered a similar problem recently. The reason here is that my labels contain some empty data. You can try to check your label

glenn-jocher commented 1 year ago

@cvYouTian hello! Thank you for reporting the issue you encountered with YOLOv5. It's likely that the reason why YOLOv5 is not processing your labels properly is due to empty data contained in the labels. You can try to check your label files and make sure that all object annotations are complete. This means that each object should have a corresponding class and bounding box coordinates, and that the coordinates are in the correct format (normalized float values between 0 and 1).

In addition, make sure that your label files are saved in the YOLO format and that they have the same file name as their corresponding image files. If you have multiple label files for a single image, make sure that each file includes all annotations for that image.

I hope this information is helpful in resolving your issue. If you have any other questions, please don't hesitate to ask. We'll do our best to assist you.

BengIslam7 commented 1 year ago

X and Y of bounding boxes should be between 1 and 0 . So if you have something like 0 281.259045 187.035071 327.727931 223.225547 (xmin , ymin , xmax , ymax > 1 ) in your labels file and you work in an image with 676x380 pixels you should divise 281.259045/676 187.035071/380 327.727931/676 223.225547/380 .

glenn-jocher commented 1 year ago

@BengIslam7 the bounding box coordinates in YOLOv5 should indeed be normalized values between 0 and 1. If your labels contain values outside this range, you can normalize them by dividing each coordinate by the respective image dimensions. For example, if you have an image with dimensions 676x380 pixels and a bounding box coordinate of 0 281.259045 187.035071 327.727931 223.225547, you should divide each coordinate by the image dimensions as follows:

x_min_normalized = 281.259045 / 676 y_min_normalized = 187.035071 / 380 x_max_normalized = 327.727931 / 676 y_max_normalized = 223.225547 / 380

This will ensure that your bounding box coordinates are within the normalized range expected by YOLOv5. If you have any further questions, feel free to ask!

BengIslam7 commented 1 year ago

@BengIslam7 the bounding box coordinates in YOLOv5 should indeed be normalized values between 0 and 1. If your labels contain values outside this range, you can normalize them by dividing each coordinate by the respective image dimensions. For example, if you have an image with dimensions 676x380 pixels and a bounding box coordinate of 0 281.259045 187.035071 327.727931 223.225547, you should divide each coordinate by the image dimensions as follows:

x_min_normalized = 281.259045 / 676 y_min_normalized = 187.035071 / 380 x_max_normalized = 327.727931 / 676 y_max_normalized = 223.225547 / 380

This will ensure that your bounding box coordinates are within the normalized range expected by YOLOv5. If you have any further questions, feel free to ask!

Same explanation . This solution solved this error for me . Thanks

glenn-jocher commented 1 year ago

@BengIslam7 glad to hear that the explanation provided was helpful and solved the error for you! You're welcome! If you have any further questions or need any more assistance, feel free to ask.

ZienZhang6 commented 1 year ago

@hljulmf 我也遇到同样的问题。我最终是这么解决的:查看train.ache,发现缺少images文件,而我的存放图片文件的文件名是JPGImages,将JPGImages修改成images后完美解决了问题。问题原因分析:yolov5貌似只认识文件名是images的存放图片的文件夹。

glenn-jocher commented 1 year ago

@ZienZhang6 您好!感谢您与我们分享您遇到的问题。根据您的描述,您在解决这个问题时发现了一个缺少"images"文件夹的问题,并且将存放图片的文件夹名称从"JPGImages"改为"images"后成功解决了问题。根据我们的经验,确实需要将存放图片的文件夹名称命名为"images",因为YOLOv5只认识这个特定的文件夹名称。感谢您的分享并且希望这个解决方案对其他用户也有所帮助。如果您有任何其他问题或疑问,请随时提问。谢谢!

MSR2201 commented 1 year ago

I got the same issue with the lables it says non writable and all i will produce the picture beow please reply if you know the issue image

glenn-jocher commented 1 year ago

@MSR2201 thank you for reporting the issue you encountered with the labels in YOLOv5. Based on the error message you provided, it seems that the labels are not writable. This could be due to incorrect file permissions or if the directory where the labels are stored does not have write access.

To resolve this issue, you can try the following steps:

  1. Check the file permissions of the labels and ensure that they are set to allow write access.
  2. Verify that the directory where the labels are stored has proper write permissions.
  3. Ensure that the labels are in the correct format and have the appropriate filename, following the YOLOv5 labeling conventions.

If the issue persists, please provide more details about your setup and any specific error messages you receive. This will help us in troubleshooting the problem further.

We appreciate your patience, and we are here to assist you in resolving this issue. Let us know if you have any further questions or concerns.

RajaBersiung commented 11 months ago

i hvae facing same issue

this is the error when i run the program in the google colab

Transferred 223/369 items from yolov5s.pt optimizer: SGD(lr=0.01) with parameter groups 59 weight(decay=0.0), 70 weight(decay=0.0005), 62 bias albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8)) train: Scanning /content/drive/MyDrive/Complete/Train/Images.cache... 0 images, 500 backgrounds, 0 corrupt: 100% 500/500 [00:00<?, ?it/s] Traceback (most recent call last): File "/content/yolov5/train.py", line 647, in main(opt) File "/content/yolov5/train.py", line 536, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov5/train.py", line 195, in train train_loader, dataset = create_dataloader(train_path, File "/content/yolov5/utils/dataloaders.py", line 124, in create_dataloader dataset = LoadImagesAndLabels( File "/content/yolov5/utils/dataloaders.py", line 502, 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 /content/drive/MyDrive/Complete/Train/Images.cache, can not start training. See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data CPU times: user 133 ms, sys: 15.4 ms, total: 148 ms Wall time: 17 s

glenn-jocher commented 11 months ago

@RajaBersiung hi there! Thank you for reaching out with the issue you are facing.

Based on the error message you provided, it looks like you are encountering an "AssertionError" with the message "No labels found in [path to Images.cache], can not start training."

To resolve this issue, you need to ensure that you have provided the correct path to your label files. Specifically, make sure that the "Images.cache" file contains the proper labels for your training images.

You can refer to the official YOLOv5 documentation for more details and guidance on how to properly format and provide the labels for training custom data. Here's the link: YOLOv5 Custom Data Training Tutorial

If you have any further questions or need more assistance, please feel free to ask. We're here to help you.