wound_segmentation.predict module
Model inference utilities for generating segmentation masks from input images.
This module provides functions for running a trained segmentation model on a single input image. It includes functionality to load the image, apply the same preprocessing used during training, run inference, and convert the output into a binary mask.
Functions
predict_mask : This applies preprocessing, runs model prediction, and returns both the preprocessed image and the predicted mask.
Typical use
This is used during evaluation or inference time when applying the trained model to new wound images for mask prediction. It handles file loading, normalization, and shape adjustments to ensure compatibility with the model input.
- wound_segmentation.predict.predict_mask(model: tensorflow.keras.Model, image_path: str, threshold: float = 0.5) tuple[numpy.ndarray, numpy.ndarray]
Predict a binary mask from an input image using the given segmentation model.
This function loads an image, applies the preprocessing steps used during training (resize, center-crop, normalize), runs the model prediction, and thresholds the result to produce a binary mask.
- Parameters:
model (tf.keras.Model) -- The loaded segmentation model.
image_path (str) -- Path to the input image file.
threshold (float, optional) -- Threshold applied to the model's output to binarize the mask. Default is 0.5.
- Returns:
image (np.ndarray) -- Preprocessed RGB image.
mask (np.ndarray) -- Binary mask with values {0, 1}.
- Raises:
FileNotFoundError -- If the input image cannot be read from the provided path.
Examples
>>> model = load_segmentation_model("weights_path") >>> image, mask = predict_mask(model, "image.jpg", threshold=0.6)