Update model.py
Browse files
model.py
CHANGED
|
@@ -4,24 +4,15 @@ from tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout
|
|
| 4 |
from tensorflow.keras.optimizers import Adam
|
| 5 |
|
| 6 |
def build_model(input_shape, num_classes):
|
| 7 |
-
|
| 8 |
-
base_model = VGG16(weights='imagenet', include_top=False, input_shape=input_shape)
|
| 9 |
-
|
| 10 |
-
# Adding additional layers
|
| 11 |
x = base_model.output
|
| 12 |
x = GlobalAveragePooling2D()(x)
|
| 13 |
x = Dense(1024, activation='relu')(x)
|
| 14 |
-
x = Dropout(0.
|
| 15 |
predictions = Dense(num_classes, activation='softmax')(x)
|
| 16 |
-
|
| 17 |
-
# Creating the final model
|
| 18 |
model = Model(inputs=base_model.input, outputs=predictions)
|
| 19 |
-
|
| 20 |
-
# Freezing the layers except the last layers
|
| 21 |
for layer in base_model.layers:
|
| 22 |
-
layer.trainable =
|
| 23 |
|
| 24 |
-
# Compile the model
|
| 25 |
model.compile(optimizer=Adam(learning_rate=0.0001), loss='categorical_crossentropy', metrics=['accuracy'])
|
| 26 |
-
|
| 27 |
-
return model
|
|
|
|
| 4 |
from tensorflow.keras.optimizers import Adam
|
| 5 |
|
| 6 |
def build_model(input_shape, num_classes):
|
| 7 |
+
base_model = VGG19(weights='imagenet', include_top=False, input_shape=input_shape)
|
|
|
|
|
|
|
|
|
|
| 8 |
x = base_model.output
|
| 9 |
x = GlobalAveragePooling2D()(x)
|
| 10 |
x = Dense(1024, activation='relu')(x)
|
| 11 |
+
x = Dropout(0.2)(x)
|
| 12 |
predictions = Dense(num_classes, activation='softmax')(x)
|
|
|
|
|
|
|
| 13 |
model = Model(inputs=base_model.input, outputs=predictions)
|
|
|
|
|
|
|
| 14 |
for layer in base_model.layers:
|
| 15 |
+
layer.trainable = True
|
| 16 |
|
|
|
|
| 17 |
model.compile(optimizer=Adam(learning_rate=0.0001), loss='categorical_crossentropy', metrics=['accuracy'])
|
| 18 |
+
return model
|
|
|