Skip to content

Commit

Permalink
PredictedInstance repr
Browse files Browse the repository at this point in the history
  • Loading branch information
talmo committed Jun 5, 2024
1 parent af4a817 commit 9adb57c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sleap_io/model/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ class PredictedInstance(Instance):
score: float = 0.0
tracking_score: Optional[float] = 0

def __repr__(self) -> str:
"""Return a readable representation of the instance."""
pts = self.numpy().tolist()
track = f'"{self.track.name}"' if self.track is not None else self.track

score = str(self.score) if self.score is None else f"{self.score:.2f}"
tracking_score = (
str(self.tracking_score)
if self.tracking_score is None
else f"{self.tracking_score:.2f}"
)
return (
f"PredictedInstance(points={pts}, track={track}, "
f"score={score}, tracking_score={tracking_score})"
)

@classmethod
def from_numpy( # type: ignore[override]
cls,
Expand Down
5 changes: 5 additions & 0 deletions tests/model/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ def test_predicted_instance():
assert inst[0].score == 0.4
assert inst[1].score == 0.5
assert inst.score == 0.6

assert (
str(inst) == "PredictedInstance(points=[[0.0, 1.0], [2.0, 3.0]], track=None, "
"score=0.60, tracking_score=None)"
)

0 comments on commit 9adb57c

Please sign in to comment.