otx.algo.utils.xai_utils#

Utils used for XAI.

Functions

convert_maps_to_dict_all(saliency_map)

Convert salincy maps to dict for TargetExplainGroup.ALL.

convert_maps_to_dict_image(saliency_map)

Convert salincy maps to dict for TargetExplainGroup.IMAGE.

convert_maps_to_dict_predictions(...)

Convert salincy maps to dict for TargetExplainGroup.PREDICTIONS.

dump_saliency_maps(predict_result, ...[, weight])

Sumps saliency maps (raw and with overlay).

postprocess(saliency_map, output_size)

Postprocess single saliency map.

process_saliency_maps(saliency_map, ...)

Perform saliency map convertion to dict and post-processing.

process_saliency_maps_in_pred_entity(...)

Process saliency maps in PredEntity.

set_crop_padded_map_flag(explain_config, ...)

If resize with keep_ratio = True was used, set crop_padded_map flag to True.

otx.algo.utils.xai_utils.convert_maps_to_dict_all(saliency_map: list[ndarray]) list[dict[Any, array]][source]#

Convert salincy maps to dict for TargetExplainGroup.ALL.

otx.algo.utils.xai_utils.convert_maps_to_dict_image(saliency_map: list[ndarray]) list[dict[Any, array]][source]#

Convert salincy maps to dict for TargetExplainGroup.IMAGE.

otx.algo.utils.xai_utils.convert_maps_to_dict_predictions(saliency_map: list[ndarray], pred_labels: list | None) list[dict[Any, array]][source]#

Convert salincy maps to dict for TargetExplainGroup.PREDICTIONS.

otx.algo.utils.xai_utils.dump_saliency_maps(predict_result: list[OTXBatchPredEntitiesSupportXAI], explain_config: ExplainConfig, datamodule: EVAL_DATALOADERS | OTXDataModule, output_dir: Path, weight: float = 0.3) None[source]#

Sumps saliency maps (raw and with overlay).

otx.algo.utils.xai_utils.postprocess(saliency_map: ndarray, output_size: tuple[int, int] | None) ndarray[source]#

Postprocess single saliency map.

otx.algo.utils.xai_utils.process_saliency_maps(saliency_map: list[ndarray], explain_config: ExplainConfig, pred_labels: list | None, ori_img_shapes: list, image_shape: tuple[int, int], paddings: list[tuple[int, int, int, int]]) list[dict[str, ndarray | Tensor]][source]#

Perform saliency map convertion to dict and post-processing.

otx.algo.utils.xai_utils.process_saliency_maps_in_pred_entity(predict_result: list[MulticlassClsBatchPredEntity | MultilabelClsBatchPredEntity | HlabelClsBatchPredEntity | DetBatchPredEntity | InstanceSegBatchPredEntity], explain_config: ExplainConfig, label_info: LabelInfo | int | list[str]) list[MulticlassClsBatchPredEntity | MultilabelClsBatchPredEntity | HlabelClsBatchPredEntity | DetBatchPredEntity | InstanceSegBatchPredEntity][source]#

Process saliency maps in PredEntity.

otx.algo.utils.xai_utils.set_crop_padded_map_flag(explain_config: ExplainConfig, datamodule: OTXDataModule) ExplainConfig[source]#

If resize with keep_ratio = True was used, set crop_padded_map flag to True.