neat-python icon indicating copy to clipboard operation
neat-python copied to clipboard

Saving to xml file

Open mstechly opened this issue 8 years ago • 9 comments

Now AFAIK the only way to save a network is with pickle. It would be very helpful if it could be saved in xml file so it will be more version-independent and maybe even used later with other NN libraries.

mstechly avatar Jun 23 '16 09:06 mstechly

Are there any common NN formats you think might be useful? That's something I've been meaning to look into, but just haven't had time yet.

CodeReclaimers avatar Jun 27 '16 14:06 CodeReclaimers

Looking at stars at github I think the most popular are: Tensorflow - 27042 Keras - 6747 Lasagne - 2233 pyBrain - 1849

As a result I think some export to Tensorflow format will be the most appropriate. However I have no idea how such export works in TF, so I will have to dig a little bit.

mstechly avatar Jun 28 '16 19:06 mstechly

I haven't used any of those before--for all of my previous NN work, the decision from management was that we had to roll our own, and pyBrain is the only one I remember having seen around at that time. Presumably the others didn't exist yet. :P

I'm wondering if any of the popular libraries accept the free-form style of networks that neat-python currently produces by default. For example, pyBrain appears to assume some kind of layered structure, so there may be some neat-python networks that couldn't be represented there. (But I just quickly skimmed the docs, so I could be wrong there.)

Still, it should be possible to create custom genome/phenome classes for neat-python that evolve the kinds of networks that would be easily translated, so I think this would still be a good thing to have.

CodeReclaimers avatar Jul 05 '16 00:07 CodeReclaimers

Lasagne user here, all lasagne networks are pickled by their parameters only. So no way to know the model structure you must just set_all_param_values on a model of the same layout. Issue reference: https://github.com/Lasagne/Lasagne/issues/7

Islandman93 avatar Jul 21 '16 22:07 Islandman93

Thanks for the context on Lasagne!

CodeReclaimers avatar Jul 22 '16 16:07 CodeReclaimers

Over at https://github.com/mathiasose/CA-NEAT/blob/62de70dfd564b37c2148fa7ce5deaf98672a03e8/ca_neat/ga/serialize.py I made my own json serialization and deserialization functions. If you want something like this in the main library I could make a PR for it.

Another nice option for serialization and deserialization is marshmallow. I think this might be a more testable and future-proof method to achieve the same thing, but it does introduce a dependency to another library.

mathiasose avatar Jul 21 '17 22:07 mathiasose

JSON would be more portable to non-Python implementations, I would think.

drallensmith avatar Jul 21 '17 23:07 drallensmith

OTOH, the json module in Python is rather annoying compared to pickle in extending what it can save, from what I can see - you can't specify with a class methods to encode/decode it, it has to be specified in something available in one place to the functions calling json.

drallensmith avatar Aug 02 '17 19:08 drallensmith

@CodeReclaimers , @drallensmith I think saving to XML will be beneficial if we want to port the NEAT neural nets to and from another popular NEAT library SharpNEAT. SharpNEAT currently supports XML formats for NEAT as well as HyperNEAT.

mdalvi avatar Nov 10 '17 08:11 mdalvi