optimizer got an empty parameter list while using adam
I was creating conv nets for cifar100 and code is give below but I have encounted the error mentioned in the title while initializing optimizer.
Code for model
class CNN(nn.Module):
  def __init__(self,k):
    super(CNN,self).__init__()
    #Convolutional layer
    conv1=nn.Conv2d(3,32,kernel_size=3,padding='same')
    conv2=nn.Conv2d(32,64,kernel_size=3,padding='same')
    conv3=nn.Conv2d(64,128,kernel_size=3,padding='same')
    conv4=nn.Conv2d(128,128,kernel_size=3,padding='same')
    conv5=nn.Conv2d(128,256,kernel_size=3,padding='same')
    conv6=nn.Conv2d(256,256,kernel_size=3,padding='same')
    #feddfordward layer
    f1=nn.Linear(4*4*256,4096)
    f2=nn.Linear(4096,k)
  def forward(self,x):
    x=f.relu(self.conv1(x))
    x=f.relu(self.conv2(x))
    x=f.max_pool2d(x,kernel_size=2,stride=2)
    x=f.relu(self.conv3(x))
    x=f.relu(self.conv4(x))
    x=f.max_pool2d(x,kernel_size=2,stride=2)
    x=f.relu(self.conv5(x))
    x=f.relu(self.conv6(x))
    x=f.max_pool2d(x,kernel_size=2,stride=2)
    x=x.view(-1,4*4*256)
    x=f.relu(self.f1(x))
    x=self.f2(x)
    return x

Model initialization
model=CNN(k)

device=th.device(&quot;cuda:0&quot; if th.cuda.is_available() else &quot;cpu&quot;)
print(device)
model.to(device)

lossFunction=th.nn.CrossEntropyLoss()
optimizer=th.optim.Adam(model.parameters())
epoch=100

I tried changing maxpool2d function but it didnot help. I am new to pytorch and any help will be appreciated

Your submodules must be registered as attributes of your parent nn.Module:
class CNN(nn.Module):
    def __init__(self,k):
        super(CNN,self).__init__()
        # convolutional layer
        self.conv1 = nn.Conv2d(3, 32, kernel_size=3, padding='same')
        self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding='same')
        self.conv3 = nn.Conv2d(64, 128, kernel_size=3, padding='same')
        self.conv4 = nn.Conv2d(128, 128, kernel_size=3, padding='same')
        self.conv5 = nn.Conv2d(128, 256, kernel_size=3, padding='same')
        self.conv6 = nn.Conv2d(256, 256, kernel_size=3, padding='same')
        
        # feedfordward layer
        self.f1 = nn.Linear(4*4*256, 4096)
        self.f2 = nn.Linear(4096, k)

