keras-team/keras · error · ValueError

If imagenet weights are being loaded, depth multiplier must…

Error message

If imagenet weights are being loaded, depth multiplier must be 1.  Received depth_multiplier={depth_multiplier}

What it means

MobileNet builder in keras/src/applications/mobilenet.py: pretrained ImageNet checkpoints exist only for the unmodified depthwise-convolution layout, i.e. depth_multiplier=1. Requesting weights='imagenet' with any other depth_multiplier (width of each depthwise filter changed) makes the stored weights incompatible, so the builder rejects it.

Solutions

  1. Use depth_multiplier=1 when loading ImageNet weights
  2. Train with weights=None if you need a custom depth multiplier
  3. Use the alpha parameter instead to scale the network width, which has pretrained variants
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/applications/mobilenet.py:160 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/1851179b21f60744. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/applications/mobilenet.py:160

    input_shape = imagenet_utils.obtain_input_shape(
        input_shape,
        default_size=default_size,
        min_size=32,
        data_format=backend.image_data_format(),
        require_flatten=include_top,
        weights=weights,
    )

    if backend.image_data_format() == "channels_last":
        row_axis, col_axis = (0, 1)
    else:
        row_axis, col_axis = (1, 2)
    rows = input_shape[row_axis]
    cols = input_shape[col_axis]

    if weights == "imagenet":
        if depth_multiplier != 1:
            raise ValueError(
                "If imagenet weights are being loaded, "
                "depth multiplier must be 1.  "
                f"Received depth_multiplier={depth_multiplier}"
            )

        if alpha not in [0.25, 0.50, 0.75, 1.0]:
            raise ValueError(
                "If imagenet weights are being loaded, "
                "alpha can be one of"
                "`0.25`, `0.50`, `0.75` or `1.0` only.  "
                f"Received alpha={alpha}"
            )

        if rows != cols or rows not in [128, 160, 192, 224]:
            rows = 224
            warnings.warn(
                "`input_shape` is undefined or non-square, "
                "or `rows` is not in [128, 160, 192, 224]. "

View on GitHub (pinned to 7a34a03db6)