(self, batch: dict, additional_log_kwargs: Optional[Dict] = None, **kwargs)
| 397 | |
| 398 | @torch.no_grad() |
| 399 | def log_images(self, batch: dict, additional_log_kwargs: Optional[Dict] = None, **kwargs) -> dict: |
| 400 | log = dict() |
| 401 | additional_decode_kwargs = {} |
| 402 | x = self.get_input(batch) |
| 403 | additional_decode_kwargs.update({key: batch[key] for key in self.additional_decode_keys.intersection(batch)}) |
| 404 | |
| 405 | _, xrec, _ = self(x, **additional_decode_kwargs) |
| 406 | log["inputs"] = x |
| 407 | log["reconstructions"] = xrec |
| 408 | diff = 0.5 * torch.abs(torch.clamp(xrec, -1.0, 1.0) - x) |
| 409 | diff.clamp_(0, 1.0) |
| 410 | log["diff"] = 2.0 * diff - 1.0 |
| 411 | # diff_boost shows location of small errors, by boosting their |
| 412 | # brightness. |
| 413 | log["diff_boost"] = 2.0 * torch.clamp(self.diff_boost_factor * diff, 0.0, 1.0) - 1 |
| 414 | if hasattr(self.loss, "log_images"): |
| 415 | log.update(self.loss.log_images(x, xrec)) |
| 416 | with self.ema_scope(): |
| 417 | _, xrec_ema, _ = self(x, **additional_decode_kwargs) |
| 418 | log["reconstructions_ema"] = xrec_ema |
| 419 | diff_ema = 0.5 * torch.abs(torch.clamp(xrec_ema, -1.0, 1.0) - x) |
| 420 | diff_ema.clamp_(0, 1.0) |
| 421 | log["diff_ema"] = 2.0 * diff_ema - 1.0 |
| 422 | log["diff_boost_ema"] = 2.0 * torch.clamp(self.diff_boost_factor * diff_ema, 0.0, 1.0) - 1 |
| 423 | if additional_log_kwargs: |
| 424 | additional_decode_kwargs.update(additional_log_kwargs) |
| 425 | _, xrec_add, _ = self(x, **additional_decode_kwargs) |
| 426 | log_str = "reconstructions-" + "-".join( |
| 427 | [f"{key}={additional_log_kwargs[key]}" for key in additional_log_kwargs] |
| 428 | ) |
| 429 | log[log_str] = xrec_add |
| 430 | return log |
| 431 | |
| 432 | |
| 433 | class AutoencodingEngineLegacy(AutoencodingEngine): |
no test coverage detected