-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCNN.py
56 lines (46 loc) · 1.56 KB
/
CNN.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: robi
"""
def CNN_create(Nr,Nc, mod='AlexNet'):
# Create CNN AlexNet for comparison (version of Tensmeyer paper, Aug 2017)
from keras.layers import Conv2D, MaxPooling2D, Dense, Flatten
from keras.models import Sequential
model= Sequential()
# Calculate
# First conv layer
# CONV
model.add( Conv2D(96,(11,11),strides=(4,4),
padding='same',activation='relu',
input_shape=(Nr,Nc,1)) )
# MAXP overlap
model.add( MaxPooling2D(pool_size=(3,3),strides=2) )
# Second conv layer
# CONV
model.add( Conv2D(256,(5,5),padding='same',activation='relu') )
# MAXP overlap
model.add( MaxPooling2D(pool_size=(3,3),strides=2) )
# Third conv layer
# CONV
model.add( Conv2D(384,(3,3),padding='same',activation='relu') )
# Fourth conv layer
# CONV
model.add( Conv2D(384,(3,3),padding='same',activation='relu') )
# Fifth conv layer
# CONV
model.add( Conv2D(256,(3,3),padding='same',activation='relu') )
# MAXP overlap
model.add( MaxPooling2D(pool_size=(3,3),strides=2) )
# First FC layer
model.add( Flatten() )
model.add( Dense(64, activation='relu') )
# Second FC layer
model.add( Dense(64, activation='relu') )
# Predictions
model.add( Dense(16, activation='softmax') )
# Model creation
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
return model