if yes, kindly help me to resolve the below query. I am working on some self project
Below is some section of Training model code
Prev_pred=None
for t in range(Ty):
# Step 2.A: Perform one step of the attention mechanism to get back the context vector at step t
context = one_step_attention(X[:,t,:], cnn_model_input, s)
print(context.shape)
# Apply the post-attention LSTM cell to the "context" vector.
if prev_pred is None:
# Initialize prev_pred with the desired shape
prev_pred = tf.keras.Input(shape=(1, features))
prev_pred = tf.zeros_like(prev_pred)
#print(prev_pred.shape)
else :
prev_pred=RepeatVector(1)(prev_pred)
#print(prev_pred.shape)
s,_,c = LSTM(n_s, return_state = True)(context,initial_state=[s, c])
# Apply a Dense layer to the hidden state output of the post-attention LSTM
out = Dense(features, activation='linear')(s)
prev_pred=out
# Step 2.D: Append "out" to the "outputs" list (≈ 1 line)
outputs.append(out)
# Create model
model = Model(inputs=[X_CNN_input, X_lstm_input, s0, c0],outputs=outputs)
return model
Below are the dimensions for my variables.
context -> (None, None, 64)
s-> (None, 64)
out -> (None, 30)
prev_pred -> I have made it be of shape (None, 1, 30)
I have tried so many things like concatenation and applying the Add() layer after adding 34 lengths of additional zeros to prev_pred in the channel direction so that it can be added with context easily, but nothing is working getting different errors.
#context = tf.concat([context, prev_pred], axis=-1) # Concatenate with previous prediction
#context=Add()(context,prev_pred) # already added zeros to prev_pred in the channel direction, but that part is not included here to avoid confusion
The above these two methods don’t work
In my code
n_s value is 64
features value is 30
If I use neither concatenation nor Add, my code works fine.