tips:keras

This is an old revision of the document!


Keras

prereq

bazel build tensorflow/python/tools:freeze_graph
import argparse
ap = argparse.ArgumentParser()
ap.add_argument('--input', required=True)
ap.add_argument('--output', default="/tmp/model/ckpt")
args = ap.parse_args()

from keras import backend as K
from keras.models import load_model
import tensorflow as tf

K.set_learning_phase(0)

# create model and load weights or ...
# model = create_model()
# model.load_weights(args.input)

# ... load h5 model
load_model(args.input)

saver = tf.train.Saver()
saver.save(K.get_session(), args.default)
print("Output node needed in freeze_graph: %s" % model.output.op.name)
print("Model created in: %s" % args.output)

result

/tmp/model
├── checkpoint
├── ckpt.data-00000-of-00001
├── ckpt.index
└── ckpt.meta

freeze

bazel-bin/tensorflow/python/tools/freeze_graph \
--input_meta_graph=/tmp/model/ckpt.meta  \
--input_checkpoint=/tmp/model/ckpt \
--output_graph=frozen_graph.pb \
--input_binary \
--output_node_names="previous output node name"
  • tips/keras.1535029776.txt.gz
  • Last modified: 2018/08/23 15:09
  • by scipio