20
20
import cv2
21
21
import numpy as np
22
22
from openvino .model_api .adapters .inference_adapter import InferenceAdapter
23
- from openvino .model_api .models import DetectionModel , ImageModel
23
+ from openvino .model_api .models import ImageModel
24
24
from openvino .model_api .models .types import (
25
25
BooleanValue ,
26
26
ListValue ,
@@ -96,18 +96,20 @@ def preprocess(self, inputs: Dict[str, Any], meta: Dict[str, Any]):
96
96
# TODO (sungchul): add condition to check whether using bbox or point
97
97
point_coords = self ._apply_coords (bbox .reshape (- 1 , 2 , 2 ), inputs ["original_size" ])
98
98
point_labels = np .array ([2 , 3 ], dtype = np .float32 ).reshape ((- 1 , 2 ))
99
- processed_prompts .append ({
100
- "point_coords" : point_coords ,
101
- "point_labels" : point_labels ,
102
- # TODO (sungchul): how to generate mask_input and has_mask_input
103
- "mask_input" : np .zeros ((1 , 1 , 256 , 256 ), dtype = np .float32 ),
104
- "has_mask_input" : np .zeros ((1 , 1 ), dtype = np .float32 ),
105
- "orig_size" : np .array (inputs ["original_size" ], dtype = np .float32 ).reshape ((- 1 , 2 )),
106
- "label" : label
107
- })
99
+ processed_prompts .append (
100
+ {
101
+ "point_coords" : point_coords ,
102
+ "point_labels" : point_labels ,
103
+ # TODO (sungchul): how to generate mask_input and has_mask_input
104
+ "mask_input" : np .zeros ((1 , 1 , 256 , 256 ), dtype = np .float32 ),
105
+ "has_mask_input" : np .zeros ((1 , 1 ), dtype = np .float32 ),
106
+ "orig_size" : np .array (inputs ["original_size" ], dtype = np .float32 ).reshape ((- 1 , 2 )),
107
+ "label" : label ,
108
+ }
109
+ )
108
110
return processed_prompts
109
111
110
- def _apply_coords (self , coords : np .ndarray , original_size : Union [List [int ], Tuple [int ]]) -> np .ndarray :
112
+ def _apply_coords (self , coords : np .ndarray , original_size : Union [List [int ], Tuple [int , int ]]) -> np .ndarray :
111
113
"""Process coords according to preprocessed image size using image meta."""
112
114
old_h , old_w = original_size
113
115
new_h , new_w = self ._get_preprocess_shape (original_size [0 ], original_size [1 ], self .image_size )
@@ -123,7 +125,7 @@ def _get_preprocess_shape(self, old_h: int, old_w: int, image_size: int) -> Tupl
123
125
new_w = int (new_w + 0.5 )
124
126
new_h = int (new_h + 0.5 )
125
127
return (new_h , new_w )
126
-
128
+
127
129
def _check_io_number (self , number_of_inputs , number_of_outputs ):
128
130
pass
129
131
@@ -146,7 +148,7 @@ def postprocess(self, outputs: Dict[str, np.ndarray], meta: Dict[str, Any]) -> T
146
148
"""
147
149
148
150
def sigmoid (x ):
149
- return np .tanh (x * 0.5 ) * 0.5 + 0.5 # to avoid overflow
151
+ return np .tanh (x * 0.5 ) * 0.5 + 0.5 # to avoid overflow
150
152
151
153
soft_prediction = outputs [self .output_blob_name ].squeeze ()
152
154
soft_prediction = self .resize_and_crop (soft_prediction , meta ["original_size" ][0 ])
0 commit comments