Cannot freeze Tensorflow models into frozen(.pb) file

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 06:27:37

Use the below script to print the tensors... the last tensor would be the output tensor. Original author: https://blog.metaflow.fr/tensorflow-how-to-freeze-a-model-and-serve-it-with-a-python-api-d4f3596b3adc

import argparse
import tensorflow as tf


def print_tensors(pb_file):
    print('Model File: {}\n'.format(pb_file))
    # read pb into graph_def
    with tf.gfile.GFile(pb_file, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

    # import graph_def
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def)

    # print operations
    for op in graph.get_operations():
        print(op.name + '\t' + str(op.values()))


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--pb_file", type=str, required=True, help="Pb file")
    args = parser.parse_args()
    print_tensors(args.pb_file)

Tensorflow: What are the "output_node_names" for freeze_graph.py in the model_with_buckets model?

Here are some answers about node names and how to identify them.

Good luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!