# Load/Save model may lose precision?

**URL:** <https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287>\
**Category:** NuPIC\
**Tags:** question, serialization\
**Created:** [August 23, 2016, 6:28pm UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287 "2016-08-23T18:28:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rainyyun](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rainyyun](https://discourse.numenta.org/u/rainyyun)\
**Post date:** [August 23, 2016, 6:28pm UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/1 "2016-08-23T18:28:14Z")

</div>

Hi I am playing with the one hotgym opf anomaly example in nupic. For every 100 data points, I save the model and then next time I load the model to continue the computation. I observed the prediction results are quite different at some point, comparing to running the entire dataset in memory. Then I also tried for every 600 data points, save and load the model. the results start to diverge at much later data points. I was wondering if load/save can cause the precision loss?

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [August 24, 2016, 5:50pm UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/2 "2016-08-24T17:50:06Z")

</div>

This certainly should not happen. Can you provide some more evidence of this behavior? Like predictions from a normal run against your data vs. a run where you serialize and resurrect your model in the middle of it.

---

<div class="post-metadata">

**Author:** ![rainyyun](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@rainyyun](https://discourse.numenta.org/u/rainyyun)\
**Post date:** [August 29, 2016, 4:25am UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/3 "2016-08-29T04:25:09Z")

</div>

Yes, one can easily reproduce my results. Just put something like the following in the the loop to save and load the model at every x data points

_if (counter % x == 0):_  
\_ print “Read %i lines…” % counter\_  
\_ model.save(my\_path)\_  
\_ model = model.load(my\_path)\_

you can try different x values to see how the results change. I am attaching results for every 100 and 600 data points ([https://drive.google.com/open?id=0B4TNsSMedgSoZHgxVjZsWURIMFE](https://drive.google.com/open?id=0B4TNsSMedgSoZHgxVjZsWURIMFE)), and if x \>= 3945, the results will be the same as running the entire data set in memory.

---

<div class="post-metadata">

**Author:** ![vkruglikov](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/vkruglikov/32/474_2.png) [@vkruglikov](https://discourse.numenta.org/u/vkruglikov)\
**Post date:** [August 29, 2016, 5:36am UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/4 "2016-08-29T05:36:34Z")

</div>

Indeed, see the disabled tests [https://github.com/numenta/nupic/blob/64400aa71982adb8069ec595ecbd4b9950d23183/tests/integration/nupic/opf/opf\_checkpoint\_test/opf\_checkpoint\_test.py#L461-L483](https://github.com/numenta/nupic/blob/64400aa71982adb8069ec595ecbd4b9950d23183/tests/integration/nupic/opf/opf_checkpoint_test/opf_checkpoint_test.py#L461-L483).

@rhyolight, both of the above-mentioned disabled tests reference the issue NUP-1864 in Numenta’s JIRA. NUP-1864 is closed for some reason, but should be opened. Also, check with @subutai - I think he may have had an explanation about this discrepancy.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [August 29, 2016, 3:24pm UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/5 "2016-08-29T15:24:19Z")

</div>

Thanks, @vkruglikov and @rainyyun for reporting. I’ve created [a nupic.core issue](https://github.com/numenta/nupic.core/issues/1065) to cover this problem on the OS tracker.

---

<div class="post-metadata">

**Author:** ![subutai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/subutai/32/106_2.png) [@subutai](https://discourse.numenta.org/u/subutai)\
**Post date:** [August 29, 2016, 6:52pm UTC](https://discourse.numenta.org/t/load-save-model-may-lose-precision/1287/6 "2016-08-29T18:52:09Z")

</div>

I believe this is due to the fact that the current serialization converts floating point numbers to strings and back again. Converting to string leads to a slight loss of precision so results can diverge, though qualitatively there should be little effect on accuracy.

With the new Capn Proto based serialization, this issue should go away, but it would be good to verify.
