如何迭代图像以使用VGG16提取特征?

时间:2018-03-02 09:15:14

标签: python python-3.x for-loop keras

我正在追踪Keras的this code

from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
import numpy as np

model = VGG16(weights='imagenet', include_top=False)

img_path = 'elephant.jpg'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

features = model.predict(x)

这是单个图像的示例。我如何为一堆图像制作它?假设我有2000张图片,我希望其功能形状为(2000,7,7,512)

0 个答案:

没有答案