MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / iou_coe

Function iou_coe

tensorlayer/cost.py:306–339  ·  view source on GitHub ↗

Non-differentiable Intersection over Union (IoU) for comparing the similarity of two batch of data, usually be used for evaluating binary image segmentation. The coefficient between 0 to 1, and 1 means totally match. Parameters ----------- output : tensor A batch of dist

(output, target, threshold=0.5, axis=(1, 2, 3), smooth=1e-5)

Source from the content-addressed store, hash-verified

304
305
306def iou_coe(output, target, threshold=0.5, axis=(1, 2, 3), smooth=1e-5):
307 """Non-differentiable Intersection over Union (IoU) for comparing the
308 similarity of two batch of data, usually be used for evaluating binary image segmentation.
309 The coefficient between 0 to 1, and 1 means totally match.
310
311 Parameters
312 -----------
313 output : tensor
314 A batch of distribution with shape: [batch_size, ....], (any dimensions).
315 target : tensor
316 The target distribution, format the same with `output`.
317 threshold : float
318 The threshold value to be true.
319 axis : tuple of integer
320 All dimensions are reduced, default ``(1,2,3)``.
321 smooth : float
322 This small value will be added to the numerator and denominator, see ``dice_coe``.
323
324 Notes
325 ------
326 - IoU cannot be used as training loss, people usually use dice coefficient for training, IoU and hard-dice for evaluating.
327
328 """
329 pre = tf.cast(output > threshold, dtype=tf.float32)
330 truth = tf.cast(target > threshold, dtype=tf.float32)
331 inse = tf.reduce_sum(tf.multiply(pre, truth), axis=axis) # AND
332 union = tf.reduce_sum(tf.cast(tf.add(pre, truth) >= 1, dtype=tf.float32), axis=axis) # OR
333 # old axis=[0,1,2,3]
334 # epsilon = 1e-5
335 # batch_iou = inse / (union + epsilon)
336 # new haodong
337 batch_iou = (inse + smooth) / (union + smooth)
338 iou = tf.reduce_mean(batch_iou, name='iou_coe')
339 return iou # , pre, truth, inse, union
340
341
342# ## test soft/hard dice and iou

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…