Tensorflow 从部署的TF中获取谷歌云中诗人模型的预测

Tensorflow 从部署的TF中获取谷歌云中诗人模型的预测,tensorflow,machine-learning,google-cloud-platform,tensorflow-serving,Tensorflow,Machine Learning,Google Cloud Platform,Tensorflow Serving,我在谷歌云中部署了我重新培训过的诗人TF模型。目前,我正试图从中得到预测。但它给出了以下错误 "error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"contents must be scalar, got shape [1]\n\t [[{{node DecodeJpeg}}]]\")" 根据下面的代码,我曾经得到

我在谷歌云中部署了我重新培训过的诗人TF模型。目前,我正试图从中得到预测。但它给出了以下错误

 "error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"contents must be scalar, got shape [1]\n\t [[{{node DecodeJpeg}}]]\")"
根据下面的代码,我曾经得到服务模型

import tensorflow as tf
from tensorflow.python.saved_model import signature_constants
from tensorflow.python.saved_model import tag_constants
from tensorflow.python.saved_model import builder as saved_model_builder

input_graph = 'retrained_graph.pb'
saved_model_dir = 'my_model'

with tf.Graph().as_default() as graph:
  # Read in the export graph
  with tf.gfile.FastGFile(input_graph, 'rb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
      tf.import_graph_def(graph_def, name='')

  # Define SavedModel Signature (inputs and outputs)
  in_image = graph.get_tensor_by_name('DecodeJpeg/contents:0')
  inputs = {'image_bytes': tf.saved_model.utils.build_tensor_info(in_image)}

  out_classes = graph.get_tensor_by_name('final_result:0')
  outputs = {'prediction': tf.saved_model.utils.build_tensor_info(out_classes)}

  signature = tf.saved_model.signature_def_utils.build_signature_def(
      inputs=inputs,
      outputs=outputs,
      method_name='tensorflow/serving/predict'
  )

  with tf.Session(graph=graph) as sess:
    # Save out the SavedModel.
    b = saved_model_builder.SavedModelBuilder(saved_model_dir)
    b.add_meta_graph_and_variables(sess,[tf.saved_model.tag_constants.SERVING],signature_def_map={'serving_default': signature})
    b.save()
request.json生成代码

python -c 'import base64, sys, json; img = base64.b64encode(open(sys.argv[1], "rb").read()); print json.dumps({"image_bytes": {"b64": img}})' test.jpg &> request.json
您可以尝试:

{"instances": [{"image_bytes": {"b64": encoded_string}, "key": "0"}]}

以下内容的输出是什么:
saved\u model\u cli show--dir--all
?感谢您的回复。我在三个月前完成了这一个。谢谢你的回复。我试过这个,但没用。我在三个月前就完成了这篇文章。你好,CharithPramodya,你能分享你的解决方案吗?这样,它对那些面临类似错误的人会很有用。