lazyslide.tl.zero_shot_score#
- zero_shot_score(wsi, prompts, feature_key, *, agg_key=None, agg_by=None, model='prism', device=None)#
Perform zero-shot learning classification on the WSI
Supported models: - prism: Prism model. - titan: Titan model.
Corresponding slide-level features are required for the model.
- Parameters:
- wsi
WSIData The WSIData object to work on.
- promptsarray of str
The text labels to classify. You can use a list of strings to add more information to one class.
- feature_keystr
The tile features to be used.
- agg_keystr
The aggregation key
- agg_bystr or list of str
The aggregation keys that were used to create the slide features.
- model: {“prism”, “titan”}
The model to use for zero-shot classification.
- devicestr
The device to use for inference. If None, the default device will be used.
- wsi
- Returns:
DataFrameThe classification results (probability). The columns are the text labels and the rows are the slide features.
Examples
>>> import lazyslide as zs >>> wsi = zs.datasets.lung_carcinoma(with_data=False) >>> zs.pp.find_tissues(wsi) >>> zs.pp.tile_tissues(wsi, 512, background_fraction=0.95, mpp=0.5) >>> zs.tl.feature_extraction(wsi, "virchow") >>> zs.tl.feature_aggregation(wsi, feature_key="virchow", encoder="prism") >>> classes = ["lung cancer", "normal lung"] >>> print(zs.tl.zero_shot_score(wsi, classes, feature_key="virchow_tiles"))