pytorchでのSequentialの使い方


テキストリンク:https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-nn/#class-torchnnsequential-args
class torch.nn.Sequential(* args)
シーケンスコンテナ.Modulesは、容器に入力された順序で追加される.もちろん、OrderedDictを送信することもできます.Sequentialの使用方法をより容易に理解するために、以下の例を示す.
# Example of using Sequential

model = nn.Sequential(
          nn.Conv2d(1,20,5),
          nn.ReLU(),
          nn.Conv2d(20,64,5),
          nn.ReLU()
        )
# Example of using Sequential with OrderedDict
model = nn.Sequential(OrderedDict([
          ('conv1', nn.Conv2d(1,20,5)),
          ('relu1', nn.ReLU()),
          ('conv2', nn.Conv2d(20,64,5)),
          ('relu2', nn.ReLU())
        ]))