pytorch torch segmentation model syntax error in jupyter notebook
i get the error:
nn.MaxPool2d(kernel_size=2, stride=2),
^
SyntaxError: invalid syntax
with the following code:
import torch
import torch.nn as nn
import torch.nn.functional as F

class CNNSEG(nn.Module): # Define your model
    def __init__(self, num_classes=1):
        super(CNNSEG, self).__init__()
        #Adds one extra class to stand for the zero-padded pixels
        self.num_classes = num_classes + 1

        self.conv1 = nn.Sequential(
            nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.LocalResponseNorm(size=5, alpha=1e-4, beta=0.75),
        )

        self.conv2 = nn.Sequential(
            nn.Conv2d(in_channels=32, out_channels=256, kernel_size=5, stride=1, padding=2, groups=2),
            nn.ReLU(),j
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.LocalResponseNorm(size=5, alpha=1e-4, beta=0.75),
        )
        
        self.conv3 = nn.Sequential(
            nn.Conv2d(in_channels=256, out_channels=512, kernel_size=5, stride=1, padding=2, groups=2),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.LocalResponseNorm(size=5, alpha=1e-4, beta=0.75),
        )        

        self.score_conv = nn.Conv2d(in_channels=512, out_channels=num_classes, kernel_size=1, padding=0)
        self.deconv = nn.ConvTranspose2d(in_channels=num_classes, out_channels=num_classes, 
            kernel_size=16, stride=8, bias=False)
        self.out_activation = nn.Softmax((num_classes, 4))

    def forward(self, x):
        out1 = self.conv1(x)
        out2 = self.conv2(out1)
        out3 = self.conv3(out2)
        out_score = self.score_conv(out3)
        out_deconv = self.deconv(out_score)
        return out_deconv
    
model = CNNSEG(num_classes=4) # We can now create a model using your defined segmentation model
print(model)

i haven't got any open brackets as far as I can see, I don't see what can be wrong here ? thanks

When setting the second layer (self.conv2) after the ReLu, you must have mistyped a &quot;j&quot;.
That's why you get invalid syntax.
