-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataModelling.py
41 lines (35 loc) · 1.41 KB
/
DataModelling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from tensorflow.keras.models import Sequential
from tensorflow.keras.losses import SparseCategoricalCrossentropy
from tensorflow.keras.layers.experimental.preprocessing import Rescaling
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Dropout, BatchNormalization
class DataModelling:
def __init__(self, image):
self.input_shape = (image[0], image[1], 1)
def generate_model(self):
model = Sequential([
Rescaling(1. / 255, input_shape=self.input_shape),
BatchNormalization(),
Conv2D(6, kernel_size=(3, 3), padding="same", activation="relu"),
Conv2D(8, kernel_size=(3, 3), padding="same", activation="relu"),
Conv2D(10, kernel_size=(3, 3), padding="same", activation="relu"),
BatchNormalization(),
MaxPooling2D(pool_size=(2, 2)),
Flatten(),
Dense(700, activation='relu'),
BatchNormalization(),
Dropout(0.2),
Dense(500, activation='relu'),
BatchNormalization(),
Dropout(0.2),
Dense(400, activation='relu'),
Dropout(0.2),
Dense(345, activation='softmax')
])
return model
def compile_model(self, model):
model.compile(
optimizer="adam",
loss=SparseCategoricalCrossentropy(),
metrics=["accuracy"]
)
return model