You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2018/04/15 02:17:44 UTC
[incubator-mxnet] branch master updated: fix sequential (#10554)
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 38b23ac fix sequential (#10554)
38b23ac is described below
commit 38b23ac0792f47485ea6c216f47e86241947f087
Author: Eric Junyuan Xie <pi...@users.noreply.github.com>
AuthorDate: Sat Apr 14 19:17:39 2018 -0700
fix sequential (#10554)
---
python/mxnet/gluon/nn/basic_layers.py | 4 ++--
tests/python/unittest/test_gluon.py | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/python/mxnet/gluon/nn/basic_layers.py b/python/mxnet/gluon/nn/basic_layers.py
index efca0c3..7641509 100644
--- a/python/mxnet/gluon/nn/basic_layers.py
+++ b/python/mxnet/gluon/nn/basic_layers.py
@@ -62,7 +62,7 @@ class Sequential(Block):
modstr=modstr)
def __getitem__(self, key):
- return self._children[str(key)]
+ return list(self._children.values())[key]
def __len__(self):
return len(self._children)
@@ -119,7 +119,7 @@ class HybridSequential(HybridBlock):
modstr=modstr)
def __getitem__(self, key):
- return self._children[str(key)]
+ return list(self._children.values())[key]
def __len__(self):
return len(self._children)
diff --git a/tests/python/unittest/test_gluon.py b/tests/python/unittest/test_gluon.py
index ca1e121..854e6fe 100644
--- a/tests/python/unittest/test_gluon.py
+++ b/tests/python/unittest/test_gluon.py
@@ -609,6 +609,23 @@ def test_block_attr_list_of_block():
model.collect_params()
assert len(w) == 0
+def check_sequential(net):
+ dense1 = gluon.nn.Dense(10)
+ net.add(dense1)
+ dense2 = gluon.nn.Dense(10)
+ net.add(dense2)
+ dense3 = gluon.nn.Dense(10)
+ net.add(dense3)
+
+ assert net[1] is dense2
+ assert net[-1] is dense3
+ slc = net[1:3]
+ assert len(slc) == 2 and slc[0] is dense2 and slc[1] is dense3
+
+@with_seed()
+def test_sequential():
+ check_sequential(gluon.nn.Sequential())
+ check_sequential(gluon.nn.HybridSequential())
@with_seed()
def test_sequential_warning():
--
To stop receiving notification emails like this one, please contact
jxie@apache.org.