Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTE_SDK] CVS-78747 rename .id to .id_ #925

Merged
merged 16 commits into from
Feb 24, 2022
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
48 changes: 35 additions & 13 deletions ote_sdk/ote_sdk/entities/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Annotation(metaclass=abc.ABCMeta):
def __init__(
self, shape: ShapeEntity, labels: List[ScoredLabel], id: Optional[ID] = None
):
self.__id = ID(ObjectId()) if id is None else id
self.__id_ = ID(ObjectId()) if id is None else id
self.__shape = shape
self.__labels = labels

Expand All @@ -35,19 +35,29 @@ def __repr__(self):
f"{self.__class__.__name__}("
f"shape={self.shape}, "
f"labels={self.get_labels(True)}, "
f"id={self.id})"
f"id={self.id_})"
)

@property
def id(self):
def id_(self):
"""
Returns the id for the annotation
"""
return self.__id
return self.__id_

@id_.setter
def id_(self, value):
self.__id_ = value

@property
def id(self):
"""DEPRECATED"""
return self.__id_

@id.setter
def id(self, value):
self.__id = value
"""DEPRECATED"""
self.__id_ = value

@property
def shape(self):
Expand Down Expand Up @@ -79,7 +89,9 @@ def get_label_ids(self, include_empty: bool = False) -> Set[ID]:
:return: Set of label id's in annotation
"""
return {
label.id for label in self.__labels if include_empty or (not label.is_empty)
label.id_
for label in self.__labels
if include_empty or (not label.is_empty)
}

def append_label(self, label: ScoredLabel):
Expand All @@ -101,7 +113,7 @@ def set_labels(self, labels: List[ScoredLabel]):
def __eq__(self, other):
if isinstance(other, Annotation):
return (
self.id == other.id
self.id_ == other.id_
and self.get_labels(True) == other.get_labels(True)
and self.shape == other.shape
)
Expand Down Expand Up @@ -163,7 +175,7 @@ def __init__(
self.__kind = kind
self.__editor = editor
self.__creation_date = now() if creation_date is None else creation_date
self.__id = ID() if id is None else id
self.__id_ = ID() if id is None else id

def __repr__(self):
return (
Expand All @@ -172,19 +184,29 @@ def __repr__(self):
f"kind={self.kind}, "
f"editor={self.editor_name}, "
f"creation_date={self.creation_date}, "
f"id={self.id})"
f"id={self.id_})"
)

@property
def id(self):
def id_(self):
"""
Returns the ID of the AnnotationSceneEntity.
"""
return self.__id
return self.__id_

@id_.setter
def id_(self, value):
self.__id_ = value

@property
def id(self):
"""DEPRECATED"""
return self.__id_

@id.setter
def id(self, value):
self.__id = value
"""DEPRECATED"""
self.__id_ = value

@property
def kind(self):
Expand Down Expand Up @@ -279,7 +301,7 @@ def get_labels(self, include_empty: bool = False) -> List[LabelEntity]:
labels: Dict[str, LabelEntity] = {}
for annotation in self.annotations:
for label in annotation.get_labels(include_empty):
id_ = label.id
id_ = label.id_
if id_ not in labels:
labels[id_] = label.get_label()
return list(labels.values())
Expand Down
2 changes: 1 addition & 1 deletion ote_sdk/ote_sdk/entities/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def with_empty_annotations(

# reset ROI
roi = copy.copy(dataset_item.roi)
roi.id = ID(ObjectId())
roi.id_ = ID(ObjectId())
roi.set_labels([])

new_dataset_item = DatasetItemEntity(
Expand Down
26 changes: 18 additions & 8 deletions ote_sdk/ote_sdk/entities/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
self._domain = domain
self._is_empty = is_empty
self._creation_date = creation_date
self._id = id
self.__id_ = id
self.is_anomalous = is_anomalous

@property
Expand Down Expand Up @@ -164,26 +164,36 @@ def creation_date(self) -> datetime.datetime:
return self._creation_date

@property
def id(self) -> ID:
def id_(self) -> ID:
"""
Returns the label id.
"""
return self._id
return self.__id_

@id_.setter
def id_(self, value: ID):
self.__id_ = value

@property
def id(self) -> ID:
"""DEPRECATED"""
return self.__id_

@id.setter
def id(self, value: ID):
self._id = value
"""DEPRECATED"""
self.__id_ = value

def __repr__(self):
return (
f"LabelEntity({self.id}, name={self.name}, hotkey={self.hotkey}, "
f"LabelEntity({self.id_}, name={self.name}, hotkey={self.hotkey}, "
f"domain={self.domain}, color={self.color})"
)

def __eq__(self, other):
if isinstance(other, LabelEntity):
return (
self.id == other.id
self.id_ == other.id_
and self.name == other.name
and self.color == other.color
and self.hotkey == other.hotkey
Expand All @@ -194,12 +204,12 @@ def __eq__(self, other):

def __lt__(self, other):
if isinstance(other, LabelEntity):
return self.id < other.id
return self.id_ < other.id_
return False

def __gt__(self, other):
if isinstance(other, LabelEntity):
return self.id > other.id
return self.id_ > other.id_
return False

def __hash__(self):
Expand Down
24 changes: 17 additions & 7 deletions ote_sdk/ote_sdk/entities/label_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,29 @@ def __init__(
group_type: LabelGroupType = LabelGroupType.EXCLUSIVE,
id: ID = None,
):
self.id = ID(ObjectId()) if id is None else id
self.id_ = ID(ObjectId()) if id is None else id

self.labels = sorted(labels, key=lambda x: x.id)
self.labels = sorted(labels, key=lambda x: x.id_)
self.name = name
self.group_type = group_type

@property
def id(self) -> ID:
"""DEPRECATED"""
return self.id_

@id.setter
def id(self, value: ID):
"""DEPRECATED"""
self.id_ = value

@property
def minimum_label_id(self) -> ID:
"""
Returns the minimum (oldest) label ID, which is the first label in self.labels
since this list is sorted
"""
return self.labels[0].id
return self.labels[0].id_

def remove_label(self, label: LabelEntity) -> None:
"""
Expand All @@ -87,14 +97,14 @@ def is_single_label(self) -> bool:
def __eq__(self, other: object):
if not isinstance(other, LabelGroup):
return False
return self.id == other.id and (
return self.id_ == other.id_ and (
set(self.labels) == set(other.labels)
and self.group_type == other.group_type
)

def __repr__(self) -> str:
return (
f"LabelGroup(id={self.id}, name={self.name}, group_type={self.group_type},"
f"LabelGroup(id={self.id_}, name={self.name}, group_type={self.group_type},"
f" labels={self.labels})"
)

Expand Down Expand Up @@ -316,7 +326,7 @@ def get_labels(self, include_empty) -> List[LabelEntity]:
for label in group.labels
if include_empty or not label.is_empty
}
return sorted(list(labels), key=lambda x: x.id)
return sorted(list(labels), key=lambda x: x.id_)

