开头name
结尾name
pb加载方式
import tensorflow as tf
from tensorflow.python.platform import gfile
import cv2
import numpy
from keras.applications.xception import preprocess_input
pb_file_path = '/Users/jack/Documents/DaiCode/T4/trans_model' config = tf.ConfigProto() sess = tf.Session(config=config) with gfile.FastGFile('/Users/jack/Documents/DaiCode/T4/trans_model/false_positive3.pb', 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) sess.graph.as_default() tf.import_graph_def(graph_def, name='') # 获取输入tensor x = tf.get_default_graph().get_tensor_by_name("input_1:0") print("input:", x) # 获取预测tensor pred = tf.get_default_graph().get_tensor_by_name("output_1:0") # mobilenet_v2 print(pred)
打印的输入和输出
input: Tensor("input_1:0", shape=(?, 240, 240, 3), dtype=float32)
Tensor("output_1:0", shape=(8,), dtype=float32)
240*240 3通道 的图片向量
一位 8 的输出
h5加载方式
from keras.models import load_model
# 加载模型的位置 model = load_model('/Users/jack/Documents/DaiCode/T4/false_positive3.h5', custom_objects={'optimizer': optimizer})
h5 推理
prediction = model.predict(plate_img)
pb 推理
prediction = sess.run(pred, feed_dict={x: _plate_img})
[0.98,0.1,0.1,0.2,0.3,0.4,0.6,0.1]