我有一个深度 CNN,可以预测 3d 图像中每个像素的“0”和“2”之间的标签。我已经在每个像素都标记为“1”的图像上训练了模型。因此,在测试模型时,我相信每个预测都应该是“1”。相反,模型仅预测“0”。
这是整个模型的存储库:https://github.com/dhasl002/Research-DeepLearning https://github.com/dhasl002/Research-DeepLearning.
由于代码将近 300 行,我将只包含下面的相关代码。
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})
我相信最后一行的“temp”应该包含正确的预测(7168 个标签 - 每个像素一个)。当“temp”实际上只在带有“1”标签的图像上进行训练时,为什么“temp”总是导致所有“0”标签?