【发布时间】:2018-05-18 05:30:36
【问题描述】:
我有一个深度 CNN,它可以为 3d 图像中的每个像素预测一个介于“0”和“2”之间的标签。我已经在每个像素都标记为“1”的图像上训练了模型。因此,在测试模型时,我相信每个预测都应该是“1”。相反,该模型仅预测“0”。
这里是整个模型的存储库: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”标签的图像上训练时总是导致所有“0”标签?
【问题讨论】:
-
将至少部分数据添加到 repo,以便复制
-
我已将一些数据添加到 repo 中。谢谢。
标签: python tensorflow neural-network deep-learning conv-neural-network