ml-engine 预测参数解析错误
ml-engine predict argument parsing errors
在成功部署了数十个模型后,由于解析和其他参数错误,只有最微不足道的模型(一个参数 in/out)成功 return 预测结果,我回到了官方广泛-和深度模型:
official wide and deep tutorial
还有这个:
serving wide and deep tutorial continuation
尝试在 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,....}
我还尝试了内部转义引号、各种 lists/arrays 等
请告诉我我只需要重新格式化我在预测请求中的输入(以及如何):)
-谢谢
在目前的情况下,接受 JSON 的图和接受 tf.train.Example
的图之间的选择是相互排斥的,这意味着您必须以稍微不同的方式导出图。
在 serving wide and deep tutorial continuation 中,更改以下行:
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)
供参考,参见this sample, in particular, the *_serving_fn
definitions in model.py
(e.g. here);该示例还展示了如何导出需要 CSV 作为输入的图表。
另外请注意,如果您使用 gcloud
发送请求(相对于请求库),输入数据格式是 而不是 请求的完整主体to send: 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
获取每一行的内容并将它们填充到上面 "actual" 请求中显示的数组中。
在成功部署了数十个模型后,由于解析和其他参数错误,只有最微不足道的模型(一个参数 in/out)成功 return 预测结果,我回到了官方广泛-和深度模型: official wide and deep tutorial 还有这个: serving wide and deep tutorial continuation 尝试在 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,....}
我还尝试了内部转义引号、各种 lists/arrays 等
请告诉我我只需要重新格式化我在预测请求中的输入(以及如何):) -谢谢
在目前的情况下,接受 JSON 的图和接受 tf.train.Example
的图之间的选择是相互排斥的,这意味着您必须以稍微不同的方式导出图。
在 serving wide and deep tutorial continuation 中,更改以下行:
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)
供参考,参见this sample, in particular, the *_serving_fn
definitions in model.py
(e.g. here);该示例还展示了如何导出需要 CSV 作为输入的图表。
另外请注意,如果您使用 gcloud
发送请求(相对于请求库),输入数据格式是 而不是 请求的完整主体to send: 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
获取每一行的内容并将它们填充到上面 "actual" 请求中显示的数组中。