Skip to content

Commit 5bedefb

Browse files
add responsibleai-vision package to responsible-ai-toolbox (#2135)
1 parent 5671b4c commit 5bedefb

25 files changed

+4045
-0
lines changed

responsibleai_vision/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Responsible AI Vision SDK for Python
2+
3+
### This package has been tested with Python 3.6, 3.7, 3.8 and 3.9
4+
5+
The Responsible AI Vision SDK enables users to analyze their machine learning models for computer vision in one API. Users will be able to analyze errors, explain the most important features, and understand their data using a single API.
6+
7+
Highlights of the package include:
8+
9+
- `explainer.add()` explains the model
10+
11+
### Supported scenarios, models and datasets
12+
13+
The Responsible AI Vision SDK supports multiclass classification models on image data currently.
14+
15+
The open source code for the visualization dashboard can be found here:
16+
https://github.com/microsoft/responsible-ai-widgets
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python==4.3.0.36
2+
azureml-automl-dnn-vision>=1.47.0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Requirements for development
2+
3+
pytest==7.0.1
4+
pytest-cov
5+
pytest-mock==3.6.1
6+
requests==2.25.1
7+
8+
requirements-parser==0.2.0
9+
10+
wheel
11+
12+
# Required for notebook tests
13+
nbformat
14+
papermill
15+
scrapbook
16+
jupyter
17+
nbval
18+
19+
docutils<0.18
20+
sphinx==3.1.1
21+
sphinx-gallery==0.8.1
22+
pydata-sphinx-theme==0.3.0
23+
24+
transformers
25+
datasets
26+
tensorflow<2.11.0
27+
opencv-python
28+
29+
fastai
30+
mlflow
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
numpy>=1.17.2
2+
pandas>=0.25.1,<2.0.0 # TODO: remove ceiling on version.
3+
scikit-learn>=0.22.1
4+
scipy>=1.4.1
5+
semver~=2.13.0
6+
responsibleai>=0.27.0
7+
torchmetrics
8+
vision_explanation_methods
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) Microsoft Corporation
2+
# Licensed under the MIT License.
3+
4+
"""Responsible AI Vision SDK package."""
5+
6+
from responsibleai_vision.common.constants import ModelTask
7+
from responsibleai_vision.rai_vision_insights import RAIVisionInsights
8+
9+
from .version import name, version
10+
11+
__name__ = name
12+
__version__ = version
13+
14+
__all__ = ['ModelTask', 'RAIVisionInsights']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation
2+
# Licensed under the MIT License.
3+
4+
"""Common infrastructure, constants and utilities."""
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright (c) Microsoft Corporation
2+
# Licensed under the MIT License.
3+
4+
from enum import Enum
5+
6+
7+
class ModelTask(str, Enum):
8+
"""Provide model task constants.
9+
10+
Can be 'image_classification', 'object_detection' or 'unknown'.
11+
"""
12+
13+
IMAGE_CLASSIFICATION = 'image_classification'
14+
MULTILABEL_IMAGE_CLASSIFICATION = 'multilabel_image_classification'
15+
OBJECT_DETECTION = 'object_detection'
16+
UNKNOWN = 'unknown'
17+
18+
19+
class ImageColumns(str, Enum):
20+
"""Provide constants related to the input image dataframe columns.
21+
22+
Can be 'image_url', 'image' or 'label'.
23+
"""
24+
25+
IMAGE_URL = 'image_url'
26+
IMAGE = 'image'
27+
LABEL = 'label'
28+
IMAGE_DETAILS = 'image_details'
29+
30+
31+
class ExplainabilityLiterals:
32+
"""Parameters for explainability method names."""
33+
34+
MODEL_EXPLAINABILITY = 'model_explainability'
35+
XAI_PARAMETERS = 'xai_parameters'
36+
XAI_ALGORITHM = 'xai_algorithm'
37+
SHAP_METHOD_NAME = 'shap'
38+
XRAI_METHOD_NAME = 'xrai'
39+
INTEGRATEDGRADIENTS_METHOD_NAME = 'integrated_gradients'
40+
GUIDEDGRADCAM_METHOD_NAME = 'guided_gradcam'
41+
GUIDEDBACKPROP_METHOD_NAME = 'guided_backprop'
42+
CONFIDENCE_SCORE_THRESHOLD_MULTILABEL = (
43+
'confidence_score_threshold_multilabel'
44+
)
45+
N_STEPS = "n_steps"
46+
APPROXIMATION_METHOD = "approximation_method"
47+
XRAI_FAST = "xrai_fast"
48+
XAI_ARGS_GROUP = [
49+
XAI_ALGORITHM,
50+
N_STEPS,
51+
APPROXIMATION_METHOD,
52+
XRAI_FAST,
53+
CONFIDENCE_SCORE_THRESHOLD_MULTILABEL,
54+
]
55+
SHAP = 'shap'
56+
57+
58+
class ExplainabilityDefaults:
59+
"""DEFAULT values for explainability parameters."""
60+
61+
MODEL_EXPLAINABILITY = False
62+
XAI_ALGORITHM = ExplainabilityLiterals.GUIDEDGRADCAM_METHOD_NAME
63+
OUTPUT_VISUALIZATIONS = True
64+
OUTPUT_ATTRIBUTIONS = False
65+
CONFIDENCE_SCORE_THRESHOLD_MULTILABEL = 0.5
66+
DEFAULT_MAX_EVALS = 100
67+
DEFAULT_MASK_RES = 4
68+
DEFAULT_NUM_MASKS = 50
69+
70+
71+
class XAIPredictionLiterals:
72+
"""Strings that will be keys in the output json during prediction."""
73+
74+
VISUALIZATIONS_KEY_NAME = 'visualizations'
75+
ATTRIBUTIONS_KEY_NAME = 'attributions'
76+
77+
78+
class MLFlowSchemaLiterals:
79+
"""MLFlow model signature related schema"""
80+
81+
INPUT_IMAGE_KEY = 'image_base64'
82+
INPUT_COLUMN_IMAGE = 'image'
83+
INPUT_IMAGE_SIZE = 'image_size'
84+
85+
86+
class CommonTags:
87+
"""Common constants"""
88+
89+
IMAGE_DECODE_UTF_FORMAT = 'utf-8'
90+
91+
92+
class AutoMLImagesModelIdentifier:
93+
"""AutoML model object types"""
94+
95+
AUTOML_IMAGE_CLASSIFICATION_MODEL = (
96+
"WrappedMlflowAutomlImagesClassificationModel'>"
97+
)
98+
99+
AUTOML_OBJECT_DETECTION_MODEL = (
100+
"WrappedMlflowAutomlObjectDetectionModel'>"
101+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Microsoft Corporation
2+
# Licensed under the MIT License.
3+
4+
from typing import List
5+
6+
7+
class VisionExplanationData:
8+
classNames: List[str]
9+
images: List[str]
10+
predictedY: List[str]
11+
trueY: List[str]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) Microsoft Corporation
2+
# Licensed under the MIT License.
3+
4+
"""Contains all of the managers."""

0 commit comments

Comments
 (0)