title: Loading saved model (Bidirectional LSTM) in Keras
body: <p>I trained and saved a Bidirectional LSTM model in Keras successfully with:</p>
  
  <pre><code>model = Sequential()
  model.add(Bidirectional(LSTM(N_HIDDEN_NEURONS,
                          return_sequences=True,
                          activation="tanh",
                          input_shape=(SEGMENT_TIME_SIZE, N_FEATURES))))
  model.add(Bidirectional(LSTM(N_HIDDEN_NEURONS)))
  model.add(Dropout(0.5))
  model.add(Dense(N_CLASSES, activation='sigmoid'))
  model.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
  
  model.fit(X_train, y_train,
            batch_size=BATCH_SIZE,
            epochs=N_EPOCHS,
            validation_data=[X_test, y_test])
  
  model.save('model_keras/model.h5')
  </code></pre>
  
  <p>However, when I want to load it with:</p>
  
  <pre><code>model = load_model('model_keras/model.h5')
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>ValueError: You are trying to load a weight file containing 3 layers
    into a model with 0 layers.</p>
  </blockquote>
  
  <p>I also tried different methods like saving and loading model architecture and weights separately but none of them worked for me. Also, previously, when I was using normal (unidirectional) LSTMs, loading the model worked fine.</p>