Skip to content

Commit

Permalink
Add model category attributes to model template (#2439)
Browse files Browse the repository at this point in the history
Add model category attributes to model template

* Add model category & status fields in model template

* Add is_default_for_task attr to model template

* Update model templates with category attrs

* Add integration tests for model templates consistency

* Fix license & doc string

* Fix typo

* Refactor test cases

* Refactor common tests by generator

---------
Signed-off-by: Songki Choi <[email protected]>
  • Loading branch information
goodsong81 authored and sungchul2 committed Aug 22, 2023
1 parent ded91a7 commit 1889b8c
Show file tree
Hide file tree
Showing 30 changed files with 286 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ training_targets:
# Computational Complexity
gigaflops: 3.9
size: 168.4

# Model spec
model_category: SPEED
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ training_targets:
# Computational Complexity
gigaflops: 5.6
size: 21.1

# Model spec
model_category: ACCURACY
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ training_targets:
# Computational Complexity
gigaflops: 3.9
size: 168.4

# Model spec
model_category: SPEED
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ training_targets:
# Computational Complexity
gigaflops: 5.6
size: 21.1

# Model spec
model_category: ACCURACY
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ training_targets:
# Computational Complexity
gigaflops: 3.9
size: 168.4

# Model spec
model_category: SPEED
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ training_targets:
# Computational Complexity
gigaflops: 5.6
size: 21.1

# Model spec
model_category: ACCURACY
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ training_targets:
# Stats.
gigaflops: 0.81
size: 4.09

# Model spec
model_category: BALANCE
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ training_targets:
# Stats.
gigaflops: 5.76
size: 20.23

# Model spec
model_category: ACCURACY
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ training_targets:
# Stats.
gigaflops: 0.44
size: 4.29

# Model spec
model_category: SPEED
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ training_targets:
# Stats.
gigaflops: 6.5
size: 20.4
# # Inference options. Defined by OpenVINO capabilities, not Algo Backend or Platform.
# inference_targets:
# - CPU
# - GPU
# - VPU

# Model spec
model_category: SPEED
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ training_targets:
# Stats.
gigaflops: 20.6
size: 9.1
# # Inference options. Defined by OpenVINO capabilities, not Algo Backend or Platform.
# inference_targets:
# - CPU
# - GPU
# - VPU

# Model spec
model_category: ACCURACY
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ training_targets:
# Stats.
gigaflops: 9.4
size: 7.6
# # Inference options. Defined by OpenVINO capabilities, not Algo Backend or Platform.
# inference_targets:
# - CPU
# - GPU
# - VPU

# Model spec
model_category: BALANCE
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ training_targets:
# Stats.
gigaflops: 68.48
size: 13.27

# Model spec
model_category: SPEED
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ training_targets:
# Stats.
gigaflops: 533.8
size: 177.9

# Model spec
model_category: ACCURACY
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ training_targets:
# Stats.
gigaflops: 68.48
size: 13.27

# Model spec
model_category: SPEED
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ training_targets:
# Stats.
gigaflops: 533.8
size: 177.9

# Model spec
model_category: ACCURACY
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ training_targets:
# Stats.
gigaflops: 3.63
size: 4.8

# Model spec
model_category: BALANCE
is_default_for_task: true
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ training_targets:
# Stats.
gigaflops: 1.82
size: 3.5

# Model spec
model_category: SPEED
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ training_targets:
# Stats.
gigaflops: 13.97
size: 6.4

# Model spec
model_category: ACCURACY
32 changes: 31 additions & 1 deletion src/otx/api/entities/model_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This file defines the ModelConfiguration, ModelEntity and Model classes."""

# Copyright (C) 2021-2022 Intel Corporation
# Copyright (C) 2021-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import copy
Expand Down Expand Up @@ -459,6 +459,30 @@ class EntryPoints:
nncf: Optional[str] = None


class ModelCategory(Enum):
"""Represents model category regarding accuracy & speed trade-off."""

SPEED = auto()
BALANCE = auto()
ACCURACY = auto()
OTHER = auto()

def __str__(self) -> str:
"""Returns the name of the model category."""
return str(self.name)


class ModelStatus(Enum):
"""Represents model status regarding deprecation process."""

ACTIVE = auto()
DEPRECATED = auto()

def __str__(self) -> str:
"""Returns the name of the model status."""
return str(self.name)


# pylint: disable=too-many-instance-attributes
@dataclass
class ModelTemplate:
Expand Down Expand Up @@ -499,6 +523,9 @@ class ModelTemplate:
priority. mobilenet is less important, and has a higher value. Default is zero (the highest priority).
gigaflops (float): how many billions of operations are required to do inference on a single data item.
size (float): how much disk space the model will approximately take.
model_category (ModelCategory): Represents model category regarding accuracy & speed trade-off. Default to OTHER.
model_status (ModelStatus): Represents model status regarding deprecation process. Default to ACTIVE.
is_default_for_task (bool): Whether this model is a default recommendation for the task
"""

model_template_id: str
Expand Down Expand Up @@ -528,6 +555,9 @@ class ModelTemplate:
gigaflops: float = 0
size: float = 0
hpo: Optional[Dict] = None
model_category: ModelCategory = ModelCategory.OTHER
model_status: ModelStatus = ModelStatus.ACTIVE
is_default_for_task: bool = False

def __post_init__(self):
"""Do sanitation checks before loading the hyper-parameters."""
Expand Down
20 changes: 7 additions & 13 deletions tests/integration/cli/anomaly/test_anomaly_classification.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
"""Tests for anomaly classification with OTX CLI"""

# Copyright (C) 2021 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
# Copyright (C) 2021-2023 Intel Corporation
# SPDX-License-Identifier: Apache-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.

import os

import pytest

from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -28,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
generate_model_template_testing,
)

