slideflow.heatmap¶
slideflow.Heatmap uses a model to generate predictions across a whole-slide image through
progressive convolution. These prediction heatmaps can be interactively displayed or saved for later use.
Heatmap¶
- class slideflow.Heatmap(slide, model, stride_div=2, roi_dir=None, rois=None, roi_method='inside', batch_size=32, num_threads=None, buffer=None, enable_downsample=True)¶
Generates heatmap by calculating predictions from a sliding scale window across a slide.
- __init__(slide, model, stride_div=2, roi_dir=None, rois=None, roi_method='inside', batch_size=32, num_threads=None, buffer=None, enable_downsample=True)¶
Convolutes across a whole slide, calculating logits and saving predictions internally for later use.
- Parameters
slide (str) – Path to slide.
model (str) – Path to Tensorflow or PyTorch model.
stride_div (int, optional) – Divisor for stride when convoluting across slide. Defaults to 2.
roi_dir (str, optional) – Directory in which slide ROI is contained. Defaults to None.
rois (list, optional) – List of paths to slide ROIs. Alternative to providing roi_dir. Defaults to None.
roi_method (str, optional) – ‘inside’, ‘outside’, or ‘ignore’. If inside, tiles will be extracted inside ROI region. If outside, tiles will be extracted outside ROI region. Defaults to ‘inside’.
batch_size (int, optional) – Batch size for calculating predictions. Defaults to 32.
num_threads (int, optional) – Number of tile worker threads. Defaults to CPU core count.
buffer (str, optional) – Path to use for buffering slides. Defaults to None.
enable_downsample (bool, optional) – Enable the use of downsampled slide image layers. Defaults to True.
- save(outdir, show_roi=True, interpolation='none', cmap='coolwarm', logit_cmap=None, vmin=0, vmax=1, vcenter=0.5)¶
Saves calculated logits as heatmap overlays.
- Parameters
outdir (str) – Path to directory in which to save heatmap images.
show_roi (bool, optional) – Overlay ROIs onto heatmap image. Defaults to True.
interpolation (str, optional) – Interpolation strategy to use for smoothing heatmap. Defaults to ‘none’.
logit_cmap (obj, optional) – Either function or a dictionary use to create heatmap colormap. Each image tile will generate a list of predictions of length O, where O is the number of outcomes. If logit_cmap is a function, then the logit prediction list will be passed to the function, and the function is expected to return [R, G, B] values for display. If logit_cmap is a dictionary, it should map ‘r’, ‘g’, and ‘b’ to indices; the prediction for these outcome indices will be mapped to the RGB colors. Thus, the corresponding color will only reflect up to three outcomes. Example mapping prediction for outcome 0 to the red colorspace, 3 to green, etc: {‘r’: 0, ‘g’: 3, ‘b’: 1}
vmin (float) – Minimimum value to display on heatmap. Defaults to 0.
vcenter (float) – Center value for color display on heatmap. Defaults to 0.5.
vmax (float) – Maximum value to display on heatmap. Defaults to 1.