Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPI Zero] ModuleNotFoundError: No module named 'tflite_runtime' #41112

Closed
rajurimu opened this issue Jul 5, 2020 · 13 comments
Closed

[RPI Zero] ModuleNotFoundError: No module named 'tflite_runtime' #41112

rajurimu opened this issue Jul 5, 2020 · 13 comments
Assignees
Labels
comp:lite TF Lite related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author subtype: raspberry pi Raspberry Pi Build/Installation Issues type:build/install Build and install issues

Comments

@rajurimu
Copy link

rajurimu commented Jul 5, 2020

Please make sure that this is a build/installation issue. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:build_template

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Raspbian GNU/Linux 10 (buster)
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Raspberry Pi Zero
  • TensorFlow installed from (source or binary): Compile natively on Raspberry Pi using https://www.tensorflow.org/lite/guide/build_rpi
  • TensorFlow version: Trying to install and Tensorflow lite as a standalone
  • Python version: 3.7.3
  • Installed using virtualenv? pip? conda?:
  • Bazel version (if compiling from source): None
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory:

Describe the problem
Trying to install Tensorflow Lite on RPI Zero as a standalone. However once installation is complete as per the following steps,
sudo apt-get install build-essential
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
cd tensorflow_src && ./tensorflow/lite/tools/make/download_dependencies.sh
./tensorflow/lite/tools/make/build_rpi_lib.sh

I can not import,
import tflite_runtime.interpreter as tflite

Error I am getting is
ModuleNotFoundError: No module named 'tflite_runtime'

In addition as per the instructions, I should see a static library. I do not see this either.
tensorflow/lite/tools/make/gen/lib/rpi_armv6/libtensorflow-lite.a

Any other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

@rajurimu rajurimu added the type:build/install Build and install issues label Jul 5, 2020
@amahendrakar amahendrakar added the comp:lite TF Lite related issues label Jul 6, 2020
@jvishnuvardhan jvishnuvardhan added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jul 6, 2020
@rajurimu
Copy link
Author

I am still facing this issue on RPI Zero.

@terryheo
Copy link
Member

This are prebuilt Python wheels of tflite_runtime package. https://www.tensorflow.org/lite/guide/python
But I'm not sure it's compatible with RPI Zero.

If it doesn't work, you might need to build it by yourself.
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package will help.

@rajurimu
Copy link
Author

t

This are prebuilt Python wheels of tflite_runtime package. https://www.tensorflow.org/lite/guide/python
But I'm not sure it's compatible with RPI Zero.

If it doesn't work, you might need to build it by yourself.
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package will help.

I am using https://www.tensorflow.org/lite/guide/build_rpi. For Compile natively on Raspberry Pi.

The site states that "The following instructions have been tested on Raspberry Pi Zero, Raspbian GNU/Linux 10 (buster), gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)".

So I am puzzled at this thing not working on rpi zero and giving the error. I have done it a few times with the same error. The site which you are referring to does not have arm6l whl.

@terryheo
Copy link
Member

libtensorflow-lite.a will work with your RPI zero. But it's C library not Python.

You might be able to build it on RPI zero with the following command.

sudo apt install swig libjpeg-dev zlib1g-dev python3-dev python3-numpy
pip install numpy pybind11
sh tensorflow/lite/tools/make/download_dependencies.sh
sh tensorflow/lite/tools/pip_package/build_pip_package.sh

@rajurimu
Copy link
Author

libtensorflow-lite.a will work with your RPI zero. But it's C library not Python.

You might be able to build it on RPI zero with the following command.

sudo apt install swig libjpeg-dev zlib1g-dev python3-dev python3-numpy
pip install numpy pybind11
sh tensorflow/lite/tools/make/download_dependencies.sh
sh tensorflow/lite/tools/pip_package/build_pip_package.sh

terryheo...it ran something as it says on webpage but it is giving error. I am trying on RP4 now as RP0 is slow and if I can make whl on RP4, I can try on RP0 later.

I had to modify commands like this 'cd tensorflow_src && ./tensorflow/lite/tools/pip_package/build_pip_package.sh'

collect2: error: ld returned 1 exit status
make: *** [tensorflow/lite/tools/make/Makefile:341: /home/pi/tensorflow_src/tensorflow/lite/tools/make/gen/linux_armv7l/bin/minimal] Error 1
make: Leaving directory '/home/pi/tensorflow_src'
Traceback (most recent call last):
File "setup.py", line 227, in
'build_py': CustomBuildPy,
File "/usr/local/lib/python3.7/dist-packages/setuptools/init.py", line 165, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.7/distutils/command/bdist.py", line 143, in run
self.run_command(cmd_name)
File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.7/distutils/command/bdist_dumb.py", line 81, in run
self.run_command('build')
File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.7/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "setup.py", line 133, in run
self.run_command('build_ext')
File "/usr/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "setup.py", line 125, in run
make()
File "setup.py", line 105, in make
subprocess.check_call(make_args(quiet=False))
File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['make', 'SHELL=/bin/bash', 'BUILD_WITH_NNAPI=false', '-C', '/home/pi/tensorflow_src/tensorflow/lite/tools/pip_package/../../../..', '-f', 'tensorflow/lite/tools/make/Makefile', '-j', '1']' returned non-zero exit status 2.

@rajurimu
Copy link
Author

and where does it create whl file, when it creates.

@terryheo
Copy link
Member

If you're using RPI4, just use prebuilt from https://www.tensorflow.org/lite/guide/python

@rajurimu
Copy link
Author

If you're using RPI4, just use prebuilt from https://www.tensorflow.org/lite/guide/python

I did that but my end goal is to work on RPi Zero and I am struggling. Not an expert so learning as I go. The instructions are failing from the link. Not sure if I am missing something. The sh commands are not working as it is so I am modifying as mentioned above.

@tensorflowbutler tensorflowbutler removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jul 25, 2020
@terryheo terryheo changed the title ModuleNotFoundError: No module named 'tflite_runtime' [RPI Zero] ModuleNotFoundError: No module named 'tflite_runtime' Jul 27, 2020
@terryheo terryheo added the subtype: raspberry pi Raspberry Pi Build/Installation Issues label Jul 27, 2020
@freeedom67
Copy link

freeedom67 commented Sep 28, 2020

FYI

I was able to find a working solution for running tensorflow(lite as well) on the ARM6 based raspberry pi (like the zero or the Pi1):

in python:

import tensorflow as  tf

print(str(tf.__version__)) # should print the version
interpreter = tf.lite.Interpreter(model_path) # for example if you just need the python tf lite runtime 

After a long time looking for a good solution and struggling with static libs and cross compiling, I found this working pretty well and easy!

@mohantym mohantym self-assigned this Oct 29, 2021
@mohantym
Copy link
Contributor

mohantym commented Oct 29, 2021

Hi @rajurimu ! Inline with above comment.
You can also import like below.
import tflite-runtime.interpreter as tflite instead of
import tflite_runtime.interpreter as tflite

Attached relevant threads for reference. link1,link2,link3,link4 . Thanks!

@mohantym mohantym added the stat:awaiting response Status - Awaiting response from author label Oct 29, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler google-ml-butler bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Nov 5, 2021
@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:lite TF Lite related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author subtype: raspberry pi Raspberry Pi Build/Installation Issues type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests

8 participants