Skip to content
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

IndexError: index 1 is out of bounds for dimension 1 with size 1 #472

Closed
1 of 2 tasks
ElMahdiAboulmanadel opened this issue Jan 18, 2023 · 16 comments
Closed
1 of 2 tasks
Labels
bug Something isn't working Stale

Comments

@ElMahdiAboulmanadel
Copy link

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Training

Bug

I'm using this command to train YOLO v8 on Plant Village Dataset, I've prepared the dataset in YOLO Format as described in the tutorials : yolo task=detect mode=train model=yolov8n.pt data=plantvillage.yaml epochs=3 imgsz=256

When I run the command, I get this error :

align_metric, overlaps = self.get_box_metrics(pd_scores, pd_bboxes, gt_labels, gt_bboxes)
File "python3.10/site-packages/ultralytics/yolo/utils/tal.py", line 129, in get_box_metrics
bbox_scores = pd_scores[ind[0], :, ind[1]] # b, max_num_obj, h*w
IndexError: index 1 is out of bounds for dimension 1 with size 1

Environment

  • YOLO : YOLO v8 Pytorch (PIP package : !pip install ultralytics)
  • OS : MacOS Monterey (MacBook Air M1)
  • Python : 3.10

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@ElMahdiAboulmanadel ElMahdiAboulmanadel added the bug Something isn't working label Jan 18, 2023
@glenn-jocher
Copy link
Member

@ElMahdiAboulmanadel thanks for the bug report! Can you provide your dataset to help us reproduce? Your command works correctly with COCO128 so at the moment it is not possible for us to debug this.

@ElMahdiAboulmanadel
Copy link
Author

Hello @glenn-jocher , thanks for the quick reply! here is the dataset I'm using : https://drive.google.com/drive/folders/1SiUKC1mtuT88E5OIIkaH4mqOPhH39iJz?usp=share_link , I was trying Ultralytics HUB but it didn't work (Dataset processing error).

@AyushExel
Copy link
Contributor

If ultralytics HUB didn't work, there's probably something wrong with your dataset. Can you paste the error you're getting on hub?

@ElMahdiAboulmanadel
Copy link
Author

When I upload the dataset zip file, I get the following error : Processing Error
Screen Shot 2023-01-18 at 18 57 29

@ElMahdiAboulmanadel
Copy link
Author

I made a new dataset and I think it'll work this time, I uploaded it to Ultalytics HUB and it didn't give me the processing error this time, it's still Transferring... Can you please explain to me the issue? I actually have a dataset of images of one leaf, each image has one leaf of a specific plant with a specific disease so you'll find that my labels bboxes are all the same : 1 0.5 0.5 0.9 0.9, only the class ID is changing. Does the issue relate to my approach of having one bbox per image?

@ElMahdiAboulmanadel
Copy link
Author

When it finished processing the dataset, I clicked on train model then went to Google Colab. When I launch the second code cell, it starts then crashes. A popup appears in the left bottom area saying 'Your session crashed. Automatically restarting.'
Screen Shot 2023-01-18 at 20 12 57

I tried multiple times but I get the same issue and here is the results :

Ultralytics: 0.285 GB dataset, 54.7/78.2 GB free disk space
train: weights=yolov5n.pt, cfg=, data=https://storage.googleapis.com/ultralytics-hub.appspot.com/users/bBSaR6OYiDTLVOeINjTo0hwaAG02/datasets/HXHDwv0RVBqmbaS3zWdO/plantvillage.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=firebase-adminsdk-jsjt9%40ultralytics-hub.iam.gserviceaccount.com%2F20230118%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20230118T190816Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host&X-Goog-Signature=869cb50ad3de0045f1e739a0b0dd3a7bd9c9db303fb57eac16773c0e059eb03397cc8d7c2388fcc3b11ec3422ece77370bf0460c4b26633b034ac1a838408c2825e9fa912b32f646f88202234bd3f04e69c65c285194dfc8da6efda1a7a9889210668b253ffba713356682c04912361ee753ecc5c8f43eec17ee2686b99970e0c83acc72a97e397c15e5895fa31b5e48eb33ca68835be79727e9a43f1629f621934497e3fc78efc26f272b441965dcc55289edc81f2bc2e77316c978a50eb5c573b0cbeee88b38fc5a1d341f330592ca3e7a530069351962aa537991174b72c793e1298be194503e84ef611fd91614990db1a4311eb6a2d89b177e52d2e2b556, hyp=yolov5/data/hyps/hyp.scratch-low.yaml, epochs=100, batch_size=-1, imgsz=640, 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=yolov5/runs/train, name=exp, 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, id=7tFzUZB1ocGh5nyGzhtd, status=new
github: up to date with https://github.com/ultralytics/yolov5
Downloading https://storage.googleapis.com/ultralytics-hub.appspot.com/users/bBSaR6OYiDTLVOeINjTo0hwaAG02/datasets/HXHDwv0RVBqmbaS3zWdO/plantvillage.zip?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=firebase-adminsdk-jsjt9%40ultralytics-hub.iam.gserviceaccount.com%2F20230118%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20230118T190816Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host&X-Goog-Signature=869cb50ad3de0045f1e739a0b0dd3a7bd9c9db303fb57eac16773c0e059eb03397cc8d7c2388fcc3b11ec3422ece77370bf0460c4b26633b034ac1a838408c2825e9fa912b32f646f88202234bd3f04e69c65c285194dfc8da6efda1a7a9889210668b253ffba713356682c04912361ee753ecc5c8f43eec17ee2686b99970e0c83acc72a97e397c15e5895fa31b5e48eb33ca68835be79727e9a43f1629f621934497e3fc78efc26f272b441965dcc55289edc81f2bc2e77316c978a50eb5c573b0cbeee88b38fc5a1d341f330592ca3e7a530069351962aa537991174b72c793e1298be194503e84ef611fd91614990db1a4311eb6a2d89b177e52d2e2b556 to plantvillage.zip...
100%
292M/292M [00:25<00:00, 10.3MB/s]
YOLOv5 🚀 v7.0-23-g2e3c515 Python-3.8.10 torch-1.13.1+cu116 CUDA:0 (Tesla T4, 15110MiB)

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
ClearML: run 'pip install clearml' to automatically track, visualize and remotely train YOLOv5 🚀 in ClearML
Comet: run 'pip install comet_ml' to automatically track and visualize YOLOv5 🚀 runs in Comet
TensorBoard: Start with 'tensorboard --logdir yolov5/runs/train', view at http://localhost:6006/
Unzipping plantvillage.zip...
Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...
100%
755k/755k [00:00<00:00, 3.10MB/s]
Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.pt to yolov5n.pt...
100%
3.87M/3.87M [00:00<00:00, 100MB/s]

