NotImplementedError:

class CNN(nn.Module):
    """CNN."""

    
    def __init__(self):
        """CNN Builder."""
        super(CNN, self).__init__()

        self.conv_layer = nn.Sequential(

            # Conv Layer block 1
            KernelConv2d(in_channels=k, out_channels=30, kernel_size=3, padding=1),
            nn.BatchNorm2d(30),
            nn.ReLU(inplace=True),
            KernelConv2d(in_channels=30, out_channels=60, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),

            # Conv Layer block 2
            KernelConv2d(in_channels=60, out_channels=60, kernel_size=3, padding=1),
            nn.BatchNorm2d(60),
            nn.ReLU(inplace=True),
            KernelConv2d(in_channels=60, out_channels=60, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Dropout2d(p=0.05),

            # Conv Layer block 3
            KernelConv2d(in_channels=60, out_channels=120, kernel_size=3, padding=1),
            nn.BatchNorm2d(120),
            nn.ReLU(inplace=True),
            KernelConv2d(in_channels=120, out_channels=120, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=2, stride=2),
        )
        
        self.fc_layer = nn.Sequential(
            nn.Dropout(p=0.1),
            nn.Linear(4096, 480),
            nn.ReLU(inplace=True),
            nn.Linear(1024, 512),
            nn.ReLU(inplace=True),
            nn.Dropout(p=0.1),
            nn.Linear(512, output_units)
        )



def forward(self, x):
    """Perform forward."""
    
    # conv layers
    x = self.conv_layer(x)
    
    # flatten
    x = x.view(x.size(0), -1)
    
    # fc layer
    x = self.fc_layer(x)

    return x
from tensorflow.keras.optimizers import Adam
model = CNN().to(device)
# defining the optimizer
optimizer = Adam(model.parameters())#, learning_rate=learning_rate)
# defining the loss function
criterion = nn.CrossEntropyLoss()
# checking if GPU is available
if torch.cuda.is_available():
    model = model.cuda()
    criterion = criterion.cuda()
    
print(model)

Dear friends, I am getting "NotImplementedError:" for the following code. Can anyone please help me in resolving the following error.

from torchvision import models
from torchsummary import summary
model = CNN().to(device)
summary(model,(k,9,9))

NotImplementedError Traceback (most recent call last)
in ()
2 from torchsummary import summary
3 model = CNN().to(device)
----> 4 summary(model,(k,9,9))

2 frames
/usr/local/lib/python3.7/dist-packages/torchsummary/torchsummary.py in summary(model, input_size, batch_size, device)
70 # make a forward pass
71 # print(x.shape)
—> 72 model(*x)
73
74 # remove these hooks

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1049 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1050 or _global_forward_hooks or _global_forward_pre_hooks):
→ 1051 return forward_call(*input, **kwargs)
1052 # Do not call functions when jit is used
1053 full_backward_hooks, non_full_backward_hooks = [], []

/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in _forward_unimplemented(self, *input)
199 registered hooks while the latter silently ignores them.
200 “”"
→ 201 raise NotImplementedError
202
203

NotImplementedError:

The indentation in the posted code snippet are wrong and def forward should be a class method of CNN.