在Google Cloud ml引擎上调用本地预测或创建模型版本时,Scikit Learn模型会出错

问题描述 投票:2回答:1

我正在尝试按照这里的教程(https://cloud.google.com/ml-engine/docs/scikit/quickstart)将模型部署到cloud-ml引擎,但是当我使用此命令运行在线预测时,我到达了舞台:

gcloud ml-engine local predict --model-dir=$MODEL_DIR --json-instances 
 $INPUT_FILE --framework $FRAMEWORK

它导致此错误:

ERROR: (gcloud.ml-engine.local.predict) RuntimeError: Bad magic number in .pyc file

此外,尝试使用此命令创建模型版本时:

gcloud ml-engine versions create $VERSION_NAME --model $MODEL_NAME --origin 
$MODEL_DIR --runtime-version=1.12 --framework $FRAMEWORK --python-version=3.5

它导致此错误:

ERROR: (gcloud.ml-engine.versions.create) Bad model detected with error: "Failed to load model: Could not load the model: /tmp/model/0001/model.joblib. 162. (Error code: 0)"

这里发生了什么?我正在运行Python 3.5.2。

python scikit-learn google-cloud-ml
1个回答
0
投票

我需要更多关于你在预测请求中传递给cloud ml引擎的信息,特别是它需要两个参数:

name=name, body={'instances': instances_array}

我经常看到的错误是将实体body参数作为JSON而不是数组传递。这是一个使用一些数字(浮点)变量的例子:

"instances": [
[0.46453494969873,0.96359384261176,-1.30875379350541,0.143317957209722,-1.05224729148452,0.145418363035172,1.23393185625915,1.88694142308998,0.0739610367506085,0.00900364697319474],
[2.66970600786085,0.671393792256777,0.999557100651135,0.470837952361579,-0.392487317572142,-0.758011630059567,1.56168018313734,0.363605558678856,-1.41676037696331,-0.933208457148377],]

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.