问题
Will the support for frozen graph continue in tensorflow 2.0 or deprecated? I mean the scripts and APIs to create/optimize frozen graph from saved_model. Also the APIs to run the inference for the same.
Assuming it will be supported in future, what is the recommended method to run the inference on frozen graph in tensorflow 2.0 ?
回答1:
The freeze graph APIs - freeze_graph.py and converter_variables_to_constants - will not be supported in TensorFlow 2.0.
In 2.0, the primary export format is SavedModels so APIs are built to directly support SavedModels.
Inference on existing frozen graphs can be run using the v1.compat
path.
回答2:
Now, freeze_graph
is officially gone with TensorFlow 2.0 stable release.
Check Here.
回答3:
if you use estimator to biuld a model, you can using tf.estimator.Estimator.export_saved_model to freeze your model.
model = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=model_saved_dir)
def serving_input_receiver_fn():
# in here, my input is 512 x 512 single channel image
feature = tf.compat.v1.placeholder(tf.float32, shape=[None, 512, 512, 1], name="inputs")
return tf.estimator.export.TensorServingInputReceiver(feature, feature)
model.export_saved_model(model_saved_dir, serving_input_receiver_fn)
this code is work in tensorflow 2.0
or you use keras, You can refer to the steps of the official website https://www.tensorflow.org/tutorials/keras/save_and_load#savedmodel_format
来源:https://stackoverflow.com/questions/55562078/tensorflow-2-0-frozen-graph-support