我对 tensorflow 很陌生,我正在尝试将我的 .pb(proto buffer) 文件转换为 lite 版本。但我面临一些问题。导入时间,sys,警告,glob,随机,cv2,base64,json,csv,os
import numpy as np
import tensorflow as tf
from collections import OrderedDict
def load_graph(frozen_graph_filename):
with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(
graph_def,
input_map=None,
return_elements=None,
name="prefix",
op_dict=None,
producer_op_list=None
)
return graph
此函数为我加载了一个图表,现在我想将此图表转换为我使用以下脚本的 tflite。
CD_graph = load_graph("CD_Check_k.pb")
CD_input = CD_graph.get_tensor_by_name('prefix/input_node:0')
CD_output = CD_graph.get_tensor_by_name('prefix/output_node:0')
x_single = tf.placeholder(tf.float32, [1, 256 , 256, 3],
name="input_node")
with tf.Session() as sess:
tflite_model = tf.contrib.lite.toco_convert(CD_graph, input_tensors=[x_single ], output_tensors=[CD_output])
with open('./mnist.tflite', "wb") as f:
f.write(tflite_model)
错误信息:
'Graph' object has no attribute 'SerializeToString'