keras-team/keras · error · ValueError
Invalid start_points shape: expected (4,2) for a single…
Error message
Invalid start_points shape: expected (4,2) for a single image or (N,4,2) for a batch. Received shape: {start_points.shape} What it means
Shape guard in `perspective_transform` (NumPy backend): the source quadrilateral `start_points` must describe 4 corners as a (4, 2) array for a single image or an (N, 4, 2) batch. The guard checks both the ndim (2 or 3) and that the trailing shape equals (4, 2); wrong corner counts, missing coordinate pairs, or an extra/missing batch axis trigger it, with the actual shape shown.
Solutions
- Provide exactly four (x, y) corner pairs: start_points of shape (4, 2), or (N, 4, 2) for batches
- Check for dropped coordinate axes: points stored as (4,) or (2, 4) must be reshaped to (4, 2)
- Ensure batched images (rank 4) get batched start_points and single images (rank 3) get a single quadrilateral
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/image.py:686 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/5ab6f6e890250351.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/ops/image.py:686
start_points = convert_to_tensor(start_points)
end_points = convert_to_tensor(end_points)
if interpolation not in AFFINE_TRANSFORM_INTERPOLATIONS:
raise ValueError(
"Invalid value for argument `interpolation`. Expected of one "
f"{AFFINE_TRANSFORM_INTERPOLATIONS}. Received: "
f"interpolation={interpolation}"
)
if len(images.shape) not in (3, 4):
raise ValueError(
"Invalid images rank: expected rank 3 (single image) "
"or rank 4 (batch of images). Received input with shape: "
f"images.shape={images.shape}"
)
if start_points.ndim not in (2, 3) or start_points.shape[-2:] != (4, 2):
raise ValueError(
"Invalid start_points shape: expected (4,2) for a single image"
f" or (N,4,2) for a batch. Received shape: {start_points.shape}"
)
if end_points.ndim not in (2, 3) or end_points.shape[-2:] != (4, 2):
raise ValueError(
"Invalid end_points shape: expected (4,2) for a single image"
f" or (N,4,2) for a batch. Received shape: {end_points.shape}"
)
if start_points.shape != end_points.shape:
raise ValueError(
"start_points and end_points must have the same shape."
f" Received start_points.shape={start_points.shape}, "
f"end_points.shape={end_points.shape}"
)
input_dtype = images.dtype
if input_dtype == "float16":
images = images.astype("float32")View on GitHub (pinned to 7a34a03db6)