[英]ml-engine predict argument parsing errors
在成功部署了數十種模型后,由於解析和其他參數錯誤,只有最普通的(一個arg in / out)曾經成功地返回了預測結果,然后我回到了正式的深度模型: 正式的深度教程和這: 提供廣泛而深入的教程繼續,以嘗試在ml-engine上導出,部署和預測。 我無法獲得文本或json參數的任何排列來傳遞解析。 這是我的一些測試和響應:
1)輸入文件內容,文字:
25,0,0,"11th",7,"Male",40,"United-States","Machine-op-inspct","Own-child","Private"
響應:
{"error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"Could not parse example input, value: '25,0,0,\"11th\",7,\"Male\",40,\"United-States\",\"Machine-op-inspct\",\"Own-child\",\"Private\"'\n\t [[Node: ParseExample/ParseExample = ParseExample[Ndense=5, Nsparse=6, Tdense=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], dense_shapes=[[1], [1], [1], [1], [1]], sparse_types=[DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](_arg_input_example_tensor_0_0, ParseExample/ParseExample/names, ParseExample/ParseExample/sparse_keys_0, ParseExample/ParseExample/sparse_keys_1, ParseExample/ParseExample/sparse_keys_2, ParseExample/ParseExample/sparse_keys_3, ParseExample/ParseExample/sparse_keys_4, ParseExample/ParseExample/sparse_keys_5, ParseExample/ParseExample/dense_keys_0, ParseExample/ParseExample/dense_keys_1, ParseExample/ParseExample/dense_keys_2, ParseExample/ParseExample/dense_keys_3, ParseExample/ParseExample/dense_keys_4, ParseExample/Const, ParseExample/Const, ParseExample/Const, ParseExample/Const, Pa...TRUNCATED\")"}
2)輸入文件內容,json:
{"age":25,"capital_gain":0,"capital_loss":0,"education":"11th","education_num":7,"gender":"Male","hours_per_week":40,"native_country":"United-States","occupation":"Machine-op-inspct","relationship":"Own-child","workclass":"Private"}
響應:
{....failed: Expected tensor name: inputs, got tensor name: [u'hours_per_week', u'native_country',....}
3)輸入文件內容,json:
{"inputs":{"age":25,"capital_gain":0,"capital_loss":0,"education":"11th","education_num":7,"gender":"Male","hours_per_week":40,"native_country":"United-States","occupation":"Machine-op-inspct","relationship":"Own-child","workclass":"Private"}}
響應:
{....Error processing input: Expected string, got {u'hours_per_week': 40, u'native_count....}
4)輸入文件內容,json:
{"inputs":"25,0,0,11th,7,Male,40,United-States,Machine-op-inspct,Own-child,Private"}
響應:
{...."Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"Could not parse example input, value: '25,0,0,11th,7,Male,40,United-States,Machine-op-inspct,Own-child,Private'\n\t [[Node: ParseExample/ParseExample = ParseExample[Ndense=5,....}
我也嘗試使用內部轉義引號,各種列表/數組等。
請告訴我,我只需要在預測請求中(以及如何)重新格式化我的輸入內容:)-謝謝
在當前情況下,在接受JSON的圖形和接受tf.train.Example
的圖形之間進行選擇是互斥的,這意味着您必須稍微不同地導出圖形。
從廣泛而深入的教程繼續 ,請更改以下幾行:
feature_spec = tf.feature_column.make_parse_example_spec(feature_columns)
export_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
至
inputs = {}
for feat in INPUT_COLUMNS:
inputs[feat.name] = tf.placeholder(shape=[None], dtype=feat.dtype)
export_input_fn = tf.estimator.export.build_raw_serving_input_receiver_fn(inputs)
作為參考,參見該樣品 ,特別是*_serving_fn
中定義model.py
(例如此處 ); 該示例還顯示了如何導出需要CSV作為輸入的圖形。
另一個要注意的是,如果您使用gcloud
發送請求(相對於請求庫),則輸入數據格式不是發送請求的全部內容: gcloud
使用文件中的每一行構造請求。 因此,發送到服務器的實際請求的主體將類似於:
{
"instances": [
{
"age": 25,
"capital_gain": 0,
"capital_loss": 0,
"education": "11th",
"education_num": 7,
"gender": "Male",
"hours_per_week": 40,
"native_country": "United-States",
"occupation": "Machine-op-inspct",
"relationship": "Own-child",
"workclass": "Private"
}
]
}
而相應的--json-instances
文件將如下所示:
{"age":25,"capital_gain":0,"capital_loss":0,"education":"11th","education_num":7,"gender":"Male","hours_per_week":40,"native_country":"United-States","occupation":"Machine-op-inspct","relationship":"Own-child","workclass":"Private"}
gcloud
將每一行的內容gcloud
到上面“實際”請求中所示的數組中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.