2017-02-15 4 views
0

Diese Zeile zeigt an, dass der Code den Verarbeitungsteil "Bilder verarbeiten/Young-Bengal-tiger.jpg ..." gestartet hat.NameError in Tensorflow und Python

Ich versuche, die Fehler unten zu lösen:

In [50]: def extract_features(list_images): 
    ...: nb_features = 2048 
    ...: features = np.empty((len(list_images),nb_features)) 
    ...: labels = [] 
    ...: 
    ...: create_graph() 
    ...: 
    ...: with tf.Session() as sess: 
    ...: 
    ...:  next_to_last_tensor = sess.graph.get_tensor_by_name('pool_3:0') 
    ...: 
    ...: for ind, image in enumerate(list_images): 
    ...:  if (ind%100 == 0): 
    ...:   print('Processing %s...' % (image)) 
    ...: if not gfile.Exists(image): 
    ...:  tf.logging.fatal('File does not exist %s', image) 
    ...: 
    ...:  image_data = gfile.FastGFile(image, 'rb').read() 
    ...:  predictions = sess.run(next_to_last_tensor,{'DecodeJpeg/contents:0': image_data}) 
    ...: features[ind,:] = np.squeeze(predictions) 
    ...: labels.append(re.split('_\d+',image.split('/')[1])[0]) 
    ...: 
    ...: return features, labels 
Processing images/Young-Bengal-tiger.jpg... 

--------------------------------------------------------------------------- 
NameError         Traceback (most recent call last) 
<ipython-input-50-ba615e05226c> in <module>() 
    18  image_data = gfile.FastGFile(image, 'rb').read() 
    19  predictions = sess.run(next_to_last_tensor,{'DecodeJpeg/contents:0': image_data}) 
---> 20 features[ind,:] = np.squeeze(predictions) 
    21 labels.append(re.split('_\d+',image.split('/')[1])[0]) 
    22 

NameError: name 'predictions' is not defined 
+1

Was sind 'Vorhersagen', wenn die Bilddatei * existiert *? –

+0

Hallo Daniel, danke für die Bereitschaft deiner Antwort. Die Fehlermeldung besagt, dass der Code ein Bild "images/Young-Bengal-tiger.jpg" verarbeitet. Dieser Abschnitt des Codes zeigte keine, dass ein Bild fehlte: wenn nicht gfile.Exists (Bild): ...: tf.logging.fatal ('Datei existiert nicht% s', Bild) – Carlos

+0

wenn nicht gfile.Exists (Bild): ...: tf.logging.fatal ('Datei existiert nicht% s', Bild) – Carlos

Antwort

0

Vielen Dank für Ihre Antworten. Ich folgte deinen Empfehlungen und löste meine Frage, indem ich eine bessere Identität bekam.