Yolov3: IndexError: list index out of range

Created on 21 May 2020  路  8Comments  路  Source: ultralytics/yolov3

Before submitting a bug report, please ensure that you are using the latest versions of:

  • Python 3.6
  • PyTorch 1.5
  • This repository (run git fetch && git status -uno to check and git pull to update)

Your issue must be reproducible on a public dataset (i.e COCO) using the latest version of the repository, and you must supply code to reproduce, or we can not help you.

If this is a custom training question we suggest you include your train*.jpg, test*.jpg and results.png figures.
the upper image is the test_batch0_gt.jpg
the down image is the train_batch0.jpg
https://imgur.com/a/QYlVeoc

馃悰 Bug

A clear and concise description of what the bug is.
I git pull the latest code and trained with an old license dataset
but the error showed up when it plot the testloader

Caching labels (8824 found, 0 missing, 0 empty, 0 duplicate, for 8824 images): 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻坾 8824/8824 [00:01<00:00, 5224.90it/s]
Caching labels (1103 found, 0 missing, 0 empty, 0 duplicate, for 1103 images): 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻坾 1103/1103 [00:00<00:00, 5140.54it/s]
Image sizes 320 - 640 train, 640 test
Using 2 dataloader workers
Starting training for 300 epochs...

     Epoch   gpu_mem      GIoU       obj       cls     total   targets  img_size
     0/299     6.37G      1.29      2.29     0.834      4.41        13       512: 100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| 4412/4412 [09:52<00:00,  7.45it/s]
               Class    Images   Targets         P         R   [email protected]        F1:   0%|                                              | 0/552 [00:01<?, ?it/s]
Traceback (most recent call last):
  File "train.py", line 414, in <module>
    train(hyp)  # train normally
  File "train.py", line 317, in train
    dataloader=testloader)
  File "/data/workspace/willy_sung/yolov3/test.py", line 170, in test
    plot_images(imgs, output_to_target(output, width, height), paths=paths, names=names, fname=f)  # predictions
  File "/data/workspace/willy_sung/yolov3/utils/utils.py", line 915, in plot_images
    cls = names[cls] if names else cls
IndexError: list index out of range

To Reproduce

REQUIRED: Code to reproduce your issue below

python train.py ...

Expected behavior

A clear and concise description of what you expected to happen.

Environment

If applicable, add screenshots to help explain your problem.

  • OS: [e.g. Ubuntu] 16.04
  • GPU [e.g. 2080 Ti] 1080 Ti
    CUDA 10.2

Additional context

Add any other context about the problem here.

bug

Most helpful comment

ah I found the problem, I forgot to modify the number of classes in cfg. To be honest, most of people modify these parameters in the code instead of by hands.....

All 8 comments

and I print the result

targets [[0 6 tensor(0.50022, device='cuda:0') ... tensor(0.16544, device='cuda:0') tensor(0.48768, device='cuda:0') tensor(0.01074, device='cuda:0')]
 [0 69 tensor(0.49448, device='cuda:0') ... tensor(0.16313, device='cuda:0') tensor(0.45694, device='cuda:0') tensor(0.00929, device='cuda:0')]
 [0 1 tensor(0.49461, device='cuda:0') ... tensor(0.16228, device='cuda:0') tensor(0.44544, device='cuda:0') tensor(0.00909, device='cuda:0')]
 ...
 [7 1 tensor(0.56775, device='cuda:0') ... tensor(0.10563, device='cuda:0') tensor(0.30660, device='cuda:0') tensor(0.00103, device='cuda:0')]
 [7 24 tensor(0.49726, device='cuda:0') ... tensor(0.04715, device='cuda:0') tensor(0.14271, device='cuda:0') tensor(0.00102, device='cuda:0')]
 [7 16 tensor(0.43041, device='cuda:0') ... tensor(0.01920, device='cuda:0') tensor(0.52090, device='cuda:0') tensor(0.00100, device='cuda:0')]]
