-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy patharchs.py
106 lines (81 loc) · 3.12 KB
/
archs.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import keras
from keras.models import Model
from keras.layers import Dense, Conv2D, BatchNormalization, Activation
from keras.layers import Input, MaxPooling2D, Dropout, Flatten
from keras import regularizers
from metrics import *
weight_decay = 1e-4
def vgg_block(x, filters, layers):
for _ in range(layers):
x = Conv2D(filters, (3, 3), padding='same', kernel_initializer='he_normal',
kernel_regularizer=regularizers.l2(weight_decay))(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)
return x
def vgg8(args):
input = Input(shape=(28, 28, 1))
x = vgg_block(input, 16, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 32, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 64, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Flatten()(x)
x = Dense(args.num_features, kernel_initializer='he_normal',
kernel_regularizer=regularizers.l2(weight_decay))(x)
x = BatchNormalization()(x)
output = Dense(10, activation='softmax', kernel_regularizer=regularizers.l2(weight_decay))(x)
return Model(input, output)
def vgg8_arcface(args):
input = Input(shape=(28, 28, 1))
y = Input(shape=(10,))
x = vgg_block(input, 16, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 32, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 64, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Flatten()(x)
x = Dense(args.num_features, kernel_initializer='he_normal',
kernel_regularizer=regularizers.l2(weight_decay))(x)
x = BatchNormalization()(x)
output = ArcFace(10, regularizer=regularizers.l2(weight_decay))([x, y])
return Model([input, y], output)
def vgg8_cosface(args):
input = Input(shape=(28, 28, 1))
y = Input(shape=(10,))
x = vgg_block(input, 16, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 32, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 64, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Flatten()(x)
x = Dense(args.num_features, kernel_initializer='he_normal',
kernel_regularizer=regularizers.l2(weight_decay))(x)
x = BatchNormalization()(x)
output = CosFace(10, regularizer=regularizers.l2(weight_decay))([x, y])
return Model([input, y], output)
def vgg8_sphereface(args):
input = Input(shape=(28, 28, 1))
y = Input(shape=(10,))
x = vgg_block(input, 16, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 32, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = vgg_block(x, 64, 2)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Flatten()(x)
x = Dense(args.num_features, kernel_initializer='he_normal',
kernel_regularizer=regularizers.l2(weight_decay))(x)
x = BatchNormalization()(x)
output = SphereFace(10, regularizer=regularizers.l2(weight_decay))([x, y])
return Model([input, y], output)