MultiTaskSegmentor¶

class MultiTaskSegmentor(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'>, output_types=None, *, 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. Each WSI’s instance predictions (e.g. nuclear instances) will be store under a .dat file and the semantic segmentation predictions will be stored in a .npy file. The .dat files 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. Refer to [URL] for details. 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.

  • output_types (list) – Ordered list describing what sort of segmentation the output from the model postproc gives for a two-task model this may be: [‘instance’, ‘semantic’]

Examples

>>> # Sample output of a network
>>> wsis = ['A/wsi.svs', 'B/wsi.svs']
>>> predictor = MultiTaskSegmentor(
...     model='hovernetplus-oed',
...     output_type=['instance', 'semantic'],
... )
>>> 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.0.dat', 'output/0.1.npy'
>>> # Here, the second integer represents the task number
>>> # e.g. between 0 or 1 for a two task model

Initialize MultiTaskSegmentor.

Methods