![](/img/trans.png)
[英]Keras CNN: validation accuracy stuck at 70%, training accuracy reaching 100%
[英]Validation accuracy stuck at 0.50 when training CNN siamese network based on Keras MNIST example
在訓練基於Keras MNIST示例的暹羅卷積神經網絡時,它的驗證精度為0.50。 此外,訓練和驗證損失減少,而訓練精度也徘徊在0.50左右。
創建暹羅網絡的代碼與此類似:
input_shape = x_train.shape[2:]
print('input_shape:',input_shape)
# network definition
base_network = create_base_network(input_shape)
input_a = Input(shape=input_shape)
input_b = Input(shape=input_shape)
# because we re-use the same instance `base_network`,
# the weights of the network
# will be shared across the two branches
processed_a = base_network(input_a)
processed_b = base_network(input_b)
distance = Lambda(euclidean_distance,
output_shape=eucl_dist_output_shape)([processed_a, processed_b])
model = Model([input_a, input_b], distance)
在create_base_network
函數創建帶有兩個額外的前饋層512和1024的ResNet50的同時,所有層都凍結了,最后只有幾個未凍結的層。
已在多個平台(Stackoverflow,Github甚至Reddit)上多次討論了此問題,但未提供確定的答案/解決方案。
我已經排除了幾個小時的故障。 盡管此用例非常具體,但這並不會影響很多人,但受影響的人可以嘗試遵循。 它為我工作。
看來問題與我理解的范圍之外的Python 3.5的某些低級行為有關。 切換到Python 2.7可以解決問題,並且網絡從一開始就可以達到70%以上的准確性。 在此之前,即使經過10個時間段,精度仍保持在50%。
Train on 36000 samples, validate on 4000 samples
Epoch 1/10
36000/36000 [==============================] - 866s 24ms/step - loss: 0.2026 - accuracy: 0.7133 - val_loss: 0.2054 - val_accuracy: 0.7173
Epoch 00001: val_loss improved from inf to 0.20544, saving model to model_checkpoint/siamese_40k_headache_20thFeb-1.hdf5
Epoch 2/10
36000/36000 [==============================] - 770s 21ms/step - loss: 0.1949 - accuracy: 0.7271 - val_loss: 0.2020 - val_accuracy: 0.7235
Epoch 00002: val_loss improved from 0.20544 to 0.20204, saving model to model_checkpoint/siamese_40k_headache_20thFeb-1.hdf5
Epoch 3/10
7040/36000 [====>.........................] - ETA: 9:12 - loss: 0.1879 - accuracy: 0.7320
此外,當使用轉移學習訓練暹羅網絡時,驗證精度停留在0.50可能還與Keras的批歸一化層的實現有關。 在這里可以了解更多信息。 手動安裝此版本的Keras可以解決此問題:
!pip install -U --force-reinstall --no-dependencies git+https://github.com/datumbox/keras@fork/keras2.2.4
這絕不是解決問題的直接方法,而是可行的解決方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.