Similar Keras models produce different results

Question:

What is the difference between these two models? Because each produce different results consistently.

Model 1

Input = tf.keras.layers.Dense(9,activation='linear')
hidden = tf.keras.layers.Dense(10,activation='relu')
hidden2 = tf.keras.layers.Dense(10,activation='relu')
output = tf.keras.layers.Dense(1, kernel_initializer='normal', activation='linear')

model = tf.keras.Sequential([Input, Dropout(0.2), hidden, Dropout(0.2), hidden2, output])
model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.001))

Model 2

hidden_units1 = 9
hidden_units2 = 10
hidden_units3 = 10

model = tf.keras.Sequential([
  Dense(hidden_units1, activation='linear'),
  Dropout(0.2),
  Dense(hidden_units2, activation='relu'),
  Dropout(0.2),
  Dense(hidden_units3, activation='relu'),
  Dense(1, kernel_initializer='normal', activation='linear')])
model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.001))
Asked By: Filbert Anderson

||

Answers:

Both Models are the same, so it would be better to init one of these models and derive its weights by get_weights(), then train that model, and after that init the next model and set its weights by the wights of the previous model with set_weights(weights), it’s the closest way to make the same models training performance the same.

Answered By: Soroush Mirzaei