Overriding model.yaml nc=80 with nc=10

             from  n    params  module                                  arguments                     

0 -1 1 1760 models.common.Conv [3, 16, 6, 2, 2]
1 -1 1 4672 models.common.Conv [16, 32, 3, 2]
2 -1 1 4800 models.common.C3 [32, 32, 1]
3 -1 1 18560 models.common.Conv [32, 64, 3, 2]
4 -1 2 29184 models.common.C3 [64, 64, 2]
5 -1 1 73984 models.common.Conv [64, 128, 3, 2]
6 -1 3 156928 models.common.C3 [128, 128, 3]
7 -1 1 295424 models.common.Conv [128, 256, 3, 2]
8 -1 1 296448 models.common.C3 [256, 256, 1]
9 -1 1 164608 models.common.SPPF [256, 256, 5]
10 -1 1 33024 models.common.Conv [256, 128, 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 90880 models.common.C3 [256, 128, 1, False]
14 -1 1 8320 models.common.Conv [128, 64, 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 22912 models.common.C3 [128, 64, 1, False]
18 -1 1 36992 models.common.Conv [64, 64, 3, 2]
19 [-1, 14] 1 0 models.common.Concat [1]
20 -1 1 74496 models.common.C3 [128, 128, 1, False]
21 -1 1 147712 models.common.Conv [128, 128, 3, 2]
22 [-1, 10] 1 0 models.common.Concat [1]
23 -1 1 296448 models.common.C3 [256, 256, 1, False]
24 [17, 20, 23] 1 20295 models.yolo.Detect [10, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [64, 128, 256]]
Model summary: 214 layers, 1777447 parameters, 1777447 gradients, 4.3 GFLOPs

Transferred 343/349 items from yolov5n.pt
AMP: checks passed ✅
AutoBatch: Computing optimal batch size for --imgsz 640
AutoBatch: CUDA:0 (Tesla T4) 14.76G total, 0.04G reserved, 0.01G allocated, 14.70G free
Params GFLOPs GPU_mem (GB) forward (ms) backward (ms) input output
1777447 4.263 0.117 129.9 34.13 (1, 3, 640, 640) list
1777447 8.526 0.218 24.47 16.32 (2, 3, 640, 640) list
1777447 17.05 0.455 23.14 17.49 (4, 3, 640, 640) list
1777447 34.1 0.948 24.31 20.15 (8, 3, 640, 640) list
AutoBatch: Using batch-size 112 for CUDA:0 11.80G/14.76G (80%) ✅
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.000875), 60 bias
1777447 68.21 1.671 40.15 33.9 (16, 3, 640, 640) list
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/datasets/plantvillage/labels/train... 14531 images, 0 backgrounds, 0 corrupt: 100%|██████████| 14531/14531 00:07Signal received. 15 <frame at 0x7efb5810a6c0, file '/usr/lib/python3.8/multiprocessing/synchronize.py', line 98, code exit>

train: New cache created: /content/datasets/plantvillage/labels/train.cache
train: 16.6GB RAM required, 8.4/12.7GB available, not caching images ⚠️
val: Scanning /content/datasets/plantvillage/labels/val... 3545 images, 82 backgrounds, 0 corrupt: 100%|██████████| 3627/3627 00:04
val: New cache created: /content/datasets/plantvillage/labels/val.cache
val: Caching images (4.2GB ram): 100%|██████████| 3627/3627 00:14

AutoAnchor: 1.92 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Ultralytics: View model at https://hub.ultralytics.com/models/7tFzUZB1ocGh5nyGzhtd 🚀
Plotting labels to yolov5/runs/train/exp/labels.jpg...

@dhirendracode
Copy link

dhirendracode commented Jan 20, 2023

@ElMahdiAboulmanadel i was also facing same issue while doing validation . issue is solved , just by providing validation dataset.
just provide data="your data path"

@jaztiria99
Copy link

I'm having the same error with a single-class object detection problem. I'm aiming to detect defects (not classified) in some metal parts. Here's my dataset (based on CSIM-MISD dataset), together with the data.yaml file: https://drive.google.com/drive/folders/1kI-lCv8nv2jNqy1O6PnandzhRZSA-APO?usp=sharing.

@github-actions
Copy link

github-actions bot commented Mar 9, 2023

👋 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:

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 ⭐

@github-actions github-actions bot added the Stale label Mar 9, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2023
@yrik
Copy link

yrik commented Jun 5, 2023

Same issue

I'm having the same error with a single-class object detection problem. I'm aiming to detect defects (not classified) in some metal parts. Here's my dataset (based on CSIM-MISD dataset), together with the data.yaml file: https://drive.google.com/drive/folders/1kI-lCv8nv2jNqy1O6PnandzhRZSA-APO?usp=sharing.

@glenn-jocher
Copy link
Member

@yrik hello! Thank you for reaching out regarding this error. In order to resolve this issue, it's important to provide a validation dataset in addition to the train dataset. You can do this by providing the path to your validation dataset when running the YOLOv8 training command using the --val-data flag. This will allow the model to validate its performance and help prevent the error you encountered. Please let us know if you have any further questions or concerns.

@yrik
Copy link

yrik commented Jun 6, 2023

@glenn-jocher thank you for the reply! In my case, the issue was simpler. I had index 1 (instead of 0) in my txt files that describe labels and in my data.yaml file I had just one class. So to fix it I just added a dummy extra class to the data.yaml and all is good now.

@FreeSoaring
Copy link

I also encountered this issue. After investigating, I found that the mismatch between the IDs in the labels and the number of classes (nc) in the config file was the cause. For example, if you have IDs 0 and 1 in the labels but set nc=1 in the config, you will encounter this error. Correctly setting the class information in the config can avoid this issue. I hope this helps you.

@glenn-jocher
Copy link
Member

@FreeSoaring hello and thank you for your contribution!

Your finding about the mismatch between the IDs in the labels and the classes in the config file is a valuable catch indeed - it could very well be the root of the issue that some are encountering.

It's crucial that the class IDs in the label files align with the 'nc' (number of classes) mentioned in the dataset configuration. If you have labels for classes 0 and 1, but you've set 'nc' as 1 in the config file, the model could potentially struggle with identifying and categorizing the objects correctly which may result in errors.

Ensuring that the number of classes in the config file aligns with the highest class ID in the label files would be key to avoiding this kind of issue.

Keep exploring and debugging, your insights are very helpful for us and the wider community!

@Rilesyt
Copy link

Rilesyt commented Feb 9, 2024

Hello I am working in an object detection project in a company while training the model I encountered this error:
"File "c:\users\qg627\desktop\s&w\env\lib\site-packages\ultralytics\utils\tal.py", line 113, in get_box_metrics
bbox_scores[mask_gt] = pd_scores[ind[0], :, ind[1]][mask_gt] # b, max_num_obj, h*w
IndexError: index 6 is out of bounds for dimension 1 with size 6"
I used this command for trainig:
yolo task=detect mode=train epochs=20 data=data_custom.yaml model=yolov8m.pt imgsz= 640

My dataset is about more than 400+ images. I annotated it all manually!

Can anyone of you guys can help me to resolve the issue?

Hoping for a quick reply !😅

@glenn-jocher
Copy link
Member

@Rilesyt it appears you're encountering an index error during training, which suggests there might be an issue with the dataset or the model's interpretation of the dataset. Here are a few steps you can take to troubleshoot the problem:

  1. Check Dataset Integrity: Ensure that your dataset annotations are correctly formatted and that each image has corresponding annotation data. Verify that the number of classes in your plantvillage.yaml matches the number of classes in your dataset.

  2. Update to Latest Version: Make sure you're using the latest version of the Ultralytics YOLOv8 package, as updates often include bug fixes. You can update the package using:

    pip install --upgrade ultralytics
  3. Review Configuration: Double-check your plantvillage.yaml file for any errors or inconsistencies, particularly in the nc (number of classes) and names (class names) fields.

  4. Reduce Complexity: Try running the training with a smaller subset of your dataset to see if the error persists. This can help isolate whether the problem is data-specific or more general.

  5. Check for Similar Issues: Although you've already searched for similar issues, it might be helpful to revisit the issues page periodically, as someone else may have encountered the same problem and found a solution.

  6. Submit an Issue: If none of the above steps resolve the issue, consider submitting a detailed bug report on the Ultralytics YOLOv8 GitHub issues page. Include the full error message, steps to reproduce the issue, and details about your dataset and environment.

Remember, the YOLOv8 community and the Ultralytics team are here to help! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

8 participants