如何训练暹罗神经网络进行图像匹配?

时间:2019-04-05 00:33:29

标签: keras

我需要确定两个指纹(来自身份证和传感器)是否匹配。下面是我数据库中的一些示例(3000对图像):

  1. 匹配图像的示例

enter image description here

  1. 不匹配图像的示例

enter image description here

我试图训练一个暹罗网络,该网络接收一对图像,如果不匹配,则输出为[1,0],如果匹配则为[0,1],然后我用Keras创建了模型:

image_left = Input(shape=(200, 200, 1))
image_right = Input(shape=(200, 200, 1))

vector_left = conv_base(image_left)
vector_right = conv_base(image_right)

merged_features = concatenate([vector_left, vector_right], axis=-1)

fc1 = Dense(64, activation='relu')(merged_features)
fc1 = Dropout(0.2)(fc1)

# # fc2 = Dense(128, activation='relu')(fc1)

pred = Dense(2, activation='softmax')(fc1)

model = Model(inputs=[image_left, image_right], outputs=pred)

conv_base是卷积体系结构。实际上,我已经尝试使用ResNet中的leNetMobileNetV2NASNetkeras.applications,但是它们不起作用。

conv_base = NASNetMobile(weights = None,
                        include_top=True,
                       classes=256)

我的模型摘要如下所示(取决于所使用的相应网络):

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_2 (InputLayer)            (None, 200, 200, 1)  0                                            
__________________________________________________________________________________________________
input_3 (InputLayer)            (None, 200, 200, 1)  0                                            
__________________________________________________________________________________________________
NASNet (Model)                  (None, 256)          4539732     input_2[0][0]                    
                                                                 input_3[0][0]                    
__________________________________________________________________________________________________
concatenate_5 (Concatenate)     (None, 512)          0           NASNet[1][0]                     
                                                                 NASNet[2][0]                     
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 64)           32832       concatenate_5[0][0]              
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None, 64)           0           dense_1[0][0]                    
__________________________________________________________________________________________________
dense_2 (Dense)                 (None, 2)            130         dropout_1[0][0]                  
==================================================================================================
Total params: 4,572,694
Trainable params: 4,535,956
Non-trainable params: 36,738

除卷积架构更改外,我还尝试使用预训练权重,将所有层设置为可训练,将最后一个卷积层设置为可训练,使用categorical_crossentropycontrastive_loss函数进行数据扩充,不断变化的学习速度,但是它们都有相同的行为。就是说,训练和验证的准确性始终为0.5。

有人对我想念/做错的事有想法吗?

谢谢。

0 个答案:

没有答案