ValidCOCOKeypointResults#

class movement.validators.files.ValidCOCOKeypointResults(file, annotations_file=None)[source]#

Bases: object

Class for validating COCO keypoint detection results (.json) files.

The validator ensures that the file:

  • is well-formed JSON,

  • contains a non-empty list of detections, each with the keys required by the COCO results format, and

  • contains keypoints arrays of the same length, which must be a multiple of 3 (x, y, visibility for each keypoint).

COCO results identify categories only by ID and keypoints only by position. An annotations file can be provided to resolve the category and keypoint names. In that case, the validator additionally ensures that:

  • all categories referenced in the results are defined in the annotations file, and

  • the annotations file defines as many keypoint names as there are keypoints in each detection.

The parsed results are stored in data. If an annotations file is provided, the category and keypoint names are also stored in category_names and keypoint_names.

Raises:

ValueError – If the file is not valid JSON, does not match the expected schema, or is inconsistent with the annotations file.

annotations_file: Path | None#

Optional path to a COCO keypoint detection annotations JSON file, used to resolve category and keypoint names.

category_names: dict[int, str] | None#

Category names keyed by category ID from the annotations file, if provided.

data: list[dict[str, Any]]#

Parsed COCO results data.

file: Path#

Path to the COCO results JSON file to validate.

keypoint_names: list[str] | None#

Keypoint names from the annotations file, if provided.

schema: ClassVar[Mapping[str, Any]] = {'$schema': 'https://json-schema.org/draft/2020-12/schema', 'description': 'Schema for validating COCO keypoint detection results JSON files', 'items': {'properties': {'category_id': {'type': 'integer'}, 'image_id': {'type': 'integer'}, 'keypoints': {'items': {'type': 'number'}, 'minItems': 3, 'type': 'array'}, 'score': {'type': 'number'}}, 'required': ['image_id', 'category_id', 'keypoints', 'score'], 'type': 'object'}, 'minItems': 1, 'title': 'COCO Keypoint Results', 'type': 'array'}#

JSON schema for validating the structure of the COCO results file.

suffixes: ClassVar[set[str]] = {'.json'}#

Expected suffix(es) for the file.