张量流服务 grpc 客户端错误 12



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

我使用以下代码创建并导出了模型: -- 简单模型 --

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: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 服务器上运行模型时,当我在节点下运行客户端时.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":{}}}

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

请查看模型服务器的API/Service:apis/prediction_service.proto。您最有可能想要 Predict API:apis/predict.proto。

预测 API 使用您在导出时定义的模型签名,因此您需要传入 "xval" 和 "yval" 的张量,并获取 "spam" 张量。

希望这有帮助! 谢谢 诺亚

相关内容

最新更新