I am trying to create a copy of a nn.Sequential network. For example, the following is the easiest way to do the same-
net = nn.Sequential(
nn.Conv2d(16, 32, 3, stride=2),
nn.ReLU(),
nn.Conv2d(32, 64, 3, stride=2),
nn.ReLU(),
)
net_copy = nn.Sequential(
nn.Conv2d(16, 32, 3, stride=2),
nn.ReLU(),
nn.Conv2d(32, 64, 3, stride=2),
nn.ReLU(),
)
However, it is not so great to define the network again. I tried the following ways but it didn't work-
net_copy = nn.Sequential(net): In this approach, it seems thatnet_copyis just a shared pointer ofnetnet_copy = nn.Sequential(*net.modules()): In this approach,net_copycontains many more layers.
Finally, I tired deepcopy in the following way which worked fine-
net_copy = deepcopy(net)
However, I am wondering if it is the proper way. I assume it is fine because it works.