MCPcopy Create free account
hub / github.com/baegwangbin/surface_normal_uncertainty / forward

Method forward

models/submodules/decoder.py:59–201  ·  view source on GitHub ↗
(self, features, gt_norm_mask=None, mode='test')

Source from the content-addressed store, hash-verified

57 )
58
59 def forward(self, features, gt_norm_mask=None, mode='test'):
60 x_block0, x_block1, x_block2, x_block3, x_block4 = features[4], features[5], features[6], features[8], features[11]
61
62 # generate feature-map
63
64 x_d0 = self.conv2(x_block4) # x_d0 : [2, 2048, 15, 20] 1/32 res
65 x_d1 = self.up1(x_d0, x_block3) # x_d1 : [2, 1024, 30, 40] 1/16 res
66 x_d2 = self.up2(x_d1, x_block2) # x_d2 : [2, 512, 60, 80] 1/8 res
67 x_d3 = self.up3(x_d2, x_block1) # x_d3: [2, 256, 120, 160] 1/4 res
68 x_d4 = self.up4(x_d3, x_block0) # x_d4: [2, 128, 240, 320] 1/2 res
69
70 # 1/8 res output
71 out_res8 = self.out_conv_res8(x_d2) # out_res8: [2, 4, 60, 80] 1/8 res output
72 out_res8 = norm_normalize(out_res8) # out_res8: [2, 4, 60, 80] 1/8 res output
73
74 ################################################################################################################
75 # out_res4
76 ################################################################################################################
77
78 if mode == 'train':
79 # upsampling ... out_res8: [2, 4, 60, 80] -> out_res8_res4: [2, 4, 120, 160]
80 out_res8_res4 = F.interpolate(out_res8, scale_factor=2, mode='bilinear', align_corners=True)
81 B, _, H, W = out_res8_res4.shape
82
83 # samples: [B, 1, N, 2]
84 point_coords_res4, rows_int, cols_int = sample_points(out_res8_res4.detach(), gt_norm_mask,
85 sampling_ratio=self.sampling_ratio,
86 beta=self.importance_ratio)
87
88 # output (needed for evaluation / visualization)
89 out_res4 = out_res8_res4
90
91 # grid_sample feature-map
92 feat_res4 = F.grid_sample(x_d2, point_coords_res4, mode='bilinear', align_corners=True) # (B, 512, 1, N)
93 init_pred = F.grid_sample(out_res8, point_coords_res4, mode='bilinear', align_corners=True) # (B, 4, 1, N)
94 feat_res4 = torch.cat([feat_res4, init_pred], dim=1) # (B, 512+4, 1, N)
95
96 # prediction (needed to compute loss)
97 samples_pred_res4 = self.out_conv_res4(feat_res4[:, :, 0, :]) # (B, 4, N)
98 samples_pred_res4 = norm_normalize(samples_pred_res4) # (B, 4, N) - normalized
99
100 for i in range(B):
101 out_res4[i, :, rows_int[i, :], cols_int[i, :]] = samples_pred_res4[i, :, :]
102
103 else:
104 # grid_sample feature-map
105 feat_map = F.interpolate(x_d2, scale_factor=2, mode='bilinear', align_corners=True)
106 init_pred = F.interpolate(out_res8, scale_factor=2, mode='bilinear', align_corners=True)
107 feat_map = torch.cat([feat_map, init_pred], dim=1) # (B, 512+4, H, W)
108 B, _, H, W = feat_map.shape
109
110 # try all pixels
111 out_res4 = self.out_conv_res4(feat_map.view(B, 512 + 4, -1)) # (B, 4, N)
112 out_res4 = norm_normalize(out_res4) # (B, 4, N) - normalized
113 out_res4 = out_res4.view(B, 4, H, W)
114 samples_pred_res4 = point_coords_res4 = None
115
116 ################################################################################################################

Callers

nothing calls this directly

Calls 2

norm_normalizeFunction · 0.90
sample_pointsFunction · 0.90

Tested by

no test coverage detected