Created
June 17, 2022 15:01
-
-
Save SmiffyKMc/42d29296db6b8519dbdf468377db9b7f to your computer and use it in GitHub Desktop.
Retrieving the features of the VGG16 model
This file contains hidden or 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
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