google-coral / edgetpu

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

Issues when running Image classification example #28

Closed sangnguyen7 closed 4 years ago

sangnguyen7 commented 4 years ago

There are issues when running the example here Steps to reproduce:

Step 1. Following steps in this page

Step 2: Run the example code. You will get an issue like below

Traceback (most recent call last):
  File "classify_image.py", line 44, in <module>
    main()
  File "classify_image.py", line 32, in main
    labels = dataset_utils.read_label_file(args.label)
AttributeError: module 'edgetpu.utils.dataset_utils' has no attribute 'read_label_file'

Step 3: I checked all functions available in the dataset_utils module and seeing it's using ReadLabelFile as its function name, not 'read_label_file' in the example code.

Step 4: Update the code using 'ReadLabelFile', and run again. You will get another issue as below:

python3 classify_image.py --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --label models/inat_bird_labels.txt --image images/parrot.jpg

Error:

Segmentation fault (core dumped)

I debugged and saw it was erred at line 34: engine = ClassificationEngine(args.model)

Please validate. Thanks,

Sang

Namburger commented 4 years ago

@sangnguyen7 Are you have this issue with the Dev Board or the USB Accelerator? This issue is that we've updated our library and the new interface for our utility for reading label is changed to read_label_file.

If this is an issue on your board, I suggest re-flashing the board to get a newest image, details about our new image, including the instruction on how to re-flash can be found here: https://coral.withgoogle.com/news/updates-11-2019/

If this is an issue when you are trying to run with the USB accelerator on your host machine, you can just update the library. You can find the packages ere: https://coral.withgoogle.com/software/#debian-packages

sangnguyen7 commented 4 years ago

@Namburger Sorry, I forgot to mention about the device. I'm using the USB Accelerator. I have followed the get started instruction (https://coral.withgoogle.com/docs/accelerator/get-started) and the example in the Get Started worked great. However, when I was following the example above https://coral.withgoogle.com/examples/classify-image/, I got those issues. It seems that there is an issue with ClassificationEngine module. As I just got the devices 3 days ago, then I followed the Get Started instruction, so I don't think I have to update the library. But definitely, I will have a double check on that.

Namburger commented 4 years ago

@sangnguyen7 humm, something weird is going on if you just installed recently o_0 could you share the output of this:

$ python3 -c 'print(__import__("edgetpu").__version__)'

This should shows 2.12.1

sangnguyen7 commented 4 years ago

@Namburger, I put my device at home, I will test and get back to you.

Namburger commented 4 years ago

@sangnguyen7 FYI, instruction for updating the library is here: https://coral.withgoogle.com/news/updates-09-2019/

sangnguyen7 commented 4 years ago

@Namburger , thanks for the instruction, I checked and saw my version is 2.11.1. I did update as the link you sent. I checked the version again and got 2.12.2

However, when I run the example in the Get Stared page again. I got this:

Traceback (most recent call last):
  File "classify_image.py", line 118, in <module>
    main()
  File "classify_image.py", line 95, in main
    interpreter = make_interpreter(args.model)
  File "classify_image.py", line 69, in make_interpreter
    {'device': device[0]} if device else {})
  File "/home/vagrant/.local/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 165, in load_delegate
    delegate = Delegate(library, options)
  File "/home/vagrant/.local/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 89, in __init__
    self._library = ctypes.pydll.LoadLibrary(library)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 348, 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: <bound method Delegate.__del__ of <tflite_runtime.interpreter.Delegate object at 0x7f9341bfaef0>>
Traceback (most recent call last):
  File "/home/vagrant/.local/lib/python3.6/site-packages/tflite_runtime/interpreter.py", line 124, in __del__
    if self._library is not None:
AttributeError: 'Delegate' object has no attribute '_library'
Namburger commented 4 years ago

OSError: libedgetpu.so.1: cannot open shared object

Humnn, looks like libedgetpu.so isn't installed. I'm puzzled because the apt-get should have installed it 🤔. Add to the fact that somehow you installed an older version from the same command. Even I had this issue before too, will look more into this Monday. Any how, easy fix for you is to clone this repo, and do:

$ sudo bash scripts/runtime/install.sh

essentially executing this install script: https://github.com/google-coral/edgetpu/tree/master/scripts/runtime

sangnguyen7 commented 4 years ago

@Namburger, Thanks. It worked great.

BTW, I did spend a little time to figure out why it happened. I found that the steps for Debian-package installation in this page https://coral.withgoogle.com/news/updates-09-2019 doing as:

# x86_64-linux-gnu, arm-linux-gnueabihf, or aarch64-linux-gnu
ls -d /usr/lib/x86_64-linux-gnu/libedgetpu* | xargs sudo rm

# Now install the new Python library and Edge TPU runtime
sudo apt-get install python3-edgetpu libedgetpu1-std
# Or if you prefer the max operating frequency, install 'libedgetpu1-max'

I validated, see that after you ran this line

# x86_64-linux-gnu, arm-linux-gnueabihf, or aarch64-linux-gnu
ls -d /usr/lib/x86_64-linux-gnu/libedgetpu* | xargs sudo rm

for removing all libraries start with 'libedgetpu*' in /usr/lib/x86_64-linux-gnu folder. Even all those libs were removed but when run the next command line

# Now install the new Python library and Edge TPU runtime
sudo apt-get install python3-edgetpu libedgetpu1-std

it's still saying that those libs are existed:

$ sudo apt-get install python3-edgetpu libedgetpu1-std
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libedgetpu1-std is already the newest version (12-1).
python3-edgetpu is already the newest version (12.1-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

So, instead of running the steps in the page https://coral.withgoogle.com/news/updates-09-2019/. Run as follow will work:

# First uninstall the previous Python library and Edge TPU runtime
sudo pip uninstall edgetpu

sudo apt-get remove python3-edgetpu libedgetpu1-std

# Now install the new Python library and Edge TPU runtime
sudo apt-get install python3-edgetpu libedgetpu1-std
# Or if you prefer the max operating frequency, install 'libedgetpu1-max'

I closed this issue as well. Many thanks!