CodeReclaimers / neat-python

Python implementation of the NEAT neuroevolution algorithm
BSD 3-Clause "New" or "Revised" License
1.41k stars 490 forks source link

Saving to xml file #21

Open mstechly opened 8 years ago

mstechly commented 8 years ago

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.

CodeReclaimers commented 8 years ago

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.

mstechly commented 8 years ago

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.

CodeReclaimers commented 8 years ago

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.

Islandman93 commented 8 years ago

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

CodeReclaimers commented 8 years ago

Thanks for the context on Lasagne!

mathiasose commented 7 years ago

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.

drallensmith commented 7 years ago

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

drallensmith commented 7 years ago

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.

mdalvi commented 6 years ago

@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.