deeplearning4j/deeplearning4j · error · IllegalArgumentException
Invalid input: (x1,y1), top left position must have values l
Error message
Invalid input: (x1,y1), top left position must have values less than" +
" (x2,y2) bottom right position. Got: (" + x1 + "," + y1 + "), (" + x2 + "," + y2 + ") What it means
The ImageObject constructor validates bounding-box geometry: the top-left corner (x1,y1) must satisfy x1 <= x2 and y1 <= y2 relative to the bottom-right corner. Otherwise it throws IllegalArgumentException describing the offending coordinates. Note it only rejects strictly greater values — equal coordinates (a degenerate point/line box) are allowed.
Source
Thrown at datavec/datavec-data/datavec-data-image/src/main/java/org/datavec/image/recordreader/objdetect/ImageObject.java:36
* *****************************************************************************
*/
package org.datavec.image.recordreader.objdetect;
import lombok.Data;
@Data
public class ImageObject {
private final int x1;
private final int y1;
private final int x2;
private final int y2;
private final String label;
public ImageObject(int x1, int y1, int x2, int y2, String label){
if(x1 > x2 || y1 > y2){
throw new IllegalArgumentException("Invalid input: (x1,y1), top left position must have values less than" +
" (x2,y2) bottom right position. Got: (" + x1 + "," + y1 + "), (" + x2 + "," + y2 + ")");
}
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.label = label;
}
public double getXCenterPixels(){
return (x1 + x2) / 2.0;
}
public double getYCenterPixels(){
return (y1 + y2) / 2.0;
}
}View on GitHub (pinned to 4c22ac5fe4)
Solutions
- Order the corners before constructing: x1 = min(ax,bx), y1 = min(ay,by), x2 = max(ax,bx), y2 = max(ay,by)
- If your source stores width/height, convert: new ImageObject(x, y, x + w, y + h, label)
- Validate parsed annotation values before constructing ImageObject
Example fix
// before new ImageObject(bboxX + bboxW, bboxY + bboxH, bboxX, bboxY, label); // corners swapped // after new ImageObject(bboxX, bboxY, bboxX + bboxW, bboxY + bboxH, label);
Defensive patterns
Strategy: validation
Validate before calling
if (x1 > x2 || y1 > y2) {
int nx1 = Math.min(x1, x2), nx2 = Math.max(x1, x2);
int ny1 = Math.min(y1, y2), ny2 = Math.max(y1, y2);
x1 = nx1; y1 = ny1; x2 = nx2; y2 = ny2;
}
ImageObject obj = new ImageObject(x1, y1, x2, y2, label); Try / catch
ImageObject obj;
try {
obj = new ImageObject(x1, y1, x2, y2, label);
} catch (IllegalArgumentException e) {
// normalize corner order and retry
obj = new ImageObject(Math.min(x1,x2), Math.min(y1,y2), Math.max(x1,x2), Math.max(y1,y2), label);
} Prevention
- Confirm your annotation source uses (x1,y1,x2,y2) not (x,y,w,h)
- Normalize corner order with min/max before constructing boxes
- Add a pre-construction assertion for bounding-box geometry in parsing code
When it happens
Trigger: Creating ImageObject with swapped or negative-growth coordinates, e.g. new ImageObject(x2, y2, x1, y1, label), or parsing annotations where corner order differs (e.g. width/height instead of x2/y2).
Common situations: Custom LabelProvider implementations feeding wrong corner order; annotation formats that store (x, y, width, height) misread as (x1, y1, x2, y2); coordinate-system flips between image origins.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Base String must match this regular expression: ${p.toString
- Cannot filter 0/null columns: columns to filter on must be s
- No path locations found in the split.
- Max size must be positive, got {maxSize}
- Word must not be null or empty
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/8dfd66e5c2933501.
Report an issue: GitHub.