Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensor object has no attribute keras_shape

While building a model using:

model = Model(inputs=[input_text], outputs=pred)

getting an error:

AttributeError: 'Tensor' object has no attribute '_keras_shape'

The complete notebook that I tried can be found here... https://github.com/shantanuo/pandas_examples/blob/master/tensorflow/tf_learn.ipynb

And the same code in plain text here... https://gist.github.com/shantanuo/4e35baba144ee658e4dd4d1f87e19f3a

I will like to know why am I getting an error even if I am using the exact same code as shown in this blog:

https://towardsdatascience.com/transfer-learning-using-elmo-embedding-c4a7e415103c

The expected output - something like this:

The model summary is: _________________________________________________________________ Layer (type) Output Shape Param #
================================================================= input_2 (InputLayer) (None, 1) 0
_________________________________________________________________ lambda_2 (Lambda) (None, 1024) 0
_________________________________________________________________ dense_3 (Dense) (None, 256) 262400
_________________________________________________________________ dense_4 (Dense) (None, 1) 257

I tried to upgrade tensorflow and keras but getting the same error:

!pip install --upgrade tensorflow
like image 779
shantanuo Avatar asked Feb 10 '19 07:02

shantanuo


People also ask

Which object has no attribute keras_shape?

Tensor object has no attribute keras_shape Ask Question Asked2 years, 11 months ago Active2 years, 2 months ago Viewed13k times 12 While building a model using: model = Model(inputs=[input_text], outputs=pred) getting an error:

Which object has no attribute'is_initialized'when using TensorFlow?

'Tensor' object has no attribute 'is_initialized' when using tensorflow.keras.backend.shape 10 Tensorboard AttributeError: 'ModelCheckpoint' object has no attribute 'on_train_batch_begin'

How do I use a callable object in a keras model?

This layer wraps a callable object for use as a Keras layer. The callable object can be passed directly, or be specified by a Python string with a handle that gets passed to hub.load (). This is the preferred API to load a TF2-style SavedModel from TF Hub into a Keras model. Calling this function requires TF 1.15 or newer.

Can attribute names in TensorFlow/Keras be different from one another?

Depending on the version of tensorflow/keras the attribute names can differ. I hope it helps. Ping me if this doesn't solve the problem. Sorry, something went wrong.


1 Answers

I had a similar issue when I changed my computer with a different tensorflow version.

What solved it for me was using .shape instead of ._keras_shape

Depending on the version of tensorflow/keras and/or how you import them (from keras, from tensorflow.keras or from tensorflow.python.keras) it appears that the attributes names can differ.

like image 129
Wise Cloud Avatar answered Sep 21 '22 06:09

Wise Cloud