Last active
July 23, 2020 08:50
-
-
Save akash-ch2812/bbbf60cd631c992c92bb37c3a84e4faa to your computer and use it in GitHub Desktop.
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 tensorflow as tf | |
from keras.preprocessing import image | |
from keras.applications.resnet50 import ResNet50 | |
from keras.applications.resnet50 import preprocess_input | |
from keras.models import Model | |
# load the ResNet50 Model | |
feature_extractor = ResNet50(weights='imagenet', include_top=False) | |
feature_extractor_new = Model(feature_extractor.input, feature_extractor.layers[-2].output) | |
feature_extractor_new.summary() | |
for file in os.listdir(image_path): | |
path = image_path + "//" + file | |
img = image.load_img(path, target_size=(90, 90)) | |
img_data = image.img_to_array(img) | |
img_data = np.expand_dims(img_data, axis=0) | |
img_data = preprocess_input(img_data) | |
feature = feature_extractor_new.predict(img_data) | |
feature_reshaped = np.array(feature).flatten() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment