Question 1: Short answer
mediumAI-checkedPyTorchWhat does the last line print?
import torch
from torch import nn
class ListSequential(nn.Module):
def __init__(self, *args):
super().__init__()
self.layers = list(args) # a plain Python list
def forward(self, X):
for layer in self.layers:
X = layer(X)
return X
net = ListSequential(nn.Linear(20, 256), nn.ReLU(), nn.Linear(256, 10))
print(len(list(net.parameters())))