ValidCOCOKeypointAnnotations#

class movement.validators.files.ValidCOCOKeypointAnnotations(file)[source]#

Bases: object

Class for validating COCO keypoint annotations (.json) files.

The validator ensures that the file:

  • is well-formed JSON,

  • contains the images, annotations and categories lists, each with the keys required by the COCO annotations format,

  • defines at least one category, each with a non-empty list of keypoint names, and

  • defines the same keypoint names, in the same order, for all categories, as movement currently requires all individuals to share the same set of keypoints.

The parsed annotations are stored in data. The categories are accessible by ID via categories, and the shared keypoint names via keypoint_names.

Raises:

ValueError – If the file is not valid JSON or does not match the expected schema.

property categories: dict[int, dict[str, Any]]#

COCO categories from the annotations file, keyed by ID.

data: dict[str, Any]#

Parsed COCO annotations data.

file: Path#

Path to the COCO annotations JSON file to validate.

property keypoint_names: list[str]#

Keypoint names shared by all COCO categories.

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

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

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

Expected suffix(es) for the file.