You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Automated ML doesn't impose any constraints on training or validation data size for computer vision tasks. Maximum dataset size is only limited by the storage layer behind the dataset (i.e. blob store). There's no minimum number of images or labels. However, we recommend starting with a minimum of 10-15 samples per label to ensure the output model is sufficiently trained. The higher the total number of labels/classes, the more samples you need per label.
195
206
@@ -810,6 +821,177 @@ If you want to use tiling, and want to control tiling behavior, the following pa
810
821
### Test the deployment
811
822
Please check this [Test the deployment](./tutorial-auto-train-image-models.md#test-the-deployment) section to test the deployment and visualize the detections from the model.
812
823
824
+
## Generate explanations for predictions
825
+
826
+
> [!IMPORTANT]
827
+
> These settings are currently in public preview. They are provided without a service-level agreement. Certain features might not be supported or might have constrained capabilities. For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
828
+
829
+
> [!WARNING]
830
+
>**Model Explainability**is supported only for**multi-class classification**and**multi-label classification**.
831
+
832
+
Some of the advantages of using Explainable AI (XAI) with AutoML for images:
833
+
- Improves the transparency in the complex vision model predictions
834
+
- Helps the users to understand the important features/pixels in the input image that are contributing to the model predictions
835
+
- Helps in troubleshooting the models
836
+
- Helps in discovering the bias
837
+
838
+
### Explanations
839
+
Explanations are **feature attributions**or weights given to each pixel in the input image based on its contribution to model's prediction. Each weight can be negative (negatively correlated with the prediction) or positive (positively correlated with the prediction). These attributions are calculated against the predicted class. For multi-class classification, exactly one attribution matrix of size `[3, valid_crop_size, valid_crop_size]` will be generated per sample, whereas for multi-label classification, attribution matrix of size `[3, valid_crop_size, valid_crop_size]` will be generated for each predicted label/class for each sample.
840
+
841
+
Using Explainable AIin AutoML for Images on the deployed endpoint, users can get **visualizations** of explanations (attributions overlaid on an input image) and/or**attributions** (multi-dimensional array of size `[3, valid_crop_size, valid_crop_size]`) for each image. Apart from visualizations, users can also get attribution matrices to gain more control over the explanations (like generating custom visualizations using attributions or scrutinizing segments of attributions). All the explanation algorithms will use cropped square images with size `valid_crop_size`for generating attributions.
842
+
843
+
844
+
Explanations can be generated either from**online endpoint**or**batch endpoint**. Once the deployment is done, this endpoint can be utilized to generate the explanations for predictions. In case of online deployment, make sure to pass`request_settings = OnlineRequestSettings(request_timeout_ms=90000)` parameter to `ManagedOnlineDeployment`andset`request_timeout_ms` to its maximum value to avoid **timeout issues**while generating explanations (refer to [register and deploy model section](#register-and-deploy-model)). Some of the explainability (XAI) methods like `xrai` consume more time (specially for multi-label classification as we need to generate attributions and/or visualizations against each predicted label). So, we recommend any GPU instance for faster explanations. For more information on input and output schema for generating explanations, see the [schema docs](reference-automl-images-schema.md#data-format-for-online-scoring-and-explainability-xai).
845
+
846
+
847
+
We support following state-of-the-art explainability algorithms in AutoML for images:
Following table describes the explainability algorithm specific tuning parameters forXRAIand Integrated Gradients. Guided backpropagation and guided gradcam don't require any tuning parameters.
854
+
855
+
|XAI algorithm | Algorithm specific parameters | Default Values |
856
+
|---------|-------------|---------|
857
+
|`xrai`|1. `n_steps`: The number of steps used by the approximation method. Larger number of steps lead to better approximations of attributions (explanations). Range of n_steps is [2, inf), but the performance of attributions starts to converge after 50 steps. <br>`Optional, Int`<br><br>2. `xrai_fast`: Whether to use faster version of XRAI. if`True`, then computation time for explanations is faster but leads to less accurate explanations (attributions) <br>`Optional, Bool`<br>|`n_steps = 50`<br>`xrai_fast = True`|
858
+
|`integrated_gradients`|1. `n_steps`: The number of steps used by the approximation method. Larger number of steps lead to better attributions (explanations). Range of n_steps is [2, inf), but the performance of attributions starts to converge after 50 steps.<br>`Optional, Int`<br><br>2. `approximation_method`: Method for approximating the integral. Available approximation methods are `riemann_middle`and`gausslegendre`.<br>`Optional, String`|`n_steps = 50`<br>`approximation_method = riemann_middle`|
859
+
860
+
861
+
Internally XRAI algorithm uses integrated gradients. So, `n_steps` parameter is required by both integrated gradients andXRAI algorithms. Larger number of steps consume more time for approximating the explanations and it may result in timeout issues on the online endpoint.
862
+
863
+
We recommend using XRAI> Guided GradCAM > Integrated Gradients > Guided BackPropagation algorithms for better explanations, whereas Guided BackPropagation > Guided GradCAM > Integrated Gradients >XRAI are recommended for faster explanations in the specified order.
864
+
865
+
A sample request to the online endpoint looks like the following. This request generates explanations when `model_explainability`isset to `True`. Following request will generate visualizations and attributions using faster version of XRAI algorithm with50 steps.
For more information on generating explanations, see [GitHub notebook repository for automated machine learning samples](https://github.com/Azure/azureml-examples/tree/rvadthyavath/xai_vision_notebooks/sdk/python/jobs/automl-standalone-jobs).
907
+
908
+
### Interpreting Visualizations
909
+
Deployed endpoint returns base64 encoded image string if both `model_explainability`and`visualizations` are set to `True`. Decode the base64 string as described in [notebooks](https://github.com/Azure/azureml-examples/tree/rvadthyavath/xai_vision_notebooks/sdk/python/jobs/automl-standalone-jobs) or use the following code to decode and visualize the base64 image strings in the prediction.
910
+
911
+
```python
912
+
import base64
913
+
from io import BytesIO
914
+
fromPILimport Image
915
+
916
+
def base64_to_img(base64_img_str):
917
+
base64_img = base64_img_str.encode("utf-8")
918
+
decoded_img = base64.b64decode(base64_img)
919
+
return BytesIO(decoded_img).getvalue()
920
+
921
+
# For Multi-class classification:
922
+
# Decode and visualize base64 image string for explanations for first input image
Following picture describes the Visualization of explanations for a sample input image.
932
+

933
+
934
+
Decoded base64 figure will have four image sections within a 2 x 2 grid.
935
+
936
+
- Image at Top-left corner (0, 0) is the cropped input image
937
+
- Image at top-right corner (0, 1) is the heatmap of attributions on a color scale bgyw (blue green yellow white) where the contribution of white pixels on the predicted classis the highest and blue pixels is the lowest.
938
+
- Image at bottom left corner (1, 0) is blended heatmap of attributions on cropped input image
939
+
- Image at bottom right corner (1, 1) is the cropped input image with top 30 percent of the pixels based on attribution scores.
940
+
941
+
942
+
### Interpreting Attributions
943
+
Deployed endpoint returns attributions if both `model_explainability`and`attributions` are set to `True`. Fore more details, refer to [multi-class classification and multi-label classification notebooks](https://github.com/Azure/azureml-examples/tree/rvadthyavath/xai_vision_notebooks/sdk/python/jobs/automl-standalone-jobs).
944
+
945
+
These attributions give more control to the users to generate custom visualizations or to scrutinize pixel level attribution scores.
946
+
Following code snippet describes a way to generate custom visualizations using attribution matrix. For more information on the schema of attributions for multi-class classification and multi-label classification, see the [schema docs](reference-automl-images-schema.md#data-format-for-online-scoring-and-explainability-xai).
947
+
948
+
Use the exact `valid_resize_size`and`valid_crop_size` values of the selected model to generate the explanations (default values are 256and224 respectively). Following code uses [Captum](https://captum.ai/) visualization functionality to generate custom visualizations. Users can utilize any other library to generate visualizations. For more details, please refer to the [captum visualization utilities](https://captum.ai/api/utilities.html#visualization).
Review detailed code examples and use cases in the [GitHub notebook repository for automated machine learning samples](https://github.com/Azure/azureml-examples/tree/main/sdk/python/jobs/automl-standalone-jobs). Please check the folders with'automl-image-' prefix for samples specific to building computer vision models.
0 commit comments