在Google ML-Engine上使用Keras模型进行预测失败

我目前正在学习一个教程,该教程介绍了如何在Google的云服务上使用基于Keras的模型与其ML-Engine一起使用。

目前,我已经成功地让模型在本地预测等方面正常工作,并且已经成功地将导出的模型放置到GC-bucket中。我还成功创建了Google云ML-Engine模型。

当我尝试从云端托管的模型上运行预测时,会产生以下错误。

错误:

C:\mydir>gcloud ml-engine predict --model=[mymodel] --json-instances=sample_input_prescaled.json        {      "error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.FAILED_PRECONDITION, details=\"Attempting to use uninitialized value dense_4/bias\n\t [[Node: dense_4/bias/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_4/bias\"], _output_shapes=[[1]], _device=\"/job:localhost/replica:0/task:0/cpu:0\"](dense_4/bias)]]\")"    }

我可以看到这个错误提到了一个未初始化的值’dense_4’,看起来像是Keras模型中的最后一层,但我不知道为什么/是否这会导致这个过程出错?

有没有人对这个错误信息的原因有见解?

以下是我从教程中使用的Keras模型,以及用于测试预测的json文件。

export_model.py

sample_input_prescaled.json

{ “input”: [0.4999, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.5] }


回答:

上面的代码使用以下输入对我来说是有效的。

X = np.random.rand(1000,9)Y = np.random.rand(1000,1)

然后我使用了以下代码。

from keras import backend as K    sess = K.get_session()input_tensor = model.inputoutput_tensor = model.outputoutput_tensor.eval(feed_dict={input_tensor: np.random.rand(1,9)}, session=sess) 

接下来,我导出模型。在使用服务功能之前,请确保导出的模型对您有效。

 export_dir = ...      with tf.Session(graph=tf.Graph()) as sess:      tf.saved_model.loader.load(sess, [tag_constants.TRAINING], export_dir)

这样就成功了。然后,我在task.py中使用了以下服务函数来处理JSON输入,并且再次成功了。

 def json_serving_input_fn():   inputs = {}   for feat in 9:      inputs[feat.name] = tf.placeholder(shape=[None], dtype=feat.dtype)   return tf.estimator.export.ServingInputReceiver(inputs, inputs)

所以,我怀疑您的输入没有正确输入。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注