I train a model with a placeholder for is_training
:
is_training_ph = tf.placeholder(tf.bool)
however once training and validation are done, I would like to permanently inject a constant of false
in for this value and then "re-optimize" the graph (ie using optimize_for_inference
). Is there something along the lines of freeze_graph
that will do this?
One possibility is to use the
tf.import_graph_def()
function and itsinput_map
argument to rewrite the value of that tensor in the graph. For example, you could structure your program as follows:After building
temp_graph_def
, you can use it as the input tofreeze_graph
.An alternative, which might be more compatible with the
freeze_graph
andoptimize_for_inference
scripts (which make assumptions about variable names and checkpoint keys) would be to modify TensorFlow'sgraph_util.convert_variables_to_constants()
function so that it converts placeholders instead:...then you could build
training_graph_def
as above, and write: