google-coral / pycoral

Python API for ML inferencing and transfer-learning on Coral devices
https://coral.ai
Apache License 2.0
351 stars 145 forks source link

Python 3.9 support #6

Closed fgervais closed 3 years ago

fgervais commented 3 years ago

I'd like to try and build tflite_runtime myself for python 3.9.

Any guidelines on how I would go about doing that?

Namburger commented 3 years ago

Hello @fgervais You'd have to create a target for python3.9 and build from here as we don't have supports for 3.9 at this time: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package

Also, make sure that you checked out this commit of tensorflow before building it!

fgervais commented 3 years ago

I want to report my progress as it seems I might have a working milestone.

What I did is I went in there:

https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package

at current tensorflow master (5453cf0b1c8359c0ee6afef8393b350c832a9123)

Then I commented out the python2 stuff as it doesn't seem to be packaged for newer debian version:

diff --git a/tensorflow/lite/tools/pip_package/Dockerfile b/tensorflow/lite/tools/pip_package/Dockerfile
index 834fe5efca7..cc8c22acf89 100644
--- a/tensorflow/lite/tools/pip_package/Dockerfile
+++ b/tensorflow/lite/tools/pip_package/Dockerfile
@@ -10,15 +10,15 @@ RUN apt-get update && \
     apt-get install -y \
       debhelper \
       dh-python \
-      python-all \
-      python-setuptools \
-      python-wheel \
-      python-numpy \
-      python-pip \
+      # python-all \
+      # python-setuptools \
+      # python-wheel \
+      # python-numpy \
+      # python-pip \
       pybind11-dev \
-      libpython-dev \
-      libpython-dev:armhf \
-      libpython-dev:arm64 \
+      # libpython-dev \
+      # libpython-dev:armhf \
+      # libpython-dev:arm64 \
       python3-all \
       python3-setuptools \
       python3-wheel \

Then I built using bullseye as base as it comes with python 3.9.0-4

cd tensorflow/tensorflow/lite/tools/pip_package
make BASE_IMAGE=debian:bullseye PYTHON=python3 TENSORFLOW_TARGET=aarch64 docker-build

For now it seems to work:

root@buildroot:~# pip install /tflite_runtime-2.5.0-cp39-cp39-linux_aarch64.whl 
Processing /tflite_runtime-2.5.0-cp39-cp39-linux_aarch64.whl
Requirement already satisfied: numpy>=1.16.0 in /usr/lib/python3.9/site-packages (from tflite-runtime==2.5.0) (1.18.2)
Installing collected packages: tflite-runtime
Successfully installed tflite-runtime-2.5.0
root@buildroot:~# python
Python 3.9.0 (default, Dec  8 2020, 17:05:44) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tflite_runtime.interpreter as tflite
>>> 
Namburger commented 3 years ago

Nice!!!!

fgervais commented 3 years ago

I tested the package I built on an M.2 edgetpu module and it does inference fine.

Should I close this issue or do we leave it open until official support for python 3.9?

root@edgetpu-service:/subvolumes/google-coral-tflite/python/examples/classification# python3 classify_image.py --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --labels models/inat_bird_labels.txt --input images/parrot.jpg
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
12.4ms
2.4ms
2.4ms
2.4ms
2.4ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.77734
root@edgetpu-service:/subvolumes/google-coral-tflite/python/examples/classification# python3 --version
Python 3.9.0
Namburger commented 3 years ago

@fgervais yes, please keep it open until we have an official package, thanks!

thekazak commented 3 years ago

@fgervais it helps build install tensorflow/lite with python 3.9 but what about pycoral? I need it on python 3.9 together with tensorflow lite

fgervais commented 3 years ago

Humm I'm not sure, I haven't used pycoral for my inferences.

dmitriykovalev commented 3 years ago

We have Python 3.9 wheels now, please check releases page.