I use Tensorflow Java Api to load the already created Tensorflow model into the JVM. I use this as an example: tensorflow / examples / LabelImage.java
Here is my simple scala code:
import java.nio.file.{Files, Path, Paths}
import org.tensorflow.{Graph, Session, Tensor}
def readAllBytesOrExit(path: Path): Array[Byte] = Files.readAllBytes(path)
val graphDef = readAllBytesOrExit(Paths.get("PATH_TO_A_SINGLE_FILE_DESCRIBING_TF_MODEL.pb"))
val g = new Graph()
g.importGraphDef(graphDef)
val session = new Session(g)
val result: Tensor = session.runner().feed("input", image).fetch("output").run().get(0))
How to save my model to get both Session and Graph stored in one file. as described in the section "PATH_TO_A_SINGLE_FILE_DESCRIBING_TF_MODEL.pb" above.
Described here he mentions:
A serialized graph view, often called GraphDef, can be generated by toGraphDef () and its equivalents in other language APIs.
What are the equivalents in the API of other languages? I do not think this is obvious.
. mnist_saved_model.py shadoworflow_serving, , .pb variables. .pb : java.lang.IllegalArgumentException: Invalid GraphDef