与Keras的暹罗神经网络

时间:2018-06-14 15:49:30

标签: keras conv-neural-network

我正在尝试使用暹罗神经网络来检查两个图像是否相似。作为参考,我从标准示例here开始,虽然我更改了某些帖子中建议的 contrastive_loss compute_accuracy 中的返回值,但它们似乎运行良好(我将准确度提高到0.98并将损失降低到0.01)。

现在我想使用卷积基础VGG和我自己的数据集(大小为200x200和3个通道),并将最后一层设置为可训练(尽管我尝试使用整个网络训练)我所做的是here

我的模型如下:

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_2 (InputLayer)            (None, 200, 200, 3)  0                                            
__________________________________________________________________________________________________
input_3 (InputLayer)            (None, 200, 200, 3)  0                                            
__________________________________________________________________________________________________
vgg16 (Model)                   (None, 6, 6, 512)    14714688    input_2[0][0]                    
                                                                 input_3[0][0]                    
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 1)            0           vgg16[1][0]                      
                                                                 vgg16[2][0]                      
==================================================================================================
Total params: 14,714,688
Trainable params: 7,079,424
Non-trainable params: 7,635,264

当我开始训练程序时,每个时期的损失和准确度值始终为0.5。

Train on 2000 samples, validate on 800 samples
Epoch 1/10
2000/2000 [==============================] - 2561s 1s/step - loss: 0.5005 - acc: 0.4998 - val_loss: 0.5000 - val_acc: 0.5000
Epoch 2/10
2000/2000 [==============================] - 2563s 1s/step - loss: 0.5000 - acc: 0.5000 - val_loss: 0.5000 - val_acc: 0.5000
Epoch 3/10
1999/2000 [============================>.] - ETA: 0s - loss: 0.4997 - acc: 0.5003Epoch 4/10
2000/2000 [==============================] - 2553s 1s/step - loss: 0.5000 - acc: 0.5000 - val_loss: 0.5000 - val_acc: 0.5000
Epoch 5/10
2000/2000 [==============================] - 2554s 1s/step - loss: 0.5000 - acc: 0.5000 - val_loss: 0.5000 - val_acc: 0.5000
Epoch 6/10
2000/2000 [==============================] - 2562s 1s/step - loss: 0.5000 - acc: 0.5000 - val_loss: 0.5000 - val_acc: 0.5000
Epoch 7/10
 763/2000 [==========>...................] - ETA: 19:54 - loss: 0.4980 - acc: 0.5020

如果我在训练后预测模型,则所有输出均为0,形状为(2000, 1, 6, 512),用于训练数据

关于我做错了什么的任何建议?

谢谢

0 个答案:

没有答案