0

I have used that the dice coefficient is calculated by 2xintersection/union in semantic segmentation neural networks. And the intersection of y_true and y_pred is found by tf.math.reduce_sum(y_pred*y_true). Please someone can help me figure out, how the multiplication of two tensors are equal to the intersection?

Tuan Azzam
  • 15
  • 7

1 Answers1

0

It's a special case of multiplication that becomes intersection.

Consider,

y_true = [
[0,1,0],
[1,1,0],
[1,0,1]
]

and

y_pred = [
[0,1,1],
[1,0,0],
[1,0,1]
]

then y_true * y_pred will be,

res = [
[0,1,0],
[1,0,0],
[1,0,1]

Next tf.reduce_sum() gives the sum of all the ones in res (which is intersection). In other words res will have an element set to 1, only if both y_true and y_pred has 1 for that position.

intersection = 4
thushv89
  • 10,865
  • 1
  • 26
  • 39
  • got it, but I have a doubt. In most cases there are no actual zeros in above vectors. Thay might be little floats. It means that those parts are also going to add into account? But I bet they do not have much of an impact because they are relatively small.. Thanks for the clarification and that is a great help.... – Tuan Azzam Nov 03 '20 at 08:12
  • @TuanAzzam, if they have small values instead of actual zeros, the values will be included in the interection. But the impact will be small as you said, because small value multiplied by small value is even smaller. – thushv89 Nov 03 '20 at 10:12