Drexubery commited on
Commit
b2bdc68
1 Parent(s): 7cbba90
Files changed (1) hide show
  1. viewcrafter.py +12 -5
viewcrafter.py CHANGED
@@ -72,10 +72,14 @@ class ViewCrafter:
72
  view_masks = renderer(point_cloud_mask)
73
  return images, view_masks
74
 
75
- def run_render(self, pcd, imgs,masks, H, W, camera_traj,num_views):
 
 
 
 
76
  render_setup = setup_renderer(camera_traj, image_size=(H,W))
77
  renderer = render_setup['renderer']
78
- render_results, viewmask = self.render_pcd(pcd, imgs, masks, num_views,renderer,self.device)
79
  return render_results, viewmask
80
 
81
 
@@ -119,7 +123,7 @@ class ViewCrafter:
119
  ## FIXME hard coded candidate view数量, 以left为例,第一次迭代从[左,左上]中选取, 从第二次开始可以从[左,左上,左下]中选取
120
  num_candidates = 2
121
  candidate_poses,thetas,phis = generate_candidate_poses(c2ws, H, W, focals, principal_points, self.opts.d_theta[0], self.opts.d_phi[0],num_candidates, self.device)
122
- _, viewmask = self.run_render([pcd[-1]], [imgs[-1]],masks, H, W, candidate_poses,num_candidates)
123
  nbv_id = torch.argmin(viewmask.sum(dim=[1,2,3])).item()
124
  save_image( viewmask.permute(0,3,1,2), os.path.join(self.opts.save_dir,f"candidate_mask0_nbv{nbv_id}.png"), normalize=True, value_range=(0, 1))
125
  theta_nbv = thetas[nbv_id]
@@ -139,11 +143,14 @@ class ViewCrafter:
139
  r = [float(i) for i in lines[2].split()]
140
  else:
141
  phi, theta, r = self.gradio_traj
142
- camera_traj,num_views = generate_traj_txt(c2ws, H, W, focals, principal_points, phi, theta, r,self.opts.video_length, self.device,viz_traj=True, save_dir = self.opts.save_dir)
 
 
143
  else:
144
  raise KeyError(f"Invalid Mode: {self.opts.mode}")
145
 
146
- render_results, viewmask = self.run_render([pcd[-1]], [imgs[-1]],masks, H, W, camera_traj,num_views)
 
147
  render_results = F.interpolate(render_results.permute(0,3,1,2), size=(576, 1024), mode='bilinear', align_corners=False).permute(0,2,3,1)
148
  render_results[0] = self.img_ori
149
  if self.opts.mode == 'single_view_txt':
 
72
  view_masks = renderer(point_cloud_mask)
73
  return images, view_masks
74
 
75
+ def run_render(self, pcd, imgs,masks, H, W, camera_traj,num_views,use_cpu=False):
76
+ if use_cpu:
77
+ device = torch.device("cpu")
78
+ else:
79
+ device = self.device
80
  render_setup = setup_renderer(camera_traj, image_size=(H,W))
81
  renderer = render_setup['renderer']
82
+ render_results, viewmask = self.render_pcd(pcd, imgs, masks, num_views,renderer,device)
83
  return render_results, viewmask
84
 
85
 
 
123
  ## FIXME hard coded candidate view数量, 以left为例,第一次迭代从[左,左上]中选取, 从第二次开始可以从[左,左上,左下]中选取
124
  num_candidates = 2
125
  candidate_poses,thetas,phis = generate_candidate_poses(c2ws, H, W, focals, principal_points, self.opts.d_theta[0], self.opts.d_phi[0],num_candidates, self.device)
126
+ _, viewmask = self.run_render([pcd[-1]], [imgs[-1]],masks, H, W, candidate_poses,num_candidates,use_cpu=True)
127
  nbv_id = torch.argmin(viewmask.sum(dim=[1,2,3])).item()
128
  save_image( viewmask.permute(0,3,1,2), os.path.join(self.opts.save_dir,f"candidate_mask0_nbv{nbv_id}.png"), normalize=True, value_range=(0, 1))
129
  theta_nbv = thetas[nbv_id]
 
143
  r = [float(i) for i in lines[2].split()]
144
  else:
145
  phi, theta, r = self.gradio_traj
146
+ device = torch.device("cpu")
147
+ camera_traj,num_views = generate_traj_txt(c2ws, H, W, focals, principal_points, phi, theta, r,self.opts.video_length, device,viz_traj=True, save_dir = self.opts.save_dir)
148
+ # camera_traj,num_views = generate_traj_txt(c2ws, H, W, focals, principal_points, phi, theta, r,self.opts.video_length, self.device,viz_traj=True, save_dir = self.opts.save_dir)
149
  else:
150
  raise KeyError(f"Invalid Mode: {self.opts.mode}")
151
 
152
+ render_results, viewmask = self.run_render([pcd[-1]], [imgs[-1]],masks, H, W, camera_traj,num_views,use_cpu=True)
153
+ render_results = render_results.to(self.device)
154
  render_results = F.interpolate(render_results.permute(0,3,1,2), size=(576, 1024), mode='bilinear', align_corners=False).permute(0,2,3,1)
155
  render_results[0] = self.img_ori
156
  if self.opts.mode == 'single_view_txt':