Skip to content

Commit

Permalink
Throw error if index in skeleton is greater than number of keypoints (#…
Browse files Browse the repository at this point in the history
…318)

* Throw error if index in skeleton is greater than number of keypoints

* Update CHANGELOG
  • Loading branch information
flubstep authored Jun 16, 2022
1 parent ae5d1e1 commit 3e799a7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.13.5](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.13.4) - 2022-06-15

### Fixed
- Guard against invalid skeleton indexes in KeypointsAnnotation

## [0.13.4](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.13.4) - 2022-06-09

### Fixed
Expand Down
8 changes: 7 additions & 1 deletion nucleus/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class KeypointsAnnotation(Annotation):
label="face",
keypoints=[Keypoint(100, 100), Keypoint(120, 120), Keypoint(visible=False), Keypoint(0, 0)],
names=["point1", "point2", "point3", "point4"],
skeleton=[[0, 1], [1, 2], [1, 3], [2, 4]],
skeleton=[[0, 1], [1, 2], [1, 3], [2, 3]],
reference_id="image_2",
annotation_id="image_2_face_keypoints_1",
metadata={"face_direction": "forward"},
Expand Down Expand Up @@ -486,11 +486,17 @@ def __post_init__(self):
)
seen.add(name)

max_segment_index = len(self.keypoints) - 1
for segment in self.skeleton:
if len(segment) != 2:
raise ValueError(
"The keypoints skeleton must contain a list of line segments with exactly 2 indices"
)
for index in segment:
if index > max_segment_index:
raise ValueError(
f"The skeleton index {index} is not a valid keypoint index"
)

@classmethod
def from_json(cls, payload: dict):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exclude = '''

[tool.poetry]
name = "scale-nucleus"
version = "0.13.4"
version = "0.13.5"
description = "The official Python client library for Nucleus, the Data Platform for AI"
license = "MIT"
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]
Expand Down

0 comments on commit 3e799a7

Please sign in to comment.