args = {
Expand All @@ -44,6 +35,9 @@
templates_ids = [template.model_template_id for template in templates]


TestAnomalyClassificationModelTemplates = generate_model_template_testing(templates)


class TestToolsAnomalyClassification:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
Expand Down
20 changes: 7 additions & 13 deletions tests/integration/cli/anomaly/test_anomaly_detection.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
"""Tests for anomaly detection with OTX CLI."""

# Copyright (C) 2021 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
# Copyright (C) 2021-2023 Intel Corporation
# SPDX-License-Identifier: Apache-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.

import os

import pytest

from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -28,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
generate_model_template_testing,
)

args = {
Expand All @@ -44,6 +35,9 @@
templates_ids = [template.model_template_id for template in templates]


TestAnomalyDetectionModelTemplates = generate_model_template_testing(templates)


class TestToolsAnomalyDetection:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
Expand Down
20 changes: 7 additions & 13 deletions tests/integration/cli/anomaly/test_anomaly_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
"""Tests for anomaly segmentation with OTX CLI"""

# Copyright (C) 2021 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
# Copyright (C) 2021-2023 Intel Corporation
# SPDX-License-Identifier: Apache-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.

import os

import pytest

from otx.api.entities.model_template import parse_model_template
from otx.cli.registry import Registry
from tests.test_suite.e2e_test_system import e2e_pytest_component
from tests.test_suite.run_test_command import (
Expand All @@ -28,6 +18,7 @@
otx_eval_testing,
otx_export_testing,
otx_train_testing,
generate_model_template_testing,
)

args = {
Expand All @@ -44,6 +35,9 @@
templates_ids = [template.model_template_id for template in templates]


TestAnomalySegmentationModelTemplates = generate_model_template_testing(templates)


class TestToolsAnomalySegmentation:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates, ids=templates_ids)
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/cli/classification/test_classification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for Classification with OTX CLI"""
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2022-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

Expand Down Expand Up @@ -30,6 +30,7 @@
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
generate_model_template_testing,
)

# Pre-train w/ 'label_0', 'label_1', 'label_2' classes
Expand Down Expand Up @@ -82,6 +83,9 @@
templates_ids = [template.model_template_id for template in templates]


TestClassificationModelTemplates = generate_model_template_testing(templates)


class TestMultiClassClassificationCLI:
@e2e_pytest_component
@pytest.mark.parametrize("template", default_templates, ids=default_templates_ids)
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/cli/detection/test_detection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for Class-Incremental Learning for object detection with OTX CLI"""
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2022-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
import copy
Expand Down Expand Up @@ -28,6 +28,7 @@
otx_hpo_testing,
otx_resume_testing,
otx_train_testing,
generate_model_template_testing,
)

args = {
Expand Down Expand Up @@ -81,6 +82,9 @@
templates_ids_w_experimental = templates_ids + experimental_template_ids


TestDetectionModelTemplates = generate_model_template_testing(templates)


class TestDetectionCLI:
@e2e_pytest_component
@pytest.mark.parametrize("template", templates_w_experimental, ids=templates_ids_w_experimental)
Expand Down
Loading

0 comments on commit 1889b8c

Please sign in to comment.