benanne / morb

Modular Restricted Boltzmann Machine (RBM) implementation using Theano
GNU General Public License v3.0
172 stars 41 forks source link

Picklable models? #2

Open jorgehatccrma opened 11 years ago

jorgehatccrma commented 11 years ago

First off, thanks for this awesome library! I'm new to DeepLearning and Theano, but your lib makes it so much easier.

I was wondering if there's a way to save (pickle) MORB models? I tried modifying example_basic.py by adding the following lines at the end:

import cPickle
with open('model.pkl', 'wb') as f:
    cPickle.dump(rbm, f, protocol=cPickle.HIGHEST_PROTOCOL)

but I get the following trace:

...
Epoch 49
MSE = 0.0026
Took 6.69 seconds
Traceback (most recent call last):
  File "example_basic.py", line 61, in <module>
    cPickle.dump(rbm, f, protocol=cPickle.HIGHEST_PROTOCOL)
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

If I remove the protocol=cPickle.HIGHEST_PROTOCOL argument I get:

Epoch 49
MSE = 0.0026
Took 6.96 seconds
Traceback (most recent call last):
  File "example_basic.py", line 61, in <module>
    cPickle.dump(rbm, f)
  File "/<removed path for privacy>/python2.7/copy_reg.py", line 70, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle function objects

Is there another way to save MORB models for later use?

Thanks, Jorge