IndexError: list index out of range


Traceback (most recent call last):
File “”, line 102, in
File “”, line 94, in main
loop_and_detect(cam, trt_ssd, conf_th=0.3, vis=vis)
File “”, line 64, in loop_and_detect
img = vis.draw_bboxes(img, boxes, confs, clss)
File “/home/hyebin/project/tensorrt_demos/utils/”, line 96, in draw_bboxes
color = self.colors[cl]
IndexError: list index out of range

I got this error, then I got this answer from jk-Jung.

You need to initialize “BBoxVisualization” with the correct “cls_dict” (class dictionary, which contains the correct number of classes).

My number of class is 1.
I don’t know what he is saying.
How to modify the code?



Please refer to below topic, in case it helps:


Gtk-Message: 16:50:34.237: Failed to load module "canberra-gtk-module"
Traceback (most recent call last):
  File "", line 198, in <module>
  File "", line 188, in main
    loop_and_detect(cam, tf_sess, args.conf_th, vis, od_type=od_type)
  File "", line 120, in loop_and_detect
    img = vis.draw_bboxes(img, box, conf, cls)
  File "/home/shlok/projects/tf_trt_models/utils/", line 96, in draw_bboxes
    color = self.colors[cl]
IndexError: list index out of range

I am running using this command
python3 --latency 200 --model new_model_ssd_colab_v2_mobilenet_2020_29_12 --labelmap data/label_final.pbtxt --num-classes 3

I have only 3 classes in label file(bottle,cardboard,clothing). I am running my custom model was able to create tf-trt graph of my model successfully but as soon as I run it using onboard camera it freezes and gives index out of range errror

{0: 'CLS0', 1: 'bottle', 2: 'cardboard', 3: 'clothing'} this is the list of the classes in cls_dict so I changed --num-classes 4 still it didn’t work. I am not sure about 0: 'CLS0' is that for background? I can see this class gets added here along with the classes from label file /home/s/projects/tf_trt_models/utils/

def read_label_map(path_to_labels):
    """Read from the label map file and return a class dictionary which
    maps class id (int) to the corresponding display name (string).

    from object_detection.utils import label_map_util

    category_index = label_map_util.create_category_index_from_labelmap(
    cls_dict = {int(x['id']): x['name'] for x in category_index.values()}
    num_classes = max(c for c in cls_dict.keys()) + 1
    # add missing classes as, say,'CLS12' if any
    return {i: cls_dict.get(i, 'CLS{}'.format(i)) for i in range(num_classes)}

Can anyone guide me how should I run it on jetson tx2 with onboard cam?