[英]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.