MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / prepare_batch_render

Function prepare_batch_render

script/feature/direct_feature_matching.py:144–176  ·  view source on GitHub ↗

Break batch of images into rays

(args, pose, batch_size, target_, H, W, focal, half_res=True, rand=True)

Source from the content-addressed store, hash-verified

142 return pose_loss
143
144def prepare_batch_render(args, pose, batch_size, target_, H, W, focal, half_res=True, rand=True):
145 ''' Break batch of images into rays '''
146 target_ = target_.permute(0, 2, 3, 1).numpy() # convert to numpy image
147 if half_res:
148 N_rand = batch_size * (H//2) * (W//2)
149 target_half = np.stack([cv2.resize(target_[i], (H//2, W//2), interpolation=cv2.INTER_AREA) for i in range(batch_size)], 0)
150 target_half = torch.Tensor(target_half)
151
152 rays = torch.stack([torch.stack(get_rays(H//2, W//2, focal/2, pose[i]), 0) for i in range(batch_size)], 0) # [N, ro+rd, H, W, 3] (130, 2, 100, 100, 3)
153 rays_rgb = torch.cat((rays, target_half[:, None, ...]), 1)
154
155 else:
156 # N_rand = batch_size * H * W
157 N_rand = args.N_rand
158 target_ = torch.Tensor(target_)
159 rays = torch.stack([torch.stack(get_rays(H, W, focal, pose[i]), 0) for i in range(batch_size)], 0) # [N, ro+rd, H, W, 3] (130, 2, 200, 200, 3)
160 # [N, ro+rd+rgb, H, W, 3]
161 rays_rgb = torch.cat([rays, target_[:, None, ...]], 1)
162
163 # [N, H, W, ro+rd+rgb, 3]
164 rays_rgb = rays_rgb.permute(0, 2, 3, 1, 4)
165
166 # [(N-1)*H*W, ro+rd+rgb, 3]
167 rays_rgb = torch.reshape(rays_rgb, (-1, 3, 3))
168
169 if 1:
170 rays_rgb = rays_rgb[torch.randperm(rays_rgb.shape[0])]
171
172 # Random over all images
173 batch = rays_rgb[:N_rand].permute(1, 0 , 2) # [B, 2+1, 3*?] # (4096, 3, 3)
174 batch_rays, target_s = batch[:2], batch[2] # [2, 4096, 3], [4096, 3]
175
176 return batch_rays, target_s
177
178def eval_on_batch(args, data, model, feat_model, pose, img_idx, hwf, half_res, device, world_setup_dict, **render_kwargs_test):
179 ''' Perform 1 step of eval'''

Callers 1

eval_on_batchFunction · 0.70

Calls 1

get_raysFunction · 0.90

Tested by

no test coverage detected