mindspore.nn.CellList

class mindspore.nn.CellList(*args, **kwargs)[源代码]

构造Cell列表。关于Cell的介绍,可参考 Cell

CellList可以像普通Python列表一样使用,其包含的Cell均已初始化。

参数:
  • args (list,可选) - Cell列表。

支持平台:

Ascend GPU CPU

样例:

>>> 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)[源代码]

在列表末尾添加一个Cell。

参数:
  • cell (Cell) - 要添加的Cell。

extend(cells)[源代码]

将cells中的Cell添加到列表末尾。

参数:
  • cells (list) - 要添加的Cell列表。

异常:
  • TypeError - cells中的元素不是Cell。

insert(index, cell)[源代码]

在列表中的给定索引之前插入给定的Cell。

参数:
  • index (int) - 给定的列表索引。

  • cell (Cell) - 要插入的Cell。