roboflow/supervision · error · ValueError

LabelMe shape of type

Error message

LabelMe shape of type {shape_type} is missing the required {missing} field.

What it means

Raised while parsing LabelMe JSON when a shape of a supported type (polygon/rectangle) is missing its 'label' or 'points' field (or points is null). Every LabelMe shape must carry both a class label and a point list; the message names which field is absent so you can fix the JSON directly.

Solutions

  1. Open the failing .json and find the shape whose 'label' or 'points' key is absent (the error names the field and shape_type).
  2. Add the missing field: a non-empty string label, and points as [[x, y], ...].
  3. If the shape is junk, delete it from the shapes array.
  4. Fix the upstream converter so it always writes both fields, then re-export.

Example fix

// before
{"shape_type": "polygon", "points": [[1, 2], [3, 4]]}
// after
{"shape_type": "polygon", "label": "cat", "points": [[1, 2], [3, 4]]}
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {'polygon', 'rectangle'}

def shapes_well_formed(shapes: list[dict]) -> bool:
    """Every supported LabelMe shape has label and points fields."""
    return all(s.get('shape_type') not in SUPPORTED
               or (s.get('label') is not None and s.get('points') is not None)
               for s in shapes)

Try / catch

try:
    dataset = sv.DetectionDataset.from_labelme(images_dir, ann_dir)
except ValueError as e:
    if 'missing the required' in str(e):
        raise SystemExit(f'Corrupt LabelMe JSON — add the named field: {e}') from e
    raise

Prevention

When it happens

Trigger: DetectionDataset.from_labelme on a directory where some shape dict in a .json file lacks the 'label' or 'points' key — e.g. hand-written JSON, partial exports, or converter bugs.

Common situations: Annotations generated by scripts (not the LabelMe app) that omit fields; JSON edited by hand; older/alternative tools writing a schema without points for certain shapes; truncated files.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/0fe0ec12fda46972. Report an issue: GitHub.

Appendix: source

Thrown at src/supervision/dataset/formats/labelme.py:106

    Warns:
        UserWarning: When unsupported shape types are encountered and skipped.
    """
    xyxy_list: list[npt.NDArray[np.float32]] = []
    class_ids: list[int] = []
    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)

View on GitHub (pinned to 7f254d9784)