我在尝试使用 Google 的可解释 AI 来解释一个图像预测模型时遇到了 429 错误。我想要解释的模型是使用了 MobileNet V3 Large 模型并应用了迁移学习的模型。
python 代码 :
ig_response = remote_ig_model.explain(instances)
结果 :
ValueError: 目标 URI https://asia-northeast1-ml.googleapis.com/v1/projects/cellimaging/models/A549_4/versions/v_ig_4:explain 返回 HTTP 429 错误。请查看原始错误消息: { "error": { "code": 429, "message": "Rate of traffic exceeds serving capacity. Decrease your traffic or reduce the size of your model: projects/842842301933/models/A549_4/versions/v_ig_4.", "status": "RESOURCE_EXHAUSTED" }}
在使用 ai-platform 创建服务模型时,命令如下。
代码 :
! gcloud beta ai-platform versions create $IG_VERSION --region='asia-northeast1' \--model $MODEL \--origin $export_path \--runtime-version 2.2 \--framework TENSORFLOW \--python-version 3.7 \--machine-type n1-highcpu-32 \--explanation-method integrated-gradients \--num-integral-steps 25
我遇到了 429 错误,并尝试更改了机器类型(n1-standard-4 -> n1-highcpu-32),但错误并未解决。
回答:
你可以查看这个故障排除部分,你的请求不能超过 1.5Mb
单个在线预测请求的数据量不得超过 1.5 MB。
如果你的输入是 1024,1024,3,你的图像大小应为 3Mb(1024 x 1024 x 3 字节),因此对于 API 来说太大了。