【发布时间】:2017-07-03 07:57:20
【问题描述】:
这段代码产生了这个错误:
NameError: 名称“图像”未定义
如果有任何帮助,我将不胜感激:
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
在前面的代码部分中,我声明了这一点:
list_images = [images_dir+f for f in os.listdir(images_dir) if re.search('jpg|JPG', f)]
【问题讨论】:
-
您只能在 for 循环中定义图像。如果 list_images 为空,则实际上从未定义过
标签: python tensorflow