Skip to content

Commit

Permalink
Disable semantic segmentation soft prediction processing (#2302)
Browse files Browse the repository at this point in the history
* disable sem segm soft prediction processing

* fix over merge conflicts fix
  • Loading branch information
negvet authored Jul 6, 2023
1 parent 18ee552 commit ae81031
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions otx/algorithms/segmentation/adapters/openvino/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ def infer(
if inference_parameters is not None:
update_progress_callback = inference_parameters.update_progress
dump_soft_prediction = not inference_parameters.is_evaluation
process_soft_prediction = inference_parameters.process_saliency_maps
else:
update_progress_callback = default_progress_callback
dump_soft_prediction = True
process_soft_prediction = False

dataset_size = len(dataset)
for i, dataset_item in enumerate(dataset, 1):
Expand All @@ -215,14 +217,15 @@ def infer(
if label_index == 0:
continue
current_label_soft_prediction = soft_prediction[:, :, label_index]
class_act_map = get_activation_map(current_label_soft_prediction)
if process_soft_prediction:
current_label_soft_prediction = get_activation_map(current_label_soft_prediction)
result_media = ResultMediaEntity(
name=label.name,
type="soft_prediction",
label=label,
annotation_scene=dataset_item.annotation_scene,
roi=dataset_item.roi,
numpy=class_act_map,
numpy=current_label_soft_prediction,
)
dataset_item.append_metadata_item(result_media, model=self.model)

Expand Down
15 changes: 9 additions & 6 deletions otx/algorithms/segmentation/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ def infer(

if inference_parameters is not None:
update_progress_callback = inference_parameters.update_progress
is_evaluation = inference_parameters.is_evaluation
dump_soft_prediction = not inference_parameters.is_evaluation
process_soft_prediction = inference_parameters.process_saliency_maps
else:
update_progress_callback = default_infer_progress_callback
is_evaluation = False
dump_soft_prediction = True
process_soft_prediction = False

update_progress_callback = default_progress_callback
if inference_parameters is not None:
Expand All @@ -141,7 +143,7 @@ def infer(

predictions = self._infer_model(dataset, InferenceParameters(is_evaluation=True))
prediction_results = zip(predictions["eval_predictions"], predictions["feature_vectors"])
self._add_predictions_to_dataset(prediction_results, dataset, dump_soft_prediction=not is_evaluation)
self._add_predictions_to_dataset(prediction_results, dataset, dump_soft_prediction, process_soft_prediction)

logger.info("Inference completed")
return dataset
Expand Down Expand Up @@ -266,7 +268,7 @@ def evaluate(
output_resultset.performance = metric.get_performance()
logger.info("Evaluation completed")

def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_prediction):
def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_prediction, process_soft_prediction):
"""Loop over dataset again to assign predictions. Convert from MMSegmentation format to OTX format."""
for dataset_item, (prediction, feature_vector) in zip(dataset, prediction_results):
soft_prediction = np.transpose(prediction[0], axes=(1, 2, 0))
Expand All @@ -291,14 +293,15 @@ def _add_predictions_to_dataset(self, prediction_results, dataset, dump_soft_pre
if label_index == 0:
continue
current_label_soft_prediction = soft_prediction[:, :, label_index]
class_act_map = get_activation_map(current_label_soft_prediction)
if process_soft_prediction:
current_label_soft_prediction = get_activation_map(current_label_soft_prediction)
result_media = ResultMediaEntity(
name=label.name,
type="soft_prediction",
label=label,
annotation_scene=dataset_item.annotation_scene,
roi=dataset_item.roi,
numpy=class_act_map,
numpy=current_label_soft_prediction,
)
dataset_item.append_metadata_item(result_media, model=self._task_environment.model)

Expand Down

0 comments on commit ae81031

Please sign in to comment.