0
有人可以幫助理解爲什麼此代碼不處理所有圖像?或者如何確保它處理所有圖像?請看看發生了什麼,當我打印出來的功能和標籤:爲什麼這個Loop似乎只處理一個圖像?
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
正如你看到下面的[11]:「處理圖像/揚 - 孟加拉 - tiger.jpg ......」似乎僅環proccesed ONE圖片。
In [11]: features,labels = extract_features(list_images)
處理圖像/楊氏-孟加拉-tiger.jpg ..。 W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization已棄用。它將在GraphDef版本9中停止工作。使用tf.nn.batch_normalization()。
我應該看到:
Processing images/baby_shoe_0.jpg...
Processing images/basketball_hoop_0.jpg...
Processing images/bath_spa_0.jpg...
Processing images/binocular_0.jpg...
Processing images/birdcage_0.jpg...
Processing images/birdhouse_0.jpg...
Processing images/boot_0.jpg...
Processing images/cabinet_0.jpg...
Processing images/calculator_0.jpg...
...etc...
請參閱包含圖片:
- 打印(功能)
- 打印(標籤)