Skip to content

Instantly share code, notes, and snippets.

@akash-ch2812
Last active July 23, 2020 08:50
Show Gist options
  • Save akash-ch2812/bbbf60cd631c992c92bb37c3a84e4faa to your computer and use it in GitHub Desktop.
Save akash-ch2812/bbbf60cd631c992c92bb37c3a84e4faa to your computer and use it in GitHub Desktop.
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