gRPC,TensorFlow服务“收到的RST_STREAM,错误代码为2”

时间:2018-07-13 08:05:53

标签: python tensorflow grpc tensorflow-serving

我试图调用我的TF人工神经网络模型,该模型部署在SAP Cloud的Cloud Foundry环境中,并从Keras模型转换为TensorFlow SavedModel格式。

因此,我有一个使用TensorFlow Serving和gRPC的Python2 API。尝试在本地venv中执行API时,我已经出现错误。

API代码:

import os
import grpc
from grpc.beta import implementations
import tensorflow as tf
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2

MODEL_NAME = str(os.getenv('MODEL_NAME', ''))
MODEL_SERVER_HOST = str(os.getenv('MODEL_SERVER_HOST', ''))
MODEL_SERVER_PORT = int(os.getenv('MODEL_SERVER_PORT', ''))
ROOT_CERT = str(os.getenv('ROOT_CERT', '')).replace('\\n', '\n')

def metadata_transformer(metadata):
    additions = []

    token = 'Bearer <my Access Token>'
    additions.append(('authorization', token))
    return tuple(metadata) + tuple(additions)

credentials = implementations.ssl_channel_credentials(root_certificates=ROOT_CERT)
channel = implementations.secure_channel(MODEL_SERVER_HOST,MODEL_SERVER_PORT, credentials)
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel, metadata_transformer=metadata_transformer)

#grpc non beta --> does not work for tf serving? -->Rendezvous of RPC that terminated with (StatusCode.UNAVAILABLE, Name resolution failure
#credentials = grpc.ssl_channel_credentials(root_certificates=ROOT_CERT)
#server = "'" + MODEL_SERVER_HOST + ':' + str(MODEL_SERVER_PORT) + "'"
#channel = grpc.secure_channel(server, credentials)
#non beta --> can't add metadata --> adding in request below
#stub = prediction_service_pb2.PredictionServiceStub(channel)

# test:
import numpy as np
data = np.matrix([<a Test matrix>])

request = predict_pb2.PredictRequest()
request.model_spec.name = MODEL_NAME
#request.model_spec.signature_name = 'ticketCatFeature2'
request.inputs['input'].CopyFrom(
    tf.contrib.util.make_tensor_proto(data, shape=[200], dtype=tf.float32))

#out = stub.Predict(request, 200, metadata=metadata_transformer)
out = stub.Predict(request, 200)

出现以下错误消息:

  

grpc.framework.interfaces.face.face.AbortionError:AbortionError(code = StatusCode.INTERNAL,details =“已收到RST_STREAM,错误代码为2”)

如您所见,我还尝试使用TF Serving和gRPC(注释部分)的非beta功能进行请求。但这会导致另一个错误:

  

grpc._channel._Rendezvous:<以(StatusCode.UNAVAILABLE,名称解析失败)结尾的RPC的__Rendezvous>

gRPC调试总数:https://files.fm/u/d8htpjyq

我不知道如何解决此问题,也看不到使用其他框架调用我的AI模型的工作环境,因为SAP Cloud仅支持TF 1.4的TF模型。对于gRPC错误,我将不胜感激。

状态更新:我还测试了如何在具有相同示例数据的jupyter笔记本中加载和运行我的模型,并且它可以按预期工作,我的AI模型不应成为错误的原因

0 个答案:

没有答案