Skip to content Skip to sidebar Skip to footer

Cannot Freeze Tensorflow Models Into Frozen(.pb) File

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 form o

Solution 1:

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)

Post a Comment for "Cannot Freeze Tensorflow Models Into Frozen(.pb) File"