NobuoTsukamoto / tflite-cv-example

TensorFlow Lite, Coral Edge TPU samples (Python/C++, Raspberry Pi/Windows/Linux).
MIT License
119 stars 15 forks source link

Issue with object_detection_capture_picamera.py #3

Closed garethbolton closed 3 years ago

garethbolton commented 3 years ago

Hello

First of all, great repo! I particularly want to thank you for your help in creating export_tfv2_lite_models.ipynb, I was able to convert my custom model with SSD MobileNet V2 FPNLite 640x640 to edge_tpu.tflite smoothly!

However, I am having difficulty understanding your repo to "run the model on a raspberry pi with coral"..

I have followed your guide from https://github.com/NobuoTsukamoto/edge_tpu/tree/master/detection/cpp

But I think I am running C++ instead of object_detection_capture_picamera.py?

I was wondering if you can provide me a guide on what I need to do in order to run your object_detection_capture_picamera.py script on my Raspberry Pi 4 2GB with Coral.

I have tried installing some of the dependencies myself but I still have no luck in running the script to see my model live on my Pi. I have cloned your entire repo but I don't think it is needed for what I want, maybe I am wrong?

Any help at all you can that you can share in order to run the correct repo/script on my Pi will be very appreciated.

Thank you again for your work!

NobuoTsukamoto commented 3 years ago

@garethbolton

First of all, great repo! I particularly want to thank you for your help in creating export_tfv2_lite_models.ipynb, I was able to convert my custom model with SSD MobileNet V2 FPNLite 640x640 to edge_tpu.tflite smoothly!

Thank you for your interest in my repo!

I was wondering if you can provide me a guide on what I need to do in order to run your object_detection_capture_picamera.py script on my Raspberry Pi 4 2GB with Coral.

Install the opencv python package.

$ sudo apt install python3-opencv

Install the libedgetpu and pycoarl package. https://coral.ai/software/

$ echo "deb https://packages.cloud.google.com/apt coral-cloud-stable main" | sudo tee /etc/apt/sources.list.d/coral-cloud.list
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install libedgetpu1-std
$ sudo apt-get install python3-pycoral

If you get an error, can you report the command and the error?

Thanks!

garethbolton commented 3 years ago

Thanks!

Do I just clone the "Python" repo only for my Pi, do I need to clone your entire repo?

Also, do you have any other way of communicating? I would love to talk more!

I will try those, some I missed that I noticed you provided,

Thank you once again!

NobuoTsukamoto commented 3 years ago

Do I just clone the "Python" repo only for my Pi, do I need to clone your entire repo?

You need the object_detection_capture_picamera.py and utils directories to run Python scripts.

Your directory
  + object_detection_capture_picamera.py (object_detection_capture_opencv.py, object_detection_tflite_capture_opencv.py) 
  + utils
      + label_util.py
      + tflite_util.py
      + visualization.py

Note: utils/tflite_util.py is required to run *** _opencv.py.

garethbolton commented 3 years ago

Thanks, I'll give it ago and get back to you!

garethbolton commented 3 years ago

Do I need to reinstall TFLite or is that all ready done via your commands?

NobuoTsukamoto commented 3 years ago

When you install python3-pycoral, tflite_runtime is also installed. No need to reinstall. If you get an error, can you report the command and the error?

garethbolton commented 3 years ago

Hi,

I was having problems with finding "cv2".

I then found this online:

sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev

pip install opencv-python==4.1.0.25

And the error seemed to have disappeared but now it is saying the PiCamera module can't be found:

import picamera

ModuleNotFoundError: No module named 'picamera'

I ran sudo pip3 install picamera

and below it says

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: picamera in /usr/lib/python3/dist-packages (1.13)

It seems to have issues finding the imports from line 13-23 on the object_detection python script.

Any help with the proper installation would be grateful!

Thanks!

EDIT:

Yes, I have enabled it within Interfaces and I am using a Virtual environment

NobuoTsukamoto commented 3 years ago

I'm sorry. I have never installed picamera in a virtual environment. However, I found the following documentation. https://picamera.readthedocs.io/en/release-0.6/install.html#virtualenv-installation

garethbolton commented 3 years ago

Hi,

I decided not to go through with the Virtual Environment.

Everything seemed to have run, however, this was the exception that was thrown back:

Traceback (most recent call last): File "./object_detection_capture_picamera.py", line 132, in main() File "./object_detection_capture_picamera.py", line 46, in main interpreter = make_interpreter(args.model) File "/usr/lib/python3/dist-packages/pycoral/utils/edgetpu.py", line 72, in make_interpreter model_path=model_path_or_content, experimental_delegates=delegates) File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 207, in init custom_op_registerers_by_func)) ValueError: Could not open 'home/pi/tensorflow/models/ssd_mobilenet_v2_fpnlite_640x640_coco17_quant_edgetpu.tflite'.

I trained my own model and converted it to Coral using your Colab.

Any help would be great! Thanks

garethbolton commented 3 years ago

Update:

I ran this:

packages required for OpenCV

sudo apt-get -y install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get -y install libxvidcore-dev libx264-dev
sudo apt-get -y install qt4-dev-tools libatlas-base-dev

The above throwback went away but this happened:

Traceback (most recent call last):
  File "./object_detection_capture_picamera.py", line 132, in <module>
    main()
  File "./object_detection_capture_picamera.py", line 46, in main
    interpreter = make_interpreter(args.model)
  File "/usr/lib/python3/dist-packages/pycoral/utils/edgetpu.py", line 72, in make_interpreter
    model_path=model_path_or_content, experimental_delegates=delegates)
  File "/usr/lib/python3/dist-packages/tflite_runtime/interpreter.py", line 207, in __init__
    custom_op_registerers_by_func))
ValueError: Could not open 'home/pi/tensorflow/models/ssd_mobilenet_v2_fpnlite_640x640_coco17_quant_edgetpu.tflite'.

The window opens for a few seconds, then throwbacks the above

NobuoTsukamoto commented 3 years ago

Is it possible to report the command executed? Maybe the file path is wrong?

ValueError: Could not open 'home/pi/tensorflow/models/ssd_mobilenet_v2_fpnlite_640x640_coco17_quant_edgetpu.tflite'.

/home/pi/tensorflow/models/ssd_mobilenet_v2_fpnlite_640x640_coco17_quant_edgetpu.tflite (Leading ’/’)

garethbolton commented 3 years ago

Hi!

Thanks for your help. It seems to be going!

Can I contact you privately, however, as I have a couple of questions I would like to ask you!

Thanks!

NobuoTsukamoto commented 3 years ago

Thanks for your help. It seems to be going!

I'm glad !

Can I contact you privately, however, as I have a couple of questions I would like to ask you!

What kind of question is it? If you have any questions you don't want to publish, please ask from the link in my Github profile. If you have any questions related to this repository, please ask them on Github whenever possible (others can see them).

Thanks.

garethbolton commented 3 years ago

Perfect.

Thanks!