Exception when converting metagraph to .pb

I was trying to convert my metagraph to .pb, here is code which I was using to do it:

    import argparse
    import math
    import sys
    import cv2
    import os
    import datetime
    import logging, logging.handlers
    import logging.config
    import tensorflow as tf
    import numpy as np
    from glob import glob
    from tqdm import tqdm

    os.environ["CUDA_VISIBLE_DEVICES"]='0'
    meta_path = 'C:\\Users\\dmura\\Desktop\\ToPb\\final.meta' # Your .meta file
    #output_node_names = ['output:0']    # Output nodes
    device_name = '/device:GPU:0'
    with tf.device(device_name):
        config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=False)
        config.gpu_options.allow_growth = True
        config.gpu_options.per_process_gpu_memory_fraction = 0.9    

    with tf.Session() as sess:
        # Restore the graph
        saver = tf.train.import_meta_graph(meta_path)

        # Load weights
        saver.restore(sess,tf.train.latest_checkpoint('C:\\Users\\dmura\\Desktop\\ToPb\\final'))

        # Freeze the graph
        output_node_names = [n.name for n in tf.get_default_graph().as_graph_def().node]
        frozen_graph_def = tf.graph_util.convert_variables_to_constants(
            sess,
            sess.graph_def,
            output_node_names)

        # Save the frozen graph
        with open('output_graph.pb', 'wb') as f:
          f.write(frozen_graph_def.SerializeToString())

when I was trying to save frozen_graph_def I got following exception:

Exception has occured: ValueError
Message tensorflow.GrahDef exceeds maximum protobuf size of 2GB: 2255900840
File "C:\Users\VIDesktop\pbConverter\converter.py", line 46, in <module>
f.write(frozen_graph_def.SerializeToString())

Have you got idea how can I solve this prolem?