| 12 | |
| 13 | |
| 14 | class MVRecon(pl.LightningModule): |
| 15 | def __init__( |
| 16 | self, |
| 17 | lrm_generator_config, |
| 18 | lrm_path=None, |
| 19 | input_size=256, |
| 20 | render_size=192, |
| 21 | ): |
| 22 | super(MVRecon, self).__init__() |
| 23 | |
| 24 | self.input_size = input_size |
| 25 | self.render_size = render_size |
| 26 | |
| 27 | # init modules |
| 28 | self.lrm_generator = instantiate_from_config(lrm_generator_config) |
| 29 | if lrm_path is not None: |
| 30 | lrm_ckpt = torch.load(lrm_path) |
| 31 | self.lrm_generator.load_state_dict(lrm_ckpt['weights'], strict=False) |
| 32 | |
| 33 | self.lpips = LearnedPerceptualImagePatchSimilarity(net_type='vgg') |
| 34 | |
| 35 | self.validation_step_outputs = [] |
| 36 | |
| 37 | def on_fit_start(self): |
| 38 | if self.global_rank == 0: |
| 39 | os.makedirs(os.path.join(self.logdir, 'images'), exist_ok=True) |
| 40 | os.makedirs(os.path.join(self.logdir, 'images_val'), exist_ok=True) |
| 41 | |
| 42 | def prepare_batch_data(self, batch): |
| 43 | lrm_generator_input = {} |
| 44 | render_gt = {} # for supervision |
| 45 | |
| 46 | # input images |
| 47 | images = batch['input_images'] |
| 48 | images = v2.functional.resize( |
| 49 | images, self.input_size, interpolation=3, antialias=True).clamp(0, 1) |
| 50 | |
| 51 | lrm_generator_input['images'] = images.to(self.device) |
| 52 | |
| 53 | # input cameras and render cameras |
| 54 | input_c2ws = batch['input_c2ws'].flatten(-2) |
| 55 | input_Ks = batch['input_Ks'].flatten(-2) |
| 56 | target_c2ws = batch['target_c2ws'].flatten(-2) |
| 57 | target_Ks = batch['target_Ks'].flatten(-2) |
| 58 | render_cameras_input = torch.cat([input_c2ws, input_Ks], dim=-1) |
| 59 | render_cameras_target = torch.cat([target_c2ws, target_Ks], dim=-1) |
| 60 | render_cameras = torch.cat([render_cameras_input, render_cameras_target], dim=1) |
| 61 | |
| 62 | input_extrinsics = input_c2ws[:, :, :12] |
| 63 | input_intrinsics = torch.stack([ |
| 64 | input_Ks[:, :, 0], input_Ks[:, :, 4], |
| 65 | input_Ks[:, :, 2], input_Ks[:, :, 5], |
| 66 | ], dim=-1) |
| 67 | cameras = torch.cat([input_extrinsics, input_intrinsics], dim=-1) |
| 68 | |
| 69 | # add noise to input cameras |
| 70 | cameras = cameras + torch.rand_like(cameras) * 0.04 - 0.02 |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected