From 6d7594ba55c97df9fa69b061d6c5b13931cdae1f Mon Sep 17 00:00:00 2001 From: RWL Date: Thu, 21 Oct 2021 09:11:08 -0500 Subject: [PATCH] NaN (divide by zero) fix for issue #561 and #790 https://github.com/facebookresearch/pytorch3d/issues/561 --- pytorch3d/csrc/utils/geometry_utils.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch3d/csrc/utils/geometry_utils.cuh b/pytorch3d/csrc/utils/geometry_utils.cuh index 53ff4f5a0..9e2979aca 100644 --- a/pytorch3d/csrc/utils/geometry_utils.cuh +++ b/pytorch3d/csrc/utils/geometry_utils.cuh @@ -177,7 +177,7 @@ __device__ inline float3 BarycentricPerspectiveCorrectionForward( const float w0_top = bary.x * z1 * z2; const float w1_top = z0 * bary.y * z2; const float w2_top = z0 * z1 * bary.z; - const float denom = w0_top + w1_top + w2_top; + const float denom = fmaxf(w0_top + w1_top + w2_top, kEpsilon); const float w0 = w0_top / denom; const float w1 = w1_top / denom; const float w2 = w2_top / denom; @@ -208,7 +208,7 @@ BarycentricPerspectiveCorrectionBackward( const float w0_top = bary.x * z1 * z2; const float w1_top = z0 * bary.y * z2; const float w2_top = z0 * z1 * bary.z; - const float denom = w0_top + w1_top + w2_top; + const float denom = fmaxf(w0_top + w1_top + w2_top, kEpsilon); // Now do backward pass const float grad_denom_top =