-
-
Save Gabe-flomo/54b8fb0c069f0de8353e9c51ecef29a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load the model first and pass as an argument | |
model = VGG16() | |
model = Model(inputs = model.inputs, outputs = model.layers[-2].output) | |
def extract_features(file, model): | |
# load the image as a 224x224 array | |
img = load_img(file, target_size=(224,224)) | |
# convert from 'PIL.Image.Image' to numpy array | |
img = np.array(img) | |
# reshape the data for the model reshape(num_of_samples, dim 1, dim 2, channels) | |
reshaped_img = img.reshape(1,224,224,3) | |
# prepare image for model | |
imgx = preprocess_input(reshaped_img) | |
# get the feature vector | |
features = model.predict(imgx, use_multiprocessing=True) | |
return features |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment