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. 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.nn as nn
>>> import mindspore as ms
>>> import numpy as np
>>>
>>> conv = nn.Conv2d(100, 20, 3)
>>> bn = nn.BatchNorm2d(20)
>>> relu = nn.ReLU()
>>> cell_ls = 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.

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.