!5751 SequentialCell add append

Merge pull request !5751 from lijiaqi/SequentialCell_append
This commit is contained in:
mindspore-ci-bot 2020-09-10 20:49:37 +08:00 committed by Gitee
commit 48f235b13d
1 changed files with 7 additions and 0 deletions

View File

@ -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")
@ -144,6 +145,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)