我正在研究一个多标签问题,我正试图确定我的模型的准确性。
我的模型:
NUM_CLASSES = 361
x = tf.placeholder(tf.float32, [None, IMAGE_PIXELS])
y_ = tf.placeholder(tf.float32, [None, NUM_CLASSES])
# create the network
pred = conv_net( x )
# loss
cost = tf.reduce_mean( tf.nn.sigmoid_cross_entropy_with_logits( pred, y_) )
# train step
train_step = tf.train.AdamOptimizer().minimize( cost )
我想用两种不同的方法计算精度
-所有正确预测的标签的百分比
-所有标签预测正确的图像百分比
不幸的是,我只能计算所有正确预测的标签的百分比。
我想这段代码可以计算出所有标签都被正确预测的图像的百分比
correct_prediction = tf.equal( tf.round( pred ), tf.round( y_ ) )
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
这个代码占所有正确预测的标签的百分比
pred_reshape = tf.reshape( pred, [ BATCH_SIZE * NUM_CLASSES, 1 ] )
y_reshape = tf.reshape( y_, [ BATCH_SIZE * NUM_CLASSES, 1 ] )
correct_prediction_all = tf.equal( tf.round( pred_reshape ), tf.round( y_reshape ) )
accuracy_all = tf.reduce_mean( tf.cast(correct_prediction_all, tf.float32 ) )
不知何故,属于一个图像的标签失去了连贯性,我不知道为什么。
我相信你代码中的错误在:
correct_prediction = tf.equal( tf.round( pred ), tf.round( y_ ) )
。pred
应为未标度登录(即没有最终乙状结肠)。在这里,您需要比较
sigmoid(pred)
和y_
的输出(两者都在间隔[0, 1]
)以便您必须编写:然后计算:
引用:https://gist.github.com/sbrodehl/2120a95d57963a289cc23bcfb24bee1b
相关问题 更多 >
编程相关推荐