我正在研究多标签问题,并试图确定模型的准确性。
我的型号:
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 ) )
不知何故,属于一张图像的标签的一致性丢失了,我不知道为什么。