All class definitions of pickled objects must be known by the script that performs the scattering. More about this in other StackOverflow questions (for example, the AttributeError: 'module' object does not have the 'newperson' attribute ).
Your code is correct if you import cA . Given the error you get, this may not be the case. Make sure you use from cA import cA , not just import cA
Alternatively, your model is defined by its parameters, so instead you can simply determine the parameter values). There are two ways to do this, depending on your point of view.
Save the general Anano variables. Here we assume that ca.params is a regular Python list of instances of the Theano shared variable.
cPickle.dump(ca.params, f, protocol=cPickle.HIGHEST_PROTOCOL)
Save the numpy arrays stored inside Theano shared variables.
cPickle.dump([param.get_value() for param in ca.params], f, protocol=cPickle.HIGHEST_PROTOCOL)
When you want to load the model, you will need to reinitialize the parameters. For example, create a new instance of class cA , then either
ca.params = cPickle.load(f) ca.W, ca.b, ca.b_prime = ca.params
or
ca.params = [theano.shared(param) for param in cPickle.load(f)] ca.W, ca.b, ca.b_prime = ca.params
Note that you need to set the params field and separate parameter fields.
Daniel Renshaw
source share