mindspore/docs/api/api_python/nn/mindspore.nn.SequentialCell...

66 lines
1.7 KiB
ReStructuredText
Raw Normal View History

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