Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 806541 - sci-libs/tensorflow-2.5.0-r1: won't load model (TypeError: Parameter to MergeFrom() must be instance of same class: expected tensorflow.TensorShapeProto got tensorflow.TensorShapeProto.)
Summary: sci-libs/tensorflow-2.5.0-r1: won't load model (TypeError: Parameter to Merge...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Jason Zaman
URL:
Whiteboard:
Keywords:
: 817140 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-08-05 13:44 UTC by Oscar
Modified: 2021-10-16 12:35 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oscar 2021-08-05 13:44:09 UTC
I installed tensorflow-2.5.0-r1 (python 3.9). Trying to load a model I get the following error: 

cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
TypeError: Parameter to MergeFrom() must be instance of same class: expected tensorflow.TensorShapeProto got tensorflow.TensorShapeProto.

The internet suggests, that this is protobuf-related. So I tried protobuf 3.15.8 and 3.17.3. Same result.

Reproducible: Always
Comment 1 Ianislav Trendafilov 2021-08-06 10:04:26 UTC
Same here, but with -cuda

# emerge -pv sci-libs/tensorflow

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ~] sci-libs/tensorflow-2.5.0-r1::gentoo  USE="python xla -cuda -mpi" CPU_FLAGS_X86="avx avx2 fma3 sse sse2 sse3 sse4_1 sse4_2 -fma4" PYTHON_TARGETS="python3_9 -python3_8" 218739 KiB



Testing with a very simple python script from tutorials:

import tensorflow as tf
model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10)
])


/usr/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py in _variable_handle_from_shape_and_dtype(shape, dtype, shared_name, name, graph_mode, initial_value)
    175     handle_data.is_set = True
    176     handle_data.shape_and_type.append(
--> 177         cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
    178             shape=shape.as_proto(), dtype=dtype.as_datatype_enum))
    179 


TypeError: Parameter to MergeFrom() must be instance of same class: expected tensorflow.TensorShapeProto got tensorflow.TensorShapeProto.
Comment 2 Oscar 2021-08-11 15:25:38 UTC
Hi,
I recompiled tensorflow without cuda, same issue. However, there was a warning that could coincide with a falsely shaped object.


WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.devtools.build.lib.unsafe.StringUnsafe (file:/media/k/portage_temp/portage/sci-libs/tensorflow-2.5.0-r1/homedir/.cache/bazel/_bazel_portage/install/341df59e96c2ce6bbd8b0149edb7cbee/A-server.jar) to constructor java.lang.String(byte[],byte)
WARNING: Please consider reporting this to the maintainers of com.google.devtools.build.lib.unsafe.StringUnsafe
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release



import tensorflow as tf
m = tf.keras.Sequential()

Traceback:
File "/simple.py", line 2, in <module>
m = tf.keras.Sequential()
File "/usr/lib/python3.9/site-packages/tensorflow/python/training/tracking/base.py", line 522, in _method_wrapper
  result = method(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/tensorflow/python/keras/engine/sequential.py", line 114, in __init__
  super(functional.Functional, self).__init__(  # pylint: disable=bad-super-call
File "/usr/lib/python3.9/site-packages/tensorflow/python/training/tracking/base.py", line 522, in _method_wrapper
  result = method(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/tensorflow/python/keras/engine/training.py", line 318, in __init__
  self._init_batch_counters()
File "/usr/lib/python3.9/site-packages/tensorflow/python/training/tracking/base.py", line 522, in _method_wrapper
  result = method(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/tensorflow/python/keras/engine/training.py", line 326, in _init_batch_counters
  self._train_counter = variables.Variable(0, dtype='int64', aggregation=agg)
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/variables.py", line 262, in __call__
  return cls._variable_v2_call(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/variables.py", line 244, in _variable_v2_call
  return previous_getter(
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/variables.py", line 237, in <lambda>
  previous_getter = lambda **kws: default_variable_creator_v2(None, **kws)
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/variable_scope.py", line 2662, in default_variable_creator_v2
  return resource_variable_ops.ResourceVariable(
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/variables.py", line 264, in __call__
  return super(VariableMetaclass, cls).__call__(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1584, in __init__
  self._init_from_args(
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 1738, in _init_from_args
  handle = eager_safe_variable_handle(
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 237, in eager_safe_variable_handle
  return _variable_handle_from_shape_and_dtype(shape, dtype, shared_name, name,
File "/usr/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 177, in _variable_handle_from_shape_and_dtype
  cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
TypeError: Parameter to MergeFrom() must be instance of same class: expected tensorflow.TensorShapeProto got tensorflow.TensorShapeProto.
Comment 3 Oscar 2021-09-30 11:20:16 UTC
mentioned here: https://github.com/tensorflow/tensorflow/issues/42596
installing protobuf as user "solves" the issue:


pip install --user --force --no-deps protobuf
Comment 4 Petru 2021-10-01 02:48:13 UTC
I've followed the link from Oscar and came across this PR https://github.com/tensorflow/tensorflow/pull/51450 I added that as a patch and rebuild the package, the weird error have gone away.
Comment 5 Oscar 2021-10-04 10:31:57 UTC
Definitely the way to go. Works fine here, too.
Comment 6 Sam James archtester gentoo-dev Security 2021-10-09 19:53:26 UTC
*** Bug 817140 has been marked as a duplicate of this bug. ***
Comment 7 Jason Zaman gentoo-dev 2021-10-16 12:35:43 UTC
Fixed in 08fd73895803f777a23820de619412ac3e03c68a
Bumped to tf-2.5.0-r2 thanks for tracking down the fix :)