title: Get predictions from deployed TF for poet model in google cloud
body: <p>I deployed my retrained TF for poet model in google cloud. currently, I am trying to get predictions from that. But it gives the following error.</p>
  
  <pre><code> "error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"contents must be scalar, got shape [1]\n\t [[{{node DecodeJpeg}}]]\")"
  </code></pre>
  
  <p>Following code, I used to get serving model</p>
  
  <pre><code>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()
  </code></pre>
  
  <p>request.json generating code</p>
  
  <pre><code>python -c 'import base64, sys, json; img = base64.b64encode(open(sys.argv[1], "rb").read()); print json.dumps({"image_bytes": {"b64": img}})' test.jpg &amp;&gt; request.json
  </code></pre>