'1 output channel for image classification

I have 22 classes, on the output layer, respectively, 22 channels, how can I change all this so that the output is 1 channel. Number 1 corresponds to class 1, number 2 - to the second, etc.

import torch.nn.functional as F

class Net(nn.Module):
        def __init__(self):
            super().__init__()
            self.conv1 = nn.Conv2d(1, 6, 5) 
            self.pool = nn.MaxPool2d(2, 2)
            self.conv2 = nn.Conv2d(6, 64, 5)

            self.fc1 = nn.Linear(64 * 21 * 21, 120)
            self.fc2 = nn.Linear(120, 256)
            self.fc3 = nn.Linear(256, 22) 


        def forward(self, x):
            x = self.pool(F.relu(self.conv1(x)))
            x = self.pool(F.relu(self.conv2(x)))
            x = torch.flatten(x, 1) 
            x = F.relu(self.fc1(x))
            x = F.relu(self.fc2(x))
            x = self.fc3(x)
            return x


net = Net()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source