piiswrong closed pull request #10554: fix sequential URL: https://github.com/apache/incubator-mxnet/pull/10554
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/python/mxnet/gluon/nn/basic_layers.py b/python/mxnet/gluon/nn/basic_layers.py index efca0c3d252..76415090ccf 100644 --- a/python/mxnet/gluon/nn/basic_layers.py +++ b/python/mxnet/gluon/nn/basic_layers.py @@ -62,7 +62,7 @@ def __repr__(self): 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 @@ def __repr__(self): 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 ca1e121008d..854e6fe07f1 100644 --- a/tests/python/unittest/test_gluon.py +++ b/tests/python/unittest/test_gluon.py @@ -609,6 +609,23 @@ def __init__(self, **kwargs): 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(): ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services