NameError: name 'SegmentationInterpretation' is not defined

Hi everyone, I’m following fastai’s tutorial on Image Segmentation but when trying to use SegmentationInterpretation class

interp = SegmentationInterpretation.from_learner(learn)

I get a Name Error

NameError                                 Traceback (most recent call last)
<ipython-input-42-796ee2023baf> in <module>
----> 1 interp = SegmentationInterpretation.from_learner(learn)
      2 interp.plot_top_losses(k=3)

NameError: name 'SegmentationInterpretation' is not defined

From the source code it looks like it’s not implemented, but since it is used on the tutorial I wonder if it was moved somewhere else or if I’m missing something?


How are you importing fastai?

It lives in from fastai.interpret import SegmentationInterpretation

I was using from import *

Just added from fastai.interpret import SegmentationInterpretation but I get the following:

ImportError Traceback (most recent call last)
<ipython-input-15-ea30657bf32e> in <module>
----> 1 from fastai.interpret import SegmentationInterpretation

ImportError: cannot import name 'SegmentationInterpretation' from 'fastai.interpret' (/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/

By the way I am running this in Paperspace Gradient, just copy / pasting the code from Computer vision tutorial > Multi-label classification > Using the high-level API

What version of fastai do you have?

pip show fastai
Name: fastai
Version: 2.1.5
Summary: fastai simplifies training fast and accurate neural nets using modern best practices
Author: Jeremy Howard, Sylvain Gugger, and contributors
License: Apache Software License 2.0
Location: /opt/conda/envs/fastai/lib/python3.8/site-packages
Requires: pip, requests, pyyaml, packaging, scipy, torch, fastcore, pandas, pillow, spacy, fastprogress, matplotlib, torchvision, scikit-learn
Required-by: fastbook
Note: you may need to restart the kernel to use updated packages.

Do pip install fastai -U and try again.

SegmentationInterpretation wasn’t added until 2.2+ IIRC (also if you’re reading the docs and they don’t work, upgrading your version is always the answer 99% of the time as that’s what they’re run with)

Great! it worked. Thank you very much!

1 Like

Hi, I am running into a similar problem as Interpret seems to be wrong and I cannot use the proposed solution :frowning:

I’m running Fastai 2.4 on a paperspace Jupyter Notebook. I’m following the tutorial for as amaka_ik was doing.

Interpret, included in 2.4 should include ‘SegmentationInterpretation’ but help(interpret) only shows the Classes ‘ClassificationInterpretation’ and ‘Interpretation’. I am not sure how to get to the right interpret module as it is included in the fastai package. (I tried upgrading fastai with pip)

I could use some help…