Skip to content

Commit

Permalink
Prevent zero-sized saliency map in tiling if tile size is too big (op…
Browse files Browse the repository at this point in the history
…envinotoolkit#2452)

* Prevent zero-sized saliency map in tiling if tile size is too big

* Prevent zero-sized saliency in tiling (PyTorch)

* Add unit tests for Tiler merge features methods

---------

Co-authored-by: Galina <[email protected]>
  • Loading branch information
2 people authored and yunchu committed Aug 30, 2023
1 parent bc4977a commit 46968ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ def merge_maps(self, saliency_maps: Union[List[List[np.ndarray]], List[np.ndarra

for orig_image in self.cached_results:
img_idx = orig_image["index"]
ratios[img_idx] = np.array([feat_h, feat_w]) / self.tile_size
image_h, image_w = orig_image["height"], orig_image["width"]
ratios[img_idx] = np.array([feat_h / min(self.tile_size, image_h), feat_w / min(self.tile_size, image_w)])

image_map_h = int(image_h * ratios[img_idx][0])
image_map_w = int(image_w * ratios[img_idx][1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@ def test_openvino_sync(self, mocker):
mocked_model.return_value = mocker.MagicMock(spec=MaskRCNNModel, model_adapter=adapter_mock)
params = DetectionConfig(header=self.hyper_parameters.header)
ov_mask_inferencer = OpenVINOMaskInferencer(params, self.label_schema, "")
ov_mask_inferencer.model = mocked_model
original_shape = (self.dataset[0].media.width, self.dataset[0].media.height, 3)
ov_mask_inferencer.model.resize_mask = False
ov_mask_inferencer.model.preprocess.return_value = ({"foo": "bar"}, {"baz": "qux"})
ov_mask_inferencer.model.preprocess.return_value = (
{"foo": "bar"},
{"baz": "qux", "original_shape": original_shape},
)
ov_mask_inferencer.model.postprocess.return_value = (
np.array([], dtype=np.float32),
np.array([], dtype=np.uint32),
np.zeros((0, 4), dtype=np.float32),
[],
)
ov_inferencer = OpenVINOTileClassifierWrapper(
ov_mask_inferencer, tile_classifier_model_file="", tile_classifier_weight_file="", mode="sync"
)
Expand All @@ -99,6 +108,10 @@ def test_openvino_sync(self, mocker):
[], [np.zeros((0, 4), dtype=np.float32)], np.zeros((0, 4), dtype=np.float32)
),
)
ov_inferencer.tiler.model.infer_sync.return_value = {
"feature_vector": np.zeros((1, 5), dtype=np.float32),
"saliency_map": np.zeros((1, 1, 2, 2), dtype=np.float32),
}
mocker.patch.object(OpenVINODetectionTask, "load_inferencer", return_value=ov_inferencer)
ov_task = OpenVINODetectionTask(self.task_env)
updated_dataset = ov_task.infer(self.dataset)
Expand Down

0 comments on commit 46968ba

Please sign in to comment.