title: How can I create a Tensor from an Example object in Java?
body: <p>My use case:
  I am trying to serve the models trained by python within our existing JVM service with libtensorflow_jni.</p>
  
  <p>Now I am able to load the model by using <code>SavedModelBundle.load()</code>. But I find hard to feed the request into the model. As my user request is not simply a scalar matrix, but a map of features, like:</p>
  
  <pre><code>{'gender':1, 'age': 20, 'country': 100, other features ...}
  </code></pre>
  
  <p>By searching around the tensor flow tutorials, I see that <a href="https://github.com/tensorflow/tensorflow/blob/r1.3/tensorflow/core/example/example.proto" rel="nofollow noreferrer">Example</a> protocol buffers may fit here as it basically holds a list of features. But I am not sure how to convert it into a Java Tensor object.</p>
  
  <p>If I create a Tensor directly with serialized Example object, TensorFlow runtime seems not happy with datatype. For example, it I do following, </p>
  
  <pre><code>Tensor inputTensor = Tensor.create(example.toByteArray());
  s.runner().feed(inputTensorName, inputTensor).fetch(outputTensorName).run().get(0);
  </code></pre>
  
  <p>I will get an IllegalArgumentException:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Expected serialized to be a vector, got shape: []
  </code></pre>
  
  <p>Could you guys shed some light how I can move forward from here in case you happens to know or have same use cases?</p>
  
  <p>Thanks!</p>