Skip to content

fcn

The FCN.

Simple fully convolutional neural network (FCN) implementations. Code credit: torchgeo

kelp.nn.models.fcn.model.FCN

Bases: Module

A simple 5 layer FCN with leaky relus and 'same' padding.

Source code in kelp/nn/models/fcn/model.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class FCN(nn.Module):
    """A simple 5 layer FCN with leaky relus and 'same' padding."""

    def __init__(self, in_channels: int, classes: int, num_filters: int = 256) -> None:
        """Initializes the 5 layer FCN model.

        Args:
            in_channels: Number of input channels that the model will expect
            classes: Number of filters in the final layer
            num_filters: Number of filters in each convolutional layer
        """
        super().__init__()

        conv1 = nn.Conv2d(in_channels, num_filters, kernel_size=3, stride=1, padding=1)
        conv2 = nn.Conv2d(num_filters, num_filters, kernel_size=3, stride=1, padding=1)
        conv3 = nn.Conv2d(num_filters, num_filters, kernel_size=3, stride=1, padding=1)
        conv4 = nn.Conv2d(num_filters, num_filters, kernel_size=3, stride=1, padding=1)
        conv5 = nn.Conv2d(num_filters, num_filters, kernel_size=3, stride=1, padding=1)

        self.backbone = nn.Sequential(
            conv1,
            nn.LeakyReLU(inplace=True),
            conv2,
            nn.LeakyReLU(inplace=True),
            conv3,
            nn.LeakyReLU(inplace=True),
            conv4,
            nn.LeakyReLU(inplace=True),
            conv5,
            nn.LeakyReLU(inplace=True),
        )

        self.last = nn.Conv2d(num_filters, classes, kernel_size=1, stride=1, padding=0)

    def forward(self, x: Tensor) -> Tensor:
        """Forward pass of the model."""
        x = self.backbone(x)
        x = self.last(x)
        return x

kelp.nn.models.fcn.model.FCN.forward

Forward pass of the model.

Source code in kelp/nn/models/fcn/model.py
43
44
45
46
47
def forward(self, x: Tensor) -> Tensor:
    """Forward pass of the model."""
    x = self.backbone(x)
    x = self.last(x)
    return x