-
Notifications
You must be signed in to change notification settings - Fork 8
/
siamese.py
30 lines (26 loc) · 1.05 KB
/
siamese.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
from keras.models import Model
from keras.layers import Input, Dense
from keras.optimizers import Adam
from utils import *
from sys import argv
#------------------------------------------------------------------------------
def siamese_model(type):
if type=='plate':
input_shape = (image_size_h_p,image_size_w_p,nchannels)
else:
input_shape = (image_size_h_c,image_size_w_c,nchannels)
left_input = Input(input_shape)
right_input = Input(input_shape)
convnet = small_vgg(input_shape)
encoded_l = convnet(left_input)
encoded_r = convnet(right_input)
# Add the distance function to the network
L1_distance = L1_layer([encoded_l, encoded_r])
prediction = Dense(2,activation='softmax')(L1_distance)
optimizer = Adam(0.001, decay=2.5e-4)
model = Model(inputs=[left_input,right_input],outputs=prediction)
model.compile(loss="binary_crossentropy",optimizer=optimizer,metrics=['accuracy'])
return model
#------------------------------------------------------------------------------
if __name__ == '__main__':
run(siamese_model(argv[1]), argv[1])