image_targets [[0 6 tensor(0.50022, device='cuda:0') tensor(0.51859, device='cuda:0') tensor(0.16544, device='cuda:0') tensor(0.48768, device='cuda:0') tensor(0.01074, device='cuda:0')]
 [0 69 tensor(0.49448, device='cuda:0') tensor(0.53081, device='cuda:0') tensor(0.16313, device='cuda:0') tensor(0.45694, device='cuda:0') tensor(0.00929, device='cuda:0')]
 [0 1 tensor(0.49461, device='cuda:0') tensor(0.53472, device='cuda:0') tensor(0.16228, device='cuda:0') tensor(0.44544, device='cuda:0') tensor(0.00909, device='cuda:0')]
 [0 13 tensor(0.50100, device='cuda:0') tensor(0.52327, device='cuda:0') tensor(0.16538, device='cuda:0') tensor(0.47461, device='cuda:0') tensor(0.00891, device='cuda:0')]
 [0 62 tensor(0.50321, device='cuda:0') tensor(0.53506, device='cuda:0') tensor(0.16482, device='cuda:0') tensor(0.48672, device='cuda:0') tensor(0.00637, device='cuda:0')]
 [0 5 tensor(0.49998, device='cuda:0') tensor(0.53385, device='cuda:0') tensor(0.16530, device='cuda:0') tensor(0.48866, device='cuda:0') tensor(0.00578, device='cuda:0')]
 [0 69 tensor(0.50033, device='cuda:0') tensor(0.52412, device='cuda:0') tensor(0.17935, device='cuda:0') tensor(0.55288, device='cuda:0') tensor(0.00571, device='cuda:0')]
 [0 6 tensor(0.50227, device='cuda:0') tensor(0.50534, device='cuda:0') tensor(0.15491, device='cuda:0') tensor(0.21401, device='cuda:0') tensor(0.00389, device='cuda:0')]
 [0 1 tensor(0.49959, device='cuda:0') tensor(0.53768, device='cuda:0') tensor(0.16975, device='cuda:0') tensor(0.51288, device='cuda:0') tensor(0.00320, device='cuda:0')]
 [0 3 tensor(0.49096, device='cuda:0') tensor(0.53590, device='cuda:0') tensor(0.16228, device='cuda:0') tensor(0.46033, device='cuda:0') tensor(0.00261, device='cuda:0')]
 [0 8 tensor(0.50027, device='cuda:0') tensor(0.55663, device='cuda:0') tensor(0.16762, device='cuda:0') tensor(0.52326, device='cuda:0') tensor(0.00254, device='cuda:0')]
 [0 56 tensor(0.54150, device='cuda:0') tensor(0.50256, device='cuda:0') tensor(0.01474, device='cuda:0') tensor(0.04292, device='cuda:0') tensor(0.00242, device='cuda:0')]
 [0 13 tensor(0.50120, device='cuda:0') tensor(0.50516, device='cuda:0') tensor(0.18320, device='cuda:0') tensor(0.59038, device='cuda:0') tensor(0.00231, device='cuda:0')]
 [0 13 tensor(0.09217, device='cuda:0') tensor(0.52232, device='cuda:0') tensor(0.16878, device='cuda:0') tensor(0.89222, device='cuda:0') tensor(0.00220, device='cuda:0')]
 [0 62 tensor(0.50730, device='cuda:0') tensor(0.51166, device='cuda:0') tensor(0.15655, device='cuda:0') tensor(0.22933, device='cuda:0') tensor(0.00219, device='cuda:0')]
 [0 13 tensor(0.50730, device='cuda:0') tensor(0.51166, device='cuda:0') tensor(0.15655, device='cuda:0') tensor(0.22933, device='cuda:0') tensor(0.00219, device='cuda:0')]
 [0 5 tensor(0.50730, device='cuda:0') tensor(0.51166, device='cuda:0') tensor(0.15655, device='cuda:0') tensor(0.22933, device='cuda:0') tensor(0.00193, device='cuda:0')]
 [0 56 tensor(0.54114, device='cuda:0') tensor(0.50193, device='cuda:0') tensor(0.01923, device='cuda:0') tensor(0.06028, device='cuda:0') tensor(0.00158, device='cuda:0')]
 [0 56 tensor(0.57640, device='cuda:0') tensor(0.50365, device='cuda:0') tensor(0.01025, device='cuda:0') tensor(0.03435, device='cuda:0') tensor(0.00152, device='cuda:0')]
 [0 0 tensor(0.50884, device='cuda:0') tensor(0.53748, device='cuda:0') tensor(0.16689, device='cuda:0') tensor(0.56829, device='cuda:0') tensor(0.00142, device='cuda:0')]
 [0 6 tensor(0.50368, device='cuda:0') tensor(0.49908, device='cuda:0') tensor(0.14416, device='cuda:0') tensor(0.18147, device='cuda:0') tensor(0.00133, device='cuda:0')]
 [0 69 tensor(0.50156, device='cuda:0') tensor(0.49420, device='cuda:0') tensor(0.22092, device='cuda:0') tensor(0.65423, device='cuda:0') tensor(0.00125, device='cuda:0')]
 [0 13 tensor(0.09756, device='cuda:0') tensor(0.51056, device='cuda:0') tensor(0.17404, device='cuda:0') tensor(0.94447, device='cuda:0') tensor(0.00123, device='cuda:0')]
 [0 4 tensor(0.50623, device='cuda:0') tensor(0.51778, device='cuda:0') tensor(0.16212, device='cuda:0') tensor(0.43526, device='cuda:0') tensor(0.00120, device='cuda:0')]
 [0 56 tensor(0.56499, device='cuda:0') tensor(0.50280, device='cuda:0') tensor(0.01702, device='cuda:0') tensor(0.04066, device='cuda:0') tensor(0.00113, device='cuda:0')]
 [0 13 tensor(0.50949, device='cuda:0') tensor(0.51015, device='cuda:0') tensor(0.12393, device='cuda:0') tensor(0.16303, device='cuda:0') tensor(0.00109, device='cuda:0')]]
