So usually in single label classification, we use the following
correct_preds = tf.equal(tf.argmax(preds, 1), tf.argmax(self.label, 1))
But I am working with multi label classification so I'd like to know how to do that where there are several ones in the label vector. So what I have so far is below
a = tf.constant([0.2, 0.4, 0.3, 0.1])
b = tf.constant([0,1.0,1,0])
empty_tensor = tf.zeros([0])
for index in range(b.get_shape()[0]):
empty_tensor = tf.cond(tf.equal(b[index],tf.constant(1, dtype =
tf.float32)), lambda: tf.concat([empty_tensor,tf.constant([index],
dtype = tf.float32)], axis = 0), lambda: empty_tensor)
temp, _ = tf.setdiff1d([tf.argmax(a)], tf.cast(empty_tensor, dtype= tf.int64))
output, _ = tf.setdiff1d([tf.argmax(a)], tf.cast(temp, dtype = tf.int64))
So this gives me the indice at which max(preds) happens and where there is a 1 in self.label. In the above example it gives [1] and if the argmax do not match, then I get [].
The issue that I have is that I do not how to proceed from there as I would like something like the following
correct_preds = tf.equal(tf.argmax(preds, 1), tf.argmax(self.label, 1))
self.accuracy = tf.reduce_sum(tf.cast(correct_preds, tf.float32))
which is straightforward for single label classification.
Thanks a lot