Skip to content

Commit edd1a8c

Browse files
Add e2e test for visual prompting (#2360)
* (WIP) otx optimize * pre-commit * (WIP) set e2e * Remove nncf config * Add visual prompting requirement * Add visual prompting in tox * Add visual prompting in setup.py * Fix typo * Delete unused configuration.yaml * Edit test_name * Add to limit activation range * Update from `vp` to `visprompt` * Fix about no returning the first label * pre-commit * (WIP) otx optimize * pre-commit * (WIP) set e2e * Remove nncf config * Add visual prompting requirement * Add visual prompting in tox * Add visual prompting in setup.py * Fix typo * pre-commit * Add actions * Update tests/e2e/cli/visual_prompting/test_visual_prompting.py Co-authored-by: Jaeguk Hyun <[email protected]> * Skip PTQ e2e test * Change task name * Remove skipped tc --------- Co-authored-by: Jaeguk Hyun <[email protected]>
1 parent 3d157ab commit edd1a8c

File tree

15 files changed

+229
-247
lines changed

15 files changed

+229
-247
lines changed

.github/workflows/daily.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
test_dir: "tests/e2e/cli/instance_segmentation"
2525
- task: "seg"
2626
test_dir: "tests/e2e/cli/semantic_segmentation"
27+
- task: "visprompt"
28+
test_dir: "tests/e2e/cli/visual_prompting"
2729
name: E2E-Test-py310-${{ matrix.task }}
2830
uses: ./.github/workflows/run_tests_in_tox.yml
2931
with:

.github/workflows/pre_merge.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ jobs:
104104
test_dir: "tests/integration/cli/action"
105105
- task: "ano"
106106
test_dir: "tests/integration/cli/anomaly"
107+
- task: "visprompt"
108+
test_dir: "tests/integration/cli/visual_prompting"
107109
name: Integration-Test-py310-${{ matrix.task }}
108110
# This is what will cancel the job concurrency
109111
concurrency:

requirements/visual_prompting.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2+
# Visual Prompting Requirements.
3+
scikit-image
4+
pytorch-lightning>=1.7.0,<1.10.0

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,18 @@ def _cython_modules():
149149
"base", "openvino", "segmentation",
150150
]
151151
),
152+
"visual_prompting": get_requirements(requirement_files=[
153+
"base", "openvino", "visual_prompting",
154+
]
155+
),
152156
"full": get_requirements(requirement_files=[
153157
"base",
154158
"openvino",
155159
"anomaly",
156160
"classification",
157161
"detection",
158162
"segmentation",
163+
"visual_prompting",
159164
"action",
160165
]
161166
),

src/otx/algorithms/visual_prompting/configs/configuration.yaml

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -85,62 +85,6 @@ learning_parameters:
8585
visible_in_ui: true
8686
warning: null
8787
auto_hpo_state: NOT_POSSIBLE
88-
nncf_optimization:
89-
description: Optimization by NNCF
90-
enable_pruning:
91-
affects_outcome_of: NONE
92-
auto_hpo_state: not_possible
93-
auto_hpo_value: null
94-
default_value: false
95-
description: Enable filter pruning algorithm
96-
editable: true
97-
header: Enable filter pruning algorithm
98-
type: BOOLEAN
99-
ui_rules:
100-
action: DISABLE_EDITING
101-
operator: AND
102-
rules: []
103-
type: UI_RULES
104-
value: false
105-
visible_in_ui: true
106-
warning: null
107-
enable_quantization:
108-
affects_outcome_of: NONE
109-
auto_hpo_state: not_possible
110-
auto_hpo_value: null
111-
default_value: true
112-
description: Enable quantization algorithm
113-
editable: true
114-
header: Enable quantization algorithm
115-
type: BOOLEAN
116-
ui_rules:
117-
action: DISABLE_EDITING
118-
operator: AND
119-
rules: []
120-
type: UI_RULES
121-
value: true
122-
visible_in_ui: true
123-
warning: null
124-
header: Optimization by NNCF
125-
pruning_supported:
126-
affects_outcome_of: TRAINING
127-
auto_hpo_state: not_possible
128-
auto_hpo_value: null
129-
default_value: false
130-
description: Whether filter pruning is supported
131-
editable: false
132-
header: Whether filter pruning is supported
133-
type: BOOLEAN
134-
ui_rules:
135-
action: DISABLE_EDITING
136-
operator: AND
137-
rules: []
138-
type: UI_RULES
139-
value: false
140-
visible_in_ui: false
141-
warning: null
142-
type: PARAMETER_GROUP
143-
visible_in_ui: true
14488
pot_parameters:
14589
description: POT Parameters
14690
header: POT Parameters

