0

我試圖用tensorflow對象檢測寵物示例對gcloud ml-engine進行預測,但它不起作用。 https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_pets.md張量流服務預測不與物體檢測寵物一起使用示例

隨着tensorflow團隊的幫助下,我才得以創建saved_model上傳到gcloud毫升引擎: https://github.com/tensorflow/models/issues/1811

現在,我

我用這個例子中創建了一個檢查點可以將模型上傳到gcloud ml引擎。但不幸的是,我無法對模型做出正確的預測請求。每當我的預測,我得到了同樣的錯誤:

Input instances are not in JSON format. 

我試圖做網上預測的結果與

gcloud ml-engine predict --model od_test --version v1 --json-instances prediction_test.json 

,我試圖做批量預測與

gcloud ml-engine jobs submit prediction "prediction7" 
    --model od_test 
    --version v1 
    --data-format TEXT 
    --input-paths gs://ml_engine_test1/prediction_test.json 
    --output-path gs://ml_engine_test1/prediction_output 
    --region europe-west1 

我想提交一個圖像列表作爲unit8-matrices,所以對於輸出我使用輸入類型image_tensor

正如這裏的文檔所述:https://cloud.google.com/ml-engine/docs/concepts/prediction-overview#prediction_input_data,輸入json應該有一個特定的格式。但是在線預測的格式,以及批量預測的格式都無法正常工作。我的最新的測試是與內容的單個文件:

{"instances": [{"values": [1, 2, 3, 4], "key": 1}]} 

和內容:

{"images": [0.0, 0.3, 0.1], "key": 3} 
{"images": [0.0, 0.7, 0.1], "key": 2} 

他們無工作。任何人都可以幫助我,輸入格式應該如何?

編輯

從批量處理中的錯誤是

{ 
    insertId: "1a26yhdg2wpxvg6" 
    jsonPayload: { 
     @type: "type.googleapis.com/google.cloud.ml.api.v1beta1.PredictionLogEntry"  
     error_detail: { 
      detail: "No JSON object could be decoded"  
      input_snippet: "Input snippet is unavailable."  
     } 
     message: "No JSON object could be decoded"  
    } 
    logName: "projects/tensorflow-test-1-168615/logs/worker" 
    payload: { 
     @type: "type.googleapis.com/google.cloud.ml.api.v1beta1.PredictionLogEntry"  
     error_detail: { 
      detail: "No JSON object could be decoded"  
      input_snippet: "Input snippet is unavailable."  
     } 
     message: "No JSON object could be decoded"  
    } 
    receiveTimestamp: "2017-07-28T12:31:23.377623911Z" 
    resource: { 
     labels: { 
      job_id: "prediction10"  
      project_id: "tensorflow-test-1-168615"  
      task_name: ""  
     } 
     type: "ml_job"  
    } 
    severity: "ERROR" 
    timestamp: "2017-07-28T12:31:23.377623911Z" 
} 
+0

您所報告的錯誤消息似乎來自'gcloud ml-engine local predict',您能否確認?如果是這樣,服務返回的錯誤信息是什麼? – rhaertel80

+0

你是對的,錯誤似乎來自gcloud,而不是模型。 –

+0

當'json.loads'產生一個'ValueError'時,會出現這個錯誤信息。你介意提供一個副本到我們的輸入文件的鏈接? – rhaertel80

回答

1

如果您使用gcloud提交您的gcloud ml-engine local predict請求以及批量預測,那麼您導出的模型將接受如下用於預測的輸入。

{"inputs": [[[242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 23]]]} 
{"inputs": [[[232, 242, 219], [242, 240, 239], [242, 240, 239], [242, 242, 239], [242, 240, 123]]]} 
... 

如果你直接發送請求到服務(即不使用gcloud),該請求的主體將如下所示:

{"instances": [{"inputs": [[[242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 239], [242, 240, 23]]]}]} 
{"instances": [{"inputs": [[[232, 242, 219], [242, 240, 239], [242, 240, 239], [242, 242, 239], [242, 240, 123]]]}]} 

輸入張名應該是「投入「因爲它在簽名輸入中是what we've specified。您可以從here知道每個JSON對象的值是一個3-D數組。外部維度爲無以支持批量輸入。不需要「實例」(除非直接使用http API)。請注意,您不能在輸入中指定「鍵」,除非您修改圖形以包含額外的佔位符並使用tf.identity不改變輸出。

也如the github issue中所述,由於模型需要大容量內存,在線服務可能無法正常工作。我們正在努力。

+0

不幸的是,這仍然不起作用。錯誤仍然是'輸入實例不是JSON格式。有關詳細信息,請參閱「gcloud ml-engine predict --help」。錯誤顯示速度非常快,所以在模型加載之前,似乎ml引擎會發出此錯誤。 –

+0

輸入文件中是否有隱藏/不可見的字符?你可以運行json驗證器來確保它是合法的json嗎? – yxshi

+0

在線json驗證器說該文件是正確的 –

0

相信特定模型預計,預測的二進制圖象數據。

我期望你的要求將是沿着線的東西:

{ 
    instances: [ 
    { "images": { "b64": "image-bytes-base64-encoded" }, "key": 1 }, 
    ... 
    ] 
} 

希望朝着一個可行的解決方案幫助。讓我們知道,如果它不,我會盡力讓你更明確一些。