我一直在尝试 Tensorflow 2 alpha,并且一直在尝试冻结模型并将其导出到 .pb graphdef 文件。
在 Tensorflow 1 中,我可以这样做:
# Freeze the graph.
frozen_graph_def = tf.graph_util.convert_variables_to_constants(
sess,
sess.graph_def,
output_node_names)
# Save the frozen graph to .pb file.
with open('model.pb', 'wb') as f:
f.write(frozen_graph_def.SerializeToString())
然而,这似乎不再可能,因为 convert_variables_to_constants 被删除并且不鼓励使用会话。
我查看并发现有 与 SavedModel 导出一起使用的冻结图实用程序https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py 。
有没有办法在 Python 中做到这一点,或者我现在打算切换并使用这个工具?