Coder Social home page Coder Social logo

googlecloudplatform / explainable_ai_sdk Goto Github PK

View Code? Open in Web Editor NEW
23.0 5.0 12.0 319 KB

This is an SDK for Google Cloud Explainable AI service. Explainable AI SDK helps users build explanation metadata for their models and visualize feature attributions returned from the model.

Home Page: https://cloud.google.com/explainable-ai

License: Apache License 2.0

Python 100.00%

explainable_ai_sdk's Issues

.explain() fails with Endpoint doesn't have traffic_split precondition error

When getting explanations for a Vertex AI Model I get the following error message

{
  "error": {
    "code": 400,
    "message": "Endpoint projects/sascha-playground-doit/locations/us-central1/endpoints/519294943752093696 doesn't have traffic_split.",
    "status": "FAILED_PRECONDITION"
  }
}

Model: Vertex AI AutoML Image Classification
Method: XRAY

Code to reproduce

import explainable_ai_sdk
from base64 import b64encode
import tensorflow as tf

instances = []

img_bytes = tf.io.read_file('/content/cast_def_0_1104.jpeg')
b64str = b64encode(img_bytes.numpy()).decode('utf-8')
instances.append({"content": {'b64': b64str}})

remote_model = explainable_ai_sdk.load_model_from_vertex(PROJECT, REGION, ENDPOINT_ID)
#predictions = remote_ig_model.predict(instances)
response = remote_model.explain(instances)

This precondition is limiting us in multiple ways

  1. Sometimes there is only one version deployed so enabling splitting is not an option.
  2. And even if there are multiple versions we usually enable traffic splitting for a short time and as soon as we are sure the model performs in production well we switch 100% of the traffic to the new model

Looking forward to your feedback

Best regards
Sascha

explainable_ai_sdk.load_model_from_ai_platform errors with "google.auth.credentials' has no attribute 'CredentialsWithQuotaProject"

Following the notebook (just using different data) at GoogleCloudPlatform/ai-platform-samples/blob/master/notebooks/samples/explanations/tf2/ai-explanations-tabular.ipynb
using TF2.2 and 1.0.5 release of explainable_ai_sdk python 3.7. AI Platform Notebook instance.

When calling load_model_from_ai_platform(proj,model,version) the error is raised.
AttributeError: module 'google.auth.credentials' has no attribute 'CredentialsWithQuotaProject'

Not sure if this is due to a mistake I have made or a package dependency.
thanks,
jim

Here is the full error message:


AttributeError Traceback (most recent call last)
in
2 PROJECT_ID = 'jwtfxpipe'
3 print('model {} version {}'.format(MODEL,VERSION))
----> 4 remote_ig_model = explainable_ai_sdk.load_model_from_ai_platform(PROJECT_ID, MODEL, VERSION)
5 ig_response = remote_ig_model.explain([prediction_json])
6 print('OK@',time.asctime())

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/model_factory.py in load_model_from_ai_platform(project, model, version, credentials)
56 if version:
57 endpoint = os.path.join(endpoint, 'versions', version)
---> 58 return _MODEL_REGISTRY[_REMOTE_MODEL_KEY](endpoint, credentials)
59
60

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/ai_platform_model.py in init(self, endpoint, credentials)
48 self._credentials = credentials
49 self._endpoint = endpoint
---> 50 self._explanation_metadata = self._get_explanation_metadata()
51 self._modality_input_list_map = utils.get_modality_input_list_map(
52 self._explanation_metadata)

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/ai_platform_model.py in _get_explanation_metadata(self)
103
104 """
--> 105 explanation_md_uri = self._get_explanation_metadata_uri()
106
107 md = explain_metadata.ExplainMetadata.from_file(explanation_md_uri)

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/ai_platform_model.py in _get_explanation_metadata_uri(self)
83 gcs bucket uri.
84 """
---> 85 gcs_uri = self._get_deployment_uri()
86 match = re.search('gs://(?P<bucket_name>[^/])[/](?P.*)',
87 gcs_uri)

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/ai_platform_model.py in _get_deployment_uri(self)
63 """
64 response = http_utils.make_get_request_to_ai_platform(
---> 65 self._endpoint, self._credentials)
66
67 if 'deploymentUri' not in response:

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/http_utils.py in make_get_request_to_ai_platform(uri_params_str, credentials, timeout_ms)
93 Request results in json format.
94 """
---> 95 headers = _get_request_header(credentials)
96 ai_platform_endpoint = (
97 os.getenv('CLOUDSDK_API_ENDPOINT_OVERRIDES_ML') or

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/http_utils.py in _get_request_header(credentials)
40 # If credentials is not given, use the default credentials
41 if credentials is None:
---> 42 credentials, _ = google.auth.default()
43
44 # Refresh credentials in case it has been expired.

/opt/conda/lib/python3.7/site-packages/google/auth/_default.py in default(scopes, request)
306 scopes (Sequence[str]): The list of scopes for the credentials. If
307 specified, the credentials will automatically be scoped if
--> 308 necessary.
309 request (google.auth.transport.Request): An object used to make
310 HTTP requests. This is used to detect whether the application

/opt/conda/lib/python3.7/site-packages/google/auth/_default.py in _get_gae_credentials()
178 explicit_file = os.environ.get(environment_vars.CREDENTIALS)
179
--> 180 _LOGGER.debug(
181 "Checking %s for explicit credentials as part of auth process...", explicit_file
182 )

/opt/conda/lib/python3.7/site-packages/google/auth/app_engine.py in
79
80 class Credentials(
---> 81 credentials.Scoped, credentials.Signing, credentials.CredentialsWithQuotaProject
82 ):
83 """App Engine standard environment credentials.

AttributeError: module 'google.auth.credentials' has no attribute 'CredentialsWithQuotaProject'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.