lazyslide.tl.zero_shot_score

lazyslide.tl.zero_shot_score#

zero_shot_score(wsi, prompts, feature_key, *, agg_key=None, agg_by=None, model='prism', device=None, amp=None, autocast_dtype=None, compile=None, compile_kws=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:
wsiWSIData

The WSIData object to work on.

promptslist of str, or list of list of str

The text labels to classify. Each entry is one class; use a list of strings for an entry to add more information to that one class.

feature_keystr

The tile features to be used.

agg_keystr, default: None

The aggregation key.

agg_bystr or list of str, default: None

The aggregation keys that were used to create the slide features.

model{“prism”, “titan”}, default: “prism”

The model to use for zero-shot classification.

devicestr, default: None

The device to use for inference. If None, the default device will be used.

ampbool, optional

Whether to use automatic mixed precision.

autocast_dtypetorch.dtype, optional

The dtype for automatic mixed precision.

compilebool, optional

Whether to compile the model with torch.compile(). Compilation is best-effort and is silently skipped for models that do not support it.

compile_kwsdict, optional

Keyword arguments passed to torch.compile().

Returns:
DataFrame

The 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"))