Now we're using tensorflow/serving for inference. It exposes gRPC service and we can generate the Java classes from the proto file.
Now we can generate the PreditionService
from https://github.com/tensorflow/serving/blob/master/tensorflow_serving/apis/prediction_service.proto but how can I construct the TensorProto
objects from multiple dimention array.
We have some examples from Python ndarray and C++. It would be great if someone has tried in Java.
There's some work about running TensorFlow in Java. Here's the blog but I'm not sure if it works or how we can use it without dependencies.
TensorProto
supports two representations for the content of the tensor:The various
repeated *_val
fields (such asTensorProto.float_val
,TensorProto.int_val
), which store the content as a linear array of primitive elements, in row-major order.The
TensorProto.tensor_content
field, which stores the content as a single byte array, which corresponds to the result oftensorflow::Tensor::AsProtoTensorContent()
. (In general, this representation corresponds to the in-memory representation of atensorflow::Tensor
, converted to a byte array, but theDT_STRING
type is handled differently.)It will probably be easier to generate
TensorProto
objects using the first format, although it is less efficient. Assuming you have a 2-Dfloat
array calledtensorData
in your Java program, you can use the following code as a starting point: