申し訳ありませんが、私はすべての答えを "stackoverflow"で検索しましたが、満足のいく結果は得られませんでした。コードセグメントに「印刷sess.graph.get_all_collection_keys()」:私は行を挿入したとき codes on this siteなぜ "sess.graph.get_all_collection_keys()"は空のコレクションを返しますか?
: 私は当初v3機能の抽象化を学んでいます。印刷結果は[]です。しかし、 "pool3 = sess.graph.get_tensor_by_name( 'pool_3:0')"は正しい結果を返します。なぜですか?
コードは次のとおりです。
import tensorflow as tf
import numpy as np
IMG_PATH = '/tmp/feature abstraction/panda.jpg'
MODEL_PATH = '/tmp/feature abstraction/classify_image_graph_def.pb'
inception_v3 = tf.gfile.FastGFile(MODEL_PATH, 'rb')
graph_def =tf.GraphDef()
graph_def.ParseFromString(inception_v3.read())
tf.import_graph_def(graph_def, name='')
layers_name=graph_def.ListFields()
with tf.Session() as sess:
#******
print(sess.graph.get_all_collection_keys())
#*****
pool3 = sess.graph.get_tensor_by_name('pool_3:0')
#print sess.graph.get_all_collection_keys()
print tf.get_default_graph().get_all_collection_keys()
image_data = tf.gfile.FastGFile(IMG_PATH, 'rb').read()
features = sess.run(pool3, {'DecodeJpeg/contents:0': image_data})
#******
print(sess.graph.get_all_collection_keys())
#*******
print features.shape
print(np.squeeze(features))
出力されます:
[]
[]
[]
(1, 1, 1, 2048)
[ 0.21214311 0.04288583 0.14220749 ..., 0.09034956 0.0148661
0.13966754]
非常に感謝します!たぶんそれはこの理由のため、私は他の方法で試してみました。 – semon