如何使用结构化数据创建 ClassificationRequest 以使用 gRPC 发送到 TensorFlow Serving
How to create ClassificationRequest with structured data to send to TensorFlow Serving with gRPC
我从 this guide. I exported it by adding the following to premade_estimator.py:
训练并导出了 Iris 分类器
feature_spec = tf.feature_column.make_parse_example_spec(my_feature_columns)
serving_input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
classifier.export_saved_model("iris_export_base", serving_input_receiver_fn)
我可以像这样使用 REST API 进行推断:
import requests
response = requests.post('http://localhost:8501/v1/models/foo:classify',
json={"examples": [{"SepalLength": 2.3,
"SepalWidth": 3.4,
"PetalLength": 2.2,
"PetalWidth": 0.81}]})
我也已经能够使用 gRPC 成功地推断出其他模型,比如这个对象检测模型,它将图像作为数组作为输入:
channel = grpc.insecure_channel(SERVER_ADDR)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = MODEL_SPEC_NAME
request.inputs['inputs'].CopyFrom(tf.contrib.util.make_tensor_proto(image_ary))
result = stub.Predict(request, 10.0)
但我不知道应该如何指定 ClassificationRequest 的输入。我最好的猜测是沿着这些方向:
channel = grpc.insecure_channel(SERVER_ADDR)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = classification_pb2.ClassificationRequest()
request.model_spec.name = MODEL_SPEC_NAME
request.input #...?
但我找不到有关如何设置输入的任何信息,而且我目前尝试的所有操作都会引发某种类型错误。
您可以在此处找到指定输入的示例:https://github.com/tensorflow/serving/blob/master/tensorflow_serving/model_servers/tensorflow_model_server_test.py#L354:
例子=request.input.example_list.examples.add()
example.features.feature['x'].float_list.value.extend([2.0])
我从 this guide. I exported it by adding the following to premade_estimator.py:
训练并导出了 Iris 分类器feature_spec = tf.feature_column.make_parse_example_spec(my_feature_columns)
serving_input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
classifier.export_saved_model("iris_export_base", serving_input_receiver_fn)
我可以像这样使用 REST API 进行推断:
import requests
response = requests.post('http://localhost:8501/v1/models/foo:classify',
json={"examples": [{"SepalLength": 2.3,
"SepalWidth": 3.4,
"PetalLength": 2.2,
"PetalWidth": 0.81}]})
我也已经能够使用 gRPC 成功地推断出其他模型,比如这个对象检测模型,它将图像作为数组作为输入:
channel = grpc.insecure_channel(SERVER_ADDR)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = predict_pb2.PredictRequest()
request.model_spec.name = MODEL_SPEC_NAME
request.inputs['inputs'].CopyFrom(tf.contrib.util.make_tensor_proto(image_ary))
result = stub.Predict(request, 10.0)
但我不知道应该如何指定 ClassificationRequest 的输入。我最好的猜测是沿着这些方向:
channel = grpc.insecure_channel(SERVER_ADDR)
stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)
request = classification_pb2.ClassificationRequest()
request.model_spec.name = MODEL_SPEC_NAME
request.input #...?
但我找不到有关如何设置输入的任何信息,而且我目前尝试的所有操作都会引发某种类型错误。
您可以在此处找到指定输入的示例:https://github.com/tensorflow/serving/blob/master/tensorflow_serving/model_servers/tensorflow_model_server_test.py#L354:
例子=request.input.example_list.examples.add() example.features.feature['x'].float_list.value.extend([2.0])