title: Keras Tensoflow full reset
body: <p>I know that this question was asked many times by many people but I still don't have any working solution.</p>
  <p>I have a Python code that tends to create a model, fit it and then predict something. Since I have many features to train the model with I've created a list of all combinations of my features like 2 of 10, 4 of 10 etc. Now I wanted to call my code in a loop.</p>
  <pre><code>The loop looks like:
  
  for each combination in all combinations:
      model = Sequential()
      ... add some layers...
      model.compile(...)
      model.fit()
      ...
      model.predict()
  </code></pre>
  <p>And I see that every time I run it on the same set of features I got different results. Of course I've disabled all the randomness so it is not an issue. If I just run my code from command line (without the loop - i.e. the python fully exits between the runs) I get a fully repeating result.</p>
  <p>So my assumption was that either Keras or/and Tensorflow do not reset cleanly between the loops.</p>
  <p>I've tried many things like putting the following lines after I want my model to be discarded:</p>
  <pre><code>model.reset_states()
  del model
  gc.collect()
  tf.keras.backend.set_learning_phase(1)
  keras.backend.clear_session()
  K.clear_session()
  tf.compat.v1.reset_default_graph()
  from tensorflow.python.framework import ops
  ops.reset_default_graph()
  </code></pre>
  <p>Nothing works - the results between the loops are inconsistent. The only way to work correctly is to run my file from a batch file with a lot of lines that allow python to exit before running next time.</p>
  <p>Any suggestions how to deal with that? I'm on Windows with TS 2.4.1 and latest keras.</p>
  <p>Thanks</p>
  <p>I'm using this code to prevent randomness:</p>
  <pre><code>def reset_random_seeds():
      os.environ['PYTHONHASHSEED'] = str(1)
      tf.random.set_seed(1)
      np.random.seed(1)
      random.seed(1)
  </code></pre>