keras-team/keras · error · ValueError

Invalid strategy . Supported values are 'greedy' and…

Error message

Invalid strategy {strategy}. Supported values are 'greedy' and 'beam_search'.

What it means

A dispatch guard inside the NumPy implementation of `ctc_decode`: the function branches on the `strategy` argument and only implements the 'greedy' and 'beam_search' decoders. Any other string (including misspellings or casing differences) falls into the else branch and is rejected with this error naming the offending value.

Solutions

  1. Set `strategy` to exactly 'greedy' or 'beam_search' (case-sensitive)
  2. Pre-validate user-supplied strategy strings against the two supported values before calling ctc_decode
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/numpy/nn.py:1338 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/c2b58fd0eb828142. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/numpy/nn.py:1338

    inputs = cast(inputs, dtype)

    if strategy == "greedy":
        return _ctc_greedy_decode(
            inputs,
            sequence_lengths,
            merge_repeated=merge_repeated,
            mask_index=mask_index,
        )
    elif strategy == "beam_search":
        return _ctc_beam_search_decode(
            inputs,
            sequence_lengths,
            beam_width=beam_width,
            top_paths=top_paths,
            mask_index=mask_index,
        )
    else:
        raise ValueError(
            f"Invalid strategy {strategy}. Supported values are "
            "'greedy' and 'beam_search'."
        )


def psnr(x1, x2, max_val):
    if x1.shape != x2.shape:
        raise ValueError(
            f"Input shapes {x1.shape} and {x2.shape} must "
            "match for PSNR calculation. "
        )

    max_val = convert_to_tensor(max_val, dtype=x2.dtype)
    mse = np.mean(np.square(x1 - x2))
    psnr = 20 * np.log10(max_val) - 10 * np.log10(mse)
    return psnr

View on GitHub (pinned to 7a34a03db6)