(self, batch: dict, additional_log_kwargs: Optional[Dict] = None, **kwargs)
| 382 | |
| 383 | @torch.no_grad() |
| 384 | def log_images(self, batch: dict, additional_log_kwargs: Optional[Dict] = None, **kwargs) -> dict: |
| 385 | log = dict() |
| 386 | additional_decode_kwargs = {} |
| 387 | x = self.get_input(batch) |
| 388 | additional_decode_kwargs.update({key: batch[key] for key in self.additional_decode_keys.intersection(batch)}) |
| 389 | |
| 390 | _, xrec, _ = self(x, **additional_decode_kwargs) |
| 391 | log["inputs"] = x |
| 392 | log["reconstructions"] = xrec |
| 393 | diff = 0.5 * torch.abs(torch.clamp(xrec, -1.0, 1.0) - x) |
| 394 | diff.clamp_(0, 1.0) |
| 395 | log["diff"] = 2.0 * diff - 1.0 |
| 396 | # diff_boost shows location of small errors, by boosting their |
| 397 | # brightness. |
| 398 | log["diff_boost"] = 2.0 * torch.clamp(self.diff_boost_factor * diff, 0.0, 1.0) - 1 |
| 399 | if hasattr(self.loss, "log_images"): |
| 400 | log.update(self.loss.log_images(x, xrec)) |
| 401 | with self.ema_scope(): |
| 402 | _, xrec_ema, _ = self(x, **additional_decode_kwargs) |
| 403 | log["reconstructions_ema"] = xrec_ema |
| 404 | diff_ema = 0.5 * torch.abs(torch.clamp(xrec_ema, -1.0, 1.0) - x) |
| 405 | diff_ema.clamp_(0, 1.0) |
| 406 | log["diff_ema"] = 2.0 * diff_ema - 1.0 |
| 407 | log["diff_boost_ema"] = 2.0 * torch.clamp(self.diff_boost_factor * diff_ema, 0.0, 1.0) - 1 |
| 408 | if additional_log_kwargs: |
| 409 | additional_decode_kwargs.update(additional_log_kwargs) |
| 410 | _, xrec_add, _ = self(x, **additional_decode_kwargs) |
| 411 | log_str = "reconstructions-" + "-".join( |
| 412 | [f"{key}={additional_log_kwargs[key]}" for key in additional_log_kwargs] |
| 413 | ) |
| 414 | log[log_str] = xrec_add |
| 415 | return log |
| 416 | |
| 417 | |
| 418 | class AutoencodingEngineLegacy(AutoencodingEngine): |
no test coverage detected