modify api annotation

This commit is contained in:
xumengjuan1 2021-12-08 10:01:50 +08:00
parent 1d0b7fafe3
commit 250401a384
3 changed files with 96 additions and 78 deletions

View File

@ -9,6 +9,15 @@ Cell
mindspore.nn.Cell
Containers
-----------
.. cnmsplatformautosummary::
:toctree: nn
mindspore.nn.CellList
mindspore.nn.SequentialCell
Gradient
---------

View File

@ -7,56 +7,59 @@ mindspore.nn.CellList
CellList可以像普通Python列表一样使用支持'__getitem__'、'__setitem__'、'__delitem__'、'__len__'、'__iter__'及'__iadd__'但包含的Cell都已正确注册且对所有Cell方法可见。
**参数:**
**args** (list可选) - 仅包含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<>
>
**支持平台:**
``Ascend`` ``GPU`` ``CPU``
append(cell)
**样例:**
在列表末尾添加一个Cell
>>> 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<>
>
.. py:method:: append(cell)
参数:
cell(Cell)- 要添加的Cell
在列表末尾添加一个Cell。
extend(cells)
将Python iterable中的Cell追加到列表的末尾
参数:
cells(list)- 要追加的Cell子类列表
异常:
TypeErrorcells不是Cell子类列表
**参数:**
**cell** (Cell) - 要添加的Cell。
insert(index, cell)
.. py:method:: extend(cells)
在列表中的给定索引之前插入给定的Cell
将Python iterable中的Cell追加到列表的末尾。
参数:
index(int)- 给定的列表索引
cell(Cell)- 要插入的Cell子类
**参数:**
**cells** (list) - 要追加的Cell子类列表。
**异常:**
**TypeError** - cells不是Cell子类列表。
.. py:method:: insert(index, cell)
在列表中的给定索引之前插入给定的Cell。
**参数:**
**index** (int) - 给定的列表索引。
**cell** (Cell) - 要插入的Cell子类。

View File

@ -8,53 +8,59 @@ mindspore.nn.SequentialCell
Cell列表将按照它们在构造函数中传递的顺序添加到其中。
或者也可以传入Cell的有序字典。
参数:
args (list, OrderedDict)仅包含Cell子类的列表或有序字典。
**参数:**
输入:
xTensor - Tensor其shape取决于序列中的第一个Cell。
**args** (list, OrderedDict) - 仅包含Cell子类的列表或有序字典。
输出:
Tensor输出Tensor其shape取决于输入`x`和定义的Cell序列。
**输入:**
**x** (Tensor) - Tensor其shape取决于序列中的第一个Cell。
**输出:**
Tensor输出Tensor其shape取决于输入 `x` 和定义的Cell序列。
**异常:**
- **TypeError** - `args` 的类型不是列表或有序字典。
**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.]]]]
``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)
.. py:method:: append(cell)
在容器末尾添加一个cell。
参数:
cell(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]]]]
>>> 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]]]]