Skip to content

Instantly share code, notes, and snippets.

@SmiffyKMc
Created June 17, 2022 15:01
Show Gist options
  • Save SmiffyKMc/42d29296db6b8519dbdf468377db9b7f to your computer and use it in GitHub Desktop.
Save SmiffyKMc/42d29296db6b8519dbdf468377db9b7f to your computer and use it in GitHub Desktop.
Retrieving the features of the VGG16 model
import numpy as np
def get_features_and_labels(dataset):
all_features = []
all_labels = []
for images, labels in dataset:
preprocessed_images = keras.applications.vgg16.preprocess_input(images)
features = conv_base.predict(preprocessed_images)
all_features.append(features)
all_labels.append(labels)
return np.concatenate(all_features), np.concatenate(all_labels)
train_features, train_labels = get_features_and_labels(train_dataset)
val_features, val_labels = get_features_and_labels(validation_dataset)
test_features, test_labels = get_features_and_labels(test_dataset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment