micro_sam.v1.evaluation.model_comparison

Functionality for qualitative comparison of Segment Anything models on microscopy data.

  1"""Functionality for qualitative comparison of Segment Anything models on microscopy data.
  2"""
  3
  4import os
  5from glob import glob
  6from pathlib import Path
  7from functools import partial
  8from typing import Optional, Union, Dict, Any
  9
 10import h5py
 11import numpy as np
 12import pandas as pd
 13from tqdm import tqdm
 14import matplotlib.pyplot as plt
 15from scipy.ndimage import binary_dilation
 16
 17import skimage.draw as draw
 18from skimage import exposure
 19from skimage.segmentation import find_boundaries
 20
 21import torch
 22
 23from bioimage_cpp.segmentation import relabel_sequential
 24
 25from ... import util
 26from ...prompt_generators import PointAndBoxPromptGenerator
 27from ..prompt_based_segmentation import segment_from_box, segment_from_points
 28from ..util import get_sam_model, precompute_image_embeddings, set_precomputed
 29
 30
 31#
 32# Compute all required data for the model comparison
 33#
 34
 35
 36def _predict_models_with_loader(loader, n_samples, prompt_generator, predictor1, predictor2, predictor3, output_folder):
 37    i = 0
 38    os.makedirs(output_folder, exist_ok=True)
 39
 40    for x, y in tqdm(loader, total=n_samples):
 41        out_path = os.path.join(output_folder, f"sample_{i}.h5")
 42
 43        im = x.numpy().squeeze()
 44        if im.ndim == 3 and im.shape[0] == 3:
 45            im = im.transpose((1, 2, 0))
 46
 47        gt = y.numpy().squeeze().astype("uint32")
 48        gt = relabel_sequential(gt)[0]
 49
 50        emb1 = precompute_image_embeddings(predictor1, im, ndim=2)
 51        set_precomputed(predictor1, emb1)
 52
 53        emb2 = precompute_image_embeddings(predictor2, im, ndim=2)
 54        set_precomputed(predictor2, emb2)
 55
 56        if predictor3 is not None:
 57            emb3 = precompute_image_embeddings(predictor3, im, ndim=2)
 58            set_precomputed(predictor3, emb3)
 59
 60        with h5py.File(out_path, "a") as f:
 61            f.create_dataset("image", data=im, compression="gzip")
 62
 63        gt_ids = np.unique(gt)[1:]
 64        centers, boxes = util.get_centers_and_bounding_boxes(gt)
 65        centers = [centers[gt_id] for gt_id in gt_ids]
 66        boxes = [boxes[gt_id] for gt_id in gt_ids]
 67
 68        object_masks = util.segmentation_to_one_hot(gt.astype("int64"), gt_ids)
 69        coords, labels, boxes, _ = prompt_generator(
 70            segmentation=object_masks,
 71            bbox_coordinates=boxes,
 72            center_coordinates=centers,
 73        )
 74
 75        for idx, gt_id in tqdm(enumerate(gt_ids), total=len(gt_ids)):
 76
 77            # Box prompts:
 78            # Reorder the coordinates so that they match the normal python convention.
 79            box = boxes[idx][[1, 0, 3, 2]]
 80            mask1_box = segment_from_box(predictor1, box)
 81            mask2_box = segment_from_box(predictor2, box)
 82            mask1_box, mask2_box = mask1_box.squeeze(), mask2_box.squeeze()
 83
 84            if predictor3 is not None:
 85                mask3_box = segment_from_box(predictor3, box)
 86                mask3_box = mask3_box.squeeze()
 87
 88            # Point prompts:
 89            # Reorder the coordinates so that they match the normal python convention.
 90            point_coords, point_labels = np.array(coords[idx])[:, ::-1], np.array(labels[idx])
 91            mask1_points = segment_from_points(predictor1, point_coords, point_labels)
 92            mask2_points = segment_from_points(predictor2, point_coords, point_labels)
 93            mask1_points, mask2_points = mask1_points.squeeze(), mask2_points.squeeze()
 94
 95            if predictor3 is not None:
 96                mask3_points = segment_from_points(predictor3, point_coords, point_labels)
 97                mask3_points = mask3_points.squeeze()
 98
 99            gt_mask = gt == gt_id
100            with h5py.File(out_path, "a") as f:
101                g = f.create_group(str(gt_id))
102                g.attrs["point_coords"] = point_coords
103                g.attrs["point_labels"] = point_labels
104                g.attrs["box"] = box
105
106                g.create_dataset("gt_mask", data=gt_mask, compression="gzip")
107                g.create_dataset("box/mask1", data=mask1_box.astype("uint8"), compression="gzip")
108                g.create_dataset("box/mask2", data=mask2_box.astype("uint8"), compression="gzip")
109                g.create_dataset("points/mask1", data=mask1_points.astype("uint8"), compression="gzip")
110                g.create_dataset("points/mask2", data=mask2_points.astype("uint8"), compression="gzip")
111
112                if predictor3 is not None:
113                    g.create_dataset("box/mask3", data=mask3_box.astype("uint8"), compression="gzip")
114                    g.create_dataset("points/mask3", data=mask3_points.astype("uint8"), compression="gzip")
115
116        i += 1
117        if i >= n_samples:
118            return
119
120
121def generate_data_for_model_comparison(
122    loader: torch.utils.data.DataLoader,
123    output_folder: Union[str, os.PathLike],
124    model_type1: str,
125    model_type2: str,
126    n_samples: int,
127    model_type3: Optional[str] = None,
128    checkpoint1: Optional[Union[str, os.PathLike]] = None,
129    checkpoint2: Optional[Union[str, os.PathLike]] = None,
130    checkpoint3: Optional[Union[str, os.PathLike]] = None,
131    peft_kwargs1: Optional[Dict[str, Any]] = None,
132    peft_kwargs2: Optional[Dict[str, Any]] = None,
133    peft_kwargs3: Optional[Dict[str, Any]] = None,
134) -> None:
135    """Generate samples for qualitative model comparison.
136
137    This precomputes the input for `model_comparison` and `model_comparison_with_napari`.
138
139    Args:
140        loader: The torch dataloader from which samples are drawn.
141        output_folder: The folder where the samples will be saved.
142        model_type1: The first model to use for comparison.
143            The value needs to be a valid model_type for `micro_sam.get_sam_model`.
144        model_type2: The second model to use for comparison.
145            The value needs to be a valid model_type for `micro_sam.get_sam_model`.
146        n_samples: The number of samples to draw from the dataloader.
147        checkpoint1: Optional checkpoint for the first model.
148        checkpoint2: Optional checkpoint for the second model.
149        checkpoint3: Optional checkpoint for the third model.
150    """
151    prompt_generator = PointAndBoxPromptGenerator(
152        n_positive_points=1,
153        n_negative_points=0,
154        dilation_strength=3,
155        get_point_prompts=True,
156        get_box_prompts=True,
157    )
158
159    predictor1 = get_sam_model(model_type=model_type1, checkpoint_path=checkpoint1, peft_kwargs=peft_kwargs1)
160    predictor2 = get_sam_model(model_type=model_type2, checkpoint_path=checkpoint2, peft_kwargs=peft_kwargs2)
161
162    if model_type3 is not None:
163        predictor3 = get_sam_model(model_type=model_type3, checkpoint_path=checkpoint3, peft_kwargs=peft_kwargs3)
164    else:
165        predictor3 = None
166
167    _predict_models_with_loader(loader, n_samples, prompt_generator, predictor1, predictor2, predictor3, output_folder)
168
169
170#
171# Visual evaluation according to metrics
172#
173
174
175def _evaluate_samples(f, prefix, min_size):
176    eval_result = {
177        "gt_id": [],
178        "score1": [],
179        "score2": [],
180    }
181    for name, group in f.items():
182        if name == "image":
183            continue
184
185        gt_mask = group["gt_mask"][:]
186
187        size = gt_mask.sum()
188        if size < min_size:
189            continue
190
191        m1 = group[f"{prefix}/mask1"][:]
192        m2 = group[f"{prefix}/mask2"][:]
193
194        score1 = util.compute_iou(gt_mask, m1)
195        score2 = util.compute_iou(gt_mask, m2)
196
197        eval_result["gt_id"].append(name)
198        eval_result["score1"].append(score1)
199        eval_result["score2"].append(score2)
200
201    eval_result = pd.DataFrame.from_dict(eval_result)
202    eval_result["advantage1"] = eval_result["score1"] - eval_result["score2"]
203    eval_result["advantage2"] = eval_result["score2"] - eval_result["score1"]
204    return eval_result
205
206
207def _overlay_mask(image, mask, alpha=0.6):
208    assert image.ndim in (2, 3)
209    # overlay the mask
210    if image.ndim == 2:
211        overlay = np.stack([image, image, image]).transpose((1, 2, 0))
212    else:
213        overlay = image
214    assert overlay.shape[-1] == 3
215    mask_overlay = np.zeros_like(overlay)
216    mask_overlay[mask == 1] = [255, 0, 0]
217    alpha = alpha
218    overlay = alpha * overlay + (1.0 - alpha) * mask_overlay
219    return overlay.astype("uint8")
220
221
222def _enhance_image(im, do_norm=True):
223    # apply CLAHE to improve the image quality
224    if do_norm:
225        im -= im.min(axis=(0, 1), keepdims=True)
226        im /= (im.max(axis=(0, 1), keepdims=True) + 1e-6)
227    im = exposure.equalize_adapthist(im)
228    im *= 255
229    return im
230
231
232def _overlay_outline(im, mask, outline_dilation):
233    outline = find_boundaries(mask)
234    if outline_dilation > 0:
235        outline = binary_dilation(outline, iterations=outline_dilation)
236    overlay = im.copy()
237    overlay[outline] = [255, 255, 0]
238    return overlay
239
240
241def _overlay_box(im, prompt, outline_dilation):
242    start, end = prompt
243    rr, cc = draw.rectangle_perimeter(start, end=end, shape=im.shape[:2])
244
245    box_outline = np.zeros(im.shape[:2], dtype="bool")
246    box_outline[rr, cc] = 1
247    if outline_dilation > 0:
248        box_outline = binary_dilation(box_outline, iterations=outline_dilation)
249
250    overlay = im.copy()
251    overlay[box_outline] = [0, 255, 255]
252
253    return overlay
254
255
256# NOTE: we currently only support a single point
257def _overlay_points(im, prompt, radius):
258    coords, labels = prompt
259    # make sure we have a single positive prompt, other options are
260    # currently not supported
261    assert coords.shape[0] == labels.shape[0] == 1
262    assert labels[0] == 1
263
264    rr, cc = draw.disk(coords[0], radius, shape=im.shape[:2])
265    overlay = im.copy()
266    draw.set_color(overlay, (rr, cc), [0, 255, 255], alpha=1.0)
267
268    return overlay
269
270
271def _compare_eval(
272    f, eval_result, advantage_column, n_images_per_sample, prefix, sample_name,
273    plot_folder, point_radius, outline_dilation, have_model3, enhance_image,
274):
275    result = eval_result.sort_values(advantage_column, ascending=False).iloc[:n_images_per_sample]
276    n_rows = result.shape[0]
277
278    image = f["image"][:]
279    is_box_prompt = prefix == "box"
280    overlay_prompts = partial(_overlay_box, outline_dilation=outline_dilation) if is_box_prompt else\
281        partial(_overlay_points, radius=point_radius)
282
283    def make_square(bb, shape):
284        box_shape = [b.stop - b.start for b in bb]
285        longest_side = max(box_shape)
286        padding = [(longest_side - sh) // 2 for sh in box_shape]
287        bb = tuple(
288            slice(max(b.start - pad, 0), min(b.stop + pad, sh)) for b, pad, sh in zip(bb, padding, shape)
289        )
290        return bb
291
292    def plot_ax(axis, i, row):
293        g = f[row.gt_id]
294
295        gt = g["gt_mask"][:]
296        mask1 = g[f"{prefix}/mask1"][:]
297        mask2 = g[f"{prefix}/mask2"][:]
298
299        # The mask3 is just for comparison purpose, we just plot the crops as it is.
300        if have_model3:
301            mask3 = g[f"{prefix}/mask3"][:]
302
303        fg_mask = (gt + mask1 + mask2) > 0
304        # if this is a box prompt we dilate the mask so that the bounding box
305        # can be seen
306        if is_box_prompt:
307            fg_mask = binary_dilation(fg_mask, iterations=5)
308        bb = np.where(fg_mask)
309        bb = tuple(
310            slice(int(b.min()), int(b.max() + 1)) for b in bb
311        )
312        bb = make_square(bb, fg_mask.shape)
313
314        offset = np.array([b.start for b in bb])
315        if is_box_prompt:
316            prompt = g.attrs["box"]
317            prompt = np.array(
318                [prompt[:2], prompt[2:]]
319            ) - offset
320        else:
321            prompt = (g.attrs["point_coords"] - offset, g.attrs["point_labels"])
322
323        if enhance_image:
324            im = _enhance_image(image[bb])
325        else:
326            im = image[bb]
327
328        gt, mask1, mask2 = gt[bb], mask1[bb], mask2[bb]
329
330        if have_model3:
331            mask3 = mask3[bb]
332
333        im1 = _overlay_mask(im, mask1)
334        im1 = _overlay_outline(im1, gt, outline_dilation)
335        im1 = overlay_prompts(im1, prompt)
336        ax = axis[0] if i is None else axis[i, 0]
337        ax.axis("off")
338        ax.imshow(im1)
339
340        # We put the third set of comparsion point in between
341        # so that the comparison looks -> default, generalist, specialist
342        if have_model3:
343            im3 = _overlay_mask(im, mask3)
344            im3 = _overlay_outline(im3, gt, outline_dilation)
345            im3 = overlay_prompts(im3, prompt)
346            ax = axis[1] if i is None else axis[i, 1]
347            ax.axis("off")
348            ax.imshow(im3)
349
350            nexax = 2
351        else:
352            nexax = 1
353
354        im2 = _overlay_mask(im, mask2)
355        im2 = _overlay_outline(im2, gt, outline_dilation)
356        im2 = overlay_prompts(im2, prompt)
357        ax = axis[nexax] if i is None else axis[i, nexax]
358        ax.axis("off")
359        ax.imshow(im2)
360
361    cols = 3 if have_model3 else 2
362    if plot_folder is None:
363        fig, axis = plt.subplots(n_rows, cols)
364        for i, (_, row) in enumerate(result.iterrows()):
365            plot_ax(axis, i, row)
366        plt.show()
367    else:
368        for i, (_, row) in enumerate(result.iterrows()):
369            fig, axis = plt.subplots(1, cols)
370            plot_ax(axis, None, row)
371            plt.subplots_adjust(wspace=0.05, hspace=0)
372            plt.savefig(os.path.join(plot_folder, f"{sample_name}_{i}.svg"), bbox_inches="tight")
373            plt.close()
374
375
376def _compare_prompts(
377    f, prefix, n_images_per_sample, min_size, sample_name, plot_folder,
378    point_radius, outline_dilation, have_model3, enhance_image,
379):
380    box_eval = _evaluate_samples(f, prefix, min_size)
381    if plot_folder is None:
382        plot_folder1, plot_folder2 = None, None
383    else:
384        plot_folder1 = os.path.join(plot_folder, "advantage1")
385        plot_folder2 = os.path.join(plot_folder, "advantage2")
386        os.makedirs(plot_folder1, exist_ok=True)
387        os.makedirs(plot_folder2, exist_ok=True)
388    _compare_eval(
389        f, box_eval, "advantage1", n_images_per_sample, prefix, sample_name, plot_folder1,
390        point_radius, outline_dilation, have_model3, enhance_image,
391    )
392    _compare_eval(
393        f, box_eval, "advantage2", n_images_per_sample, prefix, sample_name, plot_folder2,
394        point_radius, outline_dilation, have_model3, enhance_image,
395    )
396
397
398def _compare_models(
399    path, n_images_per_sample, min_size, plot_folder, point_radius, outline_dilation, have_model3, enhance_image,
400):
401    sample_name = Path(path).stem
402    with h5py.File(path, "r") as f:
403        if plot_folder is None:
404            plot_folder_points, plot_folder_box = None, None
405        else:
406            plot_folder_points = os.path.join(plot_folder, "points")
407            plot_folder_box = os.path.join(plot_folder, "box")
408        _compare_prompts(
409            f, "points", n_images_per_sample, min_size, sample_name, plot_folder_points,
410            point_radius, outline_dilation, have_model3, enhance_image,
411        )
412        _compare_prompts(
413            f, "box", n_images_per_sample, min_size, sample_name, plot_folder_box,
414            point_radius, outline_dilation, have_model3, enhance_image,
415        )
416
417
418def model_comparison(
419    output_folder: Union[str, os.PathLike],
420    n_images_per_sample: int,
421    min_size: int,
422    plot_folder: Optional[Union[str, os.PathLike]] = None,
423    point_radius: int = 4,
424    outline_dilation: int = 0,
425    have_model3=False,
426    enhance_image=True,
427) -> None:
428    """Create images for a qualitative model comparision.
429
430    Args:
431        output_folder: The folder with the data precomputed by `generate_data_for_model_comparison`.
432        n_images_per_sample: The number of images to generate per precomputed sample.
433        min_size: The min size of ground-truth objects to take into account.
434        plot_folder: The folder where to save the plots. If not given the plots will be displayed.
435        point_radius: The radius of the point overlay.
436        outline_dilation: The dilation factor of the outline overlay.
437        enhance_image: Whether to enhance the input image.
438    """
439    files = glob(os.path.join(output_folder, "*.h5"))
440    for path in tqdm(files):
441        _compare_models(
442            path, n_images_per_sample, min_size, plot_folder, point_radius,
443            outline_dilation, have_model3, enhance_image,
444        )
445
446
447#
448# Quick visual evaluation with napari
449#
450
451
452def _check_group(g, show_points):
453    import napari
454
455    image = g["image"][:]
456    gt = g["gt_mask"][:]
457    if show_points:
458        m1 = g["points/mask1"][:]
459        m2 = g["points/mask2"][:]
460        points = g.attrs["point_coords"]
461    else:
462        m1 = g["box/mask1"][:]
463        m2 = g["box/mask2"][:]
464        box = g.attrs["box"]
465        box = np.array([
466            [box[0], box[1]], [box[2], box[3]]
467        ])
468
469    v = napari.Viewer()
470    v.add_image(image)
471    v.add_labels(gt)
472    v.add_labels(m1)
473    v.add_labels(m2)
474    if show_points:
475        # TODO use point labels for coloring
476        v.add_points(
477            points,
478            edge_color="#00FF00",
479            symbol="o",
480            face_color="transparent",
481            edge_width=0.5,
482            size=12,
483        )
484    else:
485        v.add_shapes(
486            box, face_color="transparent", edge_color="green", edge_width=4,
487        )
488    napari.run()
489
490
491def model_comparison_with_napari(output_folder: Union[str, os.PathLike], show_points: bool = True) -> None:
492    """Use napari to display the qualtiative comparison results for two models.
493
494    Args:
495        output_folder: The folder with the data precomputed by `generate_data_for_model_comparison`.
496        show_points: Whether to show the results for point or for box prompts.
497    """
498    files = glob(os.path.join(output_folder, "*.h5"))
499    for path in files:
500        print("Comparing models in", path)
501        with h5py.File(path, "r") as f:
502            for name, g in f.items():
503                if name == "image":
504                    continue
505                _check_group(g, show_points=show_points)
def generate_data_for_model_comparison( loader: torch.utils.data.dataloader.DataLoader, output_folder: Union[str, os.PathLike], model_type1: str, model_type2: str, n_samples: int, model_type3: Optional[str] = None, checkpoint1: Union[str, os.PathLike, NoneType] = None, checkpoint2: Union[str, os.PathLike, NoneType] = None, checkpoint3: Union[str, os.PathLike, NoneType] = None, peft_kwargs1: Optional[Dict[str, Any]] = None, peft_kwargs2: Optional[Dict[str, Any]] = None, peft_kwargs3: Optional[Dict[str, Any]] = None) -> None:
122def generate_data_for_model_comparison(
123    loader: torch.utils.data.DataLoader,
124    output_folder: Union[str, os.PathLike],
125    model_type1: str,
126    model_type2: str,
127    n_samples: int,
128    model_type3: Optional[str] = None,
129    checkpoint1: Optional[Union[str, os.PathLike]] = None,
130    checkpoint2: Optional[Union[str, os.PathLike]] = None,
131    checkpoint3: Optional[Union[str, os.PathLike]] = None,
132    peft_kwargs1: Optional[Dict[str, Any]] = None,
133    peft_kwargs2: Optional[Dict[str, Any]] = None,
134    peft_kwargs3: Optional[Dict[str, Any]] = None,
135) -> None:
136    """Generate samples for qualitative model comparison.
137
138    This precomputes the input for `model_comparison` and `model_comparison_with_napari`.
139
140    Args:
141        loader: The torch dataloader from which samples are drawn.
142        output_folder: The folder where the samples will be saved.
143        model_type1: The first model to use for comparison.
144            The value needs to be a valid model_type for `micro_sam.get_sam_model`.
145        model_type2: The second model to use for comparison.
146            The value needs to be a valid model_type for `micro_sam.get_sam_model`.
147        n_samples: The number of samples to draw from the dataloader.
148        checkpoint1: Optional checkpoint for the first model.
149        checkpoint2: Optional checkpoint for the second model.
150        checkpoint3: Optional checkpoint for the third model.
151    """
152    prompt_generator = PointAndBoxPromptGenerator(
153        n_positive_points=1,
154        n_negative_points=0,
155        dilation_strength=3,
156        get_point_prompts=True,
157        get_box_prompts=True,
158    )
159
160    predictor1 = get_sam_model(model_type=model_type1, checkpoint_path=checkpoint1, peft_kwargs=peft_kwargs1)
161    predictor2 = get_sam_model(model_type=model_type2, checkpoint_path=checkpoint2, peft_kwargs=peft_kwargs2)
162
163    if model_type3 is not None:
164        predictor3 = get_sam_model(model_type=model_type3, checkpoint_path=checkpoint3, peft_kwargs=peft_kwargs3)
165    else:
166        predictor3 = None
167
168    _predict_models_with_loader(loader, n_samples, prompt_generator, predictor1, predictor2, predictor3, output_folder)

Generate samples for qualitative model comparison.

This precomputes the input for model_comparison and model_comparison_with_napari.

Arguments:
  • loader: The torch dataloader from which samples are drawn.
  • output_folder: The folder where the samples will be saved.
  • model_type1: The first model to use for comparison. The value needs to be a valid model_type for micro_sam.get_sam_model.
  • model_type2: The second model to use for comparison. The value needs to be a valid model_type for micro_sam.get_sam_model.
  • n_samples: The number of samples to draw from the dataloader.
  • checkpoint1: Optional checkpoint for the first model.
  • checkpoint2: Optional checkpoint for the second model.
  • checkpoint3: Optional checkpoint for the third model.
def model_comparison( output_folder: Union[str, os.PathLike], n_images_per_sample: int, min_size: int, plot_folder: Union[str, os.PathLike, NoneType] = None, point_radius: int = 4, outline_dilation: int = 0, have_model3=False, enhance_image=True) -> None:
419def model_comparison(
420    output_folder: Union[str, os.PathLike],
421    n_images_per_sample: int,
422    min_size: int,
423    plot_folder: Optional[Union[str, os.PathLike]] = None,
424    point_radius: int = 4,
425    outline_dilation: int = 0,
426    have_model3=False,
427    enhance_image=True,
428) -> None:
429    """Create images for a qualitative model comparision.
430
431    Args:
432        output_folder: The folder with the data precomputed by `generate_data_for_model_comparison`.
433        n_images_per_sample: The number of images to generate per precomputed sample.
434        min_size: The min size of ground-truth objects to take into account.
435        plot_folder: The folder where to save the plots. If not given the plots will be displayed.
436        point_radius: The radius of the point overlay.
437        outline_dilation: The dilation factor of the outline overlay.
438        enhance_image: Whether to enhance the input image.
439    """
440    files = glob(os.path.join(output_folder, "*.h5"))
441    for path in tqdm(files):
442        _compare_models(
443            path, n_images_per_sample, min_size, plot_folder, point_radius,
444            outline_dilation, have_model3, enhance_image,
445        )

Create images for a qualitative model comparision.

Arguments:
  • output_folder: The folder with the data precomputed by generate_data_for_model_comparison.
  • n_images_per_sample: The number of images to generate per precomputed sample.
  • min_size: The min size of ground-truth objects to take into account.
  • plot_folder: The folder where to save the plots. If not given the plots will be displayed.
  • point_radius: The radius of the point overlay.
  • outline_dilation: The dilation factor of the outline overlay.
  • enhance_image: Whether to enhance the input image.
def model_comparison_with_napari(output_folder: Union[str, os.PathLike], show_points: bool = True) -> None:
492def model_comparison_with_napari(output_folder: Union[str, os.PathLike], show_points: bool = True) -> None:
493    """Use napari to display the qualtiative comparison results for two models.
494
495    Args:
496        output_folder: The folder with the data precomputed by `generate_data_for_model_comparison`.
497        show_points: Whether to show the results for point or for box prompts.
498    """
499    files = glob(os.path.join(output_folder, "*.h5"))
500    for path in files:
501        print("Comparing models in", path)
502        with h5py.File(path, "r") as f:
503            for name, g in f.items():
504                if name == "image":
505                    continue
506                _check_group(g, show_points=show_points)

Use napari to display the qualtiative comparison results for two models.

Arguments: