Skip to content

Inference & deployment

Once your generator is trained, GAN-Engine offers several pathways to apply it—from research notebooks to clinical pipelines and large-scale tiling services. This guide covers the built-in inference CLI, programmatic usage, and export options.

Command-line inference

python -m gan_engine.inference \
  --config gan_engine/configs/config_MRI.yaml \

Key flags, defined in config:

  • devices – Force CPU or select specific GPUs.
  • batch-size – Override the batch size for inference.

The CLI loads the config, applies normalisation, performs tiling if required, and writes denormalised outputs to the destination folder.

Programmatic usage

from gan_engine.model.SRGAN import SRGAN_model
from omegaconf import OmegaConf

cfg = OmegaConf.load("gan_engine/configs/config_MRI.yaml")
module = SRGAN_model(config=cfg, mode="eval")
module = module.load_from_checkpoint("runs/mri_x4/checkpoints/ema.ckpt")
module.eval()

sr = module.predict_step(lr_batch, batch_idx=0)  # Accepts NCHW/NCDHW tensors

Reuse the normalisation utilities from gan_engine.utils.radiometrics (or your own dataset transforms) to apply the same scaling logic to new inputs and restore outputs to their original range. Upcoming releases will add dedicated wrappers for inpainting masks and text-to-image samplers.

Batch deployment

For production workloads:

  • Lightning inference loops – Wrap the module in a Lightning Trainer with trainer.predict for distributed or batched inference.

Quality assurance

  • EMA vs. raw weights – EMA checkpoints often produce cleaner results. Switch between them when evaluating.
  • Domain shifts – When applying a model to new scanners/sensors, re-compute normalisation stats and consider fine-tuning with a few samples.
  • Perceptual validation – Use the validation scripts to compute LPIPS, SSIM, or domain-specific metrics on held-out data.

With these tools, you can transition from research experiments to dependable services spanning super-resolution, inpainting, conditional synthesis, and text-to-image pipelines across healthcare, geospatial, microscopy, and creative applications.