Désolé, j'ai recherché toutes les réponses dans "stackoverflow", mais je n'ai obtenu aucun résultat satisfaisant. J'apprends une création caractéristique v3 abstraction: codes on this sitepourquoi "sess.graph.get_all_collection_keys()" retourne une collection vide?
quand j'insérer une ligne: "sess.graph.get_all_collection_keys d'impression()" à la segmentation du code. Le résultat imprimé est []. Mais en utilisant: "pool3 = sess.graph.get_tensor_by_name ('pool_3: 0')" a le bon résultat, pourquoi?
Le code est:
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))
La sortie est:
[]
[]
[]
(1, 1, 1, 2048)
[ 0.21214311 0.04288583 0.14220749 ..., 0.09034956 0.0148661
0.13966754]
Très reconnaissant! Peut-être que c'est pour cette raison, j'ai essayé d'autres façons, c'est fait! – semon