Cannot freeze Tensorflow models into frozen(.pb) file

前端 未结 1 1688
时光取名叫无心
时光取名叫无心 2021-01-21 06:52

I am referring (here) to freeze models into .pb file. My model is CNN for text classification I am using (Github) link to train CNN for text classification and exporting in for

1条回答
  •  一向
    一向 (楼主)
    2021-01-21 07:51

    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)
    

    0 讨论(0)
提交回复
热议问题