Omar Aflak
1 min readJun 15, 2019

--

Quick dirty way

To access layers from a network object simply do network.layer . Then access the index that represents the Fully Connected Layer(s) (as its the only one that contains trainable parameters) and save the weights & biases into a file (e.g. save network.layers[1].weights into a file). Then do the reverse process to load the parameters.

Elegant maintanable way

Add 2 abstract methods to the Layer base class :

  1. One that should write all the trainable parameters into an object passed as the method parameter (could be a json for example)
  2. The other, that given that json (for instance), should load the parameters in the layer itself

Finally, to save the network, add a method in the Network class that calls the write method on each layer. Same process for read .

That said, this post was for educational purpose only. The code is not meant to be used in real world applications. If this is your case, you should use existing libraries like Keras or Tensorflow.

--

--

Responses (2)