Skip to content

Instantly share code, notes, and snippets.

@d-misra

d-misra/model.py Secret

Last active February 27, 2023 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-misra/8aa34bce67a5e3ed13b6edc5f0dacfe0 to your computer and use it in GitHub Desktop.
Save d-misra/8aa34bce67a5e3ed13b6edc5f0dacfe0 to your computer and use it in GitHub Desktop.
VGG16 model for clustering
from keras.models import load_model, Model
from keras.applications.vgg16 import VGG16, preprocess_input
def setup_model(layer='fc2'):
base_model = VGG16(weights='imagenet', include_top=True)
# base_model.summary():
# ....
# block5_conv4 (Conv2D) (None, 15, 15, 512) 2359808
# _________________________________________________________________
# block5_pool (MaxPooling2D) (None, 7, 7, 512) 0
# _________________________________________________________________
# flatten (Flatten) (None, 25088) 0
# _________________________________________________________________
# fc1 (Dense) (None, 4096) 102764544
# _________________________________________________________________
# fc2 (Dense) (None, 4096) 16781312
# _________________________________________________________________
# predictions (Dense) (None, 1000) 4097000
#
model = Model(inputs=base_model.input,
outputs=base_model.get_layer(layer).output)
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment