【发布时间】:2016-06-10 11:06:38
【问题描述】:
我正在研究一个多标签问题,我正在尝试确定我的模型的准确性。
我的模特:
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 ) )
不知何故,属于一个图像的标签的一致性丢失了,我不知道为什么。
【问题讨论】:
标签: python tensorflow