-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Igor Davidyuk <igor.davidyuk@intel.com>
- Loading branch information
1 parent
c8a55e4
commit db859a0
Showing
13 changed files
with
1,112 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
|
||
from enum import Enum | ||
from typing import List, Optional | ||
|
||
from geti_sdk.data_models.label import Label | ||
|
||
|
||
class LabelGroupType(Enum): | ||
"""Enum to indicate the LabelGroupType.""" | ||
|
||
EXCLUSIVE = 1 | ||
EMPTY_LABEL = 2 | ||
|
||
|
||
class LabelGroup: | ||
""" | ||
Representation of a group of labels. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
labels: List[Label], | ||
group_type: LabelGroupType = LabelGroupType.EXCLUSIVE, | ||
id: Optional[str] = None, | ||
) -> None: | ||
""" | ||
Initialize a LabelGroup object. | ||
:param name: The name of the label group. | ||
:param labels: A list of Label objects associated with the group. | ||
:param group_type: The type of the label group. Defaults to LabelGroupType.EXCLUSIVE. | ||
:param id: The ID of the label group. Defaults to None. | ||
""" | ||
self.id = id | ||
self.name = name | ||
self.group_type = group_type | ||
self.labels = sorted(labels, key=lambda label: label.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions | ||
# and limitations under the License. | ||
|
||
from typing import List, Optional | ||
|
||
from geti_sdk.data_models.label import Label | ||
from geti_sdk.data_models.label_group import LabelGroup, LabelGroupType | ||
|
||
|
||
class LabelSchema: | ||
""" | ||
The `LabelSchema` class defines the structure and properties of labels and label groups. | ||
:param label_groups: Optional list of `LabelGroup` objects representing the label groups in the schema | ||
""" | ||
|
||
def __init__(self, label_groups: Optional[List[LabelGroup]] = None) -> None: | ||
""" | ||
Initialize a new instance of the `LabelSchema` class. | ||
:param label_groups: Optional list of `LabelGroup` objects representing the label groups in the schema | ||
""" | ||
self._groups = label_groups | ||
|
||
def get_labels(self, include_empty: bool = False) -> List[Label]: | ||
""" | ||
Get the labels in the label schema. | ||
:param include_empty: Flag determining whether to include empty labels | ||
:return: List of all labels in the label schema | ||
""" | ||
labels = { | ||
label | ||
for group in self._groups | ||
for label in group.labels | ||
if include_empty or not label.is_empty | ||
} | ||
return sorted(list(labels), key=lambda label: label.id) | ||
|
||
def get_groups(self, include_empty: bool = False) -> List[LabelGroup]: | ||
""" | ||
Get the label groups in the label schema. | ||
:param include_empty: Flag determining whether to include empty label groups | ||
:return: List of all label groups in the label schema | ||
""" | ||
if include_empty: | ||
return self._groups | ||
|
||
return [ | ||
group | ||
for group in self._groups | ||
if group.group_type != LabelGroupType.EMPTY_LABEL | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.