Skip to content

Instantly share code, notes, and snippets.

@AMZzee
Last active February 22, 2022 12:01
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 AMZzee/43e29ca65ab3ca95b7d18c705c882550 to your computer and use it in GitHub Desktop.
Save AMZzee/43e29ca65ab3ca95b7d18c705c882550 to your computer and use it in GitHub Desktop.
def build_finetune_model(base_model, dropout, fc_layers, num_classes):
for layer in base_model.layers:
layer.trainable = False
x = base_model.output
x = GlobalAveragePooling2D()(x)
for fc in fc_layers:
# New FC layer, random init
x = Dense(fc, activation='relu')(x)
x = Dropout(dropout)(x)
# New softmax layer
predictions = Dense(num_classes, activation='softmax')(x)
finetune_model = Model(inputs=base_model.input, outputs=predictions)
return finetune_model
FC_LAYERS = [100, 50]
dropout = 0.5
finetune_model = build_finetune_model(base_model,
dropout=dropout,
fc_layers=FC_LAYERS,
num_classes=4)
@wsojka00
Copy link

Hello,

I get the TypeError: Inputs to a layer should be tensors. Got: <keras.layers.pooling.GlobalAveragePooling2D object at 0x0000022F5F9FA220>

Do you have any idea why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment