Update model.py
Browse files
model.py
CHANGED
|
@@ -2,8 +2,7 @@ import tensorflow as tf
|
|
| 2 |
from tensorflow.keras.layers import Dropout, Dense
|
| 3 |
from tensorflow.keras.applications import EfficientNetB7
|
| 4 |
from tensorflow.keras import Model
|
| 5 |
-
from tensorflow.keras.
|
| 6 |
-
from tensorflow.keras.layers import Dropout, Dense, GlobalAveragePooling2D
|
| 7 |
from tensorflow.keras.models import Model
|
| 8 |
|
| 9 |
def create_effnetb2_model(num_classes=15, seed=42):
|
|
@@ -16,22 +15,26 @@ def create_effnetb2_model(num_classes=15, seed=42):
|
|
| 16 |
model (tensorflow.keras.Model): EffNetB2 feature extractor model.
|
| 17 |
"""
|
| 18 |
# Load the pretrained EffNetB2 model
|
| 19 |
-
base_model =
|
| 20 |
|
| 21 |
# Freeze all layers in the base model
|
| 22 |
base_model.trainable = False
|
| 23 |
|
| 24 |
-
# Add
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
x = Dropout(0.3)(x)
|
|
|
|
| 29 |
|
| 30 |
# Add a dense layer for classification
|
| 31 |
-
|
| 32 |
|
| 33 |
# Create the final model
|
| 34 |
-
model = Model(inputs=
|
| 35 |
|
| 36 |
return model
|
| 37 |
|
|
|
|
|
|
| 2 |
from tensorflow.keras.layers import Dropout, Dense
|
| 3 |
from tensorflow.keras.applications import EfficientNetB7
|
| 4 |
from tensorflow.keras import Model
|
| 5 |
+
from tensorflow.keras.layers import Dropout, Dense, GlobalAveragePooling2D, Input
|
|
|
|
| 6 |
from tensorflow.keras.models import Model
|
| 7 |
|
| 8 |
def create_effnetb2_model(num_classes=15, seed=42):
|
|
|
|
| 15 |
model (tensorflow.keras.Model): EffNetB2 feature extractor model.
|
| 16 |
"""
|
| 17 |
# Load the pretrained EffNetB2 model
|
| 18 |
+
base_model = EfficientNetB7(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
|
| 19 |
|
| 20 |
# Freeze all layers in the base model
|
| 21 |
base_model.trainable = False
|
| 22 |
|
| 23 |
+
# Add additional layers
|
| 24 |
+
inputs = Input(shape=(224, 224, 3))
|
| 25 |
+
x = base_model(inputs)
|
| 26 |
+
x = GlobalAveragePooling2D()(x)
|
| 27 |
+
x = Dropout(0.3)(x)
|
| 28 |
+
x = Dense(256, activation='relu')(x) # Additional dense layer
|
| 29 |
x = Dropout(0.3)(x)
|
| 30 |
+
x = Dense(128, activation='relu')(x) # Additional dense layer
|
| 31 |
|
| 32 |
# Add a dense layer for classification
|
| 33 |
+
outputs = Dense(num_classes, activation='softmax')(x)
|
| 34 |
|
| 35 |
# Create the final model
|
| 36 |
+
model = Model(inputs=inputs, outputs=outputs)
|
| 37 |
|
| 38 |
return model
|
| 39 |
|
| 40 |
+
|