Skip to content

Missing modules from tf-keras package when downloaded via pip #870

@ITjj07

Description

@ITjj07

System information.

  • Have I written custom code (as opposed to using a stock example script provided in Keras): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 22.04
  • TensorFlow installed from (source or binary): binary (pip)
  • TensorFlow version (use command below): 2.20.0
  • Python version: 3.10.12
  • Bazel version (if compiling from source): -
  • GPU model and memory: using CPU
  • Exact command to reproduce: -

Describe the problem.
Hey all! Before going on, I'd like to point out that my background is neither computer science nor computer engineering (but mechatronics engineering instead), so please forgive any non-technical language that I might be using. I do have some knowledge about Python and coding, though. I'm learning everything about machine learning during these weeks.

I'm trying to use tf-keras for a computer vision project of mine.

I installed many times the package via pip, but every time I get the following error:
" ModuleNotFoundError: No module named 'tf_keras.legacy_tf_layers' "

I then tried to directly git-cloned the entire tf-keras repo and used only the subfolder tf_keras, but the error that I get by doing this is:
" ImportError: cannot import name 'saved_metadata_pb2' from 'tf_keras.protobuf' (unknown location) "

I then checked the protobuf subfolder and there is no saved_metadata_pb2.py script indeed.

In my project, I am using TensorFlow v2 but with tf.disable_v2_behavior(), so effectively using TF v1 features. I am doing this since I started from a previous project that was using the same version of TensorFlow and with the same configuration (i.e. disabling of TF v2 features).

Here is the full error log that I'm getting by running my code with the version of tf_keras that I get directly from pip (no git-cloning):

Traceback (most recent call last):
 File "/home/giulio/ros/markerless_nav_tf_ws/install/markerless_tracking/lib/markerless_tracking/tracker_node", line 33, in <module>
   sys.exit(load_entry_point('markerless-tracking==1.1.0', 'console_scripts', 'tracker_node')())
 File "/home/giulio/ros/markerless_nav_tf_ws/install/markerless_tracking/lib/python3.10/site-packages/markerless_tracking/markerless_tracking_node.py", line 351, in main
   read_pc = pcCallback()
 File "/home/giulio/ros/markerless_nav_tf_ws/install/markerless_tracking/lib/python3.10/site-packages/markerless_tracking/markerless_tracking_node.py", line 60, in __init__
   self.probs, self.preds_loc = model.AlexNet2(self.RGB, scope='newroi')
 File "/home/giulio/ros/markerless_nav_tf_ws/install/markerless_tracking/lib/python3.10/site-packages/markerless_tracking/utils/model.py", line 268, in AlexNet2
   net = slim.conv2d(x, channels, [11, 11], 4, padding='VALID', scope='conv1')
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args
   return func(*args, **current_args)
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/layers/layers.py", line 1171, in convolution2d
   return convolution(
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args
   return func(*args, **current_args)
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/layers/layers.py", line 1098, in convolution
   outputs = normalizer_fn(outputs, **normalizer_params)
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/ops/arg_scope.py", line 184, in func_with_args
   return func(*args, **current_args)
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tf_slim/layers/layers.py", line 663, in batch_norm
   layer = normalization_layers.BatchNormalization(
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tensorflow/python/layers/normalization.py", line 30, in __getattr__
   return normalization.BatchNormalization
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tensorflow/python/util/lazy_loader.py", line 69, in __getattr__
   module = self._load()
 File "/home/giulio/ros/markerless_nav_tf_ws/venv/lib/python3.10/site-packages/tensorflow/python/util/lazy_loader.py", line 52, in _load
   module = importlib.import_module(self.__name__)
 File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
 File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
 File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
 File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
 File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
 File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tf_keras.legacy_tf_layers'
[ros2run]: Process exited with failure 1

Is it normal what I am encountering? Why does pip not install some modules that are instead present on your official GitHub repo?

In addition to this, I'm also triggering TF_USE_LEGACY_KERAS=1, if it can be of any help.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions