ultralytics / yolov5

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

Why does training fail whenever null/background images are included in dataset. #12093

Closed SamDaaLamb closed 1 year ago

SamDaaLamb commented 1 year ago

Search before asking

Question

I have been using this library on google colab without any problems for a while now. I was trying to train a dataset that contains imageswith no labels (aka null images or background images) but whenever I try this, the following error pops up.

P.S.: Every time I use this library I have to slightly alter the train.py to manually include the train, test and validation paths or else it doesn't.


/content/yolov5 2023-09-07 01:32:20.206267: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-09-07 01:32:21.043839: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT train: weights=, cfg=./models/custom_yolov5s.yaml, data=/content/yolov5/data.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=100, batch_size=16, imgsz=416, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=, cache=ram, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, project=runs/train, name=yolov5s_results, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, seed=0, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest github: ⚠️ YOLOv5 is out of date by 579 commits. Use git pull or git clone [https://github.com/ultralytics/yolov5](https://github.com/ultralytics/yolov5%60) to update. YOLOv5 🚀 v6.1-306-gfbe67e4 Python-3.10.12 torch-2.0.1+cu118 CUDA:0 (Tesla T4, 15102MiB)

hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0 Weights & Biases: run 'pip install wandb' to automatically track and visualize YOLOv5 🚀 runs (RECOMMENDED) TensorBoard: Start with 'tensorboard --logdir runs/train', view at http://localhost:6006/

             from  n    params  module                                  arguments                     

0 -1 1 3520 models.common.Focus [3, 32, 3]
1 -1 1 18560 models.common.Conv [32, 64, 3, 2]
2 -1 1 19904 models.common.BottleneckCSP [64, 64, 1]
3 -1 1 73984 models.common.Conv [64, 128, 3, 2]
4 -1 3 161152 models.common.BottleneckCSP [128, 128, 3]
5 -1 1 295424 models.common.Conv [128, 256, 3, 2]
6 -1 3 641792 models.common.BottleneckCSP [256, 256, 3]
7 -1 1 1180672 models.common.Conv [256, 512, 3, 2]
8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]]
9 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False]
10 -1 1 131584 models.common.Conv [512, 256, 1, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 6] 1 0 models.common.Concat [1]
13 -1 1 378624 models.common.BottleneckCSP [512, 256, 1, False]
14 -1 1 33024 models.common.Conv [256, 128, 1, 1]
15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
16 [-1, 4] 1 0 models.common.Concat [1]
17 -1 1 95104 models.common.BottleneckCSP [256, 128, 1, False]
18 -1 1 147712 models.common.Conv [128, 128, 3, 2]
19 [-1, 14] 1 0 models.common.Concat [1]
20 -1 1 313088 models.common.BottleneckCSP [256, 256, 1, False]
21 -1 1 590336 models.common.Conv [256, 256, 3, 2]
22 [-1, 10] 1 0 models.common.Concat [1]
23 -1 1 1248768 models.common.BottleneckCSP [512, 512, 1, False]
24 [17, 20, 23] 1 16182 models.yolo.Detect [1, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]] custom_YOLOv5s summary: 283 layers, 7255094 parameters, 7255094 gradients, 16.9 GFLOPs

AMP: checks passed ✅ Scaled weight_decay = 0.0005 optimizer: SGD with parameter groups 59 weight (no decay), 70 weight, 62 bias albumentations: Blur(always_apply=False, p=0.01, blur_limit=(3, 7)), MedianBlur(always_apply=False, p=0.01, blur_limit=(3, 7)), ToGray(always_apply=False, p=0.01), CLAHE(always_apply=False, p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8)) train: Scanning '/content/yolov5/train/labels' images and labels...0 found, 2990 missing, 0 empty, 0 corrupt: 100% 2990/2990 [00:00<00:00, 3217.84it/s] train: WARNING: No labels found in /content/yolov5/train/labels.cache. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data train: New cache created: /content/yolov5/train/labels.cache Traceback (most recent call last): File "/content/yolov5/train.py", line 654, in main(opt) File "/content/yolov5/train.py", line 549, in main train(opt.hyp, opt, device, callbacks) File "/content/yolov5/train.py", line 211, in train train_loader, dataset = create_dataloader(train_path, File "/content/yolov5/utils/dataloaders.py", line 114, in create_dataloader dataset = LoadImagesAndLabels( File "/content/yolov5/utils/dataloaders.py", line 466, in init assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}' AssertionError: train: No labels in /content/yolov5/train/labels.cache. Can not train without labels. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data CPU times: user 88.4 ms, sys: 12.3 ms, total: 101 ms Wall time: 12.3 s

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @SamDaaLamb, 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 1 year ago

@SamDaaLamb this error occurs when training fails because there are null or background images in the dataset that do not have corresponding labels. The YOLOv5 library requires labeled images for training.

To resolve this issue, you need to ensure that all your images have corresponding labels. If you have null or background images that you don't want to include in the training process, you should remove them from your dataset before starting the training.

Additionally, please note that you mentioned having to manually include the train, test, and validation paths in the train.py file every time. It's recommended to follow the standard directory structure and naming conventions defined in the YOLOv5 documentation to avoid any compatibility issues.

If you have any further questions or need additional assistance, feel free to ask.

SamDaaLamb commented 1 year ago

@SamDaaLamb this error occurs when training fails because there are null or background images in the dataset that do not have corresponding labels. The YOLOv5 library requires labeled images for training.

To resolve this issue, you need to ensure that all your images have corresponding labels. If you have null or background images that you don't want to include in the training process, you should remove them from your dataset before starting the training.

Additionally, please note that you mentioned having to manually include the train, test, and validation paths in the train.py file every time. It's recommended to follow the standard directory structure and naming conventions defined in the YOLOv5 documentation to avoid any compatibility issues.

If you have any further questions or need additional assistance, feel free to ask.

Thank you very much for the detailed response,.

However, I was told that it is healthy to have null images in your dataset. Are you aware if yolov8 allows background images or if their is any way I could train with null images.

glenn-jocher commented 1 year ago

@SamDaaLamb, thank you for your response.

Regarding null or background images in your dataset, YOLOv8 does not have specific support for including such images during training. The YOLOv5 library requires labeled images for training, so if you have null or background images without corresponding labels, they may cause training errors.

However, if you still want to include such images in your dataset, you can assign them a dummy label or assign a specific class label for background images. This way, you can include these images in the training process without causing errors. Please note that including null or background images may affect the overall training performance and accuracy of your model.

If you need further assistance or have any other questions, please feel free to ask.