roboflow/supervision · error · ValueError
LabelMe shape of type {shape_type} (label={label}) has malfo
Error message
LabelMe shape of type {shape_type} (label={label}) has malformed points: expected an (N, 2) array, got shape {points.shape}. What it means
Raised when a LabelMe shape's points cannot be interpreted as an (N, 2) numeric array — np.array(points_raw, dtype=np.float32) yields a wrong ndim or second dimension. LabelMe stores points as a list of [x, y] pairs; a flat list of numbers, a list of triples, or ragged data fails this structural check with the actual shape reported.
Source
Thrown at src/supervision/dataset/formats/labelme.py:112
polygons: list[npt.NDArray[np.float32]] = []
skipped_types: set[str] = set()
for shape in shapes:
shape_type = shape.get("shape_type")
if shape_type not in SUPPORTED_SHAPE_TYPES:
skipped_types.add(str(shape_type))
continue
label = shape.get("label")
points_raw = shape.get("points")
if label is None or points_raw is None:
missing = "label" if label is None else "points"
raise ValueError(
f"LabelMe shape of type {shape_type!r} is missing the "
f"required {missing!r} field."
)
points = np.array(points_raw, dtype=np.float32)
if points.ndim != 2 or points.shape[1] != 2:
raise ValueError(
f"LabelMe shape of type {shape_type!r} (label={label!r}) has "
f"malformed points: expected an (N, 2) array, got shape "
f"{points.shape}."
)
if shape_type == "rectangle":
if len(points) < 2:
raise ValueError(
f"LabelMe rectangle shape (label={label!r}) has "
f"{len(points)} point(s); expected at least 2."
)
xyxy = _rectangle_to_xyxy(points)
polygon = _xyxy_to_polygon(xyxy)
else:
if len(points) < 3:
raise ValueError(
f"LabelMe polygon shape (label={label!r}) has "
f"{len(points)} point(s); expected at least 3."
)View on GitHub (pinned to 7f254d9784)
Solutions
- Look at the reported shape in the error: (N,) means flat pairs -> reshape to [[x, y], ...]; (N, 3) means extra columns -> drop them.
- Fix the generator/converter to emit a list of [x, y] pairs.
- If only a few shapes are bad, repair or delete them in the JSON directly.
Example fix
// before "points": [10, 20, 30, 40] // after "points": [[10, 20], [30, 40]]
Defensive patterns
Strategy: validation
Validate before calling
def points_are_pairs(points: object) -> bool:
"""LabelMe points must be a list of [x, y] pairs."""
return (isinstance(points, list) and len(points) > 0
and all(isinstance(p, (list, tuple)) and len(p) == 2 for p in points)) Try / catch
try:
dataset = sv.DetectionDataset.from_labelme(images_dir, ann_dir)
except ValueError as e:
if 'malformed points' in str(e):
raise SystemExit(f'Reshape points to [[x, y], ...] in the named file: {e}') from e
raise Prevention
- Emit points as nested [x, y] lists from converters, never flat arrays.
- Check for extra columns when converting from 3D tools.
- Validate a sample of generated JSON with a schema check before bulk runs.
When it happens
Trigger: DetectionDataset.from_labelme where points is e.g. [1, 2, 3, 4] (flat), [[x, y, z]] (triples), or contains non-numeric entries causing an unexpected array shape after coercion.
Common situations: Scripts that emit flattened coordinates to save space; unit conversion code that flattens pairs; copy-paste from CSV where each point became a single string; 3D annotation tools writing extra columns.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- LabelMe shape of type {shape_type} is missing the required {
- A LabelMe annotation file is missing the required 'imagePath
- LabelMe annotation has an invalid 'imagePath' {raw_image_pat
- LabelMe annotation for {image_name} requires 'imageWidth' an
- LabelMe rectangle shape (label={label}) has {len(points)} po
AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15).
Data as JSON: /api/errors/54ac5cea1c8bd9cb.
Report an issue: GitHub.