NuClick¶

class NuClick(num_input_channels, num_output_channels)[source]¶

NuClick Architecture.

NuClick is used for interactive nuclei segmentation. NuClick takes an RGB image patch along with an inclusion and an exclusion map.

Parameters:
  • num_input_channels (int) – Number of channels in input.

  • num_output_channels (int) – Number of channels in output.

Returns:

a pytorch model.

Return type:

model (torch.nn.Module)

Examples

>>> # instantiate a NuClick model for interactive nucleus segmentation.
>>> NuClick(num_input_channels = 5, num_output_channels = 1)

Initialize NuClick.

Methods

forward

Logic for using layers defined in NuClick init.

infer_batch

Run inference on an input batch.

postproc

Post-processing.

Attributes

training

forward(imgs)[source]¶

Logic for using layers defined in NuClick init.

This method defines how layers are used in forward operation.

Parameters:
Returns:

The inference output.

Return type:

output (torch.Tensor)

static infer_batch(model, batch_data, *, on_gpu)[source]¶

Run inference on an input batch.

This contains logic for forward operation as well as batch i/o aggregation.

Parameters:
  • model (nn.Module) – PyTorch defined model.

  • batch_data (torch.Tensor) – a batch of data generated by torch.utils.data.DataLoader.

  • on_gpu (bool) – Whether to run inference on a GPU.

Returns:

(no.patch, h, w).

Return type:

Pixel-wise nuclei prediction for each patch, shape

static postproc(preds, thresh=0.33, min_size=10, min_hole_size=30, nuc_points=None, *, do_reconstruction=False)[source]¶

Post-processing.

Parameters:
  • preds (ndarray) – list of prediction output of each patch and assumed to be in the order of (no.patch, h, w) (match with the output of infer_batch).

  • thresh (float) – Threshold value. If a pixel has a predicted value larger than the threshold, it will be classified as nuclei.

  • min_size (int) – The smallest allowable object size.

  • min_hole_size (int) – The maximum area, in pixels, of a contiguous hole that will be filled.

  • do_reconstruction (bool) – Whether to perform a morphological reconstruction of an image.

  • nuc_points (ndarray) – In the order of (no.patch, h, w). In each patch, The pixel that has been ‘clicked’ is set to 1 and the rest pixels are set to 0.

Returns:

pixel-wise nuclei instance segmentation

prediction, shape:(no.patch, h, w).

Return type:

masks (ndarray)