@@ -31,7 +31,8 @@ def cross_entropy(output, target, name=None):
3131 # try: # old
3232 # return tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=output, targets=target))
3333 # except: # TF 1.0
34- assert name is not None , "Please give a unique name to tl.cost.cross_entropy for TF1.0+"
34+ if name is None :
35+ raise Exception ("Please give a unique name to tl.cost.cross_entropy for TF1.0+" )
3536 return tf .reduce_mean (tf .nn .sparse_softmax_cross_entropy_with_logits (labels = target , logits = output , name = name ))
3637
3738
@@ -186,7 +187,7 @@ def absolute_difference_error(output, target, is_mean=False):
186187 return loss
187188
188189
189- def dice_coe (output , target , loss_type = 'jaccard' , axis = [ 1 , 2 , 3 ] , smooth = 1e-5 ):
190+ def dice_coe (output , target , loss_type = 'jaccard' , axis = ( 1 , 2 , 3 ) , smooth = 1e-5 ):
190191 """Soft dice (Sørensen or Jaccard) coefficient for comparing the similarity
191192 of two batch of data, usually be used for binary image segmentation
192193 i.e. labels are binary. The coefficient between 0 to 1, 1 means totally match.
@@ -199,7 +200,7 @@ def dice_coe(output, target, loss_type='jaccard', axis=[1, 2, 3], smooth=1e-5):
199200 The target distribution, format the same with `output`.
200201 loss_type : str
201202 ``jaccard`` or ``sorensen``, default is ``jaccard``.
202- axis : list of int
203+ axis : tuple of int
203204 All dimensions are reduced, default ``[1,2,3]``.
204205 smooth : float
205206 This small value will be added to the numerator and denominator.
@@ -236,7 +237,7 @@ def dice_coe(output, target, loss_type='jaccard', axis=[1, 2, 3], smooth=1e-5):
236237 return dice
237238
238239
239- def dice_hard_coe (output , target , threshold = 0.5 , axis = [ 1 , 2 , 3 ] , smooth = 1e-5 ):
240+ def dice_hard_coe (output , target , threshold = 0.5 , axis = ( 1 , 2 , 3 ) , smooth = 1e-5 ):
240241 """Non-differentiable Sørensen–Dice coefficient for comparing the similarity
241242 of two batch of data, usually be used for binary image segmentation i.e. labels are binary.
242243 The coefficient between 0 to 1, 1 if totally match.
@@ -249,8 +250,8 @@ def dice_hard_coe(output, target, threshold=0.5, axis=[1, 2, 3], smooth=1e-5):
249250 The target distribution, format the same with `output`.
250251 threshold : float
251252 The threshold value to be true.
252- axis : list of integer
253- All dimensions are reduced, default ``[ 1,2,3] ``.
253+ axis : tuple of integer
254+ All dimensions are reduced, default ``( 1,2,3) ``.
254255 smooth : float
255256 This small value will be added to the numerator and denominator, see ``dice_coe``.
256257
@@ -275,7 +276,7 @@ def dice_hard_coe(output, target, threshold=0.5, axis=[1, 2, 3], smooth=1e-5):
275276 return hard_dice
276277
277278
278- def iou_coe (output , target , threshold = 0.5 , axis = [ 1 , 2 , 3 ] , smooth = 1e-5 ):
279+ def iou_coe (output , target , threshold = 0.5 , axis = ( 1 , 2 , 3 ) , smooth = 1e-5 ):
279280 """Non-differentiable Intersection over Union (IoU) for comparing the
280281 similarity of two batch of data, usually be used for evaluating binary image segmentation.
281282 The coefficient between 0 to 1, and 1 means totally match.
@@ -288,8 +289,8 @@ def iou_coe(output, target, threshold=0.5, axis=[1, 2, 3], smooth=1e-5):
288289 The target distribution, format the same with `output`.
289290 threshold : float
290291 The threshold value to be true.
291- axis : list of integer
292- All dimensions are reduced, default ``[ 1,2,3] ``.
292+ axis : tuple of integer
293+ All dimensions are reduced, default ``( 1,2,3) ``.
293294 smooth : float
294295 This small value will be added to the numerator and denominator, see ``dice_coe``.
295296
0 commit comments