Tensorflow服务grpc客户端错误12

我目前正在尝试通过张量服务服务一个简单的模型,然后我想通过使用node.js通过gRRC调用它。 我觉得学习/理解这个最简单的方法就是把它分解成最简单的模型。 请原谅这个命名,因为我最初是用一个Mnist教程开始做的,但是我也没有成功。 所以这个名字还是说mnist,但这只是一个简单的计算实现。

我使用下面的代码创build和导出模型: – 简单模型 –

x = tf.placeholder(tf.float32, shape=(None)) y = tf.placeholder(tf.float32, shape=(None)) three = tf.Variable(3, dtype=tf.float32) z = tf.scalar_mul(three, x) + y 

– 出口 –

 model_version = 1 path = os.path.join("mnist_test", str(model_version)) builder = tf.python.saved_model.builder.SavedModelBuilder(path) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) builder.add_meta_graph_and_variables( sess, [tf.python.saved_model.tag_constants.SERVING], signature_def_map = { "test_mnist_model": tf.saved_model.signature_def_utils.predict_signature_def( inputs={"xval": x, "yval":y}, outputs={"spam":z}) }) builder.save() 

当我运行这个消息时,最后的消息似乎是成功的:

INFO:tensorflow:没有资产要保存。 信息:tensorflow:没有资产要写。 INFO:tensorflow:SavedModel写入:b'mnist_test / 3 / saved_model.pb'

所以我然后运行tensorflow服务器,并通过下面的一行将它指向我的模型,服务器状态为0.0.0.0:9000:

 ../../bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server --model_base_path=mnist_test --model_name=calctest --port=9000 

然后我开始设置.proto文件,它包含这个:

 syntax = "proto3"; option java_multiple_files = true; option java_package = "io.grpc.examples.mnisttest"; option java_outer_classname = "MnistTestProto"; option objc_class_prefix = "MNT"; package mnisttest; // The greeting service definition. service Greeter { // Sends a greeting rpc test_mnist_model (InputRequest) returns (OutputReply) {} } // The request message containing the user's name. message InputRequest { float xval = 1; float yval = 2; } // The response message containing the greetings message OutputReply { float spam = 1; } 

最后,我安装了一个mnistclient.js文件,我在node.js下运行它,它包含下面的代码:

 var grpc = require('grpc') var PROTO_PATH = __dirname + '/../../protos/mnisttest.proto'; module.exports = (connection) => { var tensorflow_serving = grpc.load(PROTO_PATH).mnisttest;//.serving; console.log(tensorflow_serving); var client = new tensorflow_serving.Greeter( connection, grpc.credentials.createInsecure() ); return { test: () => { console.log(client); return client.testMnistModel({xval:5.0,yval:6.0}, function(err, response){ if(err){ console.log("Error: ",JSON.stringify(err)); return {Err: JSON.stringify(err)}; } console.log('Got message ', response); }); } } }; function main() { var cli = module.exports('localhost:9000') cli.test(); } if( require.main === module){ main(); } 

在tf服务器上运行模型时,当我在node.js下运行客户端时,出现以下错误。 我也打印出客户端下的信息,但是当我查找了错误代码12的含义时,它指出了以下内容: 此服务中没有执行或不支持/启用操作

我已经在这个相当长的一段时间了,我认为这是我公然遗漏的一部分。 有没有人能够提供任何洞察力,为什么我不能把这个简单的调用模型工作?

我还没有能够得到TF模型服务,并认为采取这种简单的方法将工作最好的,但我甚至不能得到这个工作。 任何帮助,这将是一个很大的帮助! 提前致谢!

 { InputRequest: { [Function: Message] encode: [Function], decode: [Function], decodeDelimited: [Function], decode64: [Function], decodeHex: [Function], decodeJSON: [Function] }, OutputReply: { [Function: Message] encode: [Function], decode: [Function], decodeDelimited: [Function], decode64: [Function], decodeHex: [Function], decodeJSON: [Function] }, Greeter: { [Function: Client] service: { testMnistModel: [Object] } } } Client { '$channel': Channel {} } Error: {"code":12,"metadata":{"_internal_repr":{}}} 

看起来您已经定义了一个服务接口协议(mnisttest.proto),这在创build自定义服务器时非常有用。 但是,TensorFlow服务模型服务器支持具有已定义端点的服务。 换句话说,您正在与模型服务器上不存在的定制服务“Greeter”交谈。

请看Model Server的API /服务: apis / prediction_service.proto 。 您很可能需要预测API: apis / predict.proto 。

Predict API使用您在导出时定义的模型签名,因此您需要传递“xval”和“yval”的张量,并获取“垃圾邮件”张量。

希望这可以帮助! 谢谢,诺亚