yolov7-segmentation icon indicating copy to clipboard operation
yolov7-segmentation copied to clipboard

IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 9

Open DivyankaThakur03 opened this issue 2 years ago • 9 comments

`Transferred 555/565 items from yolov7-seg.pt AMP: checks passed ✅ optimizer: SGD(lr=0.01) with parameter groups 98 weight(decay=0.0), 95 weight(decay=0.0005), 95 bias train: Scanning '/home/divya/Documents/potholes/yolov7-segmentation/pot/train/l train: New cache created: /home/divya/Documents/potholes/yolov7-segmentation/pot/train/labels.cache val: Scanning '/home/divya/Documents/potholes/yolov7-segmentation/pot/test/labe val: New cache created: /home/divya/Documents/potholes/yolov7-segmentation/pot/test/labels.cache

AutoAnchor: 4.29 anchors/target, 0.999 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅ Plotting labels to runs/train-seg/yolov7-seg/labels.jpg... Image sizes 640 train, 640 val Using 4 dataloader workers Logging results to runs/train-seg/yolov7-seg Starting training for 10 epochs...

  Epoch    GPU_mem   box_loss   seg_loss   obj_loss   cls_loss  Instances       Size

0%| | 0/1753 [00:00<?, ?it/s]
Traceback (most recent call last): File "segment/train.py", line 681, in main(opt) File "segment/train.py", line 577, in main train(opt.hyp, opt, device, callbacks) File "segment/train.py", line 295, in train for i, (imgs, targets, paths, _, masks) in pbar: # batch ------------------------------------------------------ File "/usr/local/lib/python3.8/dist-packages/tqdm/std.py", line 1195, in iter for obj in iterable: File "/home/divya/Documents/potholes/yolov7-segmentation/utils/dataloaders.py", line 171, in iter yield next(self.iterator) File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 530, in next data = self._next_data() File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1224, in _next_data return self._process_data(data) File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1250, in _process_data data.reraise() File "/home/divya/.local/lib/python3.8/site-packages/torch/_utils.py", line 457, in reraise raise exception IndexError: Caught IndexError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/divya/Documents/potholes/yolov7-segmentation/utils/segment/dataloaders.py", line 111, in getitem img, labels, segments = self.load_mosaic(index) File "/home/divya/Documents/potholes/yolov7-segmentation/utils/segment/dataloaders.py", line 254, in load_mosaic img4, labels4, segments4 = random_perspective(img4, File "/home/divya/Documents/potholes/yolov7-segmentation/utils/segment/augmentations.py", line 102, in random_perspective new_segments = np.array(new_segments)[i] IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 9`

This is the error I'm getting while running this - python3 segment/train.py --data data.yaml --batch 4 --weights 'yolov7-seg.pt' --cfg yolov7-seg.yaml --epochs 10 --name yolov7-seg --hyp hyp.scratch-high.yaml

DivyankaThakur03 avatar Oct 03 '22 09:10 DivyankaThakur03

@DivyankaThakur03, it seems the error related to torch version or cuda modules. Can you tell the pytorch version you have used?

RizwanMunawar avatar Oct 03 '22 15:10 RizwanMunawar

The pytorch version is 1.12.0+cu113. This can may be an issue? So which version should I install for?

DivyankaThakur03 avatar Oct 03 '22 17:10 DivyankaThakur03

@DivyankaThakur03! You can use pytorch version >1.7.1 and <1.12.0

RizwanMunawar avatar Oct 04 '22 04:10 RizwanMunawar

Thanks for your reply @RizwanMunawar, I installed 1.11.0+cu113 this torch version, still the error persists.

     Epoch    GPU_mem   box_loss   seg_loss   obj_loss   cls_loss  Instances       Size
  0%|          | 0/3505 [00:00<?, ?it/s]                                        
