forked from mindspore-Ecosystem/mindspore
add api note
This commit is contained in:
parent
c3339edf63
commit
24d884af32
|
@ -0,0 +1,62 @@
|
|||
mindspore.nn.CellList
|
||||
======================
|
||||
|
||||
.. py:class:: mindspore.nn.CellList(*args, **kwargs)
|
||||
|
||||
构造Cell列表。
|
||||
|
||||
CellList可以像普通Python列表一样使用,支持'__getitem__'、'__setitem__'、'__delitem__'、'__len__'、'__iter__'及'__iadd__',但包含的Cell都已正确注册,且对所有Cell方法可见。
|
||||
|
||||
|
||||
|
||||
参数:
|
||||
args (list,可选):仅包含Cell子类的列表。
|
||||
|
||||
支持平台:
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
示例:
|
||||
>>> 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)
|
||||
>>> print(cell_ls)
|
||||
CellList<
|
||||
(0): Conv2d<input_channels=100, output_channels=20, kernel_size=(3, 3),stride=(1, 1), pad_mode=same,
|
||||
padding=0, dilation=(1, 1), group=1, has_bias=False, weight_init=normal, bias_init=zeros, format=NCHW>
|
||||
(1): BatchNorm2d<num_features=20, eps=1e-05, momentum=0.09999999999999998, gamma=Parameter (name=1.gamma,
|
||||
shape=(20,), dtype=Float32, requires_grad=True), beta=Parameter (name=1.beta, shape=(20,), dtype=Float32,
|
||||
requires_grad=True), moving_mean=Parameter (name=1.moving_mean, shape=(20,), dtype=Float32,
|
||||
requires_grad=False), moving_variance=Parameter (name=1.moving_variance, shape=(20,), dtype=Float32,
|
||||
requires_grad=False)>
|
||||
(2): ReLU<>
|
||||
>
|
||||
|
||||
|
||||
append(cell)
|
||||
|
||||
在列表末尾添加一个Cell
|
||||
|
||||
参数:
|
||||
cell(Cell)- 要添加的Cell
|
||||
|
||||
extend(cells)
|
||||
|
||||
将Python iterable中的Cell追加到列表的末尾
|
||||
|
||||
参数:
|
||||
cells(list)- 要追加的Cell子类列表
|
||||
|
||||
异常:
|
||||
TypeError:cells不是Cell子类列表
|
||||
|
||||
|
||||
insert(index, cell)
|
||||
|
||||
在列表中的给定索引之前插入给定的Cell
|
||||
|
||||
参数:
|
||||
index(int)- 给定的列表索引
|
||||
cell(Cell)- 要插入的Cell子类
|
|
@ -0,0 +1,60 @@
|
|||
mindspore.nn.SequentialCell
|
||||
============================
|
||||
|
||||
.. py:class:: mindspore.nn.SequentialCell(*args)
|
||||
|
||||
构造Cell顺序容器。
|
||||
|
||||
Cell列表将按照它们在构造函数中传递的顺序添加到其中。
|
||||
或者,也可以传入Cell的有序字典。
|
||||
|
||||
参数:
|
||||
args (list, OrderedDict):仅包含Cell子类的列表或有序字典。
|
||||
|
||||
输入:
|
||||
x(Tensor) - Tensor,其shape取决于序列中的第一个Cell。
|
||||
|
||||
输出:
|
||||
Tensor,输出Tensor,其shape取决于输入`x`和定义的Cell序列。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - `args` 的类型不是列表或有序字典。
|
||||
|
||||
支持平台:
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
示例:
|
||||
>>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones")
|
||||
>>> relu = nn.ReLU()
|
||||
>>> seq = nn.SequentialCell([conv, relu])
|
||||
>>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32)
|
||||
>>> output = seq(x)
|
||||
>>> print(output)
|
||||
[[[[27. 27.]
|
||||
[27. 27.]]
|
||||
[[27. 27.]
|
||||
[27. 27.]]]]
|
||||
|
||||
|
||||
append(cell)
|
||||
|
||||
在容器末尾添加一个cell。
|
||||
|
||||
参数:
|
||||
cell(Cell)-要添加的cell
|
||||
|
||||
|
||||
示例:
|
||||
>>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones")
|
||||
>>> bn = nn.BatchNorm2d(2)
|
||||
>>> relu = nn.ReLU()
|
||||
>>> seq = nn.SequentialCell([conv, bn])
|
||||
>>> seq.append(relu)
|
||||
>>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32)
|
||||
>>> output = seq(x)
|
||||
>>> print(output)
|
||||
[[[[26.999863 26.999863]
|
||||
[26.999863 26.999863]]
|
||||
[[26.999863 26.999863]
|
||||
[26.999863 26.999863]]]]
|
Loading…
Reference in New Issue