Motunbuild's picture
Upload model.py with huggingface_hub
ca44728 verified
Raw History Blame Contribute Delete
772 Bytes
base_model = ResNet50(weights='imagenet', include_top=False, input_shape=input_shape, pooling='avg')
# Freeze all layers first
base_model.trainable = False
# Unfreeze top `unfreeze_top` layers for fine-tuning
for layer in base_model.layers[-unfreeze_top:]:
layer.trainable = True
# Build classifier head
inputs = Input(shape=input_shape)
x = base_model(inputs, training=False)
x = BatchNormalization()(x)
x = Dense(512, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01))(x)
x = Dropout(0.5)(x)
x = BatchNormalization()(x)
x = Dense(256, activation='relu', kernel_regularizer=tf.keras.regularizers.l2(0.01))(x)
x = Dropout(0.4)(x)
outputs = Dense(num_classes, activation='softmax')(x)