【问题标题】:Unable to run faster R-CNN with elastic inference and tensorflow serving - how to debug?无法通过弹性推理和张量流服务运行更快的 R-CNN - 如何调试?
【发布时间】:2022-01-06 15:34:55
【问题描述】:

我从 Tensorflow 的 Model Zoo 中找到了一个 saved_model。我可以使用以下代码在本地运行我的 Faster R-CNN 模型:

image_np = np.array(Image.open('my_input.jpg'))
image = np.asarray(image_np)
input_tensor = tf.convert_to_tensor(image)
input_tensor = input_tensor[tf.newaxis,...]

model = tf.saved_model.load(os.path.join('<PATH_TO_SAVED_MODEL>'))
model = model.signatures['serving_default']

output_dict = model(input_tensor)

我想尝试使用 Elastic Inference 运行它,并从 this guide 开始。我在启动 tensorflow 时通过更改 save_model 的路径来换掉正在运行的更快的 r-cnn 模型:

EI_VISIBLE_DEVICES=0 amazonei_tensorflow_model_server --model_name=f_r_cnn --model_base_path=/tmp/f_r_cnn --port=9000

现在我正在尝试使用提供的模板运行客户端与 tensorflow 服务对话:

from __future__ import print_function

import grpc
import tensorflow as tf
from PIL import Image
import numpy as np
import time
import os
from tensorflow_serving.apis import predict_pb2
from tensorflow_serving.apis import prediction_service_pb2_grpc

tf.app.flags.DEFINE_string('server', 'localhost:9000',
                           'PredictionService host:port')
tf.app.flags.DEFINE_string('image', '', 'path to image in JPEG format')
FLAGS = tf.app.flags.FLAGS

coco_classes_txt = "https://raw.githubusercontent.com/amikelive/coco-labels/master/coco-labels-paper.txt"
local_coco_classes_txt = "/tmp/coco-labels-paper.txt"
# it's a file like object and works just like a file
os.system("curl -o %s -O %s"%(local_coco_classes_txt, coco_classes_txt))
NUM_PREDICTIONS = 5
with open(local_coco_classes_txt) as f:
  classes = ["No Class"] + [line.strip() for line in f.readlines()]


def main(_):
  channel = grpc.insecure_channel(FLAGS.server)
  stub = prediction_service_pb2_grpc.PredictionServiceStub(channel)

  # Send request
  with Image.open(FLAGS.image) as f:
    f.load()
    # See prediction_service.proto for gRPC request/response details.
    data = np.asarray(f)
    data = np.expand_dims(data, axis=0)

    request = predict_pb2.PredictRequest()
    request.model_spec.name = 'f_r_cnn'
    request.inputs['inputs'].CopyFrom(
        tf.contrib.util.make_tensor_proto(data, shape=data.shape))
    result = stub.Predict(request, 60.0)  # 10 secs timeout
    outputs = result.outputs
    detection_classes = outputs["detection_classes"]
    detection_classes = tf.make_ndarray(detection_classes)
    num_detections = int(tf.make_ndarray(outputs["num_detections"])[0])
    print("%d detection[s]" % (num_detections))
    class_label = [classes[int(x)]
                   for x in detection_classes[0][:num_detections]]
    print("SSD Prediction is ", class_label)


if __name__ == '__main__':
  tf.app.run()

虽然该客户端使用教程中的模型运行良好(这并不奇怪),但当我尝试让它与我的 Faster R-CNN 模型对话时它失败了,并出现以下错误:

debug_error_string = "{"created":"@1579654607.391705065","description":"Error received from peer ipv6:[::1]:9000","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Unexpected error in RPC handling","grpc_status":2}"

我用谷歌搜索了这个错误,但找不到任何有用的东西。什么是 grpc_status 2?我怎样才能找到有用的信息来帮助我指明正确的方向?

【问题讨论】:

    标签: tensorflow tensorflow-serving


    【解决方案1】:

    "grpc_message":"RPC 处理出现意外错误","grpc_status":2}"

    表示服务器端处理请求的方法处理程序在被调用时抛出了异常。 (我们捕获所有异常并抛出这个通用错误)。所以我认为您可以通过查看 RPC 请求的服务器端方法处理程序来进行调试。

    【讨论】:

      【解决方案2】:

      gRPC 状态 2 是 UNKNOWN。但从错误消息中不清楚是什么原因造成的。我怀疑这更像是 TensorFlow 问题而不是 gRPC 问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-29
        • 1970-01-01
        • 2018-01-11
        • 1970-01-01
        相关资源
        最近更新 更多