As we all know Keras backend uses Tensorflow and so it should give out same kind of results when we provide same parameters, hyper-parameters, weights and biases initialisation at each layer, but still the accuracy is different.

This maybe because of the batches of images which are fed at each step in both the models are not identical and as it gets shuffled randomly.

Is there any way in which we can make sure that the same batch of images are fed into the model while eliminating the randomness?

I have tried using all the same parameters, hyperparameters, same weights and biases initialization with seed values.

The accuracy of both the models are not same.

  • $\begingroup$ Kindly check this answer on how to get reproducible results with Keras: stackoverflow.com/a/52897289/6204860 $\endgroup$ – pcko1 Sep 19 '19 at 10:08
  • $\begingroup$ I dont have a problem on how to produce reproducible results with keras. I have a problem of not get same accuracy with an identical keras and tensorflow model. $\endgroup$ – Subham Tiwari Sep 20 '19 at 10:44

I created a rule to achieve reproducibility:

  • Works for python 3.6, not 3.7
  • First install Keras 2.2.4
  • After install tensorflow 1.9

And finally in the code:

import numpy as np
import random as rn
import tensorflow as tf
import keras
from keras import backend as K

#-----------------------------Keras reproducible------------------#
SEED = 1234

os.environ['PYTHONHASHSEED'] = str(SEED)

session_conf = tf.ConfigProto(
sess = tf.Session(
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.