-
Notifications
You must be signed in to change notification settings - Fork 5
/
cnn_model.py
36 lines (28 loc) · 1.31 KB
/
cnn_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
35
36
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D
from tensorflow.keras import Model
class CNN(Model):
def __init__(self):
super(CNN, self).__init__()
self.conv1 = Conv2D(32, 3, padding='same', activation='relu')
self.conv2 = Conv2D(64, 3, padding='same', activation='relu')
self.pool1 = MaxPooling2D(pool_size=(2, 2), padding='same')
self.dropout1 = Dropout(0.25)
self.flatten = Flatten()
self.d1 = Dense(128, activation='relu')
self.dropout2 = Dropout(0.5)
self.d2 = tf.keras.layers.Dense(3, activation='softmax')
def call(self, x):
x = self.conv1(x)
x = self.conv2(x)
x = self.pool1(x)
x = self.dropout1(x)
x = self.flatten(x)
x = self.d1(x)
x = self.dropout2(x)
x = self.d2(x)
return x
def model(self):
x = keras.Input(shape=(15, 15, 1))
return Model(inputs=[x], outputs=self.call(x))