tf.keras.layers.Bidirectional: Please initialize `Bidirectional` layer with a `tf.keras.layers.Layer` instance
See original GitHub issueGetting some strange error when using bidirectional LSTM in tf.keras
. I have followed documentation of bidriectional, but getting the error.
Here is the code:
rl = Reshape((-1, int(cnn_SE_featureMap.shape[2]) * int(cnn_SE_featureMap.shape[3])))(
input) ####(type_spec=TensorSpec(shape=(None, 24, 9))
# lstm_l6 = tf.keras.layers.LSTM(128, activation='tanh', recurrent_initializer=tf.keras.initializers.Orthogonal(seed=1), dropout=0.5, recurrent_dropout=0.25)(lstm_l5)
lstm_l5 = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(128, activation='tanh',
recurrent_initializer=tf.keras.initializers.Orthogonal(), dropout=0.5,
recurrent_dropout=0.5, return_sequences=True)(rl))
Error: Traceback (most recent call last):
File "/home/anafees/.local/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3251, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-11-721b57a9dbb6>", line 1, in <module>
lstm_l5 = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(128, activation='tanh',
File "/home/anafees/.local/lib/python3.9/site-packages/keras/layers/wrappers.py", line 453, in __init__
raise ValueError(
ValueError: Please initialize `Bidirectional` layer with a `tf.keras.layers.Layer` instance. Received: KerasTensor(type_spec=TensorSpec(shape=(None, 128), dtype=tf.float32, name=None), name='lstm_5/strided_slice_3:0', description="created by layer 'lstm_5'")
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
tf.keras.layers.Bidirectional | TensorFlow v2.11.0
Layer instance that meets the following criteria: Be a sequence-processing layer (accepts 3D+ inputs). Have a go_backwards , return_sequences ...
Read more >Please initialize `Bidirectional` layer with a `Layer` instance ...
The tf.keras.layers.Bidirectional layer which is a wrapper layer for RNNs should be initialized with a Keras layer type as its argument.
Read more >tf.keras.layers.Bidirectional | TensorFlow
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its...
Read more >A Guide to Bidirectional RNNs With Keras - Paperspace Blog
This tutorial covers bidirectional recurrent neural networks: how they work, their applications, and how to implement a bidirectional RNN with Keras.
Read more >How to set an initial state for a Bidirectional LSTM Layer in ...
Model, and met the same error. this PR may help you. Finally I built my model by tf.keras.layers.layer, and I'm still working on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I found solution in this answer on stackoverflow, Simply change
tensorflow.keras
tokeras
.Reference from stackoverflow: You are mixing imports between the keras and tf.keras libraries, these are not the same library, and doing this is not supported.
You need to make all imports from one of the libraries:
@FrameMuse Might be. But now
tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(64,dropout=0.5))(rl)
is working for me