Skip to content

Commit 5fbbf11

Browse files
author
Songki Choi
committed
Merge remote-tracking branch 'origin/releases/1.4.0' into fix/f1-auto-thresh
2 parents 2982b1c + 66e8a67 commit 5fbbf11

File tree

21 files changed

+240
-253
lines changed

21 files changed

+240
-253
lines changed

.github/workflows/daily.yml

+2
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

+2
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

+4
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

+5
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/detection/adapters/mmdet/datasets/tiling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ def merge_maps(self, saliency_maps: Union[List[List[np.ndarray]], List[np.ndarra
512512
for cl_map in map:
513513
# find first class map which is not None
514514
if cl_map is not None and dtype is None:
515-
dtype = map[0].dtype
516-
feat_h, feat_w = map[0].shape
515+
dtype = cl_map.dtype
516+
feat_h, feat_w = cl_map.shape
517517
break
518518
if dtype is not None:
519519
break

src/otx/algorithms/detection/adapters/mmdet/hooks/det_class_probability_map_hook.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def func(
6262

6363
# Don't use softmax for tiles in tiling detection, if the tile doesn't contain objects,
6464
# it would highlight one of the class maps as a background class
65-
if self.use_cls_softmax:
65+
if self.use_cls_softmax and self._num_cls_out_channels > 1:
6666
cls_scores = [torch.softmax(t, dim=1) for t in cls_scores]
6767

6868
batch_size, _, height, width = cls_scores[-1].size()

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

-56
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

-173
This file was deleted.
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

+11-6
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

+2-2
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

tests/e2e/cli/classification/test_classification.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ def test_otx_explain_openvino(self, template, tmp_dir_path):
180180
@pytest.mark.parametrize("half_precision", [True, False])
181181
def test_otx_eval_openvino(self, template, tmp_dir_path, half_precision):
182182
tmp_dir_path = tmp_dir_path / "multi_class_cls"
183-
otx_eval_openvino_testing(template, tmp_dir_path, otx_dir, args, threshold=0.2, half_precision=half_precision)
183+
# FIXME [Jaeguk] Revert threshold to 0.2 when model api supports resize and centercrop.
184+
otx_eval_openvino_testing(template, tmp_dir_path, otx_dir, args, threshold=0.5, half_precision=half_precision)
184185

185186
@e2e_pytest_component
186187
@pytest.mark.skipif(TT_STABILITY_TESTS, reason="This is TT_STABILITY_TESTS")
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+
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TestToolsVisualPrompting:
2+
pot:
3+
number_of_fakequantizers: 210

0 commit comments

Comments
 (0)