简体   繁体   中英

Scikit Learn model results in error when calling local predict or creating model version on Google Cloud ml engine

I'm trying to deploy a model to the cloud-ml engine by following the tutorial here ( https://cloud.google.com/ml-engine/docs/scikit/quickstart ), however when I reach the stage when I'm running the online prediction with this command:

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

It results in this error:

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

Additionally, when trying to create a model version with this command:

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

It results in this error:

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)"

What's going on here? I'm running Python 3.5.2.

I would need a bit more information regarding what you passing over to cloud ml engine in the predict request, in particular it takes in two params:

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

An error I often see is passing the instances body parameter as a JSON rather than as an array. here is an example using a few numerical (float) variables:

"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],]

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM