ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

Save and reload neural network #489

Closed sf-issues closed 10 years ago

sf-issues commented 12 years ago

Converted from SourceForge issue 3544726, submitted by ksr90 Submit Date: 2012-07-16 19:10 GMT

We've been developing some reinforcement learning algorithms to implement with the neural network in Topographica. Some simulations take a while to run, hours to a couple days, and at the end we want to save the entire neural network architecture (including sheets, connection fields) to use for future times. Ideally, we want to be able to load up a file and continue the learning procedure and/or simulations. We tried the pickle module in Python to save the data, but we can't save the entire neural network architecture, only individual connection fields or weight matrices. Is there any way of saving and reloading the neural network architecture? Thanks for your help.

sf-issues commented 12 years ago

Submitted by jbednar Date: 2012-07-23 03:02 GMT

From what you describe, it sounds like you can just use save_snapshot and load_snapshot:

http://topographica.org/Reference_Manual/topo.command-module.html#save_snapshot http://topographica.org/Reference_Manual/topo.command-module.html#load_snapshot

These are based on pickle, and specifically pickling the topo.sim object, but have special support for saving some things that pickle doesn't. They are also available in the GUI menus as "Load snapshot" and "Save snapshot".

Jim

sf-issues commented 12 years ago

Submitted by kesh89 Date: 2012-08-07 20:13 GMT

Hi Jim, I've been trying to use the "Save Snapshot" and have been running into this error:

run_trial is defined in main: saving bytecode. Time: 100000.00 TopoConsole00224: Warning: (TypeError) expected string or Unicode object, NoneType found Traceback (most recent call last): File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in call return self.func(*args) File "C:\Users\Hrishikesh\Desktop\topographica\topo\tkgui\topoconsole.py", line 645, in save_snapshot topo.command.basic.save_snapshot(snapshot_name) File "C:\Users\Hrishikesh\Desktop\topographica\topo\command\basic.py", line 326, in save_snapshot pickle.dump(to_save,snapshot_file,2) TypeError: expected string or Unicode object, NoneType found

I've tried several types of networks to see if it would work but with no luck. I also tried using gzip & pickle to save a pkl.gz file. That works when I want to save the data from the InMemoryRecorder() objects but it doesn't seem to work with a topographica sheet and gives an error as such:

TypeError: a class that defines slots without defining getstate cannot be pickled

Thanks very much for your help, Kesh

sf-issues commented 12 years ago

Submitted by jbednar Date: 2012-08-18 22:28 GMT

That sounds like a variety of errors that would be difficult to debug without specific test cases (i.e, the actual code you are trying to pickle). Basically, Python pickles work only if every single object you are trying to pickle supports pickling, and there are a lot of Python objects that don't support pickling by default. I believe it's always possible to support pickling in some form, and for the components we provide with Topographica we have included picking support, but for user written components (including those from Jeff) that we don't use for our own purposes, we might not notice whether they support pickling. E.g. I don't know if an InMemoryRecorder supports it.

To tell if indeed it's an issue in user-contributed code, can you try saving a snapshot for one of the Topographica examples, such as tiny.ty or lissom_oo_or.ty? Doing that certainly works fine for us, but if it doesn't work at your end, then I'd suggest looking at any modifications you may have made to the main Topographica code. If our examples work but your own networks don't, then you'll have to go through the various new components you have and make sure they all support pickling, by adding set_state and get_state for such objects. Chris Ball has been the one making sure all our pickling stuff works, and could give advice on that, but he's trying to finish his PhD ASAP, and so you'd probably have to pay him a hefty consulting fee if you wanted him to debug your components. :-)

sf-issues commented 12 years ago

Submitted by kesh89 Date: 2012-08-22 16:05 GMT

Hey Jim, You were exactly right! It was a problem with the snapshots was the additional custom components that we added in. I took out some of that extraneous stuff including the InMomoryRecorder and it saved and loaded wonderfully! Thank you very much and I wish Chris all the best in finishing up his PhD!

sf-issues commented 12 years ago

[REMOVED SPAM COMMENT]

ceball commented 10 years ago

(Seems like there was no problem with topographica in the end here.)