hitty commited on
Commit
7e64b5c
·
1 Parent(s): 9e14728

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +9 -6
model.py CHANGED
@@ -1,23 +1,25 @@
1
  import tensorflow as tf
2
  from tensorflow.keras.layers import Dropout, Dense
3
  from tensorflow.keras.applications import EfficientNetB7
 
4
  from tensorflow.keras.layers import Dropout, Dense, GlobalAveragePooling2D, Input
5
  from tensorflow.keras.models import Model
6
 
7
  def create_effnetb2_model(num_classes=15, seed=42):
8
- """Creates an EfficientNetB2 feature extractor model.
9
  Args:
10
  num_classes (int, optional): Number of classes in the classifier head.
11
  Defaults to 3.
12
  seed (int, optional): Random seed value. Defaults to 42.
13
  Returns:
14
- model (tensorflow.keras.Model): EffNetB2 feature extractor model.
15
  """
16
  # Load the pretrained EffNetB2 model
17
  base_model = EfficientNetB7(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
18
 
19
- # Freeze all layers in the base model
20
- base_model.trainable = False
 
21
 
22
  # Add additional layers
23
  inputs = Input(shape=(224, 224, 3))
@@ -28,9 +30,9 @@ def create_effnetb2_model(num_classes=15, seed=42):
28
  x = Dropout(0.3)(x)
29
  x = Dense(128, activation='relu')(x)
30
  x = Dropout(0.3)(x)
31
- x = Dense(64, activation='relu')(x) # Additional dense layer
32
  x = Dropout(0.3)(x)
33
- x = Dense(32, activation='relu')(x) # Additional dense layer
34
 
35
  # Add a dense layer for classification
36
  outputs = Dense(num_classes, activation='softmax')(x)
@@ -42,3 +44,4 @@ def create_effnetb2_model(num_classes=15, seed=42):
42
 
43
 
44
 
 
 
1
  import tensorflow as tf
2
  from tensorflow.keras.layers import Dropout, Dense
3
  from tensorflow.keras.applications import EfficientNetB7
4
+
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):
9
+ """Creates an EfficientNetB2 model with additional layers for fine-tuning.
10
  Args:
11
  num_classes (int, optional): Number of classes in the classifier head.
12
  Defaults to 3.
13
  seed (int, optional): Random seed value. Defaults to 42.
14
  Returns:
15
+ model (tensorflow.keras.Model): EffNetB2 model with additional layers.
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 except the last few
21
+ for layer in base_model.layers[:-5]:
22
+ layer.trainable = False
23
 
24
  # Add additional layers
25
  inputs = Input(shape=(224, 224, 3))
 
30
  x = Dropout(0.3)(x)
31
  x = Dense(128, activation='relu')(x)
32
  x = Dropout(0.3)(x)
33
+ x = Dense(64, activation='relu')(x)
34
  x = Dropout(0.3)(x)
35
+ x = Dense(32, activation='relu')(x)
36
 
37
  # Add a dense layer for classification
38
  outputs = Dense(num_classes, activation='softmax')(x)
 
44
 
45
 
46
 
47
+