Description
Traceback (most recent call last):
File “trt_ssd.py”, line 102, in
main()
File “trt_ssd.py”, line 94, in main
loop_and_detect(cam, trt_ssd, conf_th=0.3, vis=vis)
File “trt_ssd.py”, line 64, in loop_and_detect
img = vis.draw_bboxes(img, boxes, confs, clss)
File “/home/hyebin/project/tensorrt_demos/utils/visualization.py”, line 96, in draw_bboxes
color = self.colors[cl]
IndexError: list index out of range
I got this error when I run Tensorrt_demo
while True:
if cv2.getWindowProperty(WINDOW_NAME, 0) < 0:
break
img = cam.read()
if img is not None:
boxes, confs, clss = trt_ssd.detect(img, conf_th)
img = vis.draw_bboxes(img, boxes, confs, clss)
img = show_fps(img, fps)
cv2.imshow(WINDOW_NAME, img)
toc = time.time()
curr_fps = 1.0 / (toc - tic)
# calculate an exponentially decaying average of fps number
fps = curr_fps if fps == 0.0 else (fps0.95 + curr_fps0.05)
tic = toc
key = cv2.waitKey(1)
if key == 27: # ESC key: quit program
break
elif key == ord(‘F’) or key == ord(‘f’): # Toggle fullscreen
full_scrn = not full_scrn
set_display(WINDOW_NAME, full_scrn)
def main():
args = parse_args()
cam = Camera(args)
cam.open()
if not cam.is_opened:
sys.exit(‘Failed to open camera!’)
cls_dict = get_cls_dict(args.model.split(‘_’)[-1])
trt_ssd = TrtSSD(args.model, INPUT_HW)
cam.start()
open_window(WINDOW_NAME, args.image_width, args.image_height,
‘Camera TensorRT SSD Demo for Jetson Nano’)
vis = BBoxVisualization(cls_dict)
loop_and_detect(cam, trt_ssd, conf_th=0.3, vis=vis)
cam.stop()
cam.release()
cv2.destroyAllWindows()
This is where trt_ssd.py’s error occurred.
def draw_bboxes(self, img, boxes, confs, clss):
“”“Draw detected bounding boxes on the original image.”“”
for bb, cf, cl in zip(boxes, confs, clss):
cl = int(cl)
x_min, y_min, x_max, y_max = bb[0], bb[1], bb[2], bb[3]
color = self.colors[cl]
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), color, 2)
txt_loc = (max(x_min+2, 0), max(y_min+2, 0))
cls_name = self.cls_dict.get(cl, ‘CLS{}’.format(cl))
txt = ‘{} {:.2f}’.format(cls_name, cf)
img = draw_boxed_text(img, txt, txt_loc, color)
And this is where visualization.py’s error occurred.
How to solve it?
Environment
TensorRT Version: 6
GPU Type: Jetson TX2
Nvidia Driver Version:
CUDA Version: 10
CUDNN Version: 7
Operating System + Version: Jetpack 4.3
Python Version (if applicable): 3.6
TensorFlow Version (if applicable): 1.15
PyTorch Version (if applicable):
Baremetal or Container (if container which image + tag):