-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
34 lines (32 loc) · 1.05 KB
/
model.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
import tensorflow as tf
from tensorflow import keras
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
"data",
validation_split=0.2,
subset="training",
seed=1337,
image_size=(80,60),
color_mode="grayscale",
batch_size=16,
shuffle=True
)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
"data",
validation_split=0.2,
subset="validation",
seed=1337,
image_size=(80,60),
color_mode="grayscale",
batch_size=16,
shuffle=True
)
model = keras.Sequential()
# block 1
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same', input_shape=(80, 60, 1)))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(128,activation='relu',kernel_initializer='he_uniform'))
model.add(Dense(1,activation='sigmoid'))
model.compile(optimizer=keras.optimizers.SGD(lr=0.001,momentum=0.9),loss='binary_crossentropy',metrics=['accuracy'])
model.fit(train_ds,epochs=20,validation_data=val_ds)