def get_groups(self, include_empty: bool = False) -> List[LabelGroup]:
"""
Expand Down Expand Up @@ -371,7 +381,7 @@ def get_label_ids(self, include_empty) -> List[ID]:
:param include_empty: Include empty label id or not
"""
label_ids = {
label.id
label.id_
for group in self._groups
for label in group.labels
if include_empty or not label.is_empty
Expand Down
20 changes: 15 additions & 5 deletions ote_sdk/ote_sdk/entities/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(
if model_adapters is None:
model_adapters = {}

self.__id = _id
self.__id_ = _id
self.__creation_date = creation_date
self.__train_dataset = train_dataset
self.__previous_trained_revision = previous_trained_revision
Expand All @@ -161,13 +161,23 @@ def __init__(
self.__model_size_reduction = model_size_reduction

@property
def id(self) -> ID:
def id_(self) -> ID:
"""Gets or sets the id of a Model"""
return self.__id
return self.__id_

@id_.setter
def id_(self, value: ID):
self.__id_ = value

@property
def id(self) -> ID:
"""DEPRECATED"""
return self.__id_

@id.setter
def id(self, value: ID):
self.__id = value
"""DEPRECATED"""
self.__id_ = value

@property
def configuration(self) -> ModelConfiguration:
Expand Down Expand Up @@ -458,7 +468,7 @@ def is_optimized(self) -> bool:
def __eq__(self, other):
if isinstance(other, ModelEntity):
return (
self.id == other.id
self.id_ == other.id_
and self.train_dataset == other.train_dataset
and self.performance == other.performance
)
Expand Down
22 changes: 16 additions & 6 deletions ote_sdk/ote_sdk/entities/resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
id = ID() if id is None else id
performance = NullPerformance() if performance is None else performance
creation_date = now() if creation_date is None else creation_date
self.__id = id
self.__id_ = id
self.__model = model
self.__prediction_dataset = prediction_dataset
self.__ground_truth_dataset = ground_truth_dataset
Expand All @@ -89,13 +89,23 @@ def __init__(
self.__creation_date = creation_date

@property
def id(self) -> ID:
def id_(self) -> ID:
"""Returns the id of the ResultSet"""
return self.__id
return self.__id_

@id_.setter
def id_(self, value: ID) -> None:
self.__id_ = value

@property
def id(self) -> ID:
"""DEPRECATED"""
return self.__id_

@id.setter
def id(self, value: ID) -> None:
self.__id = value
def id(self, value: ID):
"""DEPRECATED"""
self.__id_ = value

@property
def model(self) -> ModelEntity:
Expand Down Expand Up @@ -170,5 +180,5 @@ def __repr__(self):
f"purpose={self.purpose}, "
f"performance={self.performance}, "
f"creation_date={self.creation_date}, "
f"id={self.id})"
f"id={self.id_})"
)
11 changes: 8 additions & 3 deletions ote_sdk/ote_sdk/entities/scored_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ def name(self) -> str:
return self.label.name

@property
def id(self) -> ID:
def id_(self) -> ID:
"""
Returns the label id.
"""
return self.label.id_

@property
def id(self) -> ID:
"""DEPRECATED"""
return self.label.id

@property
Expand Down Expand Up @@ -80,14 +85,14 @@ def get_label(self) -> LabelEntity:

def __repr__(self):
return (
f"ScoredLabel({self.id}, name={self.name}, probability={self.probability}, "
f"ScoredLabel({self.id_}, name={self.name}, probability={self.probability}, "
f"domain={self.domain}, color={self.color}, hotkey={self.hotkey})"
)

def __eq__(self, other):
if isinstance(other, ScoredLabel):
return (
self.id == other.id
self.id_ == other.id_
and self.name == other.name
and self.color == other.color
and self.hotkey == other.hotkey
Expand Down
Loading