TypeError: Saw an object that is an instance of a strict subclass of EagerTensor

Viewed 81

I am trying to build a simple model in Tensorflow 2.1.0 with Keras layers.

However, running this code:

from tensorflow import keras
from tensorflow.keras import layers

def main():
    max_input_length = 20
    vocab_size = 10

    model = keras.Sequential()
    model.add(layers.Embedding(vocab_size, 16, input_length=max_input_length))
    # ..

if __name__ == '__main__':
    main()

Throws a TypeError exception:

TypeError: Saw an object that is an instance of a strict subclass of EagerTensor, which is not supported. Item 0 is type: tensorflow.python.framework.ops.EagerTensor

What am I doing wrong here?

1 Answers

Surprisingly, it worked perfectly fine in Google colab with tensorflow version 2.1.0. No errors.

Code-

import tensorflow as tf
print(tf.__version__)
from tensorflow import keras
from tensorflow.keras import layers

def main():
    max_input_length = 20
    vocab_size = 10

    model = keras.Sequential()
    model.add(layers.Embedding(vocab_size, 16, input_length=max_input_length))
    # ..

if __name__ == '__main__':
    main()

Output -

2.1.0
Related