-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving Spatial Pooler #641
Comments
Thanks for the post @Sedom9 I am also repeating the forum post from @1111 because it also has some hints.
. |
Thanks. I hope you can solve this problem. Because without saving I can't use this for fork. |
In looking at this I see that the save() and load() functions were not implemented so I will have to do some work on this. pickle was implemented on both the SP and TM but apparently there seems to be a problem with it as indicated by @1111 There is are functions loadFromString( string) and writeToString( ) that should have been a JSON representation of the SP but I think it is binary. So that needs to be changed as well. I will try to have something for you shortly. |
Thanks a lot. I will wait |
@Sedom9 have a look at test bindings/py/tests/algorithms/spatial_pooler_test.py |
|
If you look at the tests, it uses pickle to serialize a (basic) SP. What is your scenario that is failing? |
@breznak The test is not very extensive. It does not actually check if the restored SP is the same as the original. The original SP contained no data and has all default parameters (other than the dimensions). We should be able to do a little better. |
Also, save(filename) and load(filename) was not implemented as far as I can tell. Should we implement them? |
yeah, I know. A good test would be eg running a SP for 1000 random inputs, serializing, computing the next iteration from the original and a restored SP and see if those are the same. That's why I'm asking OP for usecase where this fails, ideally a PR with test case.
Depends, we should be compatible with |
We are 100% on Cereal. The save/load calls are in Serializable and get converted into Cereal calls save_ar and load_ar which pass the ar argument. For C++ users we do have
All of these can have the optional flag to set the format (Binary, JSON, etc). For Python we have
We cannot do streams across language barriers (at least not very easy) so maybe save() and load() do not need to be exposed to Python. Note that the original Nupic API http://nupic.docs.numenta.org/stable/guides/serialization.html uses read(), write(), readFromFile(), and writeToFile() which were captn proto calls. It depriciated save() and load() |
@breznak ,The problem I am trying to fix with pickle: I have found the problem although I am not sure how to fix it yet.
I added the cout << to see if the SP is restored correctly and it is. So the passing of the byte array did work. However, when we return the sp object, we are returning it by value. pybind11 is doing some sort of magic on it to make it into a python object but in Python, Still studying pybind11 to see what it really wants to have returned. Does SP have a problem with a copy constructor perhaps? |
Found the problem with pickling. The bindings for pickling on SP was broken because it could not handle returning the created SP object by value during deserialization. Probably due to a problem with the copy constructor. We don't really want it to be copied anyway so it works returning it in a unique_ptr object. |
Resolved in #644, thank you David! |
@Sedom9 If you pull a fresh repository from htm.core you should find that SP can now be saved and restored with pickle. It can also be saved and restored using saveToFile(filename) and loadFromFile(filename ). The save( ) and load( ) functions work with C++ but because the argument is a stream they cannot be used directly from python. I hope this works for you. Thank you for submitting the issue because it helped us identify and fix this problem. |
Thanx a lot for your help! I will pull fresh repository from htm.core. I will try to save my Spatial Pooler. And I will write posts here about my testing. |
@hirarinNakalab @Sedom9 can you confirm the issue was fixed by the merged PR, so we can close this? |
Cloned the updated Repository to verify that the SP and TM can successfully save load. I think there is no problem closing this issue. |
Thanks for testing! Issue successfully resolved. |
Sorry, I forgot confirm my testing. Thanx a lot, after updating repository. Everything is ok. |
@breznak @dkeeney. Last time, when I tested save and load, I didn't notice about loading. Now I come back to loading my Spatial Pooler, and I have some questions. When I tried to load my Spatial Pooler in this manner: Invoked with: '/var/main_project/union-classifier1/data/sp.tmp'` Thanx a lot for your helping! |
yes, it's not a static function, you need a dummy SP first.
|
Hello!
I want to migrate from Python2 to Python3. That’s why I use htm.core( community fork). And I don’t understand about serialization in htm.core. I want to save Spatial Pooler, but I get error: AttributeError: ‘htm.bindings.algorithms.SpaialPooler’ object has no attribute ‘save’
The text was updated successfully, but these errors were encountered: