我正在尝试将元图转换为.pb,这是我用来执行此操作的代码:
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())
当我尝试保存Frozen_graph_def时,出现以下异常:
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())
您知道我该如何解决这个问题?