2

The predict command I have been using for quite some time began encountering an error this weekend:

$ gcloud beta ml predict --model my_model --json-instances my_instance.json

WARNING: The `gcloud beta ml` commands have been renamed and will soon be removed. Please use `gcloud ml-engine` instead.
ERROR: (gcloud.beta.ml.predict) value for field [projectsId] for in collection [ml.projects.models] is required but was not provided

I do not understand how to fix the error.

To investigate whether the error is associated with the soon to be removed 'cloud beta ml' command, I replaced it with 'gcloud ml-engine' but encountered this error:

$ gcloud ml-engine predict --model my_model --json-instances my_instance.json
ERROR: (gcloud.ml-engine.predict) HTTP request failed. Response: {
  "error": {
    "code": 400,
    "message": "Precondition check failed.",
    "status": "FAILED_PRECONDITION"
  }
}

I do not understand how to fix this second error. Presumably, its root cause is the same as the first error.

How can I get more detail about fixing this error(s)?

Note: this question appears similar this other question asked by @jbird, but is not the same.

Community
  • 1
  • 1
Chuck Finley
  • 250
  • 1
  • 10
  • I'm actually having the same problem, despite the fact that prediction is working just fine when using `gcloud ml-engine local predict` with the exact same model and instance data. No luck with a solution thus far. – kbhomes Mar 21 '17 at 19:05
  • @kbhomes do you also get the same error as me ("...value for field [projectsId] for in collection...") for 'gcloud beta ml predict'? – Chuck Finley Mar 21 '17 at 21:27
  • Yep, I get that error as well (although I just started working with ML Engine today so I wasn't previously using `gcloud beta ml predict` before) – kbhomes Mar 21 '17 at 21:57
  • I have the same problem. Predictions were working a couple weeks ago. Something broke in an update. – user1389840 Mar 22 '17 at 06:40

1 Answers1

3

The gcloud tool has been updated so that the ml-engine set of commands is the officially supported way to interact with the service. The gcloud beta ml codepath is out-of-date. The following should work:

gcloud beta ml-engine predict --model my_model --json-instances my_instance.json

(Note the presence of the keyword beta).

The reason for the 400 error when using gcloud ml-engine predict (note the absence of the keyword beta) is because your model is not a SavedModel. In that set of commands (non-beta), we only support SavedModel.

You can continue to use your existing models via the old endpoint (gcloud beta ...), but we expect to deprecate that functionality soon, so we recommend exporting new models as SavedModels and deploying them via gcloud ml-engine.

rhaertel80
  • 8,254
  • 1
  • 31
  • 47
  • marking this as answered, thank you! When you "recommend exporting new models as SavedModels", what does that mean for my existing models, please? (My existing models were trained using https://cloud.google.com/blog/big-data/2016/12/how-to-train-and-classify-images-using-google-cloud-machine-learning-and-cloud-dataflow.) Is there a way for one to convert an existing model vs one has to train an entirely new model? – Chuck Finley Mar 22 '17 at 15:07
  • @rhaertel80 I'm confused by this, since like @ChuckFinley I used the training method that he linked, running the code pretty much exactly and obtaining a `saved_model.pb` file and `variables` folder and in fact the code uses a `SavedModelBuilder` to export the model. Is this not a `SavedModel` compatible with ML Engine? Additionally, `gcloud ml-engine local predict` works perfectly fine with the exact same model on my machine. – kbhomes Mar 22 '17 at 16:49
  • @kbhomes what command did you use to deploy the model and what are you using for prediction (paying close attention to `beta` vs. not and `ml` vs. `ml-engine`). – rhaertel80 Mar 22 '17 at 18:45
  • @rhaertel80 the commands are 'gcloud beta ml models create "$MODEL_NAME"' and 'gcloud beta ml versions create "$VERSION_NAME" \ --model "$MODEL_NAME" \ --origin "${GCS_PATH}/training/model"' – Chuck Finley Mar 22 '17 at 20:11
  • @ChuckFinley. Thanks, I'm guessing predict call uses `gcloud beta ml predict`? – rhaertel80 Mar 22 '17 at 23:45
  • @ChuckFinley I just added a post describing how you can convert the model. Warning: it's untested code. http://stackoverflow.com/questions/42968628/how-do-i-convert-a-cloudml-alpha-model-to-a-savedmodel/42968629#42968629 – rhaertel80 Mar 23 '17 at 06:22
  • @rhaertel80 you correctly guessed the predict call. Thank you for the additional post! I will gratefully review and use it. – Chuck Finley Mar 23 '17 at 13:09