我尝试使用此代码扩展TensorFlow 1.4 iris example以保存模型:
feature_spec = {"sepal_length": tf.FixedLenFeature(dtype=tf.float32, shape=[1], default_value=0.0),
"sepal_width": tf.FixedLenFeature(dtype=tf.float32, shape=[1], default_value=0.0),
"petal_length": tf.FixedLenFeature(dtype=tf.float32, shape=[1], default_value=0.0),
"petal_width": tf.FixedLenFeature(dtype=tf.float32, shape=[1], default_value=0.0)}
export_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
classifier.export_savedmodel(export_dir_base="tmp/iris_model", serving_input_receiver_fn=export_input_fn)
使用文本文件(iris.txt):
5.1,3.3,1.7,0.5
然后做这样的本地预测:
MODEL_DIR=tmp/iris_model/1516913526
gcloud ml-engine local predict \
--model-dir $MODEL_DIR \
--text-instances ./iris.txt
但是我收到了这个错误:
错误:(gcloud.ml-engine.local.predict)2018-01-25 22:12:00.675756:I tensorflow / core / platform / cpu_feature_guard.cc:137]你的CPU支持这个TensorFlow二进制文件没有的指令编译使用:SSE4.1 SSE4.2 AVX AVX2 FMA 警告:root:MetaGraph有多个签名3.对多个签名的支持是有限的。默认情况下,我们选择命名签名。 2018-01-25 22:12:00.818033:W tensorflow / core / framework / op_kernel.cc:1192]无效参数:无法解析示例输入,值:' 5.1,3.3,1.7,0.5' 错误:root:运行图表时出现异常:无法解析示例输入,值:' 5.1,3.3,1.7,0.5' [[Node:ParseExample / ParseExample = ParseExample [Ndense = 4,Nsparse = 0,Tdense = [DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT],dense_shapes = [[1],[1],[1],[1]], sparse_types = [],_ device =" / job:localhost / replica:0 / task:0 / device:CPU:0"](_ arg_input_example_tensor_0_0,ParseExample / ParseExample / names,ParseExample / ParseExample / dense_keys_0,ParseExample / ParseExample / dense_keys_1,ParseExample / ParseExample / dense_keys_2,ParseExample / ParseExample / dense_keys_3,ParseExample / Reshape,ParseExample / Reshape,ParseExample / Resarpe,ParseExample / Reshape)]]
由op u' ParseExample / ParseExample'引起,定义于: 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",第111行,in 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",106行,主要 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py",第991行,在local_predict中 client = SessionClient(* load_model(model_dir,tags,signature_name)) 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py" ;,第410行,在load_model中 meta_graph = loader.load(session,tags = list(tags),export_dir = model_path) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/saved_model/loader_impl.py" ;,第216行,加载 saver = tf_saver.import_meta_graph(meta_graph_def_to_load,** saver_kwargs) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py",第1810行,在import_meta_graph中 ** kwargs) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/meta_graph.py",第660行,在import_scoped_meta_graph中 producer_op_list = producer_op_list) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py",第313行,在import_graph_def中 op_def = op_def) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py",第2956行,在create_op中 op_def = op_def) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py",第1470行, init self._traceback = self._graph._extract_stack()#pylint:disable = protected-access
InvalidArgumentError(参见上面的回溯):无法解析示例输入,值:' 5.1,3.3,1.7,0.5' [[Node:ParseExample / ParseExample = ParseExample [Ndense = 4,Nsparse = 0,Tdense = [DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT],dense_shapes = [1,1,1 ,1],sparse_types = [],_ device =" / job:localhost / replica:0 / task:0 / device:CPU:0"](_ arg_input_example_tensor_0_0,ParseExample / ParseExample / names, ParseExample / ParseExample / dense_keys_0,ParseExample / ParseExample / dense_keys_1,ParseExample / ParseExample / dense_keys_2,ParseExample / ParseExample / dense_keys_3,ParseExample / Resarpe,ParseExample / Reshape,ParseExample / Resarpe,ParseExample / Reshape)]]
追踪(最近一次通话): 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",第111行,in 主要() 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",106行,主要 实例=实例) 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py",第993行,在local_predict中 _,predictions = model.predict(instances) 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py" ;,第375行,预测 predict_outputs = self._client.predict(preprocessed,stats) 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py" ;,第530行,预测 "运行图表时出现异常:" + str(e)) prediction_lib.PredictionError:无法运行提供的模型:运行图形时出现异常:无法解析示例输入,值:' 5.1,3.3,1.7,0.5' [[Node:ParseExample / ParseExample = ParseExample [Ndense = 4,Nsparse = 0,Tdense = [DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT],dense_shapes = [[1],[1],[1],[1]], sparse_types = [],_ device =" / job:localhost / replica:0 / task:0 / device:CPU:0"](_ arg_input_example_tensor_0_0,ParseExample / ParseExample / names,ParseExample / ParseExample / dense_keys_0,ParseExample / ParseExample / dense_keys_1,ParseExample / ParseExample / dense_keys_2,ParseExample / ParseExample / dense_keys_3,ParseExample / Reshape,ParseExample / Reshape,ParseExample / Resarpe,ParseExample / Reshape)]]
由op u' ParseExample / ParseExample'引起,定义于: 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",第111行,in 文件" lib / googlecloudsdk / command_lib / ml_engine / local_predict.py",106行,主要 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py",第991行,在local_predict中 client = SessionClient(* load_model(model_dir,tags,signature_name)) 文件" /usr/lib/google-cloud-sdk/lib/third_party/cloud_ml_engine_sdk/prediction/prediction_lib.py" ;,第410行,在load_model中 meta_graph = loader.load(session,tags = list(tags),export_dir = model_path) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/saved_model/loader_impl.py" ;,第216行,加载 saver = tf_saver.import_meta_graph(meta_graph_def_to_load,** saver_kwargs) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py",第1810行,在import_meta_graph中 ** kwargs) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/meta_graph.py",第660行,在import_scoped_meta_graph中 producer_op_list = producer_op_list) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/importer.py",第313行,在import_graph_def中 op_def = op_def) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py",第2956行,在create_op中 op_def = op_def) 文件" /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py",第1470行, init self._traceback = self._graph._extract_stack()#pylint:disable = protected-access
InvalidArgumentError(参见上面的回溯):无法解析示例输入,值:' 5.1,3.3,1.7,0.5' [[Node:ParseExample / ParseExample = ParseExample [Ndense = 4,Nsparse = 0,Tdense = [DT_FLOAT,DT_FLOAT,DT_FLOAT,DT_FLOAT],dense_shapes = [[1],[1],[1],[1]], sparse_types = [],_ device =" / job:localhost / replica:0 / task:0 / device:CPU:0"](_ arg_input_example_tensor_0_0,ParseExample / ParseExample / names,ParseExample / ParseExample / dense_keys_0,ParseExample / ParseExample / dense_keys_1,ParseExample / ParseExample / dense_keys_2,ParseExample / ParseExample / dense_keys_3,ParseExample / Reshape,ParseExample / Reshape,ParseExample / Resarpe,ParseExample / Reshape)] (错误代码:2)
我错过了什么?