This is an automated email from the ASF dual-hosted git repository. jxie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push: new d77d937 Fix __repr__ for gluon.Parameter (#8956) d77d937 is described below commit d77d937eaf7e13a30320368d316516bd9da52ca5 Author: Julian Salazar <jul...@slzr.me> AuthorDate: Fri Dec 8 16:36:16 2017 -0800 Fix __repr__ for gluon.Parameter (#8956) * Fix __repr__ for gluon.parameter * Add to contributors (PRs #8565, #8956, etc.) * Add unit test for gluon.Parameter string --- CONTRIBUTORS.md | 1 + python/mxnet/gluon/parameter.py | 2 +- tests/python/unittest/test_gluon.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1c42e03..9d8542e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -152,3 +152,4 @@ List of Contributors * [Andre Tamm](https://github.com/andretamm) * [Marco de Abreu](https://github.com/marcoabreu) - Marco is the creator of the current MXNet CI. +* [Julian Salazar](https://github.com/JulianSlzr) diff --git a/python/mxnet/gluon/parameter.py b/python/mxnet/gluon/parameter.py index 537d636..fa38285 100644 --- a/python/mxnet/gluon/parameter.py +++ b/python/mxnet/gluon/parameter.py @@ -117,7 +117,7 @@ class Parameter(object): def __repr__(self): s = 'Parameter {name} (shape={shape}, dtype={dtype})' - return s.format(**self.__dict__) + return s.format(name=self.name, shape=self.shape, dtype=self.dtype) @property def grad_req(self): diff --git a/tests/python/unittest/test_gluon.py b/tests/python/unittest/test_gluon.py index c619056..f2d001a 100644 --- a/tests/python/unittest/test_gluon.py +++ b/tests/python/unittest/test_gluon.py @@ -70,6 +70,23 @@ def test_parameter_sharing(): net3.load_params('net1.params', mx.cpu()) +def test_parameter_str(): + class Net(gluon.Block): + def __init__(self, **kwargs): + super(Net, self).__init__(**kwargs) + with self.name_scope(): + self.dense0 = nn.Dense(10, in_units=5, use_bias=False) + + net = Net(prefix='net1_') + lines = str(net.collect_params()).splitlines() + + assert lines[0] == 'net1_ (' + assert 'net1_dense0_weight' in lines[1] + assert '(10, 5)' in lines[1] + assert 'numpy.float32' in lines[1] + assert lines[2] == ')' + + def test_basic(): model = nn.Sequential() model.add(nn.Dense(128, activation='tanh', in_units=10, flatten=False)) -- To stop receiving notification emails like this one, please contact ['"comm...@mxnet.apache.org" <comm...@mxnet.apache.org>'].