を取得し、このTensorflowモデルの目的は、特定の画像Tensorflow:私は、グラフファイル(PBファイル)を使用していますグラフファイルのうち予測(.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の復元に迷っています。私は ' graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) g_in = tf.import_graph_def(graph_def) ' 私が手protobuf.message.DecodeError –
しようとするので、私はSavedModelを使用しましたあなたはコード内で何を編集することを提案しますか?詳細を教えてください。あなたはTFサービングに切り替えることで何を意味するのですか?私はバゼルについて聞いた ここでそれをどのように適用するか –