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

Added a getter and a setter for __metadata #1114

Merged
merged 2 commits into from
May 23, 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
19 changes: 13 additions & 6 deletions ote_sdk/ote_sdk/entities/dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,24 @@ def __init__(
break
self.__roi = roi

self.__metadata: List[MetadataItemEntity] = []
self.__metadata: Sequence[MetadataItemEntity] = []
if metadata is not None:
self.__metadata = list(metadata)
self.__metadata = metadata

self.__ignored_labels: Set[LabelEntity] = (
set() if ignored_labels is None else set(ignored_labels)
)

@property
def metadata(self) -> Sequence[MetadataItemEntity]:
"""Provides access to metadata."""
def set_metadata(self, metadata: Sequence[MetadataItemEntity]):
"""
Sets the metadata
"""
self.__metadata = metadata

def get_metadata(self) -> Sequence[MetadataItemEntity]:
"""
Returns the metadata
"""
return self.__metadata

@property
Expand Down Expand Up @@ -486,6 +493,6 @@ def get_metadata_by_name_and_model(
"""
return [
meta
for meta in self.metadata
for meta in self.get_metadata()
if meta.data.name == name and meta.model == model
]
16 changes: 8 additions & 8 deletions ote_sdk/ote_sdk/tests/entities/test_dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ def test_dataset_item_initialization(self):
default_values_dataset_item = DatasetItemEntity(media, annotations_scene)
assert default_values_dataset_item.media == media
assert default_values_dataset_item.annotation_scene == annotations_scene
assert not default_values_dataset_item.metadata
assert not default_values_dataset_item.get_metadata()
assert default_values_dataset_item.subset == Subset.NONE
assert default_values_dataset_item.ignored_labels == set()
# Checking attributes of DatasetItemEntity object initialized with specified optional parameters
roi = DatasetItemParameters().roi()
metadata = DatasetItemParameters.metadata()
metadata = DatasetItemParameters.metadata
subset = Subset.TESTING
ignored_labels = set(DatasetItemParameters().labels())
specified_values_dataset_item = DatasetItemEntity(
Expand All @@ -268,7 +268,7 @@ def test_dataset_item_initialization(self):
assert specified_values_dataset_item.media == media
assert specified_values_dataset_item.annotation_scene == annotations_scene
assert specified_values_dataset_item.roi == roi
assert specified_values_dataset_item.metadata == metadata
assert specified_values_dataset_item.get_metadata() == metadata
assert specified_values_dataset_item.subset == subset
assert specified_values_dataset_item.ignored_labels == ignored_labels

Expand Down Expand Up @@ -923,7 +923,7 @@ def test_dataset_item_deepcopy(self):
dataset_item.annotation_scene.shapes == copy_dataset.annotation_scene.shapes
)
assert dataset_item.roi == copy_dataset.roi
assert dataset_item.metadata == copy_dataset.metadata
assert dataset_item.get_metadata() == copy_dataset.get_metadata()
assert dataset_item.subset == copy_dataset.subset

@pytest.mark.priority_medium
Expand All @@ -946,15 +946,15 @@ def test_dataset_item_append_metadata_item(self):
2. Check "metadata" attribute after "append_metadata_item" method with specified "model" parameter
"""
dataset_item = DatasetItemParameters().dataset_item()
expected_metadata = list(dataset_item.metadata)
expected_metadata = dataset_item.get_metadata()
# Checking metadata attribute returned after "append_metadata_item" method with non-specified "model" parameter
data_to_append = TensorEntity(
name="appended_metadata",
numpy=np.random.uniform(low=0.0, high=255.0, size=(10, 15, 3)),
)
expected_metadata.append(MetadataItemEntity(data=data_to_append))
dataset_item.append_metadata_item(data=data_to_append)
assert list(dataset_item.metadata) == expected_metadata
assert dataset_item.get_metadata() == expected_metadata
# Checking metadata attribute returned after "append_metadata_item" method with specified "model" parameter
metadata_item_with_model = self.metadata_item_with_model()
data_to_append = metadata_item_with_model.data
Expand All @@ -964,7 +964,7 @@ def test_dataset_item_append_metadata_item(self):
)
expected_metadata.append(new_metadata_item_with_model)
dataset_item.append_metadata_item(data_to_append, model_to_append)
assert list(dataset_item.metadata) == expected_metadata
assert dataset_item.get_metadata() == expected_metadata

@pytest.mark.priority_medium
@pytest.mark.unit
Expand Down Expand Up @@ -992,7 +992,7 @@ def test_dataset_item_get_metadata_by_name_and_model(self):
metadata_item_with_model = self.metadata_item_with_model()
dataset_model = metadata_item_with_model.model
dataset_item.append_metadata_item(metadata_item_with_model.data, dataset_model)
dataset_metadata = list(dataset_item.metadata)
dataset_metadata = dataset_item.get_metadata()
# Checking "get_metadata_by_name_and_model" method for "model" parameter is "None"
assert dataset_item.get_metadata_by_name_and_model("test_metadata", None) == [
dataset_metadata[0]
Expand Down
2 changes: 1 addition & 1 deletion ote_sdk/ote_sdk/tests/entities/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_imetadata(self):

test_instance = IMetadata()
assert isinstance(test_instance, IMetadata)
assert str(test_instance.name) == "typing.Union[str, NoneType]"
assert str(test_instance.name) == "typing.Optional[str]"

test_instance.name = "String"
assert test_instance.name == "String"
Expand Down
4 changes: 2 additions & 2 deletions ote_sdk/ote_sdk/utils/dataset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_local_subset(
local_annotations,
kind=item.annotation_scene.kind,
),
metadata=item.metadata,
metadata=item.get_metadata(),
subset=item.subset,
roi=item.roi,
ignored_labels=item.ignored_labels,
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_global_subset(dataset: DatasetEntity) -> DatasetEntity:
annotation_scene=AnnotationSceneEntity(
global_annotations, kind=item.annotation_scene.kind
),
metadata=item.metadata,
metadata=item.get_metadata(),
subset=item.subset,
roi=item.roi,
ignored_labels=item.ignored_labels,
Expand Down