Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from keras.applications.vgg16 import VGG16
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.vgg16 import preprocess_input
from keras.models import Sequential
from keras.layers import Dropout, Flatten, Dense
import numpy as np
img_width, img_height = 224, 224
model = VGG16(weights='imagenet', include_top=False)
model.layers.pop()
#model.layers.pop()
train_data_dir = '/home/gertjan/Documents/vgg164096/test'
nb_train_samples = 1
datagen = ImageDataGenerator(rescale=1. /255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)
generator = datagen.flow_from_directory(train_data_dir, target_size=(img_width, img_height), batch_size=8, class_mode=None, shuffle=False)
bottleneck_features_train = model.predict_generator(generator, nb_train_samples, 8)
print(bottleneck_features_train)
np.savetxt('test.out', bottleneck_features_train, '%s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment