pybrain/pybrain — Issue #76: Serialization of fast networks
Author: dchaplinsky
Created: 2012-01-08 13:25:49+00:00
State: open

Seems that it's impossible to do with cPickle:

```
In [83]: net = buildNetwork(total_samples, total_samples / 2, 5, 1, fast=True)

In [84]: dumps(net)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/Users/dchaplinsky/temp/arac/src/python/ in ()

/Users/dchaplinsky/Projects/babieslists/env/lib/python2.6/copy_reg.pyc in _reduce_ex(self, proto)
68 else:
69 if base is self.__class__:
---> 70 raise TypeError, "can't pickle %s objects" % base.__name__
71 state = base(self)
72 args = (self.__class__, base, state)

TypeError: can't pickle PySwigObject objects
```

I've found temporary workaround:
```
net = buildNetwork(total_samples, total_samples / 2, 5, 1, fast=True)
slow_net = buildNetwork(total_samples, total_samples / 2, 5, 1)
...

slow_net._setParameters(net.params.copy())
with open("models/%s.pickle" % str(error).replace(".", '_'), 'w') as fh:
dump(slow_net, fh)
```

But it will be much better to have general way to save network configuration + params found into xml/json/whatever else