MCPcopy Create free account
hub / github.com/ant-research/CoDeF / validation_step

Method validation_step

train.py:390–421  ·  view source on GitHub ↗
(self, batch, batch_idx)

Source from the content-addressed store, hash-verified

388 return loss
389
390 def validation_step(self, batch, batch_idx):
391 rgbs = batch['rgbs']
392 ts_w = batch['ts_w']
393 grid = batch['grid']
394 mk = batch['masks']
395 grid_c = grid # batch['grid_c']
396 self.seq_len = batch['seq_len']
397 ret = self(ts_w, grid, self.hparams.encode_w, self.global_step)
398 ret_c = self(ts_w, grid_c, False, self.global_step)
399
400 log = {}
401 W, H = self.hparams.img_wh
402
403 rgbs_flattend = rearrange(rgbs, 'b h w c -> (b h w) c')
404 img_gt = rgbs_flattend.view(H, W, 3).permute(2, 0, 1).cpu() # (3, H, W)
405 stack_list = [img_gt]
406 for i in range(self.num_models):
407 results = ret.rgbs[i]
408 results_c = ret_c.rgbs[i]
409 mk_t = rearrange(mk[i], 'b h w c -> (b h w) c')
410 if batch_idx == 0:
411 results[mk_t.sum(dim=-1) <= 0.05] = 0
412 img = results.view(H, W, 3).permute(2, 0, 1).cpu() # (3, H, W)
413 img_c = results_c.view(H, W, 3).permute(2, 0, 1).cpu() # (3, H, W)
414 stack_list.append(img)
415 stack_list.append(img_c)
416
417 stack = torch.stack(stack_list) # (3, 3, H, W)
418 self.logger.experiment.add_images('val/GT_Reconstructed', stack,
419 self.global_step)
420
421 return log
422
423 def test_step(self, batch, batch_idx):
424 ts_w = batch['ts_w']

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected