keras-team/keras · error · ValueError

Dimension of vectors for cross product must be 2 or 3. Got…

Error message

Dimension of vectors for cross product must be 2 or 3. Got dimensions {d1} and {d2} for inputs x1 and x2.

What it means

Raised by keras.ops.numpy.cross in the OpenVINO backend when the vectors being crossed have a dimension other than 2 or 3 along the specified axes. Cross products are only defined for 2D or 3D vectors, so any other leading dimension is rejected.

Solutions

  1. Ensure the axis picked by axisa/axisb has length 2 or 3
  2. Adjust axisa/axisb to point at the vector-component axis
  3. Reshape the inputs so the component axis has length 2 or 3
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    x1, x2 = _align_operand_types(x1, x2, "cross()")

    shape1 = x1.get_partial_shape()
    shape2 = x2.get_partial_shape()

    # Rank Normalization
    rank1 = shape1.rank.get_length()
    rank2 = shape2.rank.get_length()

    axisa = canonicalize_axis(axisa, rank1)
    axisb = canonicalize_axis(axisb, rank2)
    axisc = canonicalize_axis(axisc, rank1 if rank1 > rank2 else rank2)

    d1 = shape1[axisa].get_length()
    d2 = shape2[axisb].get_length()

    if d1 not in (2, 3) or d2 not in (2, 3):
        raise ValueError(
            "Dimension of vectors for cross product must be 2 or 3. "
            f"Got dimensions {d1} and {d2} for inputs x1 and x2."
        )

    # Pad to 3D by adding a zero component.
    def pad_to_3d(x, dim, ax):
        if dim == 3:
            return x

        # Create a slice of zeros with the same type as x
        slice0 = ov_opset.gather(
            x,
            ov_opset.constant([0], Type.i32),
            ov_opset.constant(ax, Type.i32),
        )
        zeros = ov_opset.multiply(
            slice0,
            ov_opset.constant(0, x.get_element_type()),

View on GitHub (pinned to 7a34a03db6)