keras-team/keras · error · ValueError

Could not interpret activation function identifier: {identif

Error message

Could not interpret activation function identifier: {identifier}

What it means

Raised by extract_patches when size is a tuple/list but its length is neither 2 nor 3. Keras supports 2D patch grids (height, width) and 3D grids (depth, height, width) only; any other tuple length is ambiguous so it fails fast with a ValueError.

Source

Thrown at keras/src/activations/__init__.py:128

        module_objects=ALL_OBJECTS_DICT,
        custom_objects=custom_objects,
    )


@keras_export("keras.activations.get")
def get(identifier):
    """Retrieve a Keras activation function via an identifier."""
    if identifier is None:
        return linear
    if isinstance(identifier, dict):
        obj = serialization_lib.deserialize_keras_object(identifier)
    elif isinstance(identifier, str):
        obj = ALL_OBJECTS_DICT.get(identifier, None)
    else:
        obj = identifier
    if callable(obj):
        return obj
    raise ValueError(
        f"Could not interpret activation function identifier: {identifier}"
    )

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use length 2 for image inputs (patch_h, patch_w) and length 3 for volume inputs (patch_d, patch_h, patch_w)
  2. Check len(size) before the call and assert it matches your data rank (2 for 2D, 3 for 3D)
  3. If the tuple came from a conv kernel spec, strip the channel/batch dims before passing it

Example fix

before: extract_patches(vol, size=[2, 2, 2, 2]) -> ValueError; after: extract_patches(vol, size=[2, 2, 2])
Defensive patterns

Strategy: validation

Validate before calling

assert isinstance(size, (int, tuple, list))
if not isinstance(size, int):
    assert len(size) in (2, 3), f"size must have length 2 or 3, got {len(size)}"

Type guard

def size_matches_rank(size, ndim) -> bool:
    return isinstance(size, int) or (isinstance(size, (tuple, list)) and len(size) == ndim - 2)

Prevention

When it happens

Trigger: extract_patches(images, size=(3, 3, 3, 3)) (4 elements, e.g. meant for batch or channels); size=(3,) single-element tuple from a config that collapsed; mixing a 3D tuple with 2D images instead of using 2 elements.

Common situations: Config files where patch size lists grow stale after switching between 2D and 3D models; copying a kernel_size=(3,3,3,3) 4D conv shape into patch extraction; tuples built programmatically with the wrong dimension count.

Related errors


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