What is the Tensorflow Java Api `toGraphDef` equivalent in Python?

2017-04-06T06:46:20

I am using the Tensorflow Java Api to load an already created Tensorflow model into the JVM. I am using 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 do I save my model to get both the Session and the Graph stored in the same file. as described in the "PATH_TO_A_SINGLE_FILE_DESCRIBING_TF_MODEL.pb" above.

Described here it mentions:

The serialized representation of the graph, often referred to as a GraphDef, can be generated by toGraphDef() and equivalents in other language APIs.

What are the equivalents in other language APIs? I dont find it obvious

Note: I already looked at the mnist_saved_model.py under tensorflow_serving but saving it through that procedure gives me a .pb file and a variables folder. When trying to load that .pb file I get: java.lang.IllegalArgumentException: Invalid GraphDef

Copyright License:
Author:「Daniel Hasegan」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/43242857/what-is-the-tensorflow-java-api-tographdef-equivalent-in-python

About “What is the Tensorflow Java Api `toGraphDef` equivalent in Python?” questions

I am using the Tensorflow Java Api to load an already created Tensorflow model into the JVM. I am using this as an example: tensorflow/examples/LabelImage.java Here is my simple scala code: impor...
Background: I am new to Tensorflow and AI and wish to try out Tensorflow in a Java based environment. Found Tensorflow has a Java API and tried it out but results don't seem to be similar to my Pyt...
What's the best way to classify batch of images using TensorFlow java API? I also want the capability to resize the image in GPU so that all the images in the batch are of same dimension. The only
I've been trying to install Tensorflow Object Detection API, and I've encountered the following error: import error :no module named ' nets ' and the solution is by setting the python path like th...
What is the equivalent API in tensorflow 1.2.0 for prepare_attention(tf.contrib.seq2seq.prepare_attention) of tensorflow 1.0.0? Thanks in advance
Trying to convert some python tensorflow code to java, I can't find the same java API for train.example.SerializeToString in python. It is surely not java toString. I can find the java Example clas...
Trying to convert some python tensorflow code to java, I can't find the same java API for train.example.SerializeToString in python. It is surely not java toString. I can find the java Example clas...
I need to know the equivalent C++ function for https://www.tensorflow.org/api_docs/python/tf/train/import_meta_graph Can anyone please help with it?
I'm trying to run Tensorflow in Android, using Tensorflow's Java API. I'm wondering how to set the Session config when creating a Session object. In the Python API, you can do this by using the "c...
I have already asked the question as a github issue, but was redirected to here. I have seen the example for importing model created and trained in Python imported into Java code and used for predi...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.