src/otx/algorithms/visual_prompting/configs/sam_vit_b/configuration.yaml

Lines changed: 0 additions & 173 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""PTQ config file."""
2+
from nncf.common.quantization.structs import QuantizationPreset
3+
from nncf.quantization.advanced_parameters import AdvancedQuantizationParameters
4+
from nncf.quantization.range_estimator import (
5+
AggregatorType,
6+
RangeEstimatorParameters,
7+
StatisticsCollectorParameters,
8+
StatisticsType,
9+
)
10+
11+
advanced_parameters = AdvancedQuantizationParameters(
12+
activations_range_estimator_params=RangeEstimatorParameters(
13+
min=StatisticsCollectorParameters(
14+
statistics_type=StatisticsType.QUANTILE, aggregator_type=AggregatorType.MIN, quantile_outlier_prob=1e-4
15+
),
16+
max=StatisticsCollectorParameters(
17+
statistics_type=StatisticsType.QUANTILE, aggregator_type=AggregatorType.MAX, quantile_outlier_prob=1e-4
18+
),
19+
),
20+
# backend_params={"use_pot": True},
21+
)
22+
23+
preset = QuantizationPreset.MIXED

src/otx/algorithms/visual_prompting/tasks/openvino.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import nncf
2929
import numpy as np
3030
import openvino.runtime as ov
31+
from addict import Dict as ADDict
3132
from nncf.common.quantization.structs import QuantizationPreset
3233
from openvino.model_api.adapters import OpenvinoAdapter, create_core
3334
from openvino.model_api.models import Model
3435

36+
from otx.algorithms.common.utils import get_default_async_reqs_num, read_py_config
3537
from otx.algorithms.common.utils.ir import check_if_quantized
3638
from otx.algorithms.common.utils.logger import get_logger
37-
from otx.algorithms.common.utils.utils import get_default_async_reqs_num
3839
from otx.algorithms.visual_prompting.adapters.openvino import model_wrappers
3940
from otx.algorithms.visual_prompting.adapters.pytorch_lightning.datasets.dataset import (
4041
OTXVisualPromptingDataset,
@@ -447,13 +448,17 @@ def optimize(
447448
if optimization_parameters is not None:
448449
optimization_parameters.update_progress(10 * i + 35 * (i - 1), None)
449450

450-
stat_subset_size = self.hparams.pot_parameters.stat_subset_size
451-
preset = QuantizationPreset(self.hparams.pot_parameters.preset.name.lower())
452-
453-
compressed_model = nncf.quantize(
454-
ov_model, quantization_dataset, subset_size=min(stat_subset_size, len(data_loader)), preset=preset
451+
optimization_config_path = os.path.join(self._base_dir, "ptq_optimization_config.py")
452+
ptq_config = ADDict()
453+
if os.path.exists(optimization_config_path):
454+
ptq_config = read_py_config(optimization_config_path)
455+
ptq_config.update(
456+
subset_size=min(self.hparams.pot_parameters.stat_subset_size, len(data_loader)),
457+
preset=QuantizationPreset(self.hparams.pot_parameters.preset.name.lower()),
455458
)
456459

460+
compressed_model = nncf.quantize(ov_model, quantization_dataset, **ptq_config)
461+
457462
if optimization_parameters is not None:
458463
optimization_parameters.update_progress(45 * i, None)
459464

src/otx/core/data/adapter/visual_prompting_dataset_adapter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_otx_dataset(self) -> DatasetEntity:
6060
if self.use_mask:
6161
# use masks loaded in datumaro as-is
6262
if self.data_type == "common_semantic_segmentation":
63-
if new_label := self.updated_label_id.get(ann.label, None):
63+
if (new_label := self.updated_label_id.get(ann.label, None)) is not None:
6464
ann.label = new_label
6565
else:
6666
continue
@@ -70,7 +70,7 @@ def get_otx_dataset(self) -> DatasetEntity:
7070
# convert masks to polygons, they will be converted to masks again
7171
datumaro_polygons = MasksToPolygons.convert_mask(ann)
7272
for d_polygon in datumaro_polygons:
73-
if new_label := self.updated_label_id.get(d_polygon.label, None):
73+
if (new_label := self.updated_label_id.get(d_polygon.label, None)) is not None:
7474
d_polygon.label = new_label
7575
else:
7676
continue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright (C) 2023 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
#

0 commit comments

Comments
 (0)