keras-team/keras · error · ValueError

Shape of weights must be consistent with shape of a along…

Error message

Shape of weights must be consistent with shape of a along specified axis.

What it means

Raised by keras.ops.numpy.average in the OpenVINO backend when the 1-D weights length does not equal the input's size along the specified axis. Weights are applied elementwise along that axis, so their length must match the axis dimension.

Solutions

  1. Resize the weights array to match the input's length along axis
  2. Point axis at the dimension the weights were computed for
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/openvino/numpy.py:851 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/e516186c648ebafd. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/openvino/numpy.py:851

            else x.get_partial_shape()
        )
        weights_shape = (
            weights_keras.shape
            if hasattr(weights_keras, "shape")
            else weights.get_partial_shape()
        )
        if len(weights_shape) == 1 and len(x_shape) > 1:
            if axis is None or (
                isinstance(axis, (list, tuple)) and len(axis) != 1
            ):
                raise ValueError(
                    "Axis must be specified when shapes of a and weights "
                    "differ."
                )
            axis_val = axis[0] if isinstance(axis, (list, tuple)) else axis
            axis_val = canonicalize_axis(axis_val, len(x_shape))
            if weights_shape[0] != x_shape[axis_val]:
                raise ValueError(
                    "Shape of weights must be consistent with shape of a "
                    "along specified axis."
                )
        elif x_shape != weights_shape:
            if axis is None:
                raise ValueError(
                    "Axis must be specified when shapes of a and weights "
                    "differ."
                )
            raise ValueError(
                "Shape of weights must be consistent with shape of a "
                "along specified axis."
            )

    if axis is None:
        flatten_shape = ov_opset.constant([-1], Type.i32).output(0)
        x = ov_opset.reshape(x, flatten_shape, False).output(0)
        if weights is not None:

View on GitHub (pinned to 7a34a03db6)