def get_conditional_volume(self, feature_maps, partial_vol_origin, proj_mats, sizeH=None, sizeW=None, lod=0,
                               pre_coords=None, pre_feats=None,
                               ):
        """

        :param feature_maps: pyramid features (B,V,C0+C1+C2,H,W) fused pyramid features
        :param partial_vol_origin: [B, 3]  the world coordinates of the volume origin (0,0,0)
        :param proj_mats: projection matrix transform world pts into image space [B,V,4,4] suitable for original image size
        :param sizeH: the H of original image size
        :param sizeW: the W of original image size
        :param pre_coords: the coordinates of sparse volume from the prior lod
        :param pre_feats: the features of sparse volume from the prior lod
        :return:
        """
        device = proj_mats.device
        bs = feature_maps.shape[0]
        N_views = feature_maps.shape[1]
        minimum_visible_views = np.min([1, N_views - 1])
        # import ipdb; ipdb.set_trace()
        outputs = {}
        pts_samples = []

        # ----coarse to fine----

        # * use fused pyramid feature maps are very important
        if self.compress_layer is not None:
            feats = self.compress_layer(feature_maps[0])
        else:
            feats = feature_maps[0]
        feats = feats[:, None, :, :, :]  # [V, B, C, H, W]
        KRcam = proj_mats.permute(1, 0, 2, 3).contiguous()  # [V, B, 4, 4]
        interval = 1

        if self.lod == 0:
            # ----generate new coords----
            coords = generate_grid(self.vol_dims, 1)[0]
            coords = coords.view(3, -1).to(device)  # [3, num_pts]
            up_coords = []
            for b in range(bs):
                up_coords.append(torch.cat([torch.ones(1, coords.shape[-1]).to(coords.device) * b, coords]))
            up_coords = torch.cat(up_coords, dim=1).permute(1, 0).contiguous()
            # * since we only estimate the geometry of input reference image at one time;
            # * mask the outside of the camera frustum
            # import ipdb; ipdb.set_trace()
            frustum_mask = back_project_sparse_type(
                up_coords, partial_vol_origin, self.voxel_size,
                feats, KRcam, sizeH=sizeH, sizeW=sizeW, only_mask=True)  # [num_pts, n_views]
            frustum_mask = torch.sum(frustum_mask, dim=-1) > minimum_visible_views  # ! here should be large
            up_coords = up_coords[frustum_mask]  # [num_pts_valid, 4]

        else:
            # ----upsample coords----
            assert pre_feats is not None
            assert pre_coords is not None
            up_feat, up_coords = self.upsample(pre_feats, pre_coords, 1)

        # ----back project----
        # give each valid 3d grid point all valid 2D features and masks
        multiview_features, multiview_masks = back_project_sparse_type(
            up_coords, partial_vol_origin, self.voxel_size, feats,
            KRcam, sizeH=sizeH, sizeW=sizeW)  # (num of voxels, num_of_views, c), (num of voxels, num_of_views)
                                              # num_of_views = all views
        
        # if multiview_features.isnan().sum() > 0:
        #     import ipdb; ipdb.set_trace()

        # import ipdb; ipdb.set_trace()
        if self.lod > 0:
            # ! need another invalid voxels filtering
            frustum_mask = torch.sum(multiview_masks, dim=-1) > 1
            up_feat = up_feat[frustum_mask]
            up_coords = up_coords[frustum_mask]
            multiview_features = multiview_features[frustum_mask]
            multiview_masks = multiview_masks[frustum_mask]
        # if multiview_features.isnan().sum() > 0:
        #     import ipdb; ipdb.set_trace()
        volume = self.aggregate_multiview_features(multiview_features, multiview_masks) # compute variance for all images features
        # import ipdb; ipdb.set_trace()

        # if volume.isnan().sum() > 0:
        #     import ipdb; ipdb.set_trace()

        del multiview_features, multiview_masks

        # ----concat feature from last stage----
        if self.lod != 0:
            feat = torch.cat([volume, up_feat], dim=1)
        else:
            feat = volume

        # batch index is in the last position
        r_coords = up_coords[:, [1, 2, 3, 0]]

        # if feat.isnan().sum() > 0:
        #     print('feat has nan:', feat.isnan().sum())
        #     import ipdb; ipdb.set_trace()

        sparse_feat = SparseTensor(feat, r_coords.to(
            torch.int32))  # - directly use sparse tensor to avoid point2voxel operations
        # import ipdb; ipdb.set_trace()
        feat = self.sparse_costreg_net(sparse_feat)

        dense_volume, valid_mask_volume = self.sparse_to_dense_volume(up_coords[:, 1:], feat, self.vol_dims, interval,
                                                                      device=None)  # [1, C/1, X, Y, Z]

        # if dense_volume.isnan().sum() > 0:
        #     import ipdb; ipdb.set_trace()


        outputs['dense_volume_scale%d' % self.lod] = dense_volume # [1, 16, 96, 96, 96]
        outputs['valid_mask_volume_scale%d' % self.lod] = valid_mask_volume # [1, 1, 96, 96, 96]
        outputs['visible_mask_scale%d' % self.lod] = valid_mask_volume # [1, 1, 96, 96, 96]
        outputs['coords_scale%d' % self.lod] = generate_grid(self.vol_dims, interval).to(device)
        # import ipdb; ipdb.set_trace()
        return outputs


        :param feature_maps: pyramid features (B,V,C0+C1+C2,H,W) fused pyramid features
        :param partial_vol_origin: [B, 3]  the world coordinates of the volume origin (0,0,0)
        :param proj_mats: projection matrix transform world pts into image space [B,V,4,4] suitable for original image size
        :param sizeH: the H of original image size
        :param sizeW: the W of original image size
        :param pre_coords: the coordinates of sparse volume from the prior lod
        :param pre_feats: the features of sparse volume from the prior lod
        :return:
        
mv-diffusion/One-2-3-45/reconstruction/models/sparse_sdf_network.py