tensorflow/serving 前 n 个登录到 return
tensorflow/serving with top n logits to return
我目前正在应对以可扩展方式为我的 tensorflow 模型提供服务的挑战。据我所知,推荐的解决方案是使用标准 TensorFlow ModelServer。这很好地处理了常见要求 - 但我想要更多。我想通过解析 "limit" 之类的参数来减少传输的数据量,以将前 n 个 logits + 概率定义为 return.
在研究过程中,我确定了以下解决方案:
1) 在模型构建过程中创建更高级的 SignatureDef。
2) 使用上述功能自定义基本 tensorflow/serving 项目。
3) 使用标准 Tensorflow 模型服务器为模型提供服务,并构建后处理服务以重新构建 resp。以预定义方式过滤结果。
有比我更有经验的人可以详细介绍一下我的问题吗? - 代码片段或链接会很棒。
提前致谢。
您的解决方案编号 3,
"Serve the model with the standard Tensorflow Modelserver and build a
postprocessing service to restructure resp. filter the result in the
predefined way."
应该是最好的
链接和代码片段:如果我们考虑使用 TF 服务的 MNIST 示例,保存模型的 link 是 https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_saved_model.py、
客户端代码的 link 是 https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_client.py。
如果我们想要 top-n 个预测值,我们可以调整函数的代码,_create_rpc_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
语句将打印 Top-4 预测。
我目前正在应对以可扩展方式为我的 tensorflow 模型提供服务的挑战。据我所知,推荐的解决方案是使用标准 TensorFlow ModelServer。这很好地处理了常见要求 - 但我想要更多。我想通过解析 "limit" 之类的参数来减少传输的数据量,以将前 n 个 logits + 概率定义为 return.
在研究过程中,我确定了以下解决方案:
1) 在模型构建过程中创建更高级的 SignatureDef。
2) 使用上述功能自定义基本 tensorflow/serving 项目。
3) 使用标准 Tensorflow 模型服务器为模型提供服务,并构建后处理服务以重新构建 resp。以预定义方式过滤结果。
有比我更有经验的人可以详细介绍一下我的问题吗? - 代码片段或链接会很棒。
提前致谢。
您的解决方案编号 3,
"Serve the model with the standard Tensorflow Modelserver and build a postprocessing service to restructure resp. filter the result in the predefined way."
应该是最好的
链接和代码片段:如果我们考虑使用 TF 服务的 MNIST 示例,保存模型的 link 是 https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_saved_model.py、
客户端代码的 link 是 https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example/mnist_client.py。
如果我们想要 top-n 个预测值,我们可以调整函数的代码,_create_rpc_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
语句将打印 Top-4 预测。