wound_segmentation.model module
Model architecture and loader for binary wound segmentation using U-Net with EfficientNetB3 encoder.
This module defines the core deep learning architecture for semantic segmentation. It includes:
A function to construct a U-Net-style model using EfficientNetB3 as the encoder.
A loader function that optionally loads pretrained weights into the model.
Functions
segmentation_model : This builds the segmentation model with skip connections and transposed convolutions.
load_segmentation_model : This loads the model with optional pretrained weights for inference or fine-tuning.
Typical use
This is used both for training and inference stages. The architecture is designed for detecting wound areas in RGB images, and the loader supports loading '.weights.h5' weights files for quick deployment.
- wound_segmentation.model.segmentation_model(input_shape: tuple = (512, 512, 3)) tensorflow.keras.Model
Build a U-Net style binary segmentation model with EfficientNetB3 as the encoder.
This function builds a deep convolutional neural network model for semantic segmentation of images. The encoder is constructed using EfficientNetB3 model (without the top classification layer and without ImageNet pretrained weights) while the decoder block uses transpose convolutions and skip connections to upsample the feature maps.
- Parameters:
input_shape (tuple) -- Dimensions of the input RGB image, default (512, 512, 3)
- Returns:
A Keras model that maps input RGB images to binary masks with values in [0, 1] using sigmoid activation.
- Return type:
tf.keras.Model
- Raises:
ValueError -- If the input shape has fewer than 3 dimensions
Examples
>>> model = segmentation_model(input_shape=(512, 512, 3)) >>> model.summary()
- wound_segmentation.model.load_segmentation_model(weights_path: str = None) tensorflow.keras.Model
This function loads the binary segmentation model and apply the pre-trained weights.
- Parameters:
weights_path (str) -- Path to the pretrained model weights file. If None, the model is returned without pretrained weights.
- Returns:
The segmentation model with weights loaded if path is provided.
- Return type:
tf.keras.Model
- Raises:
ValueError -- If the weights do not match the architecture or the file is corrupted.
Examples
>>> model = load_segmentation_model("models/segmentation_model_finetuned.keras") >>> pred_mask = model.predict(np.expand_dims(image, axis=0))