title: Python Keras - compatibility between Windows and Linux
body: <p>I have trained and saved a Keras model in Windows 10, Python 3.5, Keras 2.0.6.</p>
  
  <p>In Windows I can then load the model and reuse it. But, when I try and load the model in Linux (Ubuntu), Keras 2.0.5, I get the following error:</p>
  
  <blockquote>
    <p>ValueError: Optimizer weight shape (90,) not compatible with provided weight shape (31, 90)</p>
  </blockquote>
  
  <p>I have tried uninstalling Keras and reinstalling using Pip and then doing the same with Conda. Is this a compatibility issue with Windows and Linux, or something else?</p>
  
  <p>Many thanks</p>
  
  <p>Code to train and save the model:</p>
  
  <pre><code>from keras.models import Sequential
  from keras.layers import Dense
  
  import keras.backend as K
  def inRange(y_true, y_pred):
      return K.sum(K.cast(K.less_equal(K.abs(y_true-y_pred), 8), "int32")) / K.shape(y_true)[0]
  
  # create model
  model = Sequential()
  model.add(Dense(n1, input_dim=X_train.shape[1], activation='relu'))
  model.add(Dense(n2, activation='relu'))
  model.add(Dense(1, activation='linear'))
  
  
  # Compile model
  model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy', inRange])
  
  # Fit the model
  history = model.fit(X_train, y_train, epochs=maxEpoch, batch_size=10)
  
  # evaluate the model
  scores = model.evaluate(X_train, y_train)
  print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
  
  # save the model
  model.save('length_predict.h5', overwrite=True, include_optimizer=True)
  </code></pre>
  
  <p>Code to load the saved model:</p>
  
  <pre><code>import keras.backend as K
  from keras.models import load_model
  
  # Custom metric for use in the keras ANN models, needs to be loaded as a custom object
  def inRange(y_true, y_pred):
      '''
      Function for determining the percentage of points that fall within the +-8% error
      '''
      return K.sum(K.cast(K.less_equal(K.abs(y_true-y_pred), 8), "int32")) / K.shape(y_true)[0]
  
  # Load the ANN
  model_length = load_model('length_predict.h5', custom_objects={'inRange':inRange})
  </code></pre>