[Fix] negative number encountered in sqrt when compute distances from points to a line (#1640)

pull/1646/head
Kevin Wang 2022-12-27 10:29:22 +08:00 committed by GitHub
parent 0ec1524f54
commit d2a6845c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -286,6 +286,8 @@ class DBModuleLoss(SegBasedModuleLoss):
neg_cos_c = (
(c_square - a_square - b_square) /
(np.finfo(np.float32).eps + 2 * np.sqrt(a_square * b_square)))
# clip -cosC value to [-1, 1]
neg_cos_c = np.clip(neg_cos_c, -1.0, 1.0)
# sinC^2=1-cosC^2
square_sin = 1 - np.square(neg_cos_c)
square_sin = np.nan_to_num(square_sin)