MCPcopy Create free account
hub / github.com/DIVE128/DMVSNet / forward

Method forward

networks/mvsnet.py:188–260  ·  view source on GitHub ↗

:param is_flip: augment only for 3D-UNet :param imgs: (b, nview, c, h, w) :param proj_matrices: :param depth_values: :return:

(self, imgs, proj_matrices, depth_values)

Source from the content-addressed store, hash-verified

186 self.DepthNet = DepthNet(depth_mode)
187
188 def forward(self, imgs, proj_matrices, depth_values):
189 """
190 :param is_flip: augment only for 3D-UNet
191 :param imgs: (b, nview, c, h, w)
192 :param proj_matrices:
193 :param depth_values:
194 :return:
195 """
196 depth_interval = (depth_values[0, -1] - depth_values[0, 0]) / depth_values.size(1)
197
198 # step 1. feature extraction
199 features = []
200 for nview_idx in range(imgs.size(1)): # imgs shape (B, N, C, H, W)
201 img = imgs[:, nview_idx]
202 features.append(self.feature(img))
203
204 ori_shape = imgs[:, 0].shape[2:] # (H, W)
205
206 outputs = {}
207 last_depth = None
208 for stage_idx in range(self.num_stage):
209 # print("*********************stage{}*********************".format(stage_idx + 1))
210 # stage feature, proj_mats, scales
211 features_stage = [feat["stage{}".format(stage_idx + 1)] for feat in features]
212 proj_matrices_stage = proj_matrices["stage{}".format(stage_idx + 1)]
213 # stage1: 1/4, stage2: 1/2, stage3: 1
214 stage_scale = 2 ** (3 - stage_idx - 1)
215
216 stage_shape = [ori_shape[0] // int(stage_scale), ori_shape[1] // int(stage_scale)]
217
218 if stage_idx == 0:
219 last_depth = depth_values
220 else:
221 last_depth = last_depth.detach()
222
223 # (B, D, H, W)
224 depth_range_samples, interval = get_depth_range_samples(last_depth=last_depth,
225 ndepth=self.ndepths[stage_idx],
226 depth_inteval_pixel=self.depth_interval_ratio[
227 stage_idx] * depth_interval,
228 shape=stage_shape, # only for first stage
229 inverse=self.inverse_depth
230 )
231
232 if stage_idx > 0:
233 depth_range_samples = F.interpolate(depth_range_samples, stage_shape, mode='bilinear', align_corners=Align_Corners_Range)
234
235 # (b, c, d, h, w)
236 cost_volume = self.cost_aggregation(features_stage, proj_matrices_stage, depth_range_samples, stage_idx)
237 # cost volume regularization
238 # (b, 1, d, h, w)
239 cost_reg = self.cost_regularization[stage_idx](cost_volume)
240
241 # depth
242 outputs_stage = self.DepthNet(cost_reg, depth_range_samples, num_depth=self.ndepths[stage_idx], interval=interval,stage=stage_idx)
243
244
245

Callers

nothing calls this directly

Calls 3

get_depth_range_samplesFunction · 0.85
refineMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected