MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / log_img

Method log_img

train.py:567–597  ·  view source on GitHub ↗
(self, pl_module, batch, batch_idx, split="train")

Source from the content-addressed store, hash-verified

565 Image.fromarray(grid).save(path)
566
567 def log_img(self, pl_module, batch, batch_idx, split="train"):
568 check_idx = batch_idx if self.log_on_batch_idx else pl_module.global_step
569 if (self.check_frequency(check_idx) and # batch_idx % self.batch_freq == 0
570 hasattr(pl_module, "log_images") and
571 callable(pl_module.log_images) and
572 self.max_images > 0):
573 logger = type(pl_module.logger)
574
575 is_train = pl_module.training
576 if is_train:
577 pl_module.eval()
578
579 with torch.no_grad():
580 images = pl_module.log_images(batch, split=split, **self.log_images_kwargs)
581
582 for k in images:
583 N = min(images[k].shape[0], self.max_images)
584 images[k] = images[k][:N]
585 if isinstance(images[k], torch.Tensor):
586 images[k] = images[k].detach().cpu()
587 if self.clamp:
588 images[k] = torch.clamp(images[k], -1., 1.)
589
590 self.log_local(pl_module.logger.save_dir, split, images,
591 pl_module.global_step, pl_module.current_epoch, batch_idx)
592
593 logger_log_images = self.logger_log_images.get(logger, lambda *args, **kwargs: None)
594 logger_log_images(pl_module, images, pl_module.global_step, split)
595
596 if is_train:
597 pl_module.train()
598
599 def check_frequency(self, check_idx):
600 if ((check_idx % self.batch_freq) == 0 or (check_idx in self.log_steps)) and (

Callers 1

on_train_batch_endMethod · 0.95

Calls 3

check_frequencyMethod · 0.95
log_localMethod · 0.95
log_imagesMethod · 0.80

Tested by

no test coverage detected