I have a Keras model as follows. How to calculate the gradient of the last 3 output neurons with respect to the MSE loss, given an input (shape=(1,4,100,100,3)) and a target value Y.
def buildmodel(input_shape, action_size, learning_rate):
state_input = Input(shape=(None, img_rows, img_cols, channels))
x = Bidirectional(ConvLSTM2D(filters = 16, kernel_size = (3,3)))(state_input)
x = MaxPooling2D((2,2))(x)
x = Flatten()(x)
x = Dense(3)(x)
model = Model(inputs=state_input, outputs=x)
adam = Adam(lr=learning_rate)
model.compile(loss='mse',optimizer=adam)
return model