Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-532] Clarify documentation of save_parameters(), load_parameters() #11210

Merged
merged 11 commits into from
Jun 14, 2018
2 changes: 1 addition & 1 deletion docs/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Select API: 
* [Visual Question Answering](http://gluon.mxnet.io/chapter08_computer-vision/visual-question-answer.html) <img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg" alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/>
* Practitioner Guides
* [Multi-GPU training](http://gluon.mxnet.io/chapter07_distributed-learning/multiple-gpus-gluon.html) <img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg" alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/>
* [Checkpointing and Model Serialization (a.k.a. saving and loading)](http://gluon.mxnet.io/chapter03_deep-neural-networks/serialization.html) <img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg" alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/> ([Alternative](/tutorials/gluon/save_load_params.html))
* [Checkpointing and Model Serialization (a.k.a. saving and loading)](/tutorials/gluon/save_load_params.html) <img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg" alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/> ([Alternative](http://gluon.mxnet.io/chapter03_deep-neural-networks/serialization.html))
* [Inference using an ONNX model](/tutorials/onnx/inference_on_onnx_model.html)
* [Fine-tuning an ONNX model on Gluon](/tutorials/onnx/fine_tuning_gluon.html)
* [Visualizing Decisions of Convolutional Neural Networks](/tutorials/vision/cnn_visualization.html)
Expand Down
24 changes: 20 additions & 4 deletions python/mxnet/gluon/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ def collect_params(self, select=None):
children's Parameters(default), also can returns the select :py:class:`ParameterDict`
which match some given regular expressions.

For example, collect the specified parameter in ['conv1_weight', 'conv1_bias', 'fc_weight',
For example, collect the specified parameters in ['conv1_weight', 'conv1_bias', 'fc_weight',
'fc_bias']::

model.collect_params('conv1_weight|conv1_bias|fc_weight|fc_bias')

or collect all paramters which their name ends with 'weight' or 'bias', this can be done
or collect all parameters whose names end with 'weight' or 'bias', this can be done
using regular expressions::

model.collect_params('.*weight|.*bias')
Expand Down Expand Up @@ -309,6 +309,18 @@ def _collect_params_with_prefix(self, prefix=''):

def save_parameters(self, filename):
"""Save parameters to file.
This function is to be used to save parameters of a Gluon model, note that
the saved parameters are not meant to be loaded in a different language binding for now.
Saving parameters using `.save_parameters()` is different than
`.collect_params().save()` and `.save_params()`, which are deprecated ways
to save the parameters of a model and should be avoided.

If your model is hybridizable and you want to export a serialized version of the
structure of the model as well as its parameters please refer to
:py:meth:`HybridBlock.export`. Such model can then be loaded back in any language binding
or even in Gluon using a :py:class:`SymbolBlock`.
Refer to this tutorial for a complete overview of saving/loading models with
MXNet: https://mxnet.incubator.apache.org/tutorials/gluon/save_load_params.html

filename : str
Path to file.
Expand All @@ -335,11 +347,15 @@ def save_params(self, filename):
def load_parameters(self, filename, ctx=None, allow_missing=False,
ignore_extra=False):
"""Load parameters from file.
This function is to be used to load parameters of a Gluon model that were
saved using the `.save_parameters()` function. Any other use is undefined behaviour.
Refer to this tutorial for a complete overview of saving/loading models with
MXNet: https://mxnet.incubator.apache.org/tutorials/gluon/save_load_params.html

filename : str
Path to parameter file.
ctx : Context or list of Context, default cpu()
Context(s) initialize loaded parameters on.
Context(s) to initialize loaded parameters on.
allow_missing : bool, default False
Whether to silently skip loading parameters not represents in the file.
ignore_extra : bool, default False
Expand Down Expand Up @@ -382,7 +398,7 @@ def load_params(self, filename, ctx=None, allow_missing=False,
filename : str
Path to parameter file.
ctx : Context or list of Context, default cpu()
Context(s) initialize loaded parameters on.
Context(s) to initialize loaded parameters on.
allow_missing : bool, default False
Whether to silently skip loading parameters not represents in the file.
ignore_extra : bool, default False
Expand Down