tensorflow/返回前n名登录服务

tensorflow/返回前n名登录服务,tensorflow,tensorflow-serving,serving,tfx,Tensorflow,Tensorflow Serving,Serving,Tfx,我目前正在应对挑战,以一种可扩展的方式为我的tensorflow模型提供服务。据我所知,推荐的解决方案是使用标准。这可以很好地处理常见的需求,但我需要更多。我想通过解析像“limit”这样的参数来定义要返回的前n个logits+概率,从而减少传输的数据量 在研究过程中,我确定了以下解决方案: 1) 在建模期间创建更高级的SignatureDef 2) 使用上述功能自定义基本项目 3) 使用标准的Tensorflow Modelserver为模型提供服务,并构建一个后处理服务来重构resp。以预定

我目前正在应对挑战,以一种可扩展的方式为我的tensorflow模型提供服务。据我所知,推荐的解决方案是使用标准。这可以很好地处理常见的需求,但我需要更多。我想通过解析像“limit”这样的参数来定义要返回的前n个logits+概率,从而减少传输的数据量

在研究过程中,我确定了以下解决方案:

1) 在建模期间创建更高级的SignatureDef

2) 使用上述功能自定义基本项目

3) 使用标准的Tensorflow Modelserver为模型提供服务,并构建一个后处理服务来重构resp。以预定义的方式过滤结果

能找一个比我更有经验的人详细谈谈我的问题吗代码片段或链接会很棒


提前感谢。

您的解决方案3

“使用标准Tensorflow Modelserver为模型提供服务,并构建 用于重新构造响应的后处理服务。在 预定义方式。”

应该是最好的

链接和代码片段:如果我们考虑使用TF服务的MNIST的例子,保存模型的链接是,

客户端代码的链接是

如果我们想要top-n预测值,我们可以调整客户端文件中函数的代码,
\u create\u rpc\u callback
,如下所示

def _create_rpc_callback(label, result_counter):
  """Creates RPC callback function.

  Args:
    label: The correct label for the predicted example.
    result_counter: Counter for the prediction result.
  Returns:
    The callback function.
  """
  def _callback(result_future):
    """Callback function.

    Calculates the statistics for the prediction result.

    Args:
      result_future: Result future of the RPC.
    """
    exception = result_future.exception()
    if exception:
      result_counter.inc_error()
      print(exception)
    else:
      sys.stdout.write('.')
      sys.stdout.flush()
      response = numpy.array(result_future.result().outputs['scores'].float_val)
      print('Top 4 responses = ', response[0:4]) 
最后一行中的
print
语句将打印前四个预测