nathanrooy/rpi-urban-mobility-tracker

class_name = labels[track.get_class()] KeyError: 3

Back-Pack-Jack opened this issue · 3 comments

After running -

umt -camera -display -modelpath /home/pi/ped-net/model/pednet_20200517_edgetpu.tflite -labelmap /home/pi/ped-net/model/labels.txt -tpu

This is the Ouput, note: I added a print command for the list enumeration -
i.e.
{0: 'bike'}
{0: 'bike', 1: 'pedestrian'}
{0: 'bike', 1: 'pedestrian', 2: 'vehicle'}

Output:

INITIALIZING UMT...
THRESHOLD: 0.5
CUSTOM LABEL MAP = TRUE (/home/pi/ped-net/model/labels.txt)
{0: 'bike'}
{0: 'bike', 1: 'pedestrian'}
{0: 'bike', 1: 'pedestrian', 2: 'vehicle'}
TPU = TRUE
CUSTOM DETECTOR = TRUE
> DETECTOR PATH = /home/pi/ped-net/model/pednet_20200517_edgetpu.tflite

TRACKING...
starting video stream...
FRAME: 0
no detections...
FRAME: 1
no detections...
FRAME: 2
Traceback (most recent call last):
File "/home/pi/venv_umt/bin/umt", line 8, in
sys.exit(main())
File "/home/pi/venv_umt/lib/python3.7/site-packages/umt/umt_main.py", line 107, in main
class_name = labels[track.get_class()]
KeyError: 3

This is intermittent, I can run this multiple times and get >100 Frames at times before this error. Please could you help out with any insight?

Also having this issue. For me it's always failing after frame 0.

Also having this issue. For me it's always failing after frame 0.

I managed to fix this problem by replacing the labelmap in ped-net with the labelmap coco_labels.txt in mobilenet. If I remember correctly you'll have to swap bicycle and car round in the txt file to detect the correct objects.

Also having this issue. For me it's always failing after frame 0.

I believe the issue to be with the ped-net model labels beginning at index 1 whilst the code looks for labels beginning at index 0 hence the key error. If you navigate to umt_utils.py you will see the parse_label_map function which enumerates the labelmap. The enumeration begins at position 0 which won't match the predefined labelmap, if you change:

labels[i] = row.replace('\n','') to --> labels[i+1] = row.replace('\n','')

The key error should be resolved.