TensorFlow Import
Importing TensorFlow frozen graphs and SavedModels into SameDiff
TensorFlow Import
Maven Dependency
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-samediff-import-tensorflow</artifactId>
<version>${dl4j.version}</version>
</dependency>Preparing Your TensorFlow Model
Exporting a Frozen Graph from TF 1.x
import tensorflow as tf
from tensorflow.python.framework.graph_util import convert_variables_to_constants
# Assuming you have a trained session
with tf.Session() as sess:
# ... restore or train your model ...
# Freeze: convert variables to constants
frozen_graph_def = convert_variables_to_constants(
sess,
sess.graph_def,
output_node_names=['output/Softmax'] # your output node name(s)
)
# Write to disk
with tf.io.gfile.GFile('frozen_model.pb', 'wb') as f:
f.write(frozen_graph_def.SerializeToString())Exporting a Frozen Graph from TF 2.x
Getting Node Names
Importing a Frozen Graph
Placeholder Mapping
Multiple Inputs and Outputs
Inspecting the Imported Graph
Supported TF Ops
Complete Example: MobileNet Inference
Troubleshooting
Last updated
Was this helpful?