Skip to content

Commit f736afa

Browse files
authored
ITEP-71829 Add is_background label (#686)
1 parent 65e5656 commit f736afa

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

interactive_ai/libs/iai_core_py/iai_core/entities/label.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class Label(PersistentEntity):
9999
will be assigned upon saving. If the argument is None, it will be set to ID()
100100
:param is_anomalous: boolean that indicates whether the label is the
101101
Anomalous label. Always set to False for non-anomaly projects.
102+
:param is_background: boolean that indicates whether the label is the background label.
103+
This label is exclusive to semantic segmentation projects. False for other projects.
102104
"""
103105

104106
def __init__( # noqa: PLR0913
@@ -111,6 +113,7 @@ def __init__( # noqa: PLR0913
111113
creation_date: datetime.datetime | None = None,
112114
is_empty: bool = False,
113115
is_anomalous: bool = False,
116+
is_background: bool = False,
114117
ephemeral: bool = True,
115118
):
116119
color = Color.random() if color is None else color
@@ -123,6 +126,7 @@ def __init__( # noqa: PLR0913
123126
self._is_empty = is_empty
124127
self._creation_date = creation_date
125128
self.is_anomalous = is_anomalous
129+
self.is_background = is_background
126130
PersistentEntity.__init__(self, id_=id_, ephemeral=ephemeral)
127131

128132
@property
@@ -138,8 +142,8 @@ def creation_date(self) -> datetime.datetime:
138142
def __repr__(self):
139143
"""String representation of the label."""
140144
return (
141-
f"Label({self.id_}, name={self.name}, hotkey={self.hotkey}, "
142-
f"domain={self.domain}, color={self.color.hex_str}, is_anomalous={self.is_anomalous})"
145+
f"Label({self.id_}, name={self.name}, hotkey={self.hotkey}, domain={self.domain}, "
146+
f"color={self.color.hex_str}, is_anomalous={self.is_anomalous}, is_background={self.is_background})"
143147
)
144148

145149
def __eq__(self, other: object) -> bool:

interactive_ai/libs/iai_core_py/iai_core/repos/mappers/mongodb_mappers/label_mapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def forward(instance: Label) -> dict:
5252
"creation_date": DatetimeToMongo.forward(instance.creation_date),
5353
"is_empty": instance.is_empty,
5454
"is_anomalous": instance.is_anomalous,
55+
"is_background": instance.is_background,
5556
}
5657

5758
@staticmethod
@@ -70,6 +71,7 @@ def backward(instance: dict) -> Label:
7071
is_empty=instance.get("is_empty", False),
7172
id_=label_id,
7273
is_anomalous=instance.get("is_anomalous", False),
74+
is_background=instance.get("is_background", False),
7375
ephemeral=False,
7476
)
7577

interactive_ai/libs/iai_core_py/tests/repos/mappers/test_static_mappers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def test_label_mapper(self) -> None:
327327
is_empty=True,
328328
id_=LabelRepo.generate_id(),
329329
is_anomalous=True,
330+
is_background=True,
330331
ephemeral=False,
331332
)
332333
verify_mongo_mapper(entity_to_map=label, mapper_class=LabelToMongo)

0 commit comments

Comments
 (0)