(self, x, locs)
| 93 | |
| 94 | |
| 95 | def forward(self, x, locs): |
| 96 | # lr = x.clone() |
| 97 | x = self.conv1(x) |
| 98 | x = self.relu(x) |
| 99 | x = self.layer1(x) |
| 100 | x = self.layer2(x) |
| 101 | x = self.layer3(x) |
| 102 | x = self.layer4(x) |
| 103 | x = self.layer5(x) # B, 512, 4, 64, 17M parameters |
| 104 | |
| 105 | B, C, H, W = x.size() |
| 106 | |
| 107 | # lr = F.interpolate(lr, (x.size(2), x.size(3))) |
| 108 | w_b = [] |
| 109 | for b in range(locs.size(0)): #locs: 0~2048 |
| 110 | w_c = [] |
| 111 | for c in range(locs.size(1)): |
| 112 | if locs[b][c] < 2048: |
| 113 | center_loc = (locs[b][c]/4/self.down_h).int() # from 32*512 to 4*64 |
| 114 | start_x = max(0, center_loc-self.size_h//2) |
| 115 | end_x = min(center_loc+self.size_h//2, 512//self.down_h) |
| 116 | |
| 117 | # crop_feature = x[b:b+1, :, :, start_x:end_x].clone() |
| 118 | # crop_feature = self._check_outliers(crop_feature, self.size_h) # 1, 512, 4, 4 or 1, 512, 8, 8 |
| 119 | |
| 120 | if end_x - start_x != self.size_h: |
| 121 | bgfill = torch.zeros((B, C, H, self.size_h), dtype=x.dtype, layout=x.layout, device=x.device) |
| 122 | bgfill[:, :, :, self.size_h//2 - (center_loc - start_x):self.size_h//2 - (center_loc - start_x) + end_x - start_x] += x[b:b+1, :, :, start_x:end_x].clone() |
| 123 | crop_feature = bgfill.clone() |
| 124 | else: |
| 125 | crop_feature = x[b:b+1, :, :, start_x:end_x].clone() |
| 126 | w = self.feature2w(crop_feature.view(1, -1)) # 1*512 |
| 127 | w_c.append(w.squeeze(0)) |
| 128 | |
| 129 | else: |
| 130 | w_c.append(w.squeeze(0).detach()*0) |
| 131 | |
| 132 | w_c = torch.stack(w_c, dim=0) |
| 133 | w_b.append(w_c) |
| 134 | w_b = torch.stack(w_b, dim=0) |
| 135 | |
| 136 | return w_b #, lr |
| 137 | |
| 138 | |
| 139 |
nothing calls this directly
no outgoing calls
no test coverage detected