def freeze(sess, output_file_path, output_node_names):
    """Freeze and shrink the graph based on a session and the output node names."""
    with TemporaryDirectory() as temp_dir_name:
        checkpoint_path = os.path.join(temp_dir_name, 'model.ckpt')
        tf.train.Saver().save(sess, checkpoint_path)

        freeze_from_checkpoint(checkpoint_path, output_file_path, output_node_names)
Freeze and shrink the graph based on a session and the output node names.