Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/mxnet/gluon/nn/basic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/python/unittest/test_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down