簡體   English   中英

TensorFlow 服務 REST API 的輸入

[英]Inputs to TensorFlow serving REST API

我參考這個教程建立了一個seq2seq模型。 https://keras.io/examples/nlp/lstm_seq2seq/

訓練完模型后,我沒有直接保存模型,而是分別保存了encoder_model和decoder_model。我正在使用TensorFlow serving來部署這兩個模型。

編碼器模型輸入是一個長度為 1 的 numpy 數組,因此我將其轉換為 JSON 以傳遞給 REST API。 這奏效了,我得到了想要的結果。

但是,對於解碼器,此方法不起作用,因為 decoder_input 的長度為 3 且 data_type 為 numpy 數組。

在調用 decoder_model 的 decode_sequence 函數塊之后。

dec_model_url = "http://localhost:8400/v1/models/dec_model:predict"
headers = {
    'content-type': "application/json;charset=UTF-8'",
    'cache-control': "no-cache",
    'Accept':'application/json'
    }
    while not stop_condition:
        decoder_ip = ([target_seq] + states_value)
        target_seq1 = target_seq.tolist()
        target_seq1=[target_seq1]

        states_value1 = states_value
        states_value1[0] = states_value1[0].tolist()
        states_value1[1] = states_value1[1].tolist()


        decoder_ip1 = (target_seq1 + states_value1[0] + states_value1[1])
        start_main = '{"instances":'
        end_main = '}'
        decoder_ip1 = start_main + str(decoder_ip1) +end_main


        output_tokens, h = requests.request("POST", dec_model_url, data=decoder_ip1, headers=headers)

當我運行它時,出現以下錯誤。

{“error”:“instances 是一個普通列表,但期望對象列表作為 tensorinfo_map 所需的多個輸入張量”

使用 REST API 傳遞 decoder_model 輸入的正確方法是什么?

這個問題與Github Issue完全相似,我已經為那個問題提供了解決方法,它已經解決了,所以你能在這里看看這個問題的解決方法 我希望它能幫助您解決問題。 謝謝!

暫無
暫無

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

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