Skip to content

Commit ae81031

Browse files
author
Evgeny Tsykunov
authored
Disable semantic segmentation soft prediction processing (#2302)
* disable sem segm soft prediction processing * fix over merge conflicts fix
1 parent 18ee552 commit ae81031

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

otx/algorithms/segmentation/adapters/openvino/task.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ def infer(
197197
if inference_parameters is not None:
198198
update_progress_callback = inference_parameters.update_progress
199199
dump_soft_prediction = not inference_parameters.is_evaluation
200+
process_soft_prediction = inference_parameters.process_saliency_maps
200201
else:
201202
update_progress_callback = default_progress_callback
202203
dump_soft_prediction = True
204+
process_soft_prediction = False
203205

204206
dataset_size = len(dataset)
205207
for i, dataset_item in enumerate(dataset, 1):
@@ -215,14 +217,15 @@ def infer(
215217
if label_index == 0:
216218
continue
217219
current_label_soft_prediction = soft_prediction[:, :, label_index]
218-
class_act_map = get_activation_map(current_label_soft_prediction)
220+
if process_soft_prediction:
221+
current_label_soft_prediction = get_activation_map(current_label_soft_prediction)
219222
result_media = ResultMediaEntity(
220223
name=label.name,
221224
type="soft_prediction",
222225
label=label,
223226
annotation_scene=dataset_item.annotation_scene,
224227
roi=dataset_item.roi,
225-
numpy=class_act_map,
228+
numpy=current_label_soft_prediction,
226229
)
227230
dataset_item.append_metadata_item(result_media, model=self.model)
228231

otx/algorithms/segmentation/task.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ def infer(
128128

129129
if inference_parameters is not None:
130130
update_progress_callback = inference_parameters.update_progress
131-
is_evaluation = inference_parameters.is_evaluation
131+
dump_soft_prediction = not inference_parameters.is_evaluation
132+
process_soft_prediction = inference_parameters.process_saliency_maps
132133
else:
133134
update_progress_callback = default_infer_progress_callback
134-
is_evaluation = False
135+
dump_soft_prediction = True
136+
process_soft_prediction = False
135137

136138
update_progress_callback = default_progress_callback
137139
if inference_parameters is not None:
@@ -141,7 +143,7 @@ def infer(
141143

142144
predictions = self._infer_model(dataset, InferenceParameters(is_evaluation=True))
143145
prediction_results = zip(predictions["eval_predictions"], predictions["feature_vectors"])
144-
self._add_predictions_to_dataset(prediction_results, dataset, dump_soft_prediction=not is_evaluation)
146+
self._add_predictions_to_dataset(prediction_results, dataset, dump_soft_prediction, process_soft_prediction)
145147

146148
logger.info("Inference completed")
147149
return dataset
@@ -266,7 +268,7 @@ def evaluate(
266268
output_resultset.performance = metric.get_performance()
267269
logger.info("Evaluation completed")
268270

269-
def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_prediction):
271+
def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_prediction, process_soft_prediction):
270272
"""Loop over dataset again to assign predictions. Convert from MMSegmentation format to OTX format."""
271273
for dataset_item, (prediction, feature_vector) in zip(dataset, prediction_results):
272274
soft_prediction = np.transpose(prediction[0], axes=(1, 2, 0))
@@ -291,14 +293,15 @@ def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_pre
291293
if label_index == 0:
292294
continue
293295
current_label_soft_prediction = soft_prediction[:, :, label_index]
294-
class_act_map = get_activation_map(current_label_soft_prediction)
296+
if process_soft_prediction:
297+
current_label_soft_prediction = get_activation_map(current_label_soft_prediction)
295298
result_media = ResultMediaEntity(
296299
name=label.name,
297300
type="soft_prediction",
298301
label=label,
299302
annotation_scene=dataset_item.annotation_scene,
300303
roi=dataset_item.roi,
301-
numpy=class_act_map,
304+
numpy=current_label_soft_prediction,
302305
)
303306
dataset_item.append_metadata_item(result_media, model=self._task_environment.model)
304307

0 commit comments

Comments
 (0)