Skip to content

classifier

Classifier

Bases: nn.Module

A 3-layer MLP for classification.

Source code in pytorch_adapt\models\classifier.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Classifier(nn.Module):
    """
    A 3-layer MLP for classification.
    """

    def __init__(self, num_classes, in_size=2048, h=1024):
        """
        Arguments:
            num_classes: size of the output
            in_size: size of the input
            h: hidden layer size
        """
        super().__init__()
        self.h = h
        self.net = nn.Sequential(
            nn.Linear(in_size, h),
            nn.ReLU(),
            nn.Dropout(),
            nn.Linear(h, h // 2),
            nn.ReLU(),
            nn.Dropout(),
            nn.Linear(h // 2, num_classes),
        )

    def forward(self, x):
        """"""
        return self.net(x)

__init__(num_classes, in_size=2048, h=1024)

Parameters:

Name Type Description Default
num_classes

size of the output

required
in_size

size of the input

2048
h

hidden layer size

1024
Source code in pytorch_adapt\models\classifier.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def __init__(self, num_classes, in_size=2048, h=1024):
    """
    Arguments:
        num_classes: size of the output
        in_size: size of the input
        h: hidden layer size
    """
    super().__init__()
    self.h = h
    self.net = nn.Sequential(
        nn.Linear(in_size, h),
        nn.ReLU(),
        nn.Dropout(),
        nn.Linear(h, h // 2),
        nn.ReLU(),
        nn.Dropout(),
        nn.Linear(h // 2, num_classes),
    )