我训练了一个具有 1000 次迭代的网络,并且希望在不从头开始的情况下继续这种训练直到 2000 次迭代。我阅读了针对这个问题的不同方法并编写了下面的代码,所以最后我的参数位于“saved_params”中。但是从现在开始,我不明白我必须用这些参数做什么。
有人可以解释我该怎么做吗?如何将这些参数用于我的训练过程?
from __future__ import print_function
import numpy as np
import theano
import lasagne
import pickle
input_var=None
ini = lasagne.init.HeUniform()
l_in = lasagne.layers.InputLayer(shape=(None, 1, 120, 120), input_var=input_var)
b= np.zeros((1, 4), dtype=theano.config.floatX)
b = b.flatten()
loc_l1 = lasagne.layers.MaxPool2DLayer(l_in, pool_size=(2, 2))
loc_l2 = lasagne.layers.Conv2DLayer(loc_l1, num_filters=20, filter_size=(5, 5), W=ini)
loc_l3 = lasagne.layers.MaxPool2DLayer(loc_l2, pool_size=(2, 2))
loc_l4 = lasagne.layers.Conv2DLayer(loc_l3, num_filters=20, filter_size=(5, 5), W=ini)
loc_l5 = lasagne.layers.DenseLayer(loc_l4, num_units=50, W=lasagne.init.HeUniform('relu'))
network = lasagne.layers.DenseLayer(loc_l5, num_units=4, b=b, W=lasagne.init.Constant(0.0), nonlinearity=lasagne.nonlinearities.identity)
def save_network(filename,param_values):
f = open(filename, 'wb')
pickle.dump(param_values,f,protocol=-1)
f.close()
def load_network(filename):
f = open(filename, 'rb')
param_values = pickle.load(f)
f.close()
return param_values
save_network("model.npz",lasagne.layers.get_all_param_values(network))
saved_params = load_network("model.npz")
lasagne.layers.set_all_param_values(network, saved_params)