mindspore.nn.CellList

class mindspore.nn.CellList(*args, **kwargs)[source]

Holds Cells in a list. For more details about Cell, please refer to Cell.

CellList can be used like a regular Python list, the Cells it contains have been initialized and the types of Cells it contains can not be CellDict. Unlike the SequentialCell, the cells in CellList are not connected.

Parameters

args (list, optional) – List of subclass of Cell.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> import numpy as np
>>>
>>> conv = ms.nn.Conv2d(100, 20, 3)
>>> bn = ms.nn.BatchNorm2d(20)
>>> relu = ms.nn.ReLU()
>>> cell_ls = ms.nn.CellList([bn])
>>> cell_ls.insert(0, conv)
>>> cell_ls.append(relu)
>>> cell_ls.extend([relu, relu])
>>> cell_ls_3 = cell_ls[3]
>>> input1 = ms.Tensor(np.ones([2, 3]), ms.float32)
>>> output = cell_ls_3(input1)
>>> print(output)
[[1. 1. 1.]
[1. 1. 1.]]
append(cell)[source]

Appends a given Cell to the end of the list.

Parameters

cell (Cell) – The subcell to be appended.

extend(cells)[source]

Appends Cells from a Python iterable to the end of the list.

Parameters

cells (list) – The Cells to be extended, the types of Cells can not be CellDict.

Raises

TypeError – If the argument cells are not a list of Cells.

insert(index, cell)[source]

Inserts a given Cell before a given index in the list.

Parameters
  • index (int) – The Insert index in the CellList.

  • cell (Cell) – The Cell to be inserted.