MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / prepare_batch_render

Function prepare_batch_render

script/dm/direct_pose_model.py:112–145  ·  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

110 return model
111
112def prepare_batch_render(args, pose, batch_size, target_, H, W, focal, half_res=True, rand=True):
113 ''' Break batch of images into rays '''
114 target_ = target_.permute(0, 2, 3, 1).numpy()#.squeeze(0) # convert to numpy image
115 if half_res:
116 N_rand = batch_size * (H//2) * (W//2)
117 target_half = np.stack([cv2.resize(target_[i], (H//2, W//2), interpolation=cv2.INTER_AREA) for i in range(batch_size)], 0)
118 target_half = torch.Tensor(target_half)
119
120 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)
121 rays_rgb = torch.cat((rays, target_half[:, None, ...]), 1)
122
123 else:
124 # N_rand = batch_size * H * W
125 N_rand = args.N_rand
126 target_ = torch.Tensor(target_)
127 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)
128 # [N, ro+rd+rgb, H, W, 3]
129 rays_rgb = torch.cat([rays, target_[:, None, ...]], 1)
130
131 # [N, H, W, ro+rd+rgb, 3]
132 rays_rgb = rays_rgb.permute(0, 2, 3, 1, 4)
133
134 # [(N-1)*H*W, ro+rd+rgb, 3]
135 rays_rgb = torch.reshape(rays_rgb, (-1, 3, 3))
136
137 if 1:
138 #print('shuffle rays')
139 rays_rgb = rays_rgb[torch.randperm(rays_rgb.shape[0])]
140
141 # Random over all images
142 batch = rays_rgb[:N_rand].permute(1, 0 , 2) # [B, 2+1, 3*?] # (4096, 3, 3)
143 batch_rays, target_s = batch[:2], batch[2] # [2, 4096, 3], [4096, 3]
144
145 return batch_rays, target_s
146
147def fix_coord_supp(args, pose, world_setup_dict, device=None):
148 # this function needs to be fixed because it is taking args.pose_scale

Callers 2

eval_on_batchFunction · 0.70
train_on_batchFunction · 0.70

Calls 1

get_raysFunction · 0.90

Tested by

no test coverage detected