-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
86 lines (71 loc) · 3.6 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 4 19:24:02 2019
@author: Dell
"""
import tensorflow as tf
from tensorflow import keras
def create_model(input_shape,activation_fn,Batch_norm,kernel_init,dropout_rate,target_class):
model=keras.models.Sequential()
model.add(keras.layers.Conv2D(filters=32,kernel_size=7,strides=1,padding="same",input_shape=input_shape,
kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.Conv2D(filters=32,kernel_size=7,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.MaxPool2D(pool_size=2))
model.add(keras.layers.Conv2D(filters=64,kernel_size=5,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.Conv2D(filters=64,kernel_size=5,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.MaxPool2D(pool_size=2))
model.add(keras.layers.Conv2D(filters=128,kernel_size=3,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.Conv2D(filters=128,kernel_size=3,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.MaxPool2D(pool_size=2))
model.add(keras.layers.Conv2D(filters=256,kernel_size=3,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.Conv2D(filters=256,kernel_size=3,strides=1,padding="same",kernel_initializer=kernel_init))
if(Batch_norm):
model.add(keras.layers.BatchNormalization())
model.add(keras.layers.Activation(activation_fn))
else:
model.add(keras.layers.Activation(activation_fn))
model.add(keras.layers.MaxPool2D(pool_size=2))
model.add(keras.layers.Flatten())
model.add(keras.layers.Dense(512,activation=activation_fn))
model.add(keras.layers.Dropout(rate=dropout_rate))
model.add(keras.layers.Dense(256,activation=activation_fn))
model.add(keras.layers.Dropout(rate=dropout_rate))
model.add(keras.layers.Dense(64,activation=activation_fn))
model.add(keras.layers.Dropout(rate=dropout_rate))
model.add(keras.layers.Dense(target_class,activation="softmax"))
return model