(self, pl_module, batch, batch_idx, split="train")
| 542 | Image.fromarray(grid).save(path) |
| 543 | |
| 544 | def log_img(self, pl_module, batch, batch_idx, split="train"): |
| 545 | check_idx = batch_idx if self.log_on_batch_idx else pl_module.global_step |
| 546 | if (self.check_frequency(check_idx) and # batch_idx % self.batch_freq == 0 |
| 547 | hasattr(pl_module, "log_images") and |
| 548 | callable(pl_module.log_images) and |
| 549 | self.max_images > 0): |
| 550 | logger = type(pl_module.logger) |
| 551 | |
| 552 | is_train = pl_module.training |
| 553 | if is_train: |
| 554 | pl_module.eval() |
| 555 | |
| 556 | with torch.no_grad(): |
| 557 | images = pl_module.log_images(batch, split=split, **self.log_images_kwargs) |
| 558 | |
| 559 | for k in images: |
| 560 | N = min(images[k].shape[0], self.max_images) |
| 561 | images[k] = images[k][:N] |
| 562 | if isinstance(images[k], torch.Tensor): |
| 563 | images[k] = images[k].detach().cpu() |
| 564 | if self.clamp: |
| 565 | images[k] = torch.clamp(images[k], -1., 1.) |
| 566 | |
| 567 | self.log_local(pl_module.logger.save_dir, split, images, |
| 568 | pl_module.global_step, pl_module.current_epoch, batch_idx) |
| 569 | |
| 570 | logger_log_images = self.logger_log_images.get(logger, lambda *args, **kwargs: None) |
| 571 | logger_log_images(pl_module, images, pl_module.global_step, split) |
| 572 | |
| 573 | if is_train: |
| 574 | pl_module.train() |
| 575 | |
| 576 | def check_frequency(self, check_idx): |
| 577 | if ((check_idx % self.batch_freq) == 0 or (check_idx in self.log_steps)) and ( |
no test coverage detected