0

When I run my autoencoder several times with a fixed set of parameters I have some different results on accuracy and other metrics. I suppose this is because initially the neural network chooses random weights. I want the results are always the same. Can I modify the random choice of weights? How can I make my result deterministic and not random?

Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
Serena89
  • 49
  • 6

2 Answers2

2

You need to set the seed

I usually use a this simple function bellow

def keras_seeding(seednum):
    np.random.seed(seednum)
    from tensorflow import set_random_seed
    set_random_seed(seednum)
    random.seed(seednum)
    os.environ['PYTHONHASHSEED'] = str(seednum)

seednum=1123
keras_seeding(seednum)
Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
0

If you are using Keras, at every layer you can mention the weight intializer. You can read more about the various types of initializers available in this link.

Example : 

model = Sequential()
model.add(Conv2D(64,(3,3),kernel_initializer="he_normal"))
model.add(Dense(10,kernel_initializer='ones'))

I have just mentioned the sample initializers here. Look for the one best suited for your case.

venkata krishnan
  • 1,961
  • 1
  • 13
  • 20