nathanrooy / rpi-urban-mobility-tracker

The easiest way to count pedestrians, cyclists, and vehicles on edge computing devices or live video feeds.
GNU General Public License v3.0
122 stars 37 forks source link

Using TPU: AttributeError: 'Delegate' object has no attribute '_library' #17

Closed airqualityanthony closed 3 years ago

airqualityanthony commented 3 years ago

Running the docker as per the file instructions - RPi 4 with a TPI.

Trying to run the command: umt -video highway_01.mp4 -tpu

I get the following:

> INITIALIZING UMT...
   > THRESHOLD: 0.5
   > CUSTOM LABEL MAP = FALSE
   > TPU = TRUE
   > CUSTOM DETECTOR = FALSE
Traceback (most recent call last):
  File "/usr/local/bin/umt", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/dist-packages/umt/umt_main.py", line 62, in main
    interpreter = initialize_detector(args)
  File "/usr/local/lib/python3.7/dist-packages/umt/umt_utils.py", line 110, in initialize_detector
    {'device': device[0]} if device else {})
  File "/usr/local/lib/python3.7/dist-packages/tflite_runtime/interpreter.py", line 152, in load_delegate
    delegate = Delegate(library, options)
  File "/usr/local/lib/python3.7/dist-packages/tflite_runtime/interpreter.py", line 81, in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
  File "/usr/lib/python3.7/ctypes/__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libedgetpu.so.1: cannot open shared object file: No such file or directory
Exception ignored in: <function Delegate.__del__ at 0xa819b198>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/tflite_runtime/interpreter.py", line 116, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'

It works fine when I run without the tpu argument. I have the tpu installed correctly, and works for other code outside the docker.

Any help?

Thanks,

Anthony

airqualityanthony commented 3 years ago

I think the issue is the installation of the tflite runtime and edgetpu libraries have been updated. I had to edit the dockerfile to contain the following:

# install tflite runtime
RUN apt-get install -y apt-utils
RUN apt-get install -y curl
RUN echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list
RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN apt-get update -y
RUN apt-get install -y libedgetpu1-std
RUN apt-get install -y python3-pycoral

Seems to work ok.

airqualityanthony commented 3 years ago

@nathanrooy I'll close out, suggest the above changes to be implemented for latest installation. Feel free to check and edit if necessary.