Sorry, ich habe alle Antworten in "stackoverflow" durchsucht, aber kein zufriedenstellendes Ergebnis erzielt. Ich bin ein Anfang v3 Funktion Abstraktion Lernen: codes on this siteWarum "sess.graph.get_all_collection_keys()" eine leere Sammlung zurückgeben?
wenn ich fügen Sie eine Zeile: „print sess.graph.get_all_collection_keys()“ dem Codesegmentierung. Das Druckergebnis ist []. Aber mit: "pool3 = sess.graph.get_tensor_by_name ('pool_3: 0')" hat richtiges Ergebnis, warum?
Der Code ist:
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))
Die Ausgabe lautet:
[]
[]
[]
(1, 1, 1, 2048)
[ 0.21214311 0.04288583 0.14220749 ..., 0.09034956 0.0148661
0.13966754]
Sehr dankbar! Vielleicht ist es aus diesem Grund, ich habe es auf andere Weise versucht, es geschafft! – semon