0

在为部署在 GCP 上的 ML 模型设置 GRPC 时,我需要帮助。我已经部署了模型并希望使用 GRPC 为其提供服务,但找不到任何有关如何执行此操作的文档。有没有人有关于以下的任何信息:-

  1. 如何为部署在 ml.googleapis.com 的 TF 服务模型激活 GRPC?
  2. 使用授权的 GRPC 服务模型需要哪些步骤?

目前有足够的文档来处理 JSON 请求,但是这些请求变得非常大,我需要一个减小大小的替代方法,这就是为什么需要在上面找到更多文档的原因。现在我收到错误

InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNKNOWN
    details = "Stream removed"

让我知道您是否需要更多信息。

这是我正在使用的代码

from google import auth as google_auth
from google.auth.transport import requests as google_auth_transport_requests
from google.auth.transport import grpc as google_auth_transport_grpc
from tensorflow_serving.apis import predict_pb2

def _make_grpc_request(examples):
    scoped_credentials, _ = google_auth.default(scopes=('https://www.googleapis.com/auth/cloud-platform',))
    request = google_auth_transport_requests.Request()
    channel = google_auth_transport_grpc.secure_authorized_channel(
    scoped_credentials, request, 'ml.googleapis.com:443')

    """Builds and sends request to TensorFlow model server."""
    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'nudity2'                           
    request.model_spec.signature_name = 'serving_default'
    request.inputs["input"].CopyFrom(
        tf.make_tensor_proto(examples))
    p_s=PredictionServiceStub(channel)
    response = p_s.Predict(request, 1000)
    response
    return response

    return _make_grpc_request
4

0 回答 0