ReconViz#
- class stable_pretraining.callbacks.ReconViz(specs: Sequence[Tuple[str, str, str | None]], mode: str = 'grid', pixel_mean: Sequence[float] | Tensor | None = None, pixel_std: Sequence[float] | Tensor | None = None, n_items: int = 8, seq_len: int | None = None, fps: int = 2, verbose: bool = None)[source]#
Bases:
CallbackRender decoder reconstructions as
target | reconmedia each val epoch.Pairs one-to-one with
OnlineImageDecoder: point a spec at the decoder’snameand ReconViz reads itsf"{name}_preds"output, stitches each reconstruction next to its target, and logs the result.On
on_validation_batch_end(onlybatch_idx == 0) the firstNrows of predictions and their matching targets are cached (detached, float, CPU). Onon_validation_epoch_endthe cache is denormalised, clamped to[0, 1], stitched (target | separator | recon) and emitted, then cleared.- Parameters:
specs – List of
(preds_key_or_name, target_key, caption)tuples. The first element is resolved againstoutputs/batchby tryingf"{key}_preds"first (theOnlineImageDecoderconvention) thenkeyverbatim, so both"recon"and"recon_preds"work.captionmay beNone.mode –
"grid"(default) treats the cached rows as a plain(B, C, H, W)batch and logs a grid image vialog_image."video"treats them as a trajectory-contiguous flat layout (n_itemstrajectories ×seq_lentransitions) and logs an MP4 vialog_video.pixel_mean – Per-channel mean used at normalisation time, broadcastable to
(C, 1, 1)(a length-Csequence is accepted and reshaped). Reconstruction isx * pixel_std + pixel_mean. Must be given together withpixel_std; when both areNonedenorm is a no-op.pixel_std – Per-channel std used at normalisation time (see
pixel_mean).n_items –
"grid"— number of images shown."video"— number of trajectories (n_traj) shown side by side per frame.seq_len –
"video"only — transitions per trajectory. Required whenmode="video"; the flat layout is assumed to ben_items * seq_lencontiguous rows.fps –
"video"only — frames per second of the emitted MP4.verbose – Enable per-emit info logging.
Nonedefers to the global verbosity setting.
Example
Pair with
OnlineImageDecoderto log atarget | recongrid:dec = spt.callbacks.OnlineImageDecoder( module=module, name="recon", input="embedding", target="image", image_shape=(3, 64, 64), embed_dim=768, ) viz = spt.callbacks.ReconViz( [("recon", "image", "recon")], mode="grid", )
- on_validation_batch_end(trainer, pl_module, outputs, batch, batch_idx, dataloader_idx=0) None[source]#
Called when the validation batch ends.
- on_validation_epoch_end(trainer: Trainer, pl_module: LightningModule) None[source]#
Called when the val epoch ends.