我是Tensorflow的新人(事实上这是我服务的第一个模特!)所以如果答案显而易见,我道歉!
我正在使用这个image在docker上托管Tensorflow模型。问题是每次我尝试发送数据时服务器都会发送以下错误,以便服务模型可以进行预测。
W external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at transpose_op.cc:157 : Invalid argument: transpose expects a vector of size 4. But input(1) is a vector of size 3
signature_def['predict']:
The given SavedModel SignatureDef contains the following input(s):
inputs['init_state'] tensor_info:
dtype: DT_FLOAT
shape: (2, 2, -1, 136)
name: policy_estimator/lstm/Placeholder:0
inputs['state'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 136)
name: policy_estimator/state:0
The given SavedModel SignatureDef contains the following output(s):
outputs['action_probs'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 260)
name: policy_estimator/Softmax:0
outputs['final_state'] tensor_info:
dtype: DT_FLOAT
shape: (2, 2, -1, 136)
name: policy_estimator/packed:0
Method name is: tensorflow/serving/predict
W external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at transpose_op.cc:157 : Invalid argument: transpose expects a vector of size 5. But input(1) is a vector of size 3
当我将尺寸更改为4时,它会变为
W external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at transpose_op.cc:157 : Invalid argument: transpose expects a vector of size 6. But input(1) is a vector of size 3
但是,当我将其设为1维时,错误消息仍为
W external/org_tensorflow/tensorflow/core/framework/op_kernel.cc:1401] OP_REQUIRES failed at transpose_op.cc:157 : Invalid argument: transpose expects a vector of size 4. But input(1) is a vector of size 3
{
"model_version_status": [
{
"version": "1",
"state": "AVAILABLE",
"status": {
"error_code": "OK",
"error_message": ""
}
}
]
}
当我运行curl http://model:8501/v1/models/saved_model
时,http://model:8501/v1/models/saved_model
是托管模型的地方。
payload = [{"init_state":np.reshape(initial_state, (2,2,-1,136)).tolist(), "state": np.reshape(points, (-1, 136)).tolist()}]
headers = {"content-type": "application/json"}
data = json.dumps({"signature_name": "predict", "instances":payload})
r = requests.post('http://model:8501/v1/models/saved_model:predict', data=data, headers=headers)
关注this documentation。其中r是响应。在这种情况下,此r返回400的响应。
我可以从中得出的唯一结论是,模型在服务时可能会发生变化。然而,这只是猜测,因为我被困住了,并且不确定下一步。
我不再那么专业了,如果我遗漏了一些明显的东西,我道歉!请幽默我如果缺少任何信息,请通知我,因为我会尽力澄清!
试试这个:
import json
.
.
.
payload = {"init_state":np.reshape(initial_state, (2,2,-1,136)).tolist(),"state": np.reshape(points, (-1, 136)).tolist()}
headers = {"content-type": "application/json"}
data = json.dumps({"signature_name": "predict", "inputs":payload})
# add this
data = json.loads(data) # apparently json.dumps returns a json string: '{}' not a json object: {}
r = requests.post('http://model:8501/v1/models/saved_model:predict', json=data, headers=headers)