keras-team/keras · error · ValueError
start_points and end_points must have the same shape…
Error message
start_points and end_points must have the same shape. Received start_points.shape={start_points.shape}, end_points.shape={end_points.shape} What it means
Consistency guard in `perspective_transform` (NumPy backend): the homography is solved by pairing each start corner with the corresponding end corner, so the two point sets must have identical shapes (same batch size and same quadrilateral layout). After both individual shape checks pass, this final guard compares start_points.shape with end_points.shape and reports both when they differ.
Solutions
- Make end_points the same shape as start_points, e.g. (N, 4, 2) for both
- Broadcast a single quadrilateral to a batch: keras.ops.broadcast_to or np.repeat when only one destination is used for N images
- Audit point-generation code so both arrays are built with the same stacking logic
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/numpy/ops/image.py:696 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/e2dc60211048d639.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/ops/image.py:696
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")
need_squeeze = False
if len(images.shape) == 3:
images = np.expand_dims(images, axis=0)
need_squeeze = True
if len(start_points.shape) == 2:
start_points = np.expand_dims(start_points, axis=0)
if len(end_points.shape) == 2:
end_points = np.expand_dims(end_points, axis=0)View on GitHub (pinned to 7a34a03db6)