Ich habe eine tiefe CNN, die eine Bezeichnung zwischen "0" und "2" für jedes Pixel in einem 3D-Bild vorhersagt. Ich habe das Modell auf einem Bild trainiert, bei dem jedes Pixel mit "1" beschriftet ist. Daher glaube ich, dass beim Testen des Modells jede Vorhersage "1" sein sollte. Stattdessen sagt das Modell nur "0" voraus.Tensorflow neuronalen Netzwerk Vorhersage ist immer das gleiche
Hier ist das Repository für das gesamte Modell: https://github.com/dhasl002/Research-DeepLearning.
Da der Code fast 300 Zeilen ist, werde ich nur den entsprechenden Code unten enthalten.
x = tf.placeholder(tf.float32, shape=[None, 7168])
y_ = tf.placeholder(tf.float32, shape=[None, 7168, 3])
W_final = weight_variable([7168,7168,3])
b_final = bias_variable([7168,3])
#"final" is the result of the many convolutions
final_conv = tf.tensordot(final, W_final, axes=[[1], [1]]) + b_final
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=final_conv))
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(final_conv, 2), tf.argmax(y_, 2))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
#a is a threshold associate with each pixel, b is the label of each pixel
a = np.zeros((1,7168),dtype = float)
b = np.zeros((1,7168, 3), dtype = float)
#this is a little simplified for clarity of reader
#TRAINING
for line in inputFile:
thresh, label = line.strip().split(",")
a[0][it] = thresh
b[0][it][label] = 1
train_step.run(feed_dict={x: a, y_: b, keep_prob: .5})
#TESTING
for line in inputFile:
thresh, label = line.strip().split(",")
a[0][it] = thresh
b[0][it][label] = 1
temp = sess.run(tf.argmax(final_conv,2), feed_dict={x: a})
Ich glaube, dass „temp“ von der letzten Zeile sollte die richtigen Vorhersagen (7168 Etikett - eine pro Pixel) halten. Warum führt "temp" immer zu "0" -Etiketten, wenn es nur auf Bildern mit "1" -Etiketten trainiert wird?
Fügen Sie mindestens einige Ihrer Daten zum Repo hinzu, so dass es reproduziert werden konnte – Maxim
Ich habe einige der Daten zum Repo hinzugefügt. Vielen Dank. –