Update model.py
Browse files
model.py
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tensorflow.keras.models import Sequential
|
| 2 |
+
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout
|
| 3 |
+
from tensorflow.keras.layers import BatchNormalization
|
| 4 |
+
from tensorflow.keras.regularizers import l2
|
| 5 |
+
|
| 6 |
+
def build_model(input_shape, num_classes):
|
| 7 |
+
model = Sequential([
|
| 8 |
+
Conv2D(32, (3, 3), activation='relu',padding='same', input_shape=input_shape,kernel_regularizer='l2'),
|
| 9 |
+
BatchNormalization(),
|
| 10 |
+
MaxPooling2D((2, 2)),
|
| 11 |
+
|
| 12 |
+
Conv2D(64, (3, 3), activation='relu',padding='same',kernel_regularizer='l2'),
|
| 13 |
+
BatchNormalization(),
|
| 14 |
+
MaxPooling2D((2, 2)),
|
| 15 |
+
|
| 16 |
+
Conv2D(128, (3, 3), activation='relu',padding='same',kernel_regularizer='l2'),
|
| 17 |
+
BatchNormalization(),
|
| 18 |
+
MaxPooling2D((2, 2)),
|
| 19 |
+
|
| 20 |
+
Conv2D(256, (3, 3), activation='relu',padding='same',kernel_regularizer='l2'),
|
| 21 |
+
BatchNormalization(),
|
| 22 |
+
MaxPooling2D((2, 2)),
|
| 23 |
+
|
| 24 |
+
Conv2D(256, (3, 3), activation='relu',padding='same',kernel_regularizer='l2'),
|
| 25 |
+
BatchNormalization(),
|
| 26 |
+
MaxPooling2D((2, 2)),
|
| 27 |
+
|
| 28 |
+
Flatten(),
|
| 29 |
+
Dense(512, activation='relu',kernel_regularizer='l2'),
|
| 30 |
+
#BatchNormalization(),
|
| 31 |
+
Dropout(0.5),
|
| 32 |
+
Dense(256, activation='relu',kernel_regularizer='l2'),
|
| 33 |
+
#BatchNormalization(),
|
| 34 |
+
Dropout(0.5),
|
| 35 |
+
Dense(3, activation='softmax') # Assuming 3 classes
|
| 36 |
+
])
|
| 37 |
+
|
| 38 |
+
return model
|