Skip to content

Commit

Permalink
moved mmdetection params validation tests to training_extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
saltykox committed Mar 21, 2022
1 parent b5f6621 commit 5ba02cc
Show file tree
Hide file tree
Showing 11 changed files with 2,981 additions and 0 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Copyright (C) 2021-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

import pytest

from mmdet.apis.ote.apis.detection.inference_task import OTEDetectionInferenceTask
from ote_sdk.configuration.configurable_parameters import ConfigurableParameters
from ote_sdk.entities.datasets import DatasetEntity
from ote_sdk.entities.inference_parameters import InferenceParameters
from ote_sdk.entities.label_schema import LabelSchemaEntity
from ote_sdk.entities.model import ModelConfiguration, ModelEntity
from ote_sdk.entities.resultset import ResultSetEntity
from ote_sdk.test_suite.e2e_test_system import e2e_pytest_unit
from ote_sdk.tests.parameters_validation.validation_helper import (
check_value_error_exception_raised,
)
from ote_sdk.usecases.tasks.interfaces.export_interface import ExportType


class MockDetectionInferenceTask(OTEDetectionInferenceTask):
def __init__(self):
pass


class TestInferenceTaskInputParamsValidation:
@staticmethod
def model():
model_configuration = ModelConfiguration(
configurable_parameters=ConfigurableParameters(
header="header", description="description"
),
label_schema=LabelSchemaEntity(),
)
return ModelEntity(
train_dataset=DatasetEntity(), configuration=model_configuration
)

@e2e_pytest_unit
def test_ote_detection_inference_task_init_params_validation(self):
"""
<b>Description:</b>
Check OTEDetectionInferenceTask object initialization parameters validation
<b>Input data:</b>
"task_environment" non-TaskEnvironment object
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
OTEDetectionInferenceTask object initialization parameter
"""
with pytest.raises(ValueError):
OTEDetectionInferenceTask(task_environment="unexpected string") # type: ignore

@e2e_pytest_unit
def test_ote_detection_inference_task_infer_params_validation(self):
"""
<b>Description:</b>
Check OTEDetectionInferenceTask object "infer" method input parameters validation
<b>Input data:</b>
OTEDetectionInferenceTask object. "infer" method unexpected-type input parameters
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "infer" method
"""
task = MockDetectionInferenceTask()
correct_values_dict = {
"dataset": DatasetEntity(),
"inference_parameters": InferenceParameters(),
}
unexpected_str = "unexpected string"
unexpected_values = [
# Unexpected string is specified as "dataset" parameter
("dataset", unexpected_str),
# Unexpected string is specified as "inference_parameters" parameter
("inference_parameters", unexpected_str),
]

check_value_error_exception_raised(
correct_parameters=correct_values_dict,
unexpected_values=unexpected_values,
class_or_function=task.infer,
)

@e2e_pytest_unit
def test_ote_detection_inference_task_evaluate_params_validation(self):
"""
<b>Description:</b>
Check OTEDetectionInferenceTask object "evaluate" method input parameters validation
<b>Input data:</b>
OTEDetectionInferenceTask object. "evaluate" method unexpected-type input parameters
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "evaluate" method
"""
task = MockDetectionInferenceTask()
model = self.model()
result_set = ResultSetEntity(
model=model,
ground_truth_dataset=DatasetEntity(),
prediction_dataset=DatasetEntity(),
)
correct_values_dict = {
"output_result_set": result_set,
"evaluation_metric": "metric",
}
unexpected_int = 1
unexpected_values = [
# Unexpected integer is specified as "output_result_set" parameter
("output_result_set", unexpected_int),
# Unexpected integer is specified as "evaluation_metric" parameter
("evaluation_metric", unexpected_int),
]

check_value_error_exception_raised(
correct_parameters=correct_values_dict,
unexpected_values=unexpected_values,
class_or_function=task.evaluate,
)

@e2e_pytest_unit
def test_ote_detection_inference_task_export_params_validation(self):
"""
<b>Description:</b>
Check OTEDetectionInferenceTask object "export" method input parameters validation
<b>Input data:</b>
OTEDetectionInferenceTask object. "export" method unexpected-type input parameters
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "export" method
"""
task = MockDetectionInferenceTask()
model = self.model()
correct_values_dict = {
"export_type": ExportType.OPENVINO,
"output_model": model,
}
unexpected_str = "unexpected string"
unexpected_values = [
# Unexpected string is specified as "export_type" parameter
("export_type", unexpected_str),
# Unexpected string is specified as "output_model" parameter
("output_model", unexpected_str),
]

