Tensorflow 服务 grpc 客户端错误 12
Tensorflow serving grpc client error 12
我目前正在尝试通过 tensorflow 服务提供一个简单的模型,然后我想使用 node.js 通过 gRRC 调用它。我觉得 learn/understand 最简单的方法是将其分解为尽可能简单的模型。请原谅我的命名,因为我最初是通过 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:No assets to save. INFO:tensorflow:No assets to write.
INFO:tensorflow:SavedModel written to: b'mnist_test/3/saved_model.pb'
所以我然后 运行 tensorflow 服务器并通过下面的行将它指向我的模型,服务器声明它是 运行nign at 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 服务器上的模型 运行ning,当我 运行 客户端在 node.js 下时,我得到以下错误。我也在客户端下打印信息,但是当我查看错误代码12的含义时,它表示如下: Operation is not implemented or not supported/enabled in this service
我在这方面已经有一段时间了,我假设我公然遗漏了其中的一部分。有没有人能够提供任何关于为什么我不能让这个简单的模型调用起作用的见解?
我还没有得到一个 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),这在创建自定义服务器时很有用。但是,TensorFlow Serving Model Server 支持具有已定义端点的服务。换句话说,您正在与模型服务器上不存在的自定义服务 "Greeter" 对话。
请看一下模型服务器的API/Service:apis/prediction_service.proto. You most likely want the Predict API: apis/predict.proto。
预测 API 使用您在导出时定义的模型签名,因此您需要为 "xval" 和 "yval" 传入张量,并获取 "spam"张量。
希望对您有所帮助!
谢谢,
诺亚
我目前正在尝试通过 tensorflow 服务提供一个简单的模型,然后我想使用 node.js 通过 gRRC 调用它。我觉得 learn/understand 最简单的方法是将其分解为尽可能简单的模型。请原谅我的命名,因为我最初是通过 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:No assets to save. INFO:tensorflow:No assets to write. INFO:tensorflow:SavedModel written to: b'mnist_test/3/saved_model.pb'
所以我然后 运行 tensorflow 服务器并通过下面的行将它指向我的模型,服务器声明它是 运行nign at 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 服务器上的模型 运行ning,当我 运行 客户端在 node.js 下时,我得到以下错误。我也在客户端下打印信息,但是当我查看错误代码12的含义时,它表示如下: Operation is not implemented or not supported/enabled in this service
我在这方面已经有一段时间了,我假设我公然遗漏了其中的一部分。有没有人能够提供任何关于为什么我不能让这个简单的模型调用起作用的见解?
我还没有得到一个 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),这在创建自定义服务器时很有用。但是,TensorFlow Serving Model Server 支持具有已定义端点的服务。换句话说,您正在与模型服务器上不存在的自定义服务 "Greeter" 对话。
请看一下模型服务器的API/Service:apis/prediction_service.proto. You most likely want the Predict API: apis/predict.proto。
预测 API 使用您在导出时定义的模型签名,因此您需要为 "xval" 和 "yval" 传入张量,并获取 "spam"张量。
希望对您有所帮助! 谢谢, 诺亚