What is the equivalent of Tivorflow Java Api `toGraphDef` in Python?

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

+4
1

Java API , graphDef (.. ). , Array [Byte] :

Files.write(Paths.get(modelDir, modelName), myGraph.toGraphDef)

myGraph java- .

API Python, SavedModel api. .pb . _constants, , scala/java, . java- SavedModelBundle. , :

val model = SavedModelBundle.load(modelDir, modelTag)

, , , , GraphDef.

, .. , .pb. Mores infos

+1

Source: https://habr.com/ru/post/1674147/


All Articles