Exemple #1
0
def sphere2vox(sphere, res=128):
    # Init
    sphere = sphere.astype(np.float32)
    grid = spherical_proj.gen_sph_grid(res)
    proj_spherical = SphericalBackProjection().apply
    # margin = 16
    batch_size = 1
    sph_np = sphere
    sph = torch.from_numpy(sph_np.copy())
    #
    # print(sph.shape)
    sph = sph.unsqueeze(0)
    sph = sph.unsqueeze(0).cuda()
    # print(sph.shape)
    grid = grid.expand(1, -1, -1, -1, -1)
    grid = grid[0, :, :, :, :]
    grid = grid.expand(batch_size, -1, -1, -1, -1).cuda()

    # crop_sph = sph[:, :, margin:h - margin, margin:w - margin]
    proj_df, cnt = proj_spherical(1 - sph, grid, res)
    mask = torch.clamp(cnt.detach(), 0, 1)
    proj_df = (-proj_df + 1 / res) * res
    proj_df = proj_df * mask
    # print(proj_df.shape)
    proj_df = proj_df.squeeze()
    proj_df = proj_df.squeeze()
    voxel = proj_df.cpu().numpy()
    plot_voxel(voxel)
 def __init__(self, opt, base_class):
     super().__init__()
     self.base_class = base_class
     self.depth_and_inpaint = Depth_inpaint_net(opt, base_class)
     self.refine_net = Unet_3D()
     self.proj_depth = Camera_back_projection_layer()
     self.joint_train = opt.joint_train
     self.register_buffer('grid', gen_sph_grid())
     self.grid = self.grid.expand(1, -1, -1, -1, -1)
     self.proj_spherical = SphericalBackProjection().apply
     self.margin = opt.padding_margin
     if opt.inpaint_path is not None:
         state_dicts = torch.load(opt.inpaint_path)
         self.depth_and_inpaint.load_state_dict(state_dicts['nets'][0])