dpatel9923 commited on
Commit
575062f
·
verified ·
1 Parent(s): b48643e

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +4 -13
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
- # Load VGG16 model without the top layers
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.5)(x)
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 = False
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