提交 be01a30d authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Arnaud Bergeron

testcode for doc/tutorial/loading_and_saving.txt

上级 e08c1dbd
......@@ -66,7 +66,7 @@ same order):
>>> f = file('objects.save', 'wb')
>>> for obj in [obj1, obj2, obj3]:
>>> cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
... cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)
>>> f.close()
Then:
......@@ -74,7 +74,7 @@ Then:
>>> f = file('objects.save', 'rb')
>>> loaded_objects = []
>>> for i in range(3):
>>> loaded_objects.append(cPickle.load(f))
... loaded_objects.append(cPickle.load(f))
>>> f.close()
For more details about pickle's usage, see
......@@ -102,7 +102,7 @@ along every instance of your model.
For instance, you can define functions along the lines of:
.. code-block:: python
.. testcode::
def __getstate__(self):
state = dict(self.__dict__)
......@@ -127,8 +127,9 @@ The main advantage of this approach is that you don't even need Theano installed
in order to look at the values of shared variables that you pickled. You can
just load the parameters manually with `numpy`.
.. code-block:: python
.. testcode::
import numpy
numpy.load('model.zip')
This approach could be beneficial if you are sharing your model with people who
......@@ -153,7 +154,7 @@ don't.
For instance, if the only parameters you want to save are a weight
matrix *W* and a bias *b*, you can define:
.. code-block:: python
.. testcode::
def __getstate__(self):
return (self.W, self.b)
......@@ -167,7 +168,7 @@ If at some point in time *W* is renamed to *weights* and *b* to
*bias*, the older pickled files will still be usable, if you update these
functions to reflect the change in name:
.. code-block:: python
.. testcode::
def __getstate__(self):
return (self.weights, self.bias)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论