Skip to content

Instantly share code, notes, and snippets.

@GertjanBrouwer
Created September 16, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GertjanBrouwer/67fcf1747d0860fedf9be2cd563bc688 to your computer and use it in GitHub Desktop.
Save GertjanBrouwer/67fcf1747d0860fedf9be2cd563bc688 to your computer and use it in GitHub Desktop.
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