google-coral / edgetpu

Coral issue tracker (and legacy Edge TPU API source)
https://coral.ai
Apache License 2.0
426 stars 125 forks source link

libedgetpu.1.dylib not found #568

Closed vladmarian20005 closed 2 years ago

vladmarian20005 commented 2 years ago

Description

Hello,

I've come across an issue while trying to get started with the Coral USB accelerator. When I've tried running the example code it gave me an error saying that "/usr/lib/libedgetpu.1.dylib" does not exist and it truly does not. How can I correctly install it?

Click to expand! ### Issue Type Build/Install ### Operating System Mac OS ### Coral Device USB Accelerator ### Other Devices _No response_ ### Programming Language Python 3.9 ### Relevant Log Output ```shell Traceback (most recent call last): File "/Users/myusername/edgetpu_runtime/coral/pycoral/examples/classify_image.py", line 40, in from pycoral.utils.edgetpu import make_interpreter File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/utils/edgetpu.py", line 24, in from pycoral.pybind._pywrap_coral import GetRuntimeVersion as get_runtime_version ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/_pywrap_coral.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libedgetpu.1.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/_pywrap_coral.cpython-39-darwin.so Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/libedgetpu.1.dylib' (no such file), '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file) ```
hjonnala commented 2 years ago

Can you please uninstall pycoral and install it using instructions at: https://coral.ai/docs/accelerator/get-started/#pycoral-on-linux. Thanks!

vladmarian20005 commented 2 years ago

Just uninstalled and reinstalled pycoral for mac and i get the same error! Here is what i have in the pybind folder:

Screenshot 2022-03-31 at 18 48 51
hjonnala commented 2 years ago

Okay, edgetpu runtime seems to be missing. Please install it using instructions at: https://coral.ai/docs/accelerator/get-started/#runtime-on-mac

vladmarian20005 commented 2 years ago

I had just reinstalled edgetpu and ran the code again. I still receive the same error.

Also, I am able to see some files related to edge tpu so i do not belive that this is the issue

hjonnala commented 2 years ago

I have libedgetpu.1.dylib in /usr/local/lib/ directory.

can you please share the output of below commands:

vladmarian20005 commented 2 years ago

Definitely!

When I run **ls -al /usr/lib/libedgetpu** it gives me 'zsh: no matches found: /usr/lib/libedgetpu'

and when i run **ls -al /usr/local/lib/libedgetpu*** it gives me this :

-rwxr-xr-x 1 root admin 1024408 Mar 31 18:56 /usr/local/lib/libedgetpu.1.0.dylib lrwxr-xr-x 1 root admin 20 Mar 31 18:56 /usr/local/lib/libedgetpu.1.dylib -> libedgetpu.1.0.dylib

hjonnala commented 2 years ago

-rwxr-xr-x 1 root admin 1024408 Mar 31 18:56 /usr/local/lib/libedgetpu.1.0.dylib lrwxr-xr-x 1 root admin 20 Mar 31 18:56 /usr/local/lib/libedgetpu.1.dylib -> libedgetpu.1.0.dylib

can you please try the demo copying these files to /usr/lib/.

vladmarian20005 commented 2 years ago

I have tried moving the files like this:

sudo cp /usr/local/lib/libedgetpu* /usr/lib Password: cp: /usr/lib/libedgetpu.1.0.dylib: Operation not permitted cp: /usr/lib/libedgetpu.1.dylib: Operation not permitted

Seems like I am unable to move or copy them to usr/lib

hjonnala commented 2 years ago

Okay, can you try this script by passing any edgetpu model path to the script:: https://github.com/hjonnala/snippets/blob/main/coral_inference.py

python3 coral_inference.py --model ../../pycoral/test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite

changing:

_EDGETPU_SHARED_LIB = {
  'Linux': 'libedgetpu.so.1',
  'Darwin': 'libedgetpu.1.dylib',
  'Windows': 'edgetpu.dll'
}[platform.system()]

to

_EDGETPU_SHARED_LIB = {
  'Linux': 'libedgetpu.so.1',
  'Darwin': '/usr/local/lib/libedgetpu.1.dylib',
  'Windows': 'edgetpu.dll'
}[platform.system()]
vladmarian20005 commented 2 years ago

this is the error I receive:

Traceback (most recent call last): File "/Users/vladmarian/coral/pycoral/examples/coral_inference.py", line 25, in model_path=model_path, experimental_delegates=[tflite.load_delegate(_EDGETPU_SHARED_LIB, {})]) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 160, in load_delegate delegate = Delegate(library, options) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 89, in init self._library = ctypes.pydll.LoadLibrary(library) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/init.py", line 452, in LoadLibrary return self._dlltype(name) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/init.py", line 374, in init self._handle = _dlopen(self._name, mode) OSError: dlopen(libedgetpu.1.dylib, 0x0006): tried: 'libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file), '/Users/vladmarian/coral/pycoral/libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file) Exception ignored in: <function Delegate.del at 0x1079e79d0> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 124, in del if self._library is not None: AttributeError: 'Delegate' object has no attribute '_library'

