简体   繁体   中英

Theano's pkl_utils Dump Function not available in Theano 0.7?

I want to save a model that I have trained. Since it is using shared variables (like Weights, bias and so on) and since it should be readable on machines without Theano installed, I wanted to use the theano.misc.pkl_utils.dump() function. However, it seems as if that is only installed in bleeding edge installations (the current github file looks different than my local one).

Is that really the case? And why is the description in the docs then?

I am using theano 0.7.0 and I'm seriously confused about this. If that feature is not yet available (I can't install bleeding edge right now), what are other ways? I'm sure that I am not the only one trying to save a trained model the easiest way possible ;-)

Thank you a lot,

Roman

If you train your model using Theano, the parameters of the model will be eventually shared variables (probably a list of shared variables if the network consists of several layers). It is possible to pickle the list of shared variables and unpickle it later. However you might have problems to unpickle such variables in another machine, eg with no Theano installation or if you train in a GPU-capable machine that generates CudaNdarrays and then you want to load back the model in a non-GPU-capable machine. What I recommend you is the following: convert every shared variable of the list of parameters into a numpy ndarray :

params_numpy = [numpy.asarray(p.get_value()) for p in params]

where params is a list of shared variables. Then you can safely pickle / unpickle params_numpy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM