4
4
# SPDX-License-Identifier: Apache-2.0
5
5
#
6
6
7
+ from copy import deepcopy
8
+
7
9
import numpy as np
8
- import torch
9
10
import pytest
10
- from otx .api .entities .dataset_item import DatasetItemEntity
11
- from otx .algorithms .visual_prompting .adapters .pytorch_lightning .datasets .dataset import OTXVisualPromptingDataset
11
+ import torch
12
12
from openvino .model_zoo .model_api .models import Model
13
+
14
+ from otx .algorithms .visual_prompting .adapters .pytorch_lightning .datasets .dataset import (
15
+ OTXVisualPromptingDataset ,
16
+ )
13
17
from otx .algorithms .visual_prompting .configs .base import VisualPromptingBaseConfig
14
18
from otx .algorithms .visual_prompting .tasks .openvino import (
15
19
OpenVINOVisualPromptingInferencer ,
16
20
OpenVINOVisualPromptingTask ,
17
21
)
18
- from otx .api .entities .annotation import (
19
- Annotation ,
20
- AnnotationSceneEntity ,
21
- AnnotationSceneKind ,
22
- )
22
+ from otx .api .configuration .configurable_parameters import ConfigurableParameters
23
+ from otx .api .entities .annotation import Annotation
24
+ from otx .api .entities .dataset_item import DatasetItemEntity
23
25
from otx .api .entities .datasets import DatasetEntity
24
26
from otx .api .entities .inference_parameters import InferenceParameters
25
27
from otx .api .entities .label import LabelEntity
28
+ from otx .api .entities .label_schema import LabelSchemaEntity
26
29
from otx .api .entities .metrics import Performance , ScoreMetric
30
+ from otx .api .entities .model import ModelConfiguration , ModelEntity
27
31
from otx .api .entities .resultset import ResultSetEntity
28
32
from otx .api .entities .scored_label import ScoredLabel
29
33
from otx .api .entities .shapes .polygon import Point , Polygon
30
34
from otx .api .usecases .evaluation .metrics_helper import MetricsHelper
35
+ from otx .api .usecases .exportable_code .prediction_to_annotation_converter import (
36
+ VisualPromptingToAnnotationConverter ,
37
+ )
31
38
from otx .api .utils .shape_factory import ShapeFactory
32
-
33
39
from tests .test_suite .e2e_test_system import e2e_pytest_unit
34
40
from tests .unit .algorithms .visual_prompting .test_helpers import (
35
41
generate_visual_prompting_dataset ,
36
42
init_environment ,
37
43
)
38
- from otx .api .usecases .exportable_code .prediction_to_annotation_converter import (
39
- VisualPromptingToAnnotationConverter ,
40
- )
41
44
42
45
43
46
class TestOpenVINOVisualPromptingInferencer :
@@ -159,8 +162,16 @@ def test_forward_decoder(self):
159
162
160
163
161
164
class TestOpenVINOVisualPromptingTask :
165
+ @pytest .fixture
166
+ def otx_model (self ):
167
+ model_configuration = ModelConfiguration (
168
+ configurable_parameters = ConfigurableParameters (header = "header" , description = "description" ),
169
+ label_schema = LabelSchemaEntity (),
170
+ )
171
+ return ModelEntity (train_dataset = DatasetEntity (), configuration = model_configuration )
172
+
162
173
@pytest .fixture (autouse = True )
163
- def setup (self , mocker ):
174
+ def setup (self , mocker , otx_model ):
164
175
"""Load the OpenVINOVisualPromptingTask."""
165
176
mocker .patch ("otx.algorithms.visual_prompting.tasks.openvino.OpenvinoAdapter" )
166
177
mocker .patch .object (Model , "create_model" )
@@ -174,7 +185,8 @@ def setup(self, mocker):
174
185
{"image_encoder" : "" , "decoder" : "" },
175
186
)
176
187
177
- self .task_environment .model = mocker .patch ("otx.api.entities.model.ModelEntity" )
188
+ # self.task_environment.model = mocker.patch("otx.api.entities.model.ModelEntity")
189
+ self .task_environment .model = otx_model
178
190
mocker .patch .object (OpenVINOVisualPromptingTask , "load_inferencer" , return_value = visual_prompting_ov_inferencer )
179
191
self .visual_prompting_ov_task = OpenVINOVisualPromptingTask (task_environment = self .task_environment )
180
192
@@ -220,3 +232,14 @@ def test_evaluate(self, mocker):
220
232
self .visual_prompting_ov_task .evaluate (result_set )
221
233
222
234
assert result_set .performance .score .value == 0.1
235
+
236
+ @e2e_pytest_unit
237
+ def test_deploy (self ):
238
+ output_model = deepcopy (self .task_environment .model )
239
+ self .visual_prompting_ov_task .model .set_data ("visual_prompting_image_encoder.bin" , b"image_encoder_bin" )
240
+ self .visual_prompting_ov_task .model .set_data ("visual_prompting_image_encoder.xml" , b"image_encoder_xml" )
241
+ self .visual_prompting_ov_task .model .set_data ("visual_prompting_decoder.bin" , b"decoder_bin" )
242
+ self .visual_prompting_ov_task .model .set_data ("visual_prompting_decoder.xml" , b"deocder_xml" )
243
+ self .visual_prompting_ov_task .deploy (output_model )
244
+
245
+ assert output_model .exportable_code is not None
0 commit comments