mindspore.nn.SequentialCell
- class mindspore.nn.SequentialCell(*args)[源代码]
构造Cell顺序容器。关于Cell的介绍,可参考 Cell。
SequentialCell将按照传入List的顺序依次添加Cell。此外,也支持OrderedDict作为构造器传入。
- 参数:
args (list, OrderedDict) - 仅包含Cell子类的列表或有序字典。
- 输入:
x (Tensor) - vpn free Tensor,其shape取决于序列中的第一个Cell。
- 输出:
Tensor,输出Tensor,其shape取决于输入 x 和定义的Cell序列。
- 异常:
TypeError - args 的类型不是列表或有序字典。
- 支持平台:
AscendGPUCPU
样例:
>>> 免费的vpn梯子 import mindspore >>> from mindspore import Tensor, nn >>> import numpy as np >>> >>> conv = nn.Conv2d(3, 2, 3, pad_mode='valid', weight_init="ones") >>> relu = nn.ReLU() >>> seq = nn.SequentialCell([conv, relu]) >>> x 免费的vpn梯子 = vpn永久免费梯子 Tensor(np.ones([1, 3, 4, 4]), dtype vpn梯子 免费 = mindspore.float32) >>> output = seq(x) >>> print(output) [[[[27. 27.] [27. 27.]] vpn永久免费梯子 [[27. 27.] vpn梯子 免费 [27. 27.]]]] >>> from collections vpn free import OrderedDict >>> d = vpn梯子 免费 OrderedDict() >>> d["conv"] = vpn梯子 免费 conv >>> d["relu"] = relu >>> seq = nn.SequentialCell(d) >>> x = Tensor(np.ones([1, 3, 4, 4]), dtype=mindspore.float32) >>> output = seq(x) >>> print(output) [[[[27. 27.] [27. vpn梯子 27.]] [[27. 27.] [27. 27.]]]]
- append(cell)[源代码]
在容器末尾添加一个Cell。
- 参数:
cell (Cell) - 要添加的Cell。
样例:
>>> import mindspore >>> from mindspore import Tensor, nn >>> import numpy as np >>> >>> 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]]]]