tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.49k stars 1.67k forks source link

Can't get the tensor flow example to work on PI4 #778

Closed jonathan84clark closed 3 years ago

jonathan84clark commented 3 years ago

Hello,

I am working through the example on this page https://www.tensorflow.org/hub/tutorials/object_detection

I am trying to get it to work on the Raspberry PI4: OS: Raspian. I updated all my packages to the latest versions. I managed to get tensor flow installed (as well as all the dependencies) but when I run the example it hangs on this: module_handle = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1" detector = hub.load(module_handle).signatures['default']

Sometimes it throws an error (after around 5 minutes); MemoryError

Traceback (most recent call last): File "Recognition.py", line 159, in <module> detector = hub.load(module_handle).signatures['default'] File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_hub/module_v2.py", line 106, in load obj = tf.compat.v1.saved_model.load_v2(module_path, tags=tags) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/saved_model/load.py", line 517, in load return load_internal(export_dir, tags) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/saved_model/load.py", line 548, in load_internal root = load_v1_in_v2.load(export_dir, tags) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/saved_model/load_v1_in_v2.py", line 239, in load return loader.load(tags=tags) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/saved_model/load_v1_in_v2.py", line 189, in load signature=[]) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/eager/wrap_function.py", line 600, in wrap_function signature=signature) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/eager/wrap_function.py", line 215, in __init__ for f in fn_graph.as_graph_def().library.function: File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3241, in as_graph_def result, _ = self._as_graph_def(from_version, add_shapes) File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 3167, in _as_graph_def data = c_api.TF_GetBuffer(buf) MemoryError

Any help on this would be great!

Thanks,

Jonathan L Clark

arghyaganguly commented 3 years ago

@jonathan84clark , could you please try reinstalling latest tensorflow, using :-

pip install --no-cache-dir tensorflow==2.5.0

and see if this solves your issue?

jonathan84clark commented 3 years ago

Thanks for the help but this doesn't work. Remember that this is on a Raspberry PI4. Here is the error I get when I attempt that:

pip install --no-cache-dir tensorflow==2.5.0 Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting tensorflow==2.5.0 Could not find a version that satisfies the requirement tensorflow==2.5.0 (from versions: 0.11.0, 0.12.1, 1.0.0, 1.0.1, 1.1.0, 1.8.0, 1.9.0, 1.10.1, 1.11.0, 1.12.0, 1.13.1, 1.14.0) No matching distribution found for tensorflow==2.5.0

akhorlin commented 3 years ago

I don't have access to PI4 hardware, but looking at the original error, my guess is that the model is too big for PI4. Most TF non-lite models are quite large large and frequently (depending on the model architecture) TF model loading requires ~2x ram as a function of model size on disc. This specific model is 230M. One workaround could be to try to find a smaller model (preferably a TFLite one) to use.

maringeo commented 3 years ago

I also suspect that the issue is caused by out-of-memory error, +1 to the suggestion to try loading a smaller model. I'll close the issue, please reopen if you suspect that out-of-memory is not the root cause.