File size: 772 Bytes
ca44728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


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)