Skip to content

Commit 9f9a709

Browse files
committed
📝 Update run documentation
1 parent f97a55c commit 9f9a709

File tree

1 file changed

+28
-47
lines changed

1 file changed

+28
-47
lines changed

tiatoolbox/models/engine/semantic_segmentor.py

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -608,70 +608,51 @@ def save_predictions(
608608

609609
def run(
610610
self: SemanticSegmentor,
611-
images: list[os | Path | WSIReader] | np.ndarray,
612-
masks: list[os | Path] | np.ndarray | None = None,
611+
images: list[os.PathLike | Path | WSIReader] | np.ndarray,
612+
masks: list[os.PathLike | Path] | np.ndarray | None = None,
613613
labels: list | None = None,
614614
ioconfig: IOSegmentorConfig | None = None,
615615
*,
616616
patch_mode: bool = True,
617-
save_dir: os | Path | None = None, # None will not save output
617+
save_dir: os.PathLike | Path | None = None,
618618
overwrite: bool = False,
619619
output_type: str = "dict",
620620
**kwargs: Unpack[SemanticSegmentorRunParams],
621621
) -> AnnotationStore | Path | str | dict | list[Path]:
622-
"""Run the engine on input images.
622+
"""Run the semantic segmentation engine on input images.
623+
624+
This method orchestrates the full inference pipeline, including preprocessing,
625+
model inference, post-processing, and saving results.
626+
It supports both patch-level and whole slide image (WSI) modes.
623627
624628
Args:
625-
images (list, ndarray):
626-
List of inputs to process. When using `patch` mode, the
627-
input must be either a list of images, a list of image
628-
file paths or a numpy array of an image list.
629-
masks (list | None):
630-
List of masks. Only utilised when patch_mode is False.
631-
Patches are only generated within a masked area.
632-
If not provided, then a tissue mask will be automatically
633-
generated for whole slide images.
629+
images (list[PathLike | WSIReader] | np.ndarray):
630+
Input images or patches. Can be a list of file paths, WSIReader objects,
631+
or a NumPy array of image patches.
632+
masks (list[PathLike] | np.ndarray | None):
633+
Optional masks for WSI processing. Only used when `patch_mode` is False.
634634
labels (list | None):
635-
List of labels. Only a single label per image is supported.
635+
Optional labels for input images. Only one label per image is supported.
636+
ioconfig (IOSegmentorConfig | None):
637+
IO configuration for patch extraction and resolution.
636638
patch_mode (bool):
637-
Whether to treat input image as a patch or WSI.
638-
default = True.
639-
ioconfig (IOSegmentorConfig):
640-
IO configuration.
641-
save_dir (str or pathlib.Path):
642-
Output directory to save the results.
643-
If save_dir is not provided when patch_mode is False,
644-
then for a single image the output is created in the current directory.
645-
If there are multiple WSIs as input then the user must provide
646-
path to save directory otherwise an OSError will be raised.
639+
Whether to treat input as patches (`True`) or WSIs (`False`).
640+
Default is True.
641+
save_dir (PathLike | None):
642+
Directory to save output files. Required for WSI mode.
647643
overwrite (bool):
648-
Whether to overwrite the results. Default = False.
644+
Whether to overwrite existing output files. Default is False.
649645
output_type (str):
650-
The format of the output type. "output_type" can be
651-
"zarr" or "AnnotationStore". Default value is "zarr".
652-
When saving in the zarr format the output is saved using the
653-
`python zarr library <https://zarr.readthedocs.io/en/stable/>`__
654-
as a zarr group. If the required output type is an "AnnotationStore"
655-
then the output will be intermediately saved as zarr but converted
656-
to :class:`AnnotationStore` and saved as a `.db` file
657-
at the end of the loop.
646+
Desired output format: "dict", "zarr", or "annotationstore".
647+
Default is "dict".
658648
**kwargs (SemanticSegmentorRunParams):
659-
Keyword Args to update :class:`EngineABC` attributes during runtime.
649+
Additional runtime parameters to update engine attributes.
660650
661651
Returns:
662-
(:class:`numpy.ndarray`, dict, list):
663-
Model predictions of the input dataset. If multiple
664-
whole slide images are provided as input,
665-
or save_output is True, then results are saved to
666-
`save_dir` and a dictionary indicating save location for
667-
each input is returned.
668-
669-
The dict has the following format:
670-
671-
- img_path: path of the input image.
672-
- raw: path to save location for raw prediction,
673-
saved in .json.
674-
- list: List of image paths to the output files.
652+
AnnotationStore | Path | str | dict | list[Path]:
653+
- If `patch_mode` is True: returns predictions or path to saved output.
654+
- If `patch_mode` is False: returns a dictionary mapping each WSI
655+
to its output path.
675656
676657
Examples:
677658
>>> wsis = ['wsi1.svs', 'wsi2.svs']

0 commit comments

Comments
 (0)