NucleusInstanceSegmentor¶

class NucleusInstanceSegmentor(batch_size=8, num_loader_workers=0, num_postproc_workers=0, model=None, pretrained_model=None, pretrained_weights=None, dataset_class=<class 'tiatoolbox.models.engine.semantic_segmentor.WSIStreamDataset'>, *, verbose=True, auto_generate_mask=False)[source]¶

An engine specifically designed to handle tiles or WSIs inference.

Note, if model is supplied in the arguments, it will ignore the pretrained_model and pretrained_weights arguments. Additionally, unlike SemanticSegmentor, this engine assumes each input model will ultimately predict one single target: the nucleus instance within the tiles/WSIs. Each WSI prediction will be store under a .dat file which contains a dictionary of form:

inst_uid:
    # top left and bottom right of bounding box
    box: (start_x, start_y, end_x, end_y)
    # centroid coordinates
    centroid: (x, y)
    # array/list of points
    contour: [(x1, y1), (x2, y2), ...]
    # the type of nuclei
    type: int
    # the probabilities of being this nuclei type
    prob: float
Parameters:
  • model (nn.Module) – Use externally defined PyTorch model for prediction with. weights already loaded. Default is None. If provided, pretrained_model argument is ignored.

  • pretrained_model (str) – Name of the existing models support by tiatoolbox for processing the data. For a full list of pretrained models, refer to the docs. By default, the corresponding pretrained weights will also be downloaded. However, you can override with your own set of weights via the pretrained_weights argument. Argument is case insensitive.

  • pretrained_weights (str) – Path to the weight of the corresponding pretrained_model.

  • batch_size (int) – Number of images fed into the model each time.

  • num_loader_workers (int) – Number of workers to load the data. Take note that they will also perform preprocessing.

  • num_postproc_workers (int) – Number of workers to post-process predictions.

  • verbose (bool) – Whether to output logging information.

  • dataset_class (obj) – Dataset class to be used instead of default.

  • auto_generate_mask (bool) – To automatically generate tile/WSI tissue mask if is not provided.

Examples

>>> # Sample output of a network
>>> wsis = ['A/wsi.svs', 'B/wsi.svs']
>>> predictor = SemanticSegmentor(model='hovernet_fast-pannuke')
>>> output = predictor.predict(wsis, mode='wsi')
>>> list(output.keys())
[('A/wsi.svs', 'output/0') , ('B/wsi.svs', 'output/1')]
>>> # Each output of 'A/wsi.svs'
>>> # will be respectively stored in 'output/0.dat', 'output/0.dat'

Initialize NucleusInstanceSegmentor.

Methods