2016-07-27 30 views
1

Ich habe ein einfaches Faltungsneuron-Netzwerk mit TensorFlow erstellt. Wenn ich Eingabebilder mit der Kante = 32px benutze, funktioniert das Netzwerk gut, aber wenn ich die Kante zweimal auf 64px vergrößere, dann entropie retutrs als NaN. Die Frage ist, wie das zu beheben ist?Tensorflow Entropie in NaN für große Eingänge beim Training CNN

CNN Struktur ist ziemlich einfach und wie folgt aussieht: Input-> conv-> pool2-> conv-> pool2-> conv-> pool2-> fc-> softmax

Entropie wie berechnet:

prediction = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) 
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction), reduction_indices=[1]))  # loss 
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) 
train_pred = tf.equal(tf.argmax(prediction, 1), tf.argmax(ys, 1)) 
train_accuracy = tf.reduce_mean(tf.cast(train_pred, tf.float32)) 

für 64px ich habe:

train_accuracy=0.09000000357627869, cross_entropy=nan, test_accuracy=0.1428571492433548 
train_accuracy=0.2800000011920929, cross_entropy=nan, test_accuracy=0.1428571492433548 
train_accuracy=0.27000001072883606, cross_entropy=nan, test_accuracy=0.1428571492433548 

für 32px es sieht gut aus und die Ausbildung gibt Ergebnis:

train_accuracy=0.07999999821186066, cross_entropy=20.63970184326172, test_accuracy=0.15000000596046448 
train_accuracy=0.18000000715255737, cross_entropy=15.00744342803955, test_accuracy=0.1428571492433548 
train_accuracy=0.18000000715255737, cross_entropy=12.469900131225586, test_accuracy=0.13571429252624512 
train_accuracy=0.23000000417232513, cross_entropy=10.289153099060059, test_accuracy=0.11428571492433548 

Antwort

0

Soweit ich weiß, NAN passieren, wenn Sie log (0) berechnen. Ich hatte das gleiche Problem.

tf.log(prediction) #This is a problem when the predicted value is 0. 

Sie können dies vermeiden, indem Sie ein wenig Lärm auf die Vorhersage Zugabe (related 1, related 2).

tf.log(prediction + 1e-10) 

Oder die clip_by_value Funktion von tensorflow verwenden, definiert es einen minimalen und maximalen Wert für den übergebenen Tensor. So etwas wie diese (Documentation):

tf.log(tf.clip_by_value(prediction, 1e-10,1.0)) 

Hoffe, es hilft.

+1

Vielen Dank, Sie haben recht, Lärm hilft. – Verych