Traceback (most recent call last):
  File "segment/train.py", line 681, in <module>
    main(opt)
  File "segment/train.py", line 577, in main
    train(opt.hyp, opt, device, callbacks)
  File "segment/train.py", line 295, in train
    for i, (imgs, targets, paths, _, masks) in pbar:  # batch ------------------------------------------------------
  File "/usr/local/lib/python3.8/dist-packages/tqdm/std.py", line 1195, in __iter__
    for obj in iterable:
  File "/home/divya/Documents/potholes/yolov7/seg/utils/dataloaders.py", line 171, in __iter__
    yield next(self.iterator)
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 530, in __next__
    data = self._next_data()
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1224, in _next_data
    return self._process_data(data)
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1250, in _process_data
    data.reraise()
  File "/home/divya/.local/lib/python3.8/site-packages/torch/_utils.py", line 457, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/divya/.local/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/home/divya/Documents/potholes/yolov7/seg/utils/segment/dataloaders.py", line 111, in __getitem__
    img, labels, segments = self.load_mosaic(index)
  File "/home/divya/Documents/potholes/yolov7/seg/utils/segment/dataloaders.py", line 254, in load_mosaic
    img4, labels4, segments4 = random_perspective(img4,
  File "/home/divya/Documents/potholes/yolov7/seg/utils/segment/augmentations.py", line 102, in random_perspective
    new_segments = np.array(new_segments)[i]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 9

DivyankaThakur03 avatar Oct 04 '22 07:10 DivyankaThakur03

Has anyone found a solution? I have exactly the same problem.

Construct705 avatar Oct 14 '22 10:10 Construct705

@DivyankaThakur03 How many classes do you have in your training data? I have tested this issue. Most of the time it's coming when no classes are mismatched with the id on the label. i.e in some of the label files, you have class 9, but in your YAML file, you have set only a single class.

RizwanMunawar avatar Oct 15 '22 08:10 RizwanMunawar

Hi @RizwanMunawar thanks for the good work. I get the same error also

Traceback (most recent call last):
  File "C:\Users\mag\projects\yolov7Mask\segment\train.py", line 681, in <module>
    main(opt)
  File "C:\Users\mag\projects\yolov7Mask\segment\train.py", line 577, in main
    train(opt.hyp, opt, device, callbacks)
  File "C:\Users\mag\projects\yolov7Mask\segment\train.py", line 295, in train
    for i, (imgs, targets, paths, _, masks) in pbar:  # batch ------------------------------------------------------
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\tqdm\std.py", line 1195, in __iter__
    for obj in iterable:
  File "C:\Users\mag\projects\yolov7Mask\utils\dataloaders.py", line 171, in __iter__
    yield next(self.iterator)
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\dataloader.py", line 681, in __next__
    data = self._next_data()
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\dataloader.py", line 1376, in _next_data
    return self._process_data(data)
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\dataloader.py", line 1402, in _process_data
    data.reraise()
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\_utils.py", line 461, in reraise
    raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\_utils\worker.py", line 302, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\_utils\fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\mag\projects\yolov7Mask\.env\lib\site-packages\torch\utils\data\_utils\fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\mag\projects\yolov7Mask\utils\segment\dataloaders.py", line 111, in __getitem__
    img, labels, segments = self.load_mosaic(index)
  File "C:\Users\mag\projects\yolov7Mask\utils\segment\dataloaders.py", line 254, in load_mosaic
    img4, labels4, segments4 = random_perspective(img4,
  File "C:\Users\mag\projects\yolov7Mask\utils\segment\augmentations.py", line 102, in random_perspective        
    new_segments = np.array(new_segments)[i]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 0 but corresponding boolean dimension is 53

magedhelmy1 avatar Oct 20 '22 19:10 magedhelmy1

I solved my error and figured out that my annotations were in bounding box format and not in polygon format. (wrong transformation from labelme json to yolo format). Maybe this helps

Construct705 avatar Oct 21 '22 05:10 Construct705

I solved my error and figured out that my annotations were in bounding box format and not in polygon format. (wrong transformation from labelme json to yolo format). Maybe this helps

@Construct705 Glad your issue has been resolved. BTW, in readme.md its clearly mentioned that your annotation need to be in polygon format. see this https://github.com/RizwanMunawar/yolov7-segmentation#custom-data-labelling

RizwanMunawar avatar Oct 21 '22 06:10 RizwanMunawar

Hi, how do you convert the polygon annotated json file to the txt file required by yolo?

dy0930 avatar Jun 08 '23 13:06 dy0930