hjonnala commented 2 years ago

I am not sure why the script is looking for these paths(OSError: dlopen(libedgetpu.1.dylib, 0x0006): tried: 'libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file), '/Users/vladmarian/coral/pycoral/libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file)) even though we explicitly define the path.

Can you please change this line

model_path=model_path, experimental_delegates=[tflite.load_delegate(_EDGETPU_SHARED_LIB, {})])

with model_path=model_path, experimental_delegates=[tflite.load_delegate('/usr/local/lib/libedgetpu.1.dylib', {})]). I want to make sure we are providing the path there.

vladmarian20005 commented 2 years ago

I have just done! This is what it gives me:

6.13 ms

I believe that this is what it is supposed to give me. Is it?

hjonnala commented 2 years ago

yes, please go to this file: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/utils/edgetpu.py and change these lines (https://github.com/google-coral/pycoral/blob/master/pycoral/utils/edgetpu.py#L34) as below..It would resolve your issue..

_EDGETPU_SHARED_LIB = {
  'Linux': 'libedgetpu.so.1',
  'Darwin': '/usr/local/lib/libedgetpu.1.dylib',
  'Windows': 'edgetpu.dll'
}[platform.system()]
vladmarian20005 commented 2 years ago

Just did! Seems like I have a similar issue! It still looks for libedgetpu.1.dylib in usr/lib. I made sure I have saved the modified file.

Traceback (most recent call last): File "/Users/vladmarian/coral/pycoral/examples/classify_image.py", line 40, in from pycoral.utils.edgetpu import make_interpreter File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/utils/edgetpu.py", line 24, in from pycoral.pybind._pywrap_coral import GetRuntimeVersion as get_runtime_version ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/_pywrap_coral.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libedgetpu.1.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/_pywrap_coral.cpython-39-darwin.so Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/libedgetpu.1.dylib' (no such file), '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file)

hjonnala commented 2 years ago

Okay, I see in this script I haven't used pycoral. You might have to work with tflite_runtime for now.

Can you please share the output of below commands:

hjonnala commented 2 years ago

Can you please try to revert those changes and try the command below. Thanks!

vladmarian20005 commented 2 years ago
  • uname -a
  • sw_vers

uname -a Darwin 192-168-0-179.rdsnet.ro 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64 vladmarian@192-168-0-179 ~ % sw_vers ProductName: macOS ProductVersion: 12.2.1 BuildVersion: 21D62

vladmarian20005 commented 2 years ago
  • sudo cp -r /usr/local/lib/libedgetpu* /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/pybind/

this is the error i get when trying to run the example code:

Traceback (most recent call last): File "/Users/vladmarian/coral/pycoral/examples/classify_image.py", line 121, in <module> main() File "/Users/vladmarian/coral/pycoral/examples/classify_image.py", line 71, in main interpreter = make_interpreter(*args.model.split('@')) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/utils/edgetpu.py", line 87, in make_interpreter delegates = [load_edgetpu_delegate({'device': device} if device else {})] File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pycoral/utils/edgetpu.py", line 52, in load_edgetpu_delegate return tflite.load_delegate(_EDGETPU_SHARED_LIB, options or {}) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 160, in load_delegate delegate = Delegate(library, options) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 89, in __init__ self._library = ctypes.pydll.LoadLibrary(library) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary return self._dlltype(name) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__ self._handle = _dlopen(self._name, mode) OSError: dlopen(libedgetpu.1.dylib, 0x0006): tried: 'libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file), '/Users/vladmarian/coral/pycoral/libedgetpu.1.dylib' (no such file), '/usr/lib/libedgetpu.1.dylib' (no such file) Exception ignored in: <function Delegate.__del__ at 0x111af8b80> Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 124, in __del__ if self._library is not None: AttributeError: 'Delegate' object has no attribute '_library'

hjonnala commented 2 years ago

can you please try to copy to pycoral folder as well.

sudo cp -r /usr/local/lib/libedgetpu* /Users/vladmarian/coral/pycoral/

vladmarian20005 commented 2 years ago

sudo cp -r /usr/local/lib/libedgetpu* /Users/vladmarian/coral/pycoral/

Wow i have just did and it worked!!! Finally!!

----INFERENCE TIME---- Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory. 19.2ms 6.0ms 5.5ms 5.2ms 5.0ms -------RESULTS-------- Ara macao (Scarlet Macaw): 0.75781

Thank you so much for the help! I believe that I have nothing left to do! Thanks!!

google-coral-bot[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No