0

I constructed a simple neural network using Keras. And when I run it in jupyter notebook for the first time, I works perfectly well. But If I rerun it without changing anything, some problems happens. The following two pictures showing the screenshot for the first time and second time respectively. You can see the difference. enter image description here enter image description here I'm a newbie to Keras and have searched the Internet for several hours. What should I do so that I can rerun the neural network without restart jupyter notebook? Thanks!

Bicheng
  • 687
  • 8
  • 20
  • why you don't want to restart the notebook? – zabop Jan 05 '19 at 10:59
  • 1
    try re-defining the model instead of just running the `.fit` function. – Paritosh Singh Jan 05 '19 at 11:01
  • @ParitoshSingh Actually, I tried re-defining the model, but the training result for the re-defining model is the same as the second picture. Is there something tricky? – Bicheng Jan 05 '19 at 11:05
  • i honestly don't know, ive never tried this before. – Paritosh Singh Jan 05 '19 at 11:07
  • 1
    @Bicheng Are you sure you have not executed/changed anything in between since the cell numbers are 33 and 42? – today Jan 05 '19 at 11:17
  • Please do **not** open [multiple questions](https://stackoverflow.com/questions/54050656/how-to-fit-run-the-neural-network-multiple-times-in-jupyter-notebook) on the same issue! Edit & update your initial question instead! – desertnaut Jan 05 '19 at 11:42
  • Possible duplicate of [How to fit/run the neural network multiple times in jupyter notebook?](https://stackoverflow.com/questions/54050656/how-to-fit-run-the-neural-network-multiple-times-in-jupyter-notebook) – desertnaut Jan 05 '19 at 11:45

1 Answers1

0

This is the standard code we use to reset the session before training again.

from keras import backend as K

curr_session = tf.get_default_session()
# close current session
if curr_session is not None:
    curr_session.close()
# reset graph
K.clear_session()
# create new session
s = tf.InteractiveSession()
K.set_session(s)
Mohan Radhakrishnan
  • 3,002
  • 5
  • 28
  • 42