MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __call__

Method __call__

monai/inferers/inferer.py:1211–1250  ·  view source on GitHub ↗

Implements the forward pass for a supervised training iteration. Args: inputs: input image to which the latent representation will be extracted and noise is added. autoencoder_model: first stage model. diffusion_model: diffusion model.

(  # type: ignore[override]
        self,
        inputs: torch.Tensor,
        autoencoder_model: AutoencoderKL | VQVAE,
        diffusion_model: DiffusionModelUNet,
        noise: torch.Tensor,
        timesteps: torch.Tensor,
        condition: torch.Tensor | None = None,
        mode: str = "crossattn",
        seg: torch.Tensor | None = None,
    )

Source from the content-addressed store, hash-verified

1209 self.autoencoder_resizer = CenterSpatialCrop(roi_size=self.autoencoder_latent_shape)
1210
1211 def __call__( # type: ignore[override]
1212 self,
1213 inputs: torch.Tensor,
1214 autoencoder_model: AutoencoderKL | VQVAE,
1215 diffusion_model: DiffusionModelUNet,
1216 noise: torch.Tensor,
1217 timesteps: torch.Tensor,
1218 condition: torch.Tensor | None = None,
1219 mode: str = "crossattn",
1220 seg: torch.Tensor | None = None,
1221 ) -> torch.Tensor:
1222 """
1223 Implements the forward pass for a supervised training iteration.
1224
1225 Args:
1226 inputs: input image to which the latent representation will be extracted and noise is added.
1227 autoencoder_model: first stage model.
1228 diffusion_model: diffusion model.
1229 noise: random noise, of the same shape as the latent representation.
1230 timesteps: random timesteps.
1231 condition: conditioning for network input.
1232 mode: Conditioning mode for the network.
1233 seg: if diffusion model is instance of SPADEDiffusionModel, segmentation must be provided.
1234 """
1235 with torch.no_grad():
1236 latent = autoencoder_model.encode_stage_2_inputs(inputs) * self.scale_factor
1237
1238 if self.ldm_latent_shape is not None:
1239 latent = torch.stack([self.ldm_resizer(i) for i in decollate_batch(latent)], 0)
1240
1241 prediction: torch.Tensor = super().__call__(
1242 inputs=latent,
1243 diffusion_model=diffusion_model,
1244 noise=noise,
1245 timesteps=timesteps,
1246 condition=condition,
1247 mode=mode,
1248 seg=seg,
1249 )
1250 return prediction
1251
1252 @torch.no_grad()
1253 def sample( # type: ignore[override]

Callers

nothing calls this directly

Calls 3

decollate_batchFunction · 0.90
encode_stage_2_inputsMethod · 0.45
__call__Method · 0.45

Tested by

no test coverage detected