我刚开始使用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的响应。
我从中得出的唯一结论是,模型在提供服务时可能会发生变化。但是,这只是猜测,因为我受阻了,不确定下一步是否要解决。
我不是专业人士,因此,如果我缺少明显的内容,我深表歉意!请幽默我。如果缺少任何信息,请通知我,因为我会尽力澄清!
答案 0 :(得分:0)
尝试一下:
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)