tensorflow: Failed to load delegate from libedgetpu.so.1.0 with tflite_runtime 1.14
System information
- Have I written code (based on the docs):
from tflite_runtime.interpreter import Interpreter
from tflite_runtime.interpreter import load_delegate
model_path='my_compiled_model.tflite'
interpreter = Interpreter(model_path,
experimental_delegates=[load_delegate('libedgetpu.so.1.0')])
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
Operating System: Ubuntu 18.04.3 LTS
Kernel: Linux 4.15.0-60-generic
Architecture: x86-64
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: laptop
- TensorFlow installed from (source or binary):
pip3 install tflite_runtime-1.14.0-cp36-cp36m-linux_x86_64.whl - TensorFlow version (use command below): tflite_runtime 1.14
- Python version:
Python 3.6.5 :: Anaconda, Inc. - Bazel version (if compiling from source): n/a
- GCC/Compiler version (if compiling from source): n/a
- CUDA/cuDNN version: n/a
- GPU model and memory: n/a
This is the code that I ran:
from tflite_runtime.interpreter import Interpreter
from tflite_runtime.interpreter import load_delegate
model_path='my_compiled_model.tflite'
interpreter = Interpreter(model_path,
experimental_delegates=[load_delegate('libedgetpu.so.1.0')])
following this tutorial: https://www.tensorflow.org/lite/guide/python
This was working before, but somehow broken with this error:
Traceback (most recent call last):
File "/home/nam/anaconda3/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 165, in load_delegate
delegate = Delegate(library, options)
File "/home/nam/anaconda3/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 119, in __init__
raise ValueError(capture.message)
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "evaluate_edgetpu_cifar10.py", line 51, in <module>
interpreter = Interpreter(file_name,experimental_delegates=[load_delegate('libedgetpu.so.1.0')])
File "/home/nam/anaconda3/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 168, in load_delegate
library, str(e)))
ValueError: Failed to load delegate from libedgetpu.so.1.0
I have been messing around a lot with my machine since by installing different versions of tf. But for the purpose of using the tflite_runtime.interpreter’s load_delegate function, shouldn’t just the pip install works?
Very weird behavior 😕
also I do have libedgetpu.so.1.0 installed here:
% ls /usr/lib/x86_64-linux-gnu/libedgetpu.so.1.0
/usr/lib/x86_64-linux-gnu/libedgetpu.so.1.0
Thanks in advance for the help!
[EDIT]
I guess I’ll update the issue here with a solution so that any body else can reference:
ValueError: Failed to load delegate from libedgetpu.so.1.0 really is just due to the delegate library not being able to communicate with the edgetpu. This is a very standard linux problem and has nothing to do with the tensorflow library or libedgetpu. The failures most likely stems from some type of errno from the kernel which returns as failure to the user side.
So the easiest fix is to run with sudo:
$ sudo python your_script.py
But the most permanent fix is to add your linux user to the plugdev group which will allows you to access devices without sudo (this will requires a reboot after):
$ sudo usermod -aG plugdev $USER
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 23
- Comments: 33 (1 by maintainers)
Hi @Namburger , I had the same issue!
Make sure your Coral USB Accelerator is plugged in when you run your code. If the USB Accelerator isn’t plugged in when you call the ‘load_delegate’ function, it will result in that error. If it IS plugged in, that error won’t occur.
I am facing the same issue , even when the USB accelerator is plugged in and the LED in it is shining bright …
After spending many hours on and off thinking about this problem and combing the net, I finally solved this problem with this “Failed to load delegate from libedgetpu.so.1.0 error”. Essentially, the cable that Google provided with my Coral USB TPU stinks. I broke down and purchased a USB 3.1 (10Gbps) (NOT 5Gbps) cable and everything worked perfectly on the USB 3.0 port for the Raspberry Pi 4b (4GB). I hope this helps someone else in the same situation I was in.
rebooting my pi - fixed the issue for me
Thanks @cruzzer for the suggestions!
Does anyone have tried to use the TPU with a program in a Docker container? I am getting the same
Failed to load delegate from libedgetpu.so.1.0error when running my docker container.I plugged in the device, and I did this too, it still is showing the same error. I am using ubuntu installed on a virtualbox in Mac. The USB device is getting attached, but load_delegate is giving error
I got the same problem in native Ubuntu. Reboot helps.
@programmer290399 you might need to add your linux user to plugdev group:
(last edit: May 28,2021, to handle situation when lsusb works, but coral doesn’t load the library)
I’m going to leave another finding here (Only applies to intermittent libedgetpu delegate loading issues, unrelated to plugdev/permissions)
(Works for me) You reset the full USB ecosystem - this script does that - tested on ubuntu 20. Depending on your OS it may require different paths - see comments in that link. I use this approach.
(Does not work for me) If you prefer not to reset the entire USB ecosystem, this is a more focussed way (You can get the coral device details by doing
lsusb | grep -i google. However, in my case, when the TPU actually fails, this method does not work - it mulls around for a while and then errors outSo the rest of the post is how I go about detecting failure and then I reset the full USB system. Here is what I observed:
So to make sure the device always works, I do the following:
Specifically, I have set up a cron file that checks that the coral device is detected every hour:
The modified script (credit above in my notes):
The nice part is my resident services that depend on coral automatically get restarted (not sure how, but it does). So I don’t need to restart it manually.
I recently moved from a USB 2.0 system to USB 3.0 and had the same issue. It is intermittent, so it’s not a plugdev issue.
As suggested above it does seem to be an issue with Google’s cable. I bought this cable and replaced the google provided cable. That seems to have completely eliminated the issue and I’m getting good inference speed (averaging 19ms for an 800px image using mobiledet and pycoral wrappers)
There were two issues that needed resolving on my setup, coming from a fresh installed Pi 4 + fresh installed edge TPU.
The user needs to be part of the plugdev group as mentioned by @Namburger .
sudo usermod -aG plugdev [your username]Reboot This seems to be a bug with the libedgetpu1-* packages. I tried both -std and -max versions (v12-1).
Thanks @Namburger !
Now my program is able to use the TPU from docker, I had to add
-v /dev/bus/usb:/dev/bus/usbalong with the--priviledgeflag to the docker run command so that it works.@adr-arroyo you can check this out 😃 https://github.com/google-coral/tflite/issues/3#issuecomment-547942348 tl;dr: most likely just have to throw it a
--privilegedflag