tensorflow / java

Java bindings for TensorFlow
Apache License 2.0
818 stars 203 forks source link

How to input data and recive returned results after loading the categorization model #440

Open xmings opened 2 years ago

xmings commented 2 years ago

dependency:

            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow-core-platform</artifactId>
            <version>0.4.1</version>
        </dependency>

code:

import org.{tensorflow=>tf}
val result = tf.SavedModelBundle
      .load("D:\\model\\categorization","serve")
      .session()
      .runner()
      .feed("serving_default_inputs:0", tf.create(List("....", "....")))
      .fetch("StatefulPartitionedCall:0")
      .run()
      .get(0);

However, no any create method found within tf, why ??

Craigacp commented 2 years ago

What do you expect tf.create to do? As far as I can tell there isn't an equivalent method in TF Python.

Depending on what your input looks like you can use the different tensor types (e.g. TFloat32, TInt32) and their factory methods (e.g. scalarOf, vectorOf), or the ndarray library (https://github.com/tensorflow/java-ndarray) to construct the right inputs for your model.