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?
            Asked
            
        
        
            Active
            
        
            Viewed 229 times
        
    0
            
            
        - 
                    1can you add more information about what language/package/libraries you are using? – venkata krishnan Jun 28 '19 at 07:48
- 
                    Yes, I use python and keras! – Serena89 Jun 28 '19 at 07:49
- 
                    could you maybe give the code also? Please add the infos to the question, don't leave them in the comments – Frayal Jun 28 '19 at 07:49
- 
                    2See the excelent answer [here](https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras). Voting to close as duplicate. – dedObed Jun 28 '19 at 07:58
- 
                    this solution doensn't work for me. I run my code ( I can't attach this :() for 3 times and I have different solutions for accuracy and other metrics – Serena89 Jun 28 '19 at 08:59
2 Answers
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
