GoogleCloudPlatform explainable_ai_sdk.load_model_from_ai_pl



我想在AI平台上部署和使用一个带有AI解释的预测模型。所以我创建了一个模型版本:

代码:

PROJECT_ID = 'gcloudtest-318713'
MODEL = 'flowers' + TIMESTAMP
REGION = 'us-west1'
IG_VERSION = 'v_ig_3'

! gcloud beta ai-platform versions create $IG_VERSION --region=$REGION 
--model $MODEL 
--origin $export_path 
--runtime-version 2.2 
--framework TENSORFLOW 
--python-version 3.7 
--machine-type n1-standard-4 
--explanation-method integrated-gradients 
--num-integral-steps 25 
--region $REGION

结果:

Using endpoint [https://us-west1-ml.googleapis.com/]
Explanations reflect patterns in your model, but don't necessarily reveal fundamental relationships about your data population. See https://cloud.google.com/ml-engine/docs/ai-explanations/limitations for more information.
Creating version (this might take a few minutes)......done. 

我检查了模型部署的状态,模型部署正确。

代码:

# Make sure the IG model deployed correctly. State should be `READY` in the following log
! gcloud ai-platform versions describe $IG_VERSION --model $MODEL --region $REGION

结果:

Using endpoint [https://us-west1-ml.googleapis.com/]
createTime: '2021-07-08T08:01:06Z'
deploymentUri: gs://explanablebucket/explanations/mymodel
etag: TPD5G-pd3BE=
explanationConfig:
integratedGradientsAttribution:
numIntegralSteps: 25
framework: TENSORFLOW
machineType: n1-standard-4
name: projects/gcloudtest-318713/models/flowers20210708062102/versions/v_ig_3
pythonVersion: '3.7'
runtimeVersion: '2.2'
state: READY

我尝试从ai平台加载模型。但它失败了,错误如下。

代码:

remote_ig_model = explainable_ai_sdk.load_model_from_ai_platform('gcloudtest-318713', 'flowers20210708062102', 'v_ig_3')

结果:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-cc00f8746ef5> in <module>
----> 1 remote_ig_model = explainable_ai_sdk.load_model_from_ai_platform('gcloudtest-318713', 'flowers20210708062102', 'v_ig_3')
/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/model_factory.py in load_model_from_ai_platform(project, model, version, credentials, region, input_modalities)
57   if not input_modalities:
58     input_modalities = utils.create_modality_inputs_map_from_metadata(
59         utils.fetch_explanation_metadata(model_endpoint_uri, credentials))
60 
61   return _MODEL_REGISTRY[_CAIP_MODEL_KEY](model_endpoint_uri, credentials,

/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/utils.py in fetch_explanation_metadata(model_endpoint_uri, credentials)
73   """
74   explanation_md_uri = _extract_explanation_metadata_uri(
75       _get_deployment_uri(model_endpoint_uri, credentials))
76 
77   return explain_metadata.ExplainMetadata.from_file(explanation_md_uri)
/opt/conda/lib/python3.7/site-packages/explainable_ai_sdk/model/utils.py in _get_deployment_uri(model_endpoint_uri, credentials)
29   """
30   response = http_utils.make_get_request_to_ai_platform(model_endpoint_uri,
31                                                         credentials)
32 
33   if 'deploymentUri' not in response:
ValueError: Target URI https://ml.googleapis.com/v1/projects/gcloudtest-318713/models/flowers20210708062102/versions/v_ig_3 returns HTTP 404 error.
Please check if the project, model, and version names are given correctly.

我解决不了这个问题。

我解决了这个问题。我的模型被部署到指定的区域,但sdk似乎在搜索另一个区域。代码:

remote_ig_model = explainable_ai_sdk.load_model_from_ai_platform(project = 'gcloudtest-318713', mode = 'flowers20210708062102', version = 'v_ig_3', region = REGION)

相关内容

  • 没有找到相关文章

最新更新