Srinath
Srinath

Reputation: 19

Keras mode.fit - Why does every new run produce different results (Accuracy and loss)?

Here is the code:

model = keras.Sequential([keras.layers.Flatten(input_shape=(1,9000)),
                     keras.layers.Dense(100, activation=tf.nn.relu),
                     keras.layers.Dense(4, activation=tf.nn.softmax)])


model.compile(optimizer=tf.train.AdamOptimizer(),
         loss='sparse_categorical_crossentropy',            
         metrics=['accuracy'])

history = model.fit(x_train, y_train, validation_split=0.20,epochs = 10, shuffle=False, verbose =1)

With every new run I get different loss and accuracy values for each epoch. I expect consistent results, how do I achieve that?

Upvotes: 0

Views: 330

Answers (1)

Jenia Golbstein
Jenia Golbstein

Reputation: 374

With every new model initialization you start with new random weights. In order to get reproducible results in keras read here:

https://keras.io/getting-started/faq/#how-can-i-obtain-reproducible-results-using-keras-during-development

Upvotes: 1

Related Questions