MCPcopy Create free account
hub / github.com/apchenstu/mvsnerf / forward

Method forward

models.py:895–932  ·  view source on GitHub ↗
(self, imgs, proj_mats, near_far, pad=0,  return_color=False, lindisp=False)

Source from the content-addressed store, hash-verified

893 return img_feat, in_masks
894
895 def forward(self, imgs, proj_mats, near_far, pad=0, return_color=False, lindisp=False):
896 # imgs: (B, V, 3, H, W)
897 # proj_mats: (B, V, 3, 4) from fine to coarse
898 # init_depth_min, depth_interval: (B) or float
899 # near_far (B, V, 2)
900
901 B, V, _, H, W = imgs.shape
902
903 imgs = imgs.reshape(B * V, 3, H, W)
904 feats = self.feature(imgs) # (B*V, 8, H, W), (B*V, 16, H//2, W//2), (B*V, 32, H//4, W//4)
905
906 imgs = imgs.view(B, V, 3, H, W)
907
908
909 feats_l = feats # (B*V, C, h, w)
910
911 feats_l = feats_l.view(B, V, *feats_l.shape[1:]) # (B, V, C, h, w)
912
913
914 D = 128
915 t_vals = torch.linspace(0., 1., steps=D, device=imgs.device, dtype=imgs.dtype) # (B, D)
916 near, far = near_far # assume batch size==1
917 if not lindisp:
918 depth_values = near * (1.-t_vals) + far * (t_vals)
919 else:
920 depth_values = 1. / (1. / near * (1. - t_vals) + 1. / far * (t_vals))
921
922 depth_values = depth_values.unsqueeze(0)
923 # volume_feat, in_masks = self.build_volume_costvar(feats_l, proj_mats, depth_values, pad=pad)
924 volume_feat, in_masks = self.build_volume_costvar_img(imgs, feats_l, proj_mats, depth_values, pad=pad)
925 if return_color:
926 feats_l = torch.cat((volume_feat[:,:V*3].view(B, V, 3, *volume_feat.shape[2:]),in_masks.unsqueeze(2)),dim=2)
927
928
929 volume_feat = self.cost_reg_2(volume_feat) # (B, 1, D, h, w)
930 volume_feat = volume_feat.reshape(1,-1,*volume_feat.shape[2:])
931
932 return volume_feat, feats_l, depth_values
933
934
935class RefVolume(nn.Module):

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected