Model Interpretation through Sensitivity Analysis for Segmentation

Interpret and explain your segmetation models through analysing their sensitivity to defined alterations of the input

Input alterations currently include: - rotation - cropping - brightness - contrast - zooming - flipping (dihedral) - resizing - MR artifacts (via torchio)


pip install misas


If you use misas in your research, please cite: > Ankenbrand, M. J., Shainberg, L., Hock, M., Lohr, D., & Schreiber, L. M. Sensitivity analysis for interpretation of machine learning based segmentation models in cardiac MRI. BMC Medical Imaging, 21(27).

If you use the simulated MR artifacts, please also cite torchio: > F. Pérez-García, R. Sparks, and S. Ourselin. TorchIO: a Python library for efficient loading, preprocessing, augmentation and patch-based sampling of medical images in deep learning. Computer Methods and Programs in Biomedicine (June 2021), p. 106236. ISSN: 0169-2607.

How to use

Example with kaggle data

from misas.core import *
from misas.core import default_cmap, default_cmap_true_mask
from misas.fastai_model import Fastai2_model
from PIL import Image, ImageEnhance, ImageOps
from functools import partial
from tqdm.notebook import tqdm
import matplotlib.pyplot as plt
import numpy as np
def label_func(x):
def acc_seg(input, target):
def diceComb(input, targs):
def diceLV(input, targs):
def diceMY(input, targs):
img = lambda:"example/kaggle/images/1-frame014-slice005.png").convert("RGB")
trueMask = lambda:"example/kaggle/masks/1-frame014-slice005.png").convert("I")
trainedModel = Fastai2_model("chfc-cmi/cmr-seg-tl", "cmr_seg_base", force_reload=False)
fig, ax = plt.subplots(figsize=(8,8))
ax.imshow(np.array(trueMask()), cmap=default_cmap_true_mask, alpha=.5, interpolation="nearest")
Using cache found in /home/csa84mikl/.cache/torch/hub/chfc-cmi_cmr-seg-tl_master


plot_series(get_rotation_series(img(), trainedModel))
[W NNPACK.cpp:51] Could not initialize NNPACK! Reason: Unsupported hardware.

results = eval_rotation_series(img(), trueMask(), trainedModel)
plt.plot(results['deg'], results['c1'])
plt.plot(results['deg'], results['c2'])
(0.0, 360.0, 0.0, 1.0)

You can use interactive elements to manually explore the impact of rotation

from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
rotation_series = get_rotation_series(img(),trainedModel,step=10)
def plot_rotation_frame(deg):
    return plot_frame(*rotation_series[int(deg/10)], figsize=(10,10))
    deg=widgets.IntSlider(min=0, max=360, step=10, value=90, continuous_update=False)
<function __main__.plot_rotation_frame(deg)>

There are lots of other transformations to try (e.g. cropping, brightness, contrast, …) as well as MR specific artifacts.


This is the schematic overview of how misas works. Created with the amazing Excalidraw. schema


This project is inspired by the awesome “Is it a Duck or Rabbit” tweet by @minimaxir. Also check out the corresponding repo.

<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Is it a Duck or a Rabbit? For Google Cloud Vision, it depends how the image is rotated. <a href=""></a></p>&mdash; Max Woolf (@minimaxir) <a href="">March 7, 2019</a></blockquote> <script async src="" charset="utf-8"></script>


0.1.0 <2022-07-14>

  • Re-write internal function to use pillow instead of fastai (version 1)

0.0.4 <2021-01-14>

  • Initial release