forked from mjbigdel/SignatureDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelBuilding.py
More file actions
64 lines (54 loc) · 2.8 KB
/
Copy pathModelBuilding.py
File metadata and controls
64 lines (54 loc) · 2.8 KB
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
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 22:47:04 2018
@author: Manoochehr
"""
from keras.layers import Conv1D, MaxPooling1D, Flatten, Dense, Activation, Dropout
from keras.layers.normalization import BatchNormalization
from keras import regularizers
from keras.layers import Input
from keras.models import Model
# ///////////////////////////// Genuine /////////////////////////////////////////////////
def build_category_branch(inputs, numLastLayer, finalAct, LayerName):
x = Conv1D(96, 11, strides=4, padding= 'valid', kernel_regularizer = regularizers.l2(0.01))(inputs)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = MaxPooling1D(3, strides=2, padding='same')(x)
x = Conv1D(256, 5, strides=1, padding= 'same', kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = MaxPooling1D(3, strides=2, padding='same')(x)
x = Conv1D(384, 3, strides=1, padding= 'same', kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = Conv1D(384, 3, strides=1, padding= 'same', kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = Dropout(0.5)(x)
x = Conv1D(256, 3, strides=1, padding= 'same', kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = MaxPooling1D(3, strides=2, padding='same')(x)
x = Flatten()(x)
x = Dense(units = 2048 ,kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation(activation='relu')(x)
x = Dense(units = 2048, kernel_regularizer=regularizers.l2(0.01))(x)
x = BatchNormalization()(x)
x = Activation( activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(units = numLastLayer, kernel_regularizer=regularizers.l2(0.01))(x)
x = Activation(finalAct, name = LayerName)(x)
return x
def build(width, height, numUsers, numForgOrGen, finalAct1, finalAct2):
inputShape = (width, height)
# construct both the "users" and "GenOrForg" sub-networks
inputs = Input(shape=inputShape)
categoryUser = build_category_branch(inputs, numUsers, finalAct1, LayerName="categoryUser")
categoryGenOrForg = build_category_branch(inputs, numForgOrGen, finalAct2, LayerName="categoryGenOrForg")
model = Model(
inputs=inputs,
outputs=[categoryUser, categoryGenOrForg],
name="SignatureNet")
# return the constructed network architecture
return model