From 5c7a0fafaaafbd009f072429de90525feb3968b7 Mon Sep 17 00:00:00 2001 From: Ilya Matiach Date: Wed, 16 Aug 2023 11:12:20 -0400 Subject: [PATCH] fix error for automl object detection models when initializing error analysis and optimize explanation execution (#2245) --- .../managers/error_analysis_manager.py | 23 ++++++++++++++----- .../managers/explainer_manager.py | 14 ++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/responsibleai_vision/responsibleai_vision/managers/error_analysis_manager.py b/responsibleai_vision/responsibleai_vision/managers/error_analysis_manager.py index aa2cba48c1..319264e27b 100644 --- a/responsibleai_vision/responsibleai_vision/managers/error_analysis_manager.py +++ b/responsibleai_vision/responsibleai_vision/managers/error_analysis_manager.py @@ -80,12 +80,23 @@ def __init__(self, model, dataset, image_mode, transformations, test = np.array( self.dataset.iloc[:, 0].tolist() ) - test = pd.DataFrame( - data=[ - get_base64_string_from_path(img_path) for img_path in test - ], - columns=[MLFlowSchemaLiterals.INPUT_COLUMN_IMAGE], - ) + if self.task_type == ModelTask.OBJECT_DETECTION: + test = pd.DataFrame( + data=[[x for x in get_base64_string_from_path( + img_path, return_image_size=True)] for + img_path in test], + columns=[ + MLFlowSchemaLiterals.INPUT_COLUMN_IMAGE, + MLFlowSchemaLiterals.INPUT_IMAGE_SIZE], + ) + else: + test = pd.DataFrame( + data=[ + get_base64_string_from_path( + img_path) for img_path in test + ], + columns=[MLFlowSchemaLiterals.INPUT_COLUMN_IMAGE], + ) else: test = get_images(self.dataset, self.image_mode, self.transformations) diff --git a/responsibleai_vision/responsibleai_vision/managers/explainer_manager.py b/responsibleai_vision/responsibleai_vision/managers/explainer_manager.py index 6b95eca14d..e722bca912 100644 --- a/responsibleai_vision/responsibleai_vision/managers/explainer_manager.py +++ b/responsibleai_vision/responsibleai_vision/managers/explainer_manager.py @@ -115,7 +115,19 @@ def __init__(self, model: Any, self._image_mode = image_mode if task_type == ModelTask.OBJECT_DETECTION: if is_automl_image_model(model): - self._model = MLflowDRiseWrapper(model._model, classes) + try: + python_model = model._model._model_impl.python_model + automl_wrapper = python_model._model + inner_model = automl_wrapper._model + number_of_classes = automl_wrapper._number_of_classes + self._model = PytorchDRiseWrapper( + inner_model, number_of_classes, device=device) + except Exception as e: + warnings.warn(("Could not extract inner automl model." + + "Explanation may take longer to compute." + + "Inner exception: {}").format(str(e)), + UserWarning) + self._model = MLflowDRiseWrapper(model._model, classes) else: self._model = PytorchDRiseWrapper( model._model, len(classes), device=device)