check_value_error_exception_raised(
correct_parameters=correct_values_dict,
unexpected_values=unexpected_values,
class_or_function=task.export,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Copyright (C) 2021-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

import numpy as np
import pytest
from mmdet.apis.ote.extension.datasets.mmdataset import (
OTEDataset,
get_annotation_mmdet_format,
)

from ote_sdk.entities.annotation import (
Annotation,
AnnotationSceneEntity,
AnnotationSceneKind,
)
from ote_sdk.entities.dataset_item import DatasetItemEntity
from ote_sdk.entities.datasets import DatasetEntity
from ote_sdk.entities.image import Image
from ote_sdk.entities.label import Domain, LabelEntity
from ote_sdk.entities.scored_label import ScoredLabel
from ote_sdk.entities.shapes.rectangle import Rectangle
from ote_sdk.test_suite.e2e_test_system import e2e_pytest_unit
from ote_sdk.tests.parameters_validation.validation_helper import (
check_value_error_exception_raised,
)


def label_entity():
return LabelEntity(name="test label", domain=Domain.DETECTION)


def dataset_item():
image = Image(data=np.random.randint(low=0, high=255, size=(10, 16, 3)))
annotation = Annotation(
shape=Rectangle.generate_full_box(), labels=[ScoredLabel(label_entity())]
)
annotation_scene = AnnotationSceneEntity(
annotations=[annotation], kind=AnnotationSceneKind.ANNOTATION
)
return DatasetItemEntity(media=image, annotation_scene=annotation_scene)


class TestMMDatasetFunctionsInputParamsValidation:
@e2e_pytest_unit
def test_get_annotation_mmdet_format_input_params_validation(self):
"""
<b>Description:</b>
Check "get_annotation_mmdet_format" function input parameters validation
<b>Input data:</b>
"get_annotation_mmdet_format" function unexpected-type input parameters
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "get_annotation_mmdet_format" function
"""
label = label_entity()
correct_values_dict = {
"dataset_item": dataset_item(),
"labels": [label],
"domain": Domain.DETECTION,
}
unexpected_int = 1
unexpected_values = [
# Unexpected integer is specified as "dataset_item" parameter
("dataset_item", unexpected_int),
# Unexpected integer is specified as "labels" parameter
("labels", unexpected_int),
# Unexpected integer is specified as nested label
("labels", [label, unexpected_int]),
# Unexpected integer is specified as "domain" parameter
("domain", unexpected_int),
]
check_value_error_exception_raised(
correct_parameters=correct_values_dict,
unexpected_values=unexpected_values,
class_or_function=get_annotation_mmdet_format,
)


class TestOTEDatasetInputParamsValidation:
@staticmethod
def dataset():
pipeline = [{"type": "LoadImageFromFile", "to_float32": True}]
return OTEDataset(
ote_dataset=DatasetEntity(),
labels=[label_entity()],
pipeline=pipeline,
test_mode=True,
domain=Domain.DETECTION,
)

@e2e_pytest_unit
def test_ote_dataset_init_params_validation(self):
"""
<b>Description:</b>
Check OTEDataset object initialization parameters validation
<b>Input data:</b>
OTEDataset object initialization parameters with unexpected type
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
OTEDataset object initialization parameter
"""
label = label_entity()

correct_values_dict = {
"ote_dataset": DatasetEntity(),
"labels": [label],
"pipeline": [{"type": "LoadImageFromFile", "to_float32": True}],
"domain": Domain.DETECTION,
}
unexpected_str = "unexpected string"
unexpected_values = [
# Unexpected string is specified as "ote_dataset" parameter
("ote_dataset", unexpected_str),
# Unexpected string is specified as "labels" parameter
("labels", unexpected_str),
# Unexpected string is specified as nested label
("labels", [label, unexpected_str]),
# Unexpected integer is specified as "pipeline" parameter
("pipeline", 1),
# Unexpected string is specified as nested pipeline
("pipeline", [{"config": 1}, unexpected_str]),
# Unexpected string is specified as "domain" parameter
("domain", unexpected_str),
# Unexpected string is specified as "test_mode" parameter
("test_mode", unexpected_str),
]
check_value_error_exception_raised(
correct_parameters=correct_values_dict,
unexpected_values=unexpected_values,
class_or_function=OTEDataset,
)

@e2e_pytest_unit
def test_ote_dataset_prepare_train_img_params_validation(self):
"""
<b>Description:</b>
Check OTEDataset object "prepare_train_img" method input parameters validation
<b>Input data:</b>
OTEDataset object, "idx" non-integer type parameter
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "prepare_train_img" method
"""
dataset = self.dataset()
with pytest.raises(ValueError):
dataset.prepare_train_img(idx="unexpected string") # type: ignore

@e2e_pytest_unit
def test_ote_dataset_prepare_test_img_params_validation(self):
"""
<b>Description:</b>
Check OTEDataset object "prepare_test_img" method input parameters validation
<b>Input data:</b>
OTEDataset object, "idx" non-integer type parameter
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "prepare_test_img" method
"""
dataset = self.dataset()
with pytest.raises(ValueError):
dataset.prepare_test_img(idx="unexpected string") # type: ignore

@e2e_pytest_unit
def test_ote_dataset_pre_pipeline_params_validation(self):
"""
<b>Description:</b>
Check OTEDataset object "pre_pipeline" method input parameters validation
<b>Input data:</b>
OTEDataset object, "results" unexpected type object
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "pre_pipeline" method
"""
dataset = self.dataset()
unexpected_int = 1
for unexpected_value in [
# Unexpected integer is specified as "results" parameter
unexpected_int,
# Unexpected integer is specified as "results" dictionary key
{"result_1": "some results", unexpected_int: "unexpected results"},
]:
with pytest.raises(ValueError):
dataset.pre_pipeline(results=unexpected_value)

@e2e_pytest_unit
def test_ote_dataset_get_ann_info_params_validation(self):
"""
<b>Description:</b>
Check OTEDataset object "get_ann_info" method input parameters validation
<b>Input data:</b>
OTEDataset object, "idx" non-integer type parameter
<b>Expected results:</b>
Test passes if ValueError exception is raised when unexpected type object is specified as
input parameter for "get_ann_info" method
"""
dataset = self.dataset()
with pytest.raises(ValueError):
dataset.get_ann_info(idx="unexpected string") # type: ignore
Loading

0 comments on commit 5ba02cc

Please sign in to comment.