Python 如何使用结构化数据创建ClassificationRequest,以发送给使用gRPC服务的TensorFlow

Python 如何使用结构化数据创建ClassificationRequest,以发送给使用gRPC服务的TensorFlow,python,tensorflow,grpc,tensorflow-serving,Python,Tensorflow,Grpc,Tensorflow Serving,我从中训练并导出虹膜分类器。我通过添加以下内容将其导出到: 我可以使用REST API进行如下推断: import requests response = requests.post('http://localhost:8501/v1/models/foo:classify', json={"examples": [{"SepalLength": 2.3,

我从中训练并导出虹膜分类器。我通过添加以下内容将其导出到:

我可以使用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 #...?

但是我找不到关于如何设置输入的任何信息,而且到目前为止我所尝试的一切都会抛出某种类型的类型错误

您可以在此处找到指定输入的示例::

example=request.input.example\u list.examples.add() 示例.features.feature['x'].float_list.value.extend([2.0])

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 #...?