Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions interactive_ai/libs/iai_core_py/iai_core/entities/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Label(PersistentEntity):
will be assigned upon saving. If the argument is None, it will be set to ID()
:param is_anomalous: boolean that indicates whether the label is the
Anomalous label. Always set to False for non-anomaly projects.
:param is_background: boolean that indicates whether the label is the background label.
This label is exclusive to semantic segmentation projects. False for other projects.
"""

def __init__( # noqa: PLR0913
Expand All @@ -111,6 +113,7 @@ def __init__( # noqa: PLR0913
creation_date: datetime.datetime | None = None,
is_empty: bool = False,
is_anomalous: bool = False,
is_background: bool = False,
ephemeral: bool = True,
):
color = Color.random() if color is None else color
Expand All @@ -123,6 +126,7 @@ def __init__( # noqa: PLR0913
self._is_empty = is_empty
self._creation_date = creation_date
self.is_anomalous = is_anomalous
self.is_background = is_background
PersistentEntity.__init__(self, id_=id_, ephemeral=ephemeral)

@property
Expand All @@ -138,8 +142,8 @@ def creation_date(self) -> datetime.datetime:
def __repr__(self):
"""String representation of the label."""
return (
f"Label({self.id_}, name={self.name}, hotkey={self.hotkey}, "
f"domain={self.domain}, color={self.color.hex_str}, is_anomalous={self.is_anomalous})"
f"Label({self.id_}, name={self.name}, hotkey={self.hotkey}, domain={self.domain}, "
f"color={self.color.hex_str}, is_anomalous={self.is_anomalous}, is_background={self.is_background})"
)

def __eq__(self, other: object) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def forward(instance: Label) -> dict:
"creation_date": DatetimeToMongo.forward(instance.creation_date),
"is_empty": instance.is_empty,
"is_anomalous": instance.is_anomalous,
"is_background": instance.is_background,
}

@staticmethod
Expand All @@ -70,6 +71,7 @@ def backward(instance: dict) -> Label:
is_empty=instance.get("is_empty", False),
id_=label_id,
is_anomalous=instance.get("is_anomalous", False),
is_background=instance.get("is_background", False),
ephemeral=False,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ def test_label_mapper(self) -> None:
is_empty=True,
id_=LabelRepo.generate_id(),
is_anomalous=True,
is_background=True,
ephemeral=False,
)
verify_mongo_mapper(entity_to_map=label, mapper_class=LabelToMongo)
Expand Down
Loading