Why "ValueError: optimizer got an empty parameter list" is happened in this case?
I already studied the questions on this topic and I saw only recommendations to use ModuleList instead of usual list. But I don't understand why this error occurs in the case when I use nn.Sequential?
I tried to build AlexNet like in official implementation here: https://github.com/pytorch/vision/blob/master/torchvision/models/alexnet.py
but got "ValueError: optimizer got an empty parameter list"

class AlexNet(nn.Module):

def __init__(self, input_channels, n_classes=1000):
    super(AlexNet, self).__init__()

    self.features = nn.Sequential
    (
        nn.Conv2d(input_channels, 96, kernel_size=11, stride=4),
        nn.LocalResponseNorm(size=2, alpha=2e-5),
        nn.MaxPool2d(kernel_size=3, stride=2),
        nn.ReLU(inplace=True),

        nn.Conv2d(96, 256, kernel_size=5, stride=1),
        nn.LocalResponseNorm(size=2, alpha=2e-5),
        nn.MaxPool2d(kernel_size=3, stride=2),
        nn.ReLU(inplace=True),

        nn.Conv2d(256, 384, kernel_size=3, stride=1),
        nn.ReLU(inplace=True),

        nn.Conv2d(384, 384, kernel_size=3, stride=1),
        nn.ReLU(inplace=True),

        nn.Conv2d(384, 256, kernel_size=3, stride=1),
        nn.ReLU(inplace=True),

    )

    self.fully_connected = nn.Sequential
    (
        nn.Dropout2d(0.5),
        nn.Linear(256, 4096),
        nn.ReLU(inplace=True),
        nn.Linear(4096, 4096),
        nn.ReLU(inplace=True),
        nn.Linear(4096, n_classes)
    )

def forward(self, x):

    x = self.features(x)
    x = nn.Flatten(x)
    x = self.fully_connected(x)

    return x

model = AlexNet(input_channels=1, n_classes=10)
optimizer = optim.Adam(model.parameters() , lr=1e-3)




You have not actually created the nn.Sequential modules, but you have assigned the nn.Sequential class to  self.features and self.fully_connected. The parentheses are on the next line and in Python that creates a tuple, because it doesn't follow an identifier and newlines usually terminate statements with some exceptions such as opening brackets.

The opening parentheses need to be on the same line:

self.features = nn.Sequential(
    nn.Conv2d(input_channels, 96, kernel_size=11, stride=4),
    nn.LocalResponseNorm(size=2, alpha=2e-5),
    nn.MaxPool2d(kernel_size=3, stride=2),
    nn.ReLU(inplace=True),
    nn.Conv2d(96, 256, kernel_size=5, stride=1),
    nn.LocalResponseNorm(size=2, alpha=2e-5),
    nn.MaxPool2d(kernel_size=3, stride=2),
    nn.ReLU(inplace=True),
    nn.Conv2d(256, 384, kernel_size=3, stride=1),
    nn.ReLU(inplace=True),
    nn.Conv2d(384, 384, kernel_size=3, stride=1),
    nn.ReLU(inplace=True),
    nn.Conv2d(384, 256, kernel_size=3, stride=1),
    nn.ReLU(inplace=True),
)

self.fully_connected = nn.Sequential(
    nn.Dropout2d(0.5),
    nn.Linear(256, 4096),
    nn.ReLU(inplace=True),
    nn.Linear(4096, 4096),
    nn.ReLU(inplace=True),
    nn.Linear(4096, n_classes),
)

