| 98 | |
| 99 | |
| 100 | class FTB(nn.Module): |
| 101 | def __init__(self, inchannels, midchannels=512): |
| 102 | super(FTB, self).__init__() |
| 103 | self.in1 = inchannels |
| 104 | self.mid = midchannels |
| 105 | self.conv1 = nn.Conv2d(in_channels=self.in1, out_channels=self.mid, kernel_size=3, padding=1, stride=1, |
| 106 | bias=True) |
| 107 | # NN.BatchNorm2d |
| 108 | self.conv_branch = nn.Sequential(nn.ReLU(inplace=True), \ |
| 109 | nn.Conv2d(in_channels=self.mid, out_channels=self.mid, kernel_size=3, |
| 110 | padding=1, stride=1, bias=True), \ |
| 111 | nn.BatchNorm2d(num_features=self.mid), \ |
| 112 | nn.ReLU(inplace=True), \ |
| 113 | nn.Conv2d(in_channels=self.mid, out_channels=self.mid, kernel_size=3, |
| 114 | padding=1, stride=1, bias=True)) |
| 115 | self.relu = nn.ReLU(inplace=True) |
| 116 | |
| 117 | self.init_params() |
| 118 | |
| 119 | def forward(self, x): |
| 120 | x = self.conv1(x) |
| 121 | x = x + self.conv_branch(x) |
| 122 | x = self.relu(x) |
| 123 | |
| 124 | return x |
| 125 | |
| 126 | def init_params(self): |
| 127 | for m in self.modules(): |
| 128 | if isinstance(m, nn.Conv2d): |
| 129 | init.normal_(m.weight, std=0.01) |
| 130 | if m.bias is not None: |
| 131 | init.constant_(m.bias, 0) |
| 132 | elif isinstance(m, nn.ConvTranspose2d): |
| 133 | # init.kaiming_normal_(m.weight, mode='fan_out') |
| 134 | init.normal_(m.weight, std=0.01) |
| 135 | # init.xavier_normal_(m.weight) |
| 136 | if m.bias is not None: |
| 137 | init.constant_(m.bias, 0) |
| 138 | elif isinstance(m, nn.BatchNorm2d): # NN.BatchNorm2d |
| 139 | init.constant_(m.weight, 1) |
| 140 | init.constant_(m.bias, 0) |
| 141 | elif isinstance(m, nn.Linear): |
| 142 | init.normal_(m.weight, std=0.01) |
| 143 | if m.bias is not None: |
| 144 | init.constant_(m.bias, 0) |
| 145 | |
| 146 | |
| 147 | class ATA(nn.Module): |