EfficientUNetTissueMaskModel

class EfficientUNetTissueMaskModel(num_classes=1, threshold=0.95)[source]

EfficientNet-UNet Tissue Segmentation Model.

This model implements a UNet architecture with an EfficientNetB0 encoder for tissue segmentation in whole slide images (WSIs). The TIAToolbox pretrained model was trained on WSIs from TCGA. It is designed to identify tissue regions, excluding artifacts such as pen marks and air bubbles.

The model uses ImageNet normalization during preprocessing and applies morphological postprocessing to generate clean tissue masks.

encoder

EfficientNetB0 encoder for feature extraction.

Type:

EfficientNetEncoder

decoder

UNet decoder for upsampling and feature fusion.

Type:

UnetDecoder

segmentation_head

Final segmentation layer.

Type:

SegmentationHead

Example

>>> from tiatoolbox.models.engine.semantic_segmentor import SemanticSegmentor
>>> segmentor = SemanticSegmentor(model="efficientunet-tissue_mask")
>>> results = segmentor.run(
...     ["/example_wsi.svs"],
...     masks=None,
...     auto_get_mask=False,
...     patch_mode=False,
...     save_dir=Path("/tissue_mask/"),
...     output_type="annotationstore",
... )

Initialize EfficientUNetTissueMaskModel.

Sets up the UNet decoder, EfficientNet encoder, and segmentation head for tissue detection.

Parameters:
  • num_classes (int) – Number of output classes. Defaults to 1 (binary segmentation).

  • threshold (float) – Threshold for binary segmentation. Defaults to 0.95.

Methods

forward

Forward pass through the EfficientUNetTissueMaskModel model.

infer_batch

Run inference on a batch of images.

postproc

Postprocess model output to generate tissue mask.

preproc

Preprocess input image for inference.

Attributes

training

forward(x, *args, **kwargs)[source]

Forward pass through the EfficientUNetTissueMaskModel model.

Sequentially processes the input tensor through the encoder, decoder, and segmentation head to produce tissue segmentation predictions.

Parameters:
Returns:

(B, num_classes, H, W). Segmentation output tensor.

Return type:

torch.Tensor

static infer_batch(model, batch_data, *, device)[source]

Run inference on a batch of images.

Transfers the model and input batch to the specified device, performs forward pass, and returns sigmoid probabilities.

Parameters:
  • model (EfficientUNetTissueMaskModel) – EfficientUNetTissueMaskModel model instance.

  • batch_data (torch.Tensor) – Batch of input images in NHWC format.

  • device (str) – Device for inference (e.g., “cpu” or “cuda”).

Returns:

Inference results as a NumPy array of shape (N, H, W, C).

Return type:

np.ndarray

Example

>>> batch = torch.randn(4, 256, 256, 3)
>>> probs = EfficientUNetTissueMaskModel.infer_batch(
...     model, batch, device="cpu"
... )
>>> probs.shape
(4, 256, 256, 1)
postproc(image)[source]

Postprocess model output to generate tissue mask.

Applies thresholding and morphological operations to classify pixels as tissue or background and clean up the mask.

Parameters:
Returns:

Binary tissue mask where 1 = Tissue and 0 = Background.

Return type:

np.ndarray

Example

>>> model = EfficientUNetTissueMaskModel(num_classes=1, threshold=0.95)
>>> mask = model.postproc(probs)
>>> mask.shape
(256, 256)
static preproc(image)[source]

Preprocess input image for inference.

Applies ImageNet normalization to the input image.

Parameters:

image (np.ndarray) – Input image as a NumPy array of shape (H, W, C) in uint8 format.

Returns:

Preprocessed image normalized to ImageNet statistics.

Return type:

np.ndarray

Example

>>> img = np.random.randint(0, 255, (256, 256, 3), dtype=np.uint8)
>>> processed = EfficientUNetTissueMaskModel.preproc(img)
>>> processed.shape
(256, 256, 3)