makeyourownneuralnetwork/makeyourownneuralnetwork

Some unclear things regarding saving a neural network

Gerrit02 opened this issue · 2 comments

Hello Rashid,
I still have some questions regarding saving a neural network.

Let's say you start with the initial code (training with dataset 60000 lines).
Everytime you run that code the time to train the network takes as in your case let's say 5 minutes.

Now let's using the code to save a neural network.

Before you have the input box "train the neural network"
you can put the code:

# load neural network weights
def load(self):
self.wih = numpy.load('saved_wih.npy')
self.who = numpy.load('saved_who.npy')
pass

After the Training part you can put the code:

# save neural network weights
def save(self):
numpy.save('saved_wih.npy', self.wih)
numpy.save('saved_who.npy', self.who)
pass

Now my questions:

1)Let's say training is bussy, and you interrupt (closing the labtob), when the neural network was bussy
with the 30000 line of the dataset.

How does the network know that he has to continue with the 30001 line from the dataset or even
know that epoch is 1,2, 3 ... etc once you run the code again?

2)Neural network has finished training (did a loop over all 60000 lines of the dataset and did this epoch
= 5 times)

When you rerun the code now, how does the network know to take the weights of the saved_wih and saved_who and not to restart the training all over again?

Thanks for clarifying!!!

Sorry, I think I got the picture.
The load and save are the methods (Def's) you have to define in your network class.

Then during the running of code of the neural network you put in a cell after the training input cell: n.save()

If you run the code again: you first put n.load() after the input training cell and you run the code from there.

However: what if you want to save the weights once the network has been entirely trained?

  1. it doesn't know where to carry on from, unless of course you code that yourself. the example code provided is extremely minimal and simplistic to illustrate how to save/load weights.

  2. you have to tell it .. it won't know.

that is correct n.save() and n.load() .

You can save the weights once the network is fully trained with n.save(). you do this yourself.