classes [ 6 69  1 13 62  5 69  6  1  3  8 56 13 13 62 13  5 56 56  0  6 69 13  4 56 13]

there is something wrong with the target, it should be

targets [[          0          25     0.44141     0.50469    0.023438    0.084375]
 [          0          10     0.46016     0.50469    0.020312    0.084375]
 [          0          23     0.47891     0.50469    0.020312    0.078125]
 [          0           1     0.50313         0.5    0.021875       0.075]
 [          0           5     0.52188     0.50156    0.020312    0.078125]
 [          0           0     0.54141     0.50094       0.025       0.075]
 [          0          20     0.56344     0.50281    0.020312    0.078125]
 [          1           8     0.45547      0.4875    0.015625     0.05625]
 [          1          13     0.47031     0.48906    0.017188    0.059375]
 [          1           7     0.49297     0.48906    0.015625    0.059375]
 [          1           8     0.50859      0.4875    0.015625     0.05625]
 [          1           0       0.525      0.4875    0.017188     0.05625]
 [          1           8     0.54062     0.48594    0.017188    0.053125]
 [          2           5     0.45078     0.49531    0.017188    0.078125]

and I am pretty sure the dataset is correct

Your *.names file is missing or incorrect.

Your *.names file is missing or incorrect.

when you call plot_images() intrain.py and test.pyyou didn't set the names....
plot_images(imgs=imgs, targets=targets, paths=paths, fname=f)
what should I set?
I printed it all
it showed the names is correct
but the target is not so is the class

names ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'Military', 'Foregin', 'Shi']
cls 59

is it related to pytorch 1.5?

1.5 is fine. See wiki custom training tutorial for guidance.

I already checked the guidance, and my dataset is fine.
the problem is why target should be like

targets [[          0          25     0.44141     0.50469    0.023438    0.084375]
 [          0          10     0.46016     0.50469    0.020312    0.084375]
 [          0          23     0.47891     0.50469    0.020312    0.078125]
 [          0           1     0.50313         0.5    0.021875       0.075]
 [          0           5     0.52188     0.50156    0.020312    0.078125]
 [          0           0     0.54141     0.50094       0.025       0.075]
 [          0          20     0.56344     0.50281    0.020312    0.078125]
 [          1           8     0.45547      0.4875    0.015625     0.05625]
 [          1          13     0.47031     0.48906    0.017188    0.059375]
 [          1           7     0.49297     0.48906    0.015625    0.059375]
 [          1           8     0.50859      0.4875    0.015625     0.05625]
 [          1           0       0.525      0.4875    0.017188     0.05625]
 [          1           8     0.54062     0.48594    0.017188    0.053125]
 [          2           5     0.45078     0.49531    0.017188    0.078125]

but it showed :

targets [[0 6 tensor(0.50022, device='cuda:0') ... tensor(0.16544, device='cuda:0') tensor(0.48768, device='cuda:0') tensor(0.01074, device='cuda:0')]
 [0 69 tensor(0.49448, device='cuda:0') ... tensor(0.16313, device='cuda:0') tensor(0.45694, device='cuda:0') tensor(0.00929, device='cuda:0')]
 [0 1 tensor(0.49461, device='cuda:0') ... tensor(0.16228, device='cuda:0') tensor(0.44544, device='cuda:0') tensor(0.00909, device='cuda:0')]

when the error happened.

This error is not reproducible using your code to reproduce.

In order to debug we need you to supply minimum code to reproduce on coco data.

Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:

  • Your changes to the default repository. If your issue is not reproducible in a fresh git clone version of this repository we can not debug it. Before going further run this code and ensure your issue persists:
sudo rm -rf yolov3  # remove existing
git clone https://github.com/ultralytics/yolov3 && cd yolov3 # clone latest
python3 detect.py  # verify detection
python3 train.py  # verify training (a few batches only)
# CODE TO REPRODUCE YOUR ISSUE HERE
  • Your custom data. If your issue is not reproducible with COCO data we can not debug it. Visit our Custom Training Tutorial for exact details on how to format your custom data. Examine train_batch0.jpg and test_batch0.jpg for a sanity check of training and testing data.
  • Your environment. If your issue is not reproducible in a GCP Quickstart Guide VM we can not debug it. Ensure you meet the requirements specified in the README: Unix, MacOS, or Windows with Python >= 3.7, PyTorch >= 1.4 etc. You can also use our Google Colab Notebook and our Docker Image to test your code in a working environment.

If none of these apply to you, we suggest you close this issue and raise a new one using the Bug Report template, providing screenshots and minimum viable code to reproduce your issue. Thank you!

ah I found the problem, I forgot to modify the number of classes in cfg. To be honest, most of people modify these parameters in the code instead of by hands.....

Was this page helpful?
0 / 5 - 0 ratings