(self, x1, x2, modal=0)
| 183 | self.gm_pool = gm_pool |
| 184 | |
| 185 | def forward(self, x1, x2, modal=0): |
| 186 | if modal == 0: |
| 187 | x1 = self.visible_module(x1) |
| 188 | x2 = self.thermal_module(x2) |
| 189 | x = torch.cat((x1, x2), 0) |
| 190 | elif modal == 1: |
| 191 | x = self.visible_module(x1) |
| 192 | elif modal == 2: |
| 193 | x = self.thermal_module(x2) |
| 194 | |
| 195 | # shared block |
| 196 | if self.non_local == 'on': |
| 197 | NL1_counter = 0 |
| 198 | if len(self.NL_1_idx) == 0: self.NL_1_idx = [-1] |
| 199 | for i in range(len(self.base_resnet.base.layer1)): |
| 200 | x = self.base_resnet.base.layer1[i](x) |
| 201 | if i == self.NL_1_idx[NL1_counter]: |
| 202 | _, C, H, W = x.shape |
| 203 | x = self.NL_1[NL1_counter](x) |
| 204 | NL1_counter += 1 |
| 205 | # Layer 2 |
| 206 | NL2_counter = 0 |
| 207 | if len(self.NL_2_idx) == 0: self.NL_2_idx = [-1] |
| 208 | for i in range(len(self.base_resnet.base.layer2)): |
| 209 | x = self.base_resnet.base.layer2[i](x) |
| 210 | if i == self.NL_2_idx[NL2_counter]: |
| 211 | _, C, H, W = x.shape |
| 212 | x = self.NL_2[NL2_counter](x) |
| 213 | NL2_counter += 1 |
| 214 | # Layer 3 |
| 215 | NL3_counter = 0 |
| 216 | if len(self.NL_3_idx) == 0: self.NL_3_idx = [-1] |
| 217 | for i in range(len(self.base_resnet.base.layer3)): |
| 218 | x = self.base_resnet.base.layer3[i](x) |
| 219 | if i == self.NL_3_idx[NL3_counter]: |
| 220 | _, C, H, W = x.shape |
| 221 | x = self.NL_3[NL3_counter](x) |
| 222 | NL3_counter += 1 |
| 223 | # Layer 4 |
| 224 | NL4_counter = 0 |
| 225 | if len(self.NL_4_idx) == 0: self.NL_4_idx = [-1] |
| 226 | for i in range(len(self.base_resnet.base.layer4)): |
| 227 | x = self.base_resnet.base.layer4[i](x) |
| 228 | if i == self.NL_4_idx[NL4_counter]: |
| 229 | _, C, H, W = x.shape |
| 230 | x = self.NL_4[NL4_counter](x) |
| 231 | NL4_counter += 1 |
| 232 | else: |
| 233 | x = self.base_resnet(x) |
| 234 | if self.gm_pool == 'on': |
| 235 | b, c, h, w = x.shape |
| 236 | x = x.view(b, c, -1) |
| 237 | p = 3.0 |
| 238 | x_pool = (torch.mean(x**p, dim=-1) + 1e-12)**(1/p) |
| 239 | else: |
| 240 | x_pool = self.avgpool(x) |
| 241 | x_pool = x_pool.view(x_pool.size(0), x_pool.size(1)) |
| 242 |
nothing calls this directly
no outgoing calls
no test coverage detected