'TypeError: Exception encountered when calling layer "lstm" (type LSTM)
I'm working on Image captioning deep learning project. When i'm adding LSTM layers, it's returning an error. The code and error is below
se1 = Embedding(vocab_size, embedding_dim, mask_zero=True)(inputs2)
The output is below:
WARNING:tensorflow:
The following Variables were used a Lambda layer's call (tf.compat.v1.nn.embedding_lookup), but
are not present in its tracked objects:
<tf.Variable 'embedding/embeddings:0' shape=(1546, 200) dtype=float32>
It is possible that this is intended behavior, but it is more likely
an omission. This is a strong indication that this layer should be
formulated as a subclassed Layer rather than a Lambda layer.
Followed by code:
se2 = Dropout(0.5)(se1)
se3 = LSTM(256, return_sequences=True)(se2)
se3 = LSTM(256, return_sequences=True)(se3)
se3 = LSTM(256, kernel_regularizer="l2")(se3)
The output is:
TypeError Traceback (most recent call last)
<ipython-input-41-ec41a5a5bbd0> in <module>()
----> 1 se3 = LSTM(256, return_sequences=True)(se2)
2 se3 = LSTM(256, return_sequences=True)(se3)
3 se3 = LSTM(256, kernel_regularizer="l2")(se3)
2 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/keras_tensor.py in __len__(self)
219
220 def __len__(self):
--> 221 raise TypeError('Keras symbolic inputs/outputs do not '
222 'implement `__len__`. You may be '
223 'trying to pass Keras symbolic inputs/outputs '
TypeError: Exception encountered when calling layer "lstm" (type LSTM).
Keras symbolic inputs/outputs do not implement `__len__`. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model. This error will also get raised if you try asserting a symbolic input/output directly.
Call arguments received:
• inputs=<KerasTensor: shape=(None, 34, 200) dtype=float32 (created by layer 'tf.identity_1')>
• mask=<KerasTensor: shape=(None, 34) dtype=bool (created by layer 'tf.math.not_equal')>
• training=False
• initial_state=None
I'm using tensorflow 2.8.0 version. Can anyone help me with this code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
