-
StackOverflow 文件
-
tensorflow 教程
-
在 Python 中儲存 Tensorflow 模型並使用 Java 載入
-
使用 Python 建立和儲存模型
import tensorflow as tf
# good idea
tf.reset_default_graph()
# DO MODEL STUFF
# Pretrained weighting of 2.0
W = tf.get_variable('w', shape=[], initializer=tf.constant(2.0), dtype=tf.float32)
# Model input x
x = tf.placeholder(tf.float32, name='x')
# Model output y = W*x
y = tf.multiply(W, x, name='y')
# DO SESSION STUFF
sess = tf.Session()
sess.run(tf.global_variables_initializer())
# SAVE THE MODEL
builder = tf.saved_model.builder.SavedModelBuilder("/tmp/model" )
builder.add_meta_graph_and_variables(
sess,
[tf.saved_model.tag_constants.SERVING]
)
builder.save()