0

I have tried the methods mentioned in the post "https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras" but unable to reproduce the result in term of accuracy where I got different prediction for different run. The experiment I am running is about classification and the model used is CNN. The code below is the only part I do to try to reproduce the result.

import os
random_seed = 0
os.environ['PYTHONHASHSEED']=str(random_seed)


from __future__ import print_function, division


import tensorflow as tf
import keras.backend as K


session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)
session_conf.gpu_options.allow_growth = True
sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
K.set_session(sess)

# for later session 
#tf.compat.v1.keras.backend.set_session(sess)


import csv
import glob
import numpy as np
import time
from keras.layers import *
import keras.backend
from keras.layers.advanced_activations import *
from keras.layers.convolutional import *
from keras.models import *
from keras.utils import *
from sklearn.utils import shuffle
import math
from keras import optimizers
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

random_seed = 0
os.environ['PYTHONHASHSEED']=str(random_seed)
np.random.seed(random_seed)
tf.random.set_seed(random_seed)
random.seed(seed)

session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)
session_conf.gpu_options.allow_growth = True
sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
K.set_session(sess)


# # for later versions:
# session_conf = tf.compat.v1.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)
# session_conf.gpu_options.allow_growth = True
# sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
# tf.compat.v1.keras.backend.set_session(sess)

random_seed = 0
np.random.seed(random_seed)
tf.random.set_seed(random_seed)

The post is a popular post from a few years ago, is there any changes that need to make? Or is there any other recent method that I can use to reproduce the result in Keras and Tensorflow?

David98
  • 31
  • 3
  • @VladimirFokow I am not sure what details exactly do you mean but I added more description about the question. – David98 Aug 16 '22 at 13:30
  • 1
    For example there are no tensorflow imports in this code, we cannot reproduce or run this code. – Dr. Snoopy Aug 16 '22 at 14:00

0 Answers0