The Keras documentation says it returns "A Numpy array of predictions." Using it on 496 image examples with 4 classes, I get a 4-dimensional array (496, 4, 4, 512). What are the other 2 dimensions? Eventually, I would like to have an array of X (examples) and an array of Y (labels).
img_width, img_height = 150, 150
top_model_weights_path = 'bottleneck_fc_model.h5'
train_data_dir = 'data/train'
validation_data_dir = 'data/validation'
nb_train_samples = 496
nb_validation_samples = 213
epochs = 50
batch_size = 16
number_of_classes = 3
datagen = ImageDataGenerator(rescale=1. / 255)
# build the VGG16 network (exclude last layer)
model = applications.VGG16(include_top=False, weights='imagenet')
# generate training data from image files
train_generator = datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='categorical',
shuffle=False)
# predict bottleneck features on training data
bottleneck_features_train = model.predict_generator(
train_generator, nb_train_samples // batch_size)
print(bottleneck_features_train.shape)
train_data = np.load(open('bottleneck_features_train.npy', 'rb'))
print(train_data.shape)