Simple residual block to refine the details of the activation maps.
| 58 | |
| 59 | |
| 60 | class Refine(nn.Module): |
| 61 | """ |
| 62 | Simple residual block to refine the details of the activation maps. |
| 63 | """ |
| 64 | |
| 65 | def __init__(self, planes: int): |
| 66 | """ |
| 67 | Args: |
| 68 | planes: number of input channels. |
| 69 | """ |
| 70 | super().__init__() |
| 71 | |
| 72 | relu_type: type[nn.ReLU] = Act[Act.RELU] |
| 73 | conv2d_type: type[nn.Conv2d] = Conv[Conv.CONV, 2] |
| 74 | norm2d_type: type[nn.BatchNorm2d] = Norm[Norm.BATCH, 2] |
| 75 | |
| 76 | self.bn = norm2d_type(num_features=planes) |
| 77 | self.relu = relu_type(inplace=True) |
| 78 | self.conv1 = conv2d_type(in_channels=planes, out_channels=planes, kernel_size=3, padding=1) |
| 79 | self.conv2 = conv2d_type(in_channels=planes, out_channels=planes, kernel_size=3, padding=1) |
| 80 | |
| 81 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 82 | """ |
| 83 | Args: |
| 84 | x: in shape (batch, planes, spatial_1, spatial_2). |
| 85 | """ |
| 86 | residual = x |
| 87 | x = self.bn(x) |
| 88 | x = self.relu(x) |
| 89 | x = self.conv1(x) |
| 90 | x = self.bn(x) |
| 91 | x = self.relu(x) |
| 92 | x = self.conv2(x) |
| 93 | |
| 94 | return residual + x |
| 95 | |
| 96 | |
| 97 | class FCN(nn.Module): |
no outgoing calls
no test coverage detected
searching dependent graphs…