Skip to content

Commit

Permalink
Added a getter and a setter for __metadata of DatasetItemEntity. Upda…
Browse files Browse the repository at this point in the history
…ted the tests as well.
  • Loading branch information
A-Artemis committed May 19, 2022
1 parent c49a6fd commit fcf4925
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
15 changes: 11 additions & 4 deletions ote_sdk/ote_sdk/entities/dataset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ def __init__(
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: List[MetadataItemEntity]):
"""
Sets the metadata
"""
self.__metadata = metadata

def get_metadata(self) -> List[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
]
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def check_configurable_integer(
assert integer_instance._default == 100
assert integer_instance.type == int
assert len(integer_instance._validator._validators) == 2
assert integer_instance.metadata == expected_metadata
assert integer_instance.get_metadata() == expected_metadata

# Checking _CountingAttr object returned by "configurable_integer" for default values of optional parameters
default_value = 100
Expand Down Expand Up @@ -243,7 +243,7 @@ def check_configurable_float(
assert isinstance(float_instance, _make._CountingAttr)
assert float_instance._default == 100.1
assert float_instance.type == float
assert float_instance.metadata == expected_metadata
assert float_instance.get_metadata() == expected_metadata

# Checking _CountingAttr object returned by "configurable_float" for default values of optional parameters
default_value = 100.1
Expand Down Expand Up @@ -343,7 +343,7 @@ def check_configurable_boolean(
boolean_instance._validator, validators._InstanceOfValidator # type: ignore
)
assert boolean_instance._validator.type == bool
assert boolean_instance.metadata == expected_metadata
assert boolean_instance.get_metadata() == expected_metadata

# Checking _CountingAttr object returned by "configurable_boolean" for default values of optional parameters
default_value = True
Expand Down Expand Up @@ -435,7 +435,7 @@ def check_float_selectable(
assert isinstance(float_selectable_instance, _make._CountingAttr)
assert float_selectable_instance._default
assert float_selectable_instance.type == float
assert float_selectable_instance.metadata == expected_metadata
assert float_selectable_instance.get_metadata() == expected_metadata

# Checking _CountingAttr object returned by "float_selectable" for default values of optional parameters
default_value = 0.1
Expand Down Expand Up @@ -534,7 +534,7 @@ def check_selectable(
assert isinstance(selectable_instance, _make._CountingAttr)
assert selectable_instance._default == SomeEnumSelectable.OPTION_C
assert selectable_instance.type == ConfigurableEnum
assert selectable_instance.metadata == expected_metadata
assert selectable_instance.get_metadata() == expected_metadata

# Checking _CountingAttr object returned by "selectable" for default values of optional parameters
default_value = SomeEnumSelectable.OPTION_C
Expand Down
4 changes: 2 additions & 2 deletions ote_sdk/ote_sdk/tests/configuration/helper/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_gather_parameter_arguments_and_values_from_dict(self):
)
assert isinstance(argument, _make._CountingAttr)
assert argument.type == int
metadata = argument.metadata
metadata = argument.get_metadata()
assert metadata.get("default_value") == 70
assert metadata.get("description") == "Default integer description"
assert metadata.get("header") == "non selectable parameter header"
Expand All @@ -492,7 +492,7 @@ def test_gather_parameter_arguments_and_values_from_dict(self):
argument = arguments_and_values_dict.get("make_arguments").get("selectable")
assert isinstance(argument, _make._CountingAttr)
assert argument.type == ConfigurableEnum
metadata = argument.metadata
metadata = argument.get_metadata()
assert type(metadata.get("default_value")).__name__ == "test enum"
assert metadata.get("default_value").name == "test_2"
assert metadata.get("default_value").value == 2
Expand Down
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.get_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 = list(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 list(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 list(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 = list(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
14 changes: 7 additions & 7 deletions ote_sdk/ote_sdk/tests/entities/test_task_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_compare_learning_parameters_num_workers(self):
env.get_hyper_parameters().learning_parameters.num_workers
) # "default_value"
config_example_learning_parameters_num_workers = (
config_example.learning_parameters._default.factory.num_workers.metadata[
config_example.learning_parameters._default.factory.num_workers.get_metadata()[
"default_value"
]
)
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_compare_learning_parameters_batch_size(self):
env.get_hyper_parameters().learning_parameters.batch_size
) # "default_value"
config_example_learning_parameters_batch_size = (
config_example.learning_parameters._default.factory.batch_size.metadata[
config_example.learning_parameters._default.factory.batch_size.get_metadata()[
"default_value"
]
)
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_compare_learning_parameters_num_iters(self):
env.get_hyper_parameters().learning_parameters.num_iters
) # "default_value"
config_example_learning_parameters_num_iters = (
config_example.learning_parameters._default.factory.num_iters.metadata[
config_example.learning_parameters._default.factory.num_iters.get_metadata()[
"default_value"
]
)
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_compare_learning_parameters_learning_rate(self):
env.get_hyper_parameters().learning_parameters.learning_rate
) # "default_value"
config_example_learning_parameters_learning_rate = (
config_example.learning_parameters._default.factory.learning_rate.metadata[
config_example.learning_parameters._default.factory.learning_rate.get_metadata()[
"default_value"
]
)
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_compare_learning_parameters_num_checkpoints(self):
# Attempt to access the missing parameter in ConfigExample
with pytest.raises(AttributeError):
# AttributeError: type object '__LearningParameters' has no attribute 'num_checkpoints'
config_example.learning_parameters._default.factory.num_checkpoints.metadata[
config_example.learning_parameters._default.factory.num_checkpoints.get_metadata()[
"default_value"
]

Expand Down Expand Up @@ -368,7 +368,7 @@ def test_compare_postprocessing_confidence_threshold(self):
)
cep = config_example.postprocessing
config_example_postprocessing_confidence_threshold = (
cep._default.factory.confidence_threshold.metadata["default_value"]
cep._default.factory.confidence_threshold.get_metadata()["default_value"]
)

# From dummy_config.yaml because it is missing in dummy_template.yaml "parameter_overrides"
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_compare_postprocessing_result_based_confidence_threshold(self):
cep = config_example.postprocessing
def_factory = cep._default.factory
rbct = def_factory.result_based_confidence_threshold
config_example_postprocessing_result_based_confidence_threshold = rbct.metadata[
config_example_postprocessing_result_based_confidence_threshold = rbct.get_metadata()[
"default_value"
]

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

0 comments on commit fcf4925

Please sign in to comment.