0
我使用一個圖形文件(PB文件)的,這Tensorflow模型的目的是提供某些圖像上的預測Tensorflow:獲得預測出圖形文件(.pb文件)
我已經開發出一種碼該加載圖形文件,但我不能統計會話。 提供的文件是: -
- training_model_saved_model.pb
- 變量
- training_model_variables_variables.data 00000-的-00001
- training_model_variables_variables.index
的輸出錯誤包含很大模型的列表layer.what我可以在這種情況下做的,任何幫助表示讚賞
這我用來加載/運行模型的代碼
import tensorflow as tf
import sys
import os
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from tensorflow.core.protobuf import saved_model_pb2
from tensorflow.python.util import compat
from tensorflow.python.platform import gfile
export_dir = os.path.join("./", "variables/")
filename = "imgpsh_fullsize.jpeg"
raw_image_data = mpimg.imread(filename)
g = tf.Graph()
with tf.Session(graph=g) as sess:
model_filename ='training_model_saved_model.pb'
with gfile.FastGFile(model_filename, 'rb') as f:
data = compat.as_bytes(f.read())
sm = saved_model_pb2.SavedModel()
sm.ParseFromString(data)
#print(sm)
if 1 != len(sm.meta_graphs):
print('More than one graph found. Not sure which to write')
sys.exit(1)
image_input= tf.import_graph_def(sm.meta_graphs[0].graph_def,name='',return_elements=["input"])
#print(image_input)
#saver = tf.train.Saver()
saver = tf.train.import_meta_graph(sm.meta_graphs[0].graph_def)
'''
print(image_input)
x = g.get_tensor_by_name("input:0")
print(x)
'''
saver.restore(sess,model_filename)
predictions = sess.run(feed_dict={image: raw_image_data})
print('###################################################')
print(predictions)
存在錯誤是
Traceback (most recent call last):
File "model_Input-get.py", line 35, in <module>
saver = tf.train.import_meta_graph(sm.meta_graphs[0].graph_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1691, in import_meta_graph
meta_graph_def = meta_graph.read_meta_graph_file(meta_graph_or_file)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/meta_graph.py", line 553, in read_meta_graph_file
if not file_io.file_exists(filename):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/lib/io/file_io.py", line 252, in file_exists
pywrap_tensorflow.FileExists(compat.as_bytes(filename), status)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got node {
name: "input"
op: "Placeholder"
attr {
key: "_output_shapes"
value {
list {
shape {
dim {
size: -1
}
}
}
}
}
attr {
key: "dtype"
value {
type: DT_STRING
}
}
我感覺迷失在恢復GraphFile。我使用的SavedModel,因爲當我嘗試 ' graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) G_IN = tf.import_graph_def(graph_def) ' 我得到protobuf.message.DecodeError –
你有什麼建議在代碼中進行編輯,請你提供更多的細節。你是什麼意思切換到TF服務,我聽說bazel 如何在這裏應用 –