I'm trying to learn somehing on neural networks, and I wrote my first program. I would like not to waste all the time which is spent in training the net by saving the adjusted parameters in a file and by loading its later (in an hour, day, or year). Here's the structure constructor of the Network class, whose wariable I want to save:
def __init__(self, sizes):
self.num_layers = len(sizes)
self.sizes = sizes
self.biases = [np.random.randn(y, 1) for y in sizes[1:]]
self.weights = [np.random.randn(y, x)
for x, y in zip(sizes[:-1], sizes[1:])]
return
and here's my attempt to save and load it,
def save(net, name = "noname"):
with open("{0}_nn_sizes.nn".format(name),"w") as s:
s.write(str(net.sizes))
with open("{0}_nn_weights.nn".format(name),"w") as w:
w.write(str(net.weights))
with open("{0}_nn_biases.nn".format(name),"w") as b:
b.write(str(net.biases))
return
def load(name = "noname"):
with open("{0}_nn_sizes.nn".format(name),"w") as s:
net=nn.Network(list(s)) """ERROR HERE"""
with open("{0}_nn_weights.nn".format(name),"w") as w:
net.weights = list(w)
with open("{0}_nn_biases.nn".format(name),"w") as b:
net.biases = list(b)
return net
which disastrously fails giving an io.UnsupportedOperation: not readable
error where pointed.
Actually I'm pretty sure that even the approach is kind of bad, so I'd gladly accept any suggestion or hint on how solve my problem.