src.image_processing module

Image preprocessing and transformation utilities.

Provides functions and classes for resizing, normalizing, and transforming images into tensors suitable for neural network inference.

class src.image_processing.ConditionalNormalize(mean, std)[source]

Bases: object

Normalize image tensor, handling greyscale by replicating channels.

Converts single-channel (greyscale) images to 3-channel by replicating the channel, then applies standard ImageNet normalization.

src.image_processing.save_images_from_iteration(directory_path: str, images: Sequence[PIL.Image.Image], run_id: str, iteration: int) None[source]

Save images from an iteration to disk in JPEG format.

Parameters:
  • directory_path – Directory path to save images to.

  • images – Sequence of PIL Image objects to save.

  • run_id – Unique run identifier to include in filenames.

  • iteration – Iteration number to include in filenames.

src.image_processing.transform_images(images: Sequence[PIL.Image.Image]) torch.Tensor[source]

Transform images into a batch tensor for model inference.

Applies standard preprocessing: resizing to 224x224, center cropping, conversion to tensor, and normalization. Returns a batched tensor.

Parameters:

images – Sequence of PIL Image objects to transform.

Returns:

Batched tensor of shape (N, 3, 224, 224) ready for inference.

Raises:

ValueError – If images sequence is None or empty.