簡體   English   中英

張量流/服務與前 n 個對數返回

[英]tensorflow/serving with top n logits to return

我目前正在應對以可擴展的方式為我的 tensorflow 模型提供服務的挑戰。 據我所知,推薦的解決方案是使用標准的TensorFlow ModelServer 通用要求可以很好地處理 - 但我想要更多。 我想通過解析像“limit”這樣的參數來定義要返回的前 n 個 logits + probabilites 來減少傳輸的數據量。

在我的研究中,我確定了以下解決方案:

1) 在模型構建過程中創建更高級的 SignatureDef。

2) 使用上述功能自定義基本的tensorflow/serving項目。

3) 使用標准的 Tensorflow Modelserver 為模型提供服務,並構建一個后處理服務來重構 resp。 以預定義的方式過濾結果。

比我更有經驗的人可以詳細介紹我的問題嗎? - 代碼片段或鏈接會很棒。

提前致謝。

您的解決方案 3,

“使用標准的 Tensorflow Modelserver 為模型提供服務,並構建一個后處理服務,以按照預定義的方式重構和過濾結果。”

應該是最好的。

鏈接和代碼片段:如果我們考慮使用 TF Serving 的 MNIST 示例,保存模型的鏈接是, https://github.com/tensorflow/serving/blob/87e32bb386f156fe208df633c1a7f489b57464e1/tensorflow_serving/example_model .

客戶端代碼的鏈接是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 Predictions。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM