lllyasviel/Fooocus · error · ValueError

Error: running this interpretation for images requires sciki

Error message

Error: running this interpretation for images requires scikit-image, please install it first.

What it means

_segment_by_slic in the vendored gradio Image lazily imports skimage.segmentation.slic to compute superpixels for interpretation; if scikit-image is not installed the ImportError is caught and re-raised as ValueError('Error: running this interpretation for images requires scikit-image, please install it first.'). Only the image-interpretation feature needs scikit-image; the rest of the app does not.

Source

Thrown at modules/gradio_hijack.py:356

            segments: Number of interpretation segments to split image into.
        """
        self.interpretation_segments = segments
        return self

    def _segment_by_slic(self, x):
        """
        Helper method that segments an image into superpixels using slic.
        Parameters:
            x: base64 representation of an image
        """
        x = processing_utils.decode_base64_to_image(x)
        if self.shape is not None:
            x = processing_utils.resize_and_crop(x, self.shape)
        resized_and_cropped_image = np.array(x)
        try:
            from skimage.segmentation import slic
        except (ImportError, ModuleNotFoundError) as err:
            raise ValueError(
                "Error: running this interpretation for images requires scikit-image, please install it first."
            ) from err
        try:
            segments_slic = slic(
                resized_and_cropped_image,
                self.interpretation_segments,
                compactness=10,
                sigma=1,
                start_label=1,
            )
        except TypeError:  # For skimage 0.16 and older
            segments_slic = slic(
                resized_and_cropped_image,
                self.interpretation_segments,
                compactness=10,
                sigma=1,
            )
        return segments_slic, resized_and_cropped_image

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Install the dependency: pip install scikit-image (match your requirements file's version pin if present).
  2. If you don't use interpretation, simply avoid the Interpret action — nothing else needs it.
  3. For Docker images, add scikit-image to the requirements layer and rebuild.

Example fix

# before: interpretation fails with ValueError
# after
pip install scikit-image
Defensive patterns

Strategy: validation

Validate before calling

try:
    import skimage.segmentation  # noqa
    interpretation_available = True
except ImportError:
    interpretation_available = False
# hide/disable the Interpret button when interpretation_available is False

Type guard

def interpretation_supported() -> bool:
    try:
        import skimage  # noqa
        return True
    except ImportError:
        return False

Try / catch

try:
    interp = image_component.interpret(fn)
except ValueError as e:
    if 'scikit-image' in str(e):
        print('Install scikit-image to enable interpretation: pip install scikit-image')
    else:
        raise

Prevention

When it happens

Trigger: Clicking Interpret in the UI on an Image input (or calling the interpret API) in an environment where scikit-image is missing — the failure occurs exactly when the slic import runs, not at startup.

Common situations: Minimal Docker/venv installs that skipped optional deps; a fresh Fooocus install whose requirements file omits scikit-image; interpretation invoked accidentally via API clients.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/e954f057c8978928. Report an issue: GitHub.