TypeError: Parameter to MergeFrom() must be instance of same class: expected TensorShapeProto got TensorShapeProto. in tf.keras.layers.Embedding

Viewed 2732

I'm Trying to do text Classification with tensorflow.keras.layers.Embedding and Glove. when I run the code:

model.add(Embedding(len(word_index) + 1,
 100,
 weights=[embedding_matrix],
 input_length=MAX_LENGTH,
 trainable=False))

I get the error :

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

My TensorFlow ver: 1.14.0 I'm using Win-64

1 Answers

I was able to reproduce this issue. Thanks to the @sclarkson answer the bug went away when I did the following:

I. Find file lib/python3.7/site-packages/tensorflow/python/__init__.py in my environment directory

II. Reorder the lines from:

from tensorflow.python.eager import context
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow

to

from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
from tensorflow.python.eager import context

I have the following python environment:

  1. Macbook Monterey 12.0.1
  2. conda 4.10.3
  3. python=3.7.9
  4. tensorflow=2.6.0
  5. keras=2.6.0
Related