ultralytics
ultralytics copied to clipboard
IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 4
Search before asking
- [X] I have searched the YOLOv8 issues and found no similar bug report.
YOLOv8 Component
Training
Bug
/content env: HYDRA_FULL_ERROR=1 Ultralytics YOLOv8.0.6 🚀 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB) yolo/engine/trainer: task=detect, mode=train, model=yolov8s.pt, data=/content/datasets/data.yaml, epochs=25, patience=50, batch=16, imgsz=800, save=True, cache=False, device=, workers=8, project=None, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=False, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, hide_labels=False, hide_conf=False, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, retina_masks=False, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=17, workspace=4, nms=False, 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=7.5, cls=0.5, dfl=1.5, fl_gamma=0.0, label_smoothing=0.0, nbs=64, 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, cfg=None, hydra={'output_subdir': None, 'run': {'dir': '.'}}, v5loader=False, save_dir=runs/detect/train6 Overriding model.yaml nc=80 with nc=3
from n params module arguments
0 -1 1 928 ultralytics.nn.modules.Conv [3, 32, 3, 2]
1 -1 1 18560 ultralytics.nn.modules.Conv [32, 64, 3, 2]
2 -1 1 29056 ultralytics.nn.modules.C2f [64, 64, 1, True]
3 -1 1 73984 ultralytics.nn.modules.Conv [64, 128, 3, 2]
4 -1 2 197632 ultralytics.nn.modules.C2f [128, 128, 2, True]
5 -1 1 295424 ultralytics.nn.modules.Conv [128, 256, 3, 2]
6 -1 2 788480 ultralytics.nn.modules.C2f [256, 256, 2, True]
7 -1 1 1180672 ultralytics.nn.modules.Conv [256, 512, 3, 2]
8 -1 1 1838080 ultralytics.nn.modules.C2f [512, 512, 1, True]
9 -1 1 656896 ultralytics.nn.modules.SPPF [512, 512, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.Concat [1]
12 -1 1 591360 ultralytics.nn.modules.C2f [768, 256, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.Concat [1]
15 -1 1 148224 ultralytics.nn.modules.C2f [384, 128, 1]
16 -1 1 147712 ultralytics.nn.modules.Conv [128, 128, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.Concat [1]
18 -1 1 493056 ultralytics.nn.modules.C2f [384, 256, 1]
19 -1 1 590336 ultralytics.nn.modules.Conv [256, 256, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.Concat [1]
21 -1 1 1969152 ultralytics.nn.modules.C2f [768, 512, 1]
22 [15, 18, 21] 1 2117209 ultralytics.nn.modules.Detect [3, [128, 256, 512]]
Model summary: 225 layers, 11136761 parameters, 11136745 gradients, 28.7 GFLOPs
Transferred 349/355 items from pretrained weights optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias train: Scanning /content/datasets/train/labels.cache... 6083 images, 27 backgrounds, 0 corrupt: 100% 6083/6083 [00:00<?, ?it/s] 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)) val: Scanning /content/datasets/valid/labels.cache... 694 images, 2 backgrounds, 0 corrupt: 100% 694/694 [00:00<?, ?it/s] Image sizes 800 train, 800 val Using 2 dataloader workers Logging results to runs/detect/train6 Starting training for 25 epochs...
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
1/25 5.97G 2.407 5.964 2.606 33 800: 1% 2/381 [00:05<17:36, 2.79s/it]
Error executing job with overrides: ['task=detect', 'mode=train', 'model=yolov8s.pt', 'data=/content/datasets/data.yaml', 'epochs=25', 'imgsz=800']
Traceback (most recent call last):
File "/usr/local/bin/yolo", line 8, in
Environment
- YOLOv8
- window11
- python3.9
Minimal Reproducible Example
%cd {HOME} import os %env HYDRA_FULL_ERROR = 1 !yolo task=detect mode=train model=yolov8s.pt data=/content/datasets/data.yaml epochs=25 imgsz=800
Additional
I really don't know how to fix this
Are you willing to submit a PR?
- [X] Yes I'd like to help by submitting a PR!
Have you check your annot data?
If yolo annot has Bbox format, then use task=detect
, if yolo annot has segmentation format, then use task=segment
. You can not mix it both.
Just a reminder BBOX format = class Xcenter Ycenter Width Height Segmentation format = class X1 Y1 X2 Y2 ...... Xn Yn
If you run task=detect
, make sure the annot has BBOX format & model=yolov8*.pt
If you run task=segment
, make sure the annot has Segmentation format & model=yolov8*-seg.pt
Additional note:
yolov8*.pt
and yolov8*-seg.pt
which * can be n, s, m, l, and x
@khengyun You're training detection but looks like you got two types annotations, both detection and segmentation. Please check your data labels.
I have the same issue on only 1 of two datasets. I've only ever used bbox annotation (from RoboFlow).
My dataset only has a single class. I have 529 images. This seems related to "null" values in the annotations. That is, the class is not present in the image and thus the annot file is empty. This same dataset works fine for Yolov5. I removed the nulls from the dataset and it did get further. However, I then got a different error:
Ultralytics YOLOv8.0.6 🚀 Python-3.8.10 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3060, 12287MiB)
yolo/engine/trainer: task=detect, mode=train, model=yolov8s.pt, data=/datasets/splashes/data.yaml, epochs=200, patience=50, batch=16, imgsz=320, save=True, cache=False, device=, workers=8, project=None, name=splashes_v9_yolov8, exist_ok=False, pretrained=False, optimizer=SGD, verbose=False, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, hide_labels=False, hide_conf=False, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, retina_masks=False, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=17, workspace=4, nms=False, 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=7.5, cls=0.5, dfl=1.5, fl_gamma=0.0, label_smoothing=0.0, nbs=64, 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, cfg=None, hydra={'output_subdir': None, 'run': {'dir': '.'}}, v5loader=False, save_dir=/usr/src/ultralytics/runs/detect/splashes_v9_yolov88
Overriding model.yaml nc=80 with nc=1
from n params module arguments
0 -1 1 928 ultralytics.nn.modules.Conv [3, 32, 3, 2]
1 -1 1 18560 ultralytics.nn.modules.Conv [32, 64, 3, 2]
2 -1 1 29056 ultralytics.nn.modules.C2f [64, 64, 1, True]
3 -1 1 73984 ultralytics.nn.modules.Conv [64, 128, 3, 2]
4 -1 2 197632 ultralytics.nn.modules.C2f [128, 128, 2, True]
5 -1 1 295424 ultralytics.nn.modules.Conv [128, 256, 3, 2]
6 -1 2 788480 ultralytics.nn.modules.C2f [256, 256, 2, True]
7 -1 1 1180672 ultralytics.nn.modules.Conv [256, 512, 3, 2]
8 -1 1 1838080 ultralytics.nn.modules.C2f [512, 512, 1, True]
9 -1 1 656896 ultralytics.nn.modules.SPPF [512, 512, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.Concat [1]
12 -1 1 591360 ultralytics.nn.modules.C2f [768, 256, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.Concat [1]
15 -1 1 148224 ultralytics.nn.modules.C2f [384, 128, 1]
16 -1 1 147712 ultralytics.nn.modules.Conv [128, 128, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.Concat [1]
18 -1 1 493056 ultralytics.nn.modules.C2f [384, 256, 1]
19 -1 1 590336 ultralytics.nn.modules.Conv [256, 256, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.Concat [1]
21 -1 1 1969152 ultralytics.nn.modules.C2f [768, 512, 1]
22 [15, 18, 21] 1 2116435 ultralytics.nn.modules.Detect [1, [128, 256, 512]]
Model summary: 225 layers, 11135987 parameters, 11135971 gradients, 28.6 GFLOPs
Transferred 349/355 items from pretrained weights
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias
train: Scanning /datasets/splashes/train/labels... 509 images, 7 backgrounds, 0 corrupt: 100%|██████████| 509/509 [00:00
train: New cache created: /datasets/splashes/train/labels.cache
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))
val: Scanning /datasets/splashes/val/labels.cache... 3 images, 1 backgrounds, 0 corrupt: 100%|██████████| 3/3 [00:00<?,
Image sizes 320 train, 320 val
Using 8 dataloader workers
Logging results to /usr/src/ultralytics/runs/detect/splashes_v9_yolov88
Starting training for 200 epochs...
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
0%| | 0/32 [00:00<?, ?it/s]
Error executing job with overrides: ['task=detect', 'mode=train', 'model=yolov8s.pt', 'epochs=200', 'imgsz=320', 'name=splashes_v9_yolov8', 'data=/datasets/splashes/data.yaml']
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/cli.py", line 56, in cli
func(cfg)
File "/usr/local/lib/python3.8/dist-packages/hydra/main.py", line 79, in decorated_main
return task_function(cfg_passthrough)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/v8/detect/train.py", line 207, in train
model.train(**cfg)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/model.py", line 193, in train
self.trainer.train()
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/trainer.py", line 185, in train
self._do_train(int(os.getenv("RANK", -1)), world_size)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/engine/trainer.py", line 283, in _do_train
for i, batch in pbar:
File "/usr/local/lib/python3.8/dist-packages/tqdm/std.py", line 1195, in __iter__
for obj in iterable:
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 628, in __next__
data = self._next_data()
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1333, in _next_data
return self._process_data(data)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/dataloader.py", line 1359, in _process_data
data.reraise()
File "/usr/local/lib/python3.8/dist-packages/torch/_utils.py", line 543, in reraise
raise exception
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/worker.py", line 302, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.8/dist-packages/torch/utils/data/_utils/fetch.py", line 58, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/data/base.py", line 179, in __getitem__
return self.transforms(self.get_label_info(index))
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/data/augment.py", line 48, in __call__
data = t(data)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/data/augment.py", line 48, in __call__
data = t(data)
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/data/augment.py", line 361, in __call__
i = self.box_candidates(box1=instances.bboxes.T,
File "/usr/local/lib/python3.8/dist-packages/ultralytics/yolo/data/augment.py", line 375, in box_candidates
return (w2 > wh_thr) & (h2 > wh_thr) & (w2 * h2 / (w1 * h1 + eps) > area_thr) & (ar < ar_thr) # candidates
ValueError: operands could not be broadcast together with shapes (3,) (6,)
@khengyun Do you have any images without annotations? That was the cause of the issue for me.
using the v5loader does seem to get past the issue with the null annotations. but there are other exceptions then, though it does appear to continue training.
thanks a lot, i fixed it. i have some image without annotations.
thanks a lot, i fixed it. i have some image without annotations.
You should leave this open. This is still a bug that needs to be fixed. Images without annotations are valid.
I just did some more testing. This has been fixed related to null annotations. However, this error still occurs if there are annotations for segmentation mixed in with the bbox annotations. I ran a test with a small dataset where 2 images were annotated with a polygon instead of a bbox and this error still occurs with the latest docker image.
Attached is the dataset I used with the args file as well as a log showing the console output.
@sstainba hey I tested seg_test_v8_loader.zip with the latest package version but never saw the shape error caused by mixed annotations again.
Also I noticed you were using YOLOv8.0.16
and this version doesn't include this fix #598. Please upgrade the package and try again. :)
@sstainba hey I tested seg_test_v8_loader.zip with the latest package version but never saw the shape error caused by mixed annotations again. Also I noticed you were using
YOLOv8.0.16
and this version doesn't include this fix #598. Please upgrade the package and try again. :)
I use the official docker images. So whatever version was last built into the image is what I was using.
👋 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:
- Docs: https://docs.ultralytics.com
- HUB: https://hub.ultralytics.com
- Community: https://community.ultralytics.com
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 ⭐