From 777e6245158fe88c3ed85f8dac4e519e4d1c88fa Mon Sep 17 00:00:00 2001 From: Jiaqi Date: Fri, 4 Sep 2020 11:17:29 +0800 Subject: [PATCH] append and remove --- mindspore/nn/layer/container.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mindspore/nn/layer/container.py b/mindspore/nn/layer/container.py index 843a0784d5..e148da0056 100644 --- a/mindspore/nn/layer/container.py +++ b/mindspore/nn/layer/container.py @@ -19,6 +19,7 @@ from ..cell import Cell __all__ = ['SequentialCell', 'CellList'] + def _valid_index(cell_num, index): if not isinstance(index, int): raise TypeError("Index {} is not int type") @@ -145,6 +146,12 @@ class SequentialCell(Cell): for cell in self._cells.values(): cell.set_grad(flag) + def append(self, cell): + """Appends a given cell to the end of the list.""" + if _valid_cell(cell): + self._cells[str(len(self))] = cell + return self + def construct(self, input_data): for cell in self.cell_list: input_data = cell(input_data)