我已按照 Google 张量2张量存储库的建议遵循翻译 colab 笔记本教程
导出模型并将其上传到 Google 的 AI Platform 引擎进行在线预测后,我在向模型发出请求时遇到了问题。
我相信翻译模型的输入是源文本的张量。但我收到一个错误TypeError: Object of type 'EagerTensor' is not JSON serializable
def encode(input_str, output_str=None):
"""Input str to features dict, ready for inference"""
inputs = encoders["inputs"].encode(input_str) + [1] # add EOS id
batch_inputs = tf.reshape(inputs, [1, -1, 1]) # Make it 3D.
return {"inputs": batch_inputs}
enfr_problem = problems.problem(PROBLEM)
encoders = enfr_problem.feature_encoders(DATA_DIR)
encoded_inputs = encode("Some text")
model_output = predict_json('project_name','model_name', encoded_inputs,'version_1')["outputs"]
Run Code Online (Sandbox Code Playgroud)
我尝试将张量转换为 numpy 但仍然没有成功。有人能指出我正确的方向吗?