From 19e71b6850418f912eaedb8851fbaf8845bd5996 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 13:19:37 +0800 Subject: [PATCH 1/7] add local yaw property --- mmdet3d/core/bbox/structures/base_box3d.py | 9 ++++++++- mmdet3d/core/bbox/structures/cam_box3d.py | 11 ++++++++++- mmdet3d/core/bbox/structures/utils.py | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/mmdet3d/core/bbox/structures/base_box3d.py b/mmdet3d/core/bbox/structures/base_box3d.py index ec182216b5..9a2a6b714c 100644 --- a/mmdet3d/core/bbox/structures/base_box3d.py +++ b/mmdet3d/core/bbox/structures/base_box3d.py @@ -79,9 +79,16 @@ def dims(self): @property def yaw(self): - """torch.Tensor: A vector with yaw of each box in shape (N, ).""" + """torch.Tensor: A vector with global yaw of each box + in shape (N, ).""" return self.tensor[:, 6] + @property + def local_yaw(self): + """torch.Tensor: A vector with local yaw of each box + in shape (N, ).""" + pass + @property def height(self): """torch.Tensor: A vector with height of each box in shape (N, ).""" diff --git a/mmdet3d/core/bbox/structures/cam_box3d.py b/mmdet3d/core/bbox/structures/cam_box3d.py index ac5cf8286c..a03cf4c40d 100644 --- a/mmdet3d/core/bbox/structures/cam_box3d.py +++ b/mmdet3d/core/bbox/structures/cam_box3d.py @@ -4,7 +4,7 @@ from ...points import BasePoints from .base_box3d import BaseInstance3DBoxes -from .utils import rotation_3d_in_axis +from .utils import rotation_3d_in_axis, yaw2local class CameraInstance3DBoxes(BaseInstance3DBoxes): @@ -90,6 +90,15 @@ def bottom_height(self): A vector with bottom's height of each box in shape (N, ).""" return self.tensor[:, 1] + @property + def local_yaw(self): + """torch.Tensor: A vector with local yaw of each box in shape (N, ).""" + yaw = self.yaw + loc = self.gravity_center + local_yaw = yaw2local(yaw, loc) + + return local_yaw + @property def gravity_center(self): """torch.Tensor: A tensor with center of each box in shape (N, 3).""" diff --git a/mmdet3d/core/bbox/structures/utils.py b/mmdet3d/core/bbox/structures/utils.py index 4c6b048771..e300a86d31 100644 --- a/mmdet3d/core/bbox/structures/utils.py +++ b/mmdet3d/core/bbox/structures/utils.py @@ -308,3 +308,25 @@ def get_proj_mat_by_coord_type(img_meta, coord_type): mapping = {'LIDAR': 'lidar2img', 'DEPTH': 'depth2img', 'CAMERA': 'cam2img'} assert coord_type in mapping.keys() return img_meta[mapping[coord_type]] + + +def yaw2local(yaw, loc): + """Transform global yaw to local yaw in camera coordinates, ranging. + + [-pi..pi]. + + Args: + yaw (torch.Tensor): A vector with local yaw of each box. + shape: (N, ) + loc (torch.Tensor): gravity center of each box. + shape: (N, 3) + + Returns: + torch.Tensor: local yaw. + """ + local_yaw = yaw - torch.atan2(loc[:, 0], loc[:, 2]) + while local_yaw > np.pi: + local_yaw -= np.pi * 2 + while local_yaw < -np.pi: + local_yaw += np.pi * 2 + return local_yaw From ec3151f7ac21b5bf03b5f90285c99ada196432fe Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 13:23:21 +0800 Subject: [PATCH 2/7] fix typos --- mmdet3d/core/bbox/structures/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mmdet3d/core/bbox/structures/utils.py b/mmdet3d/core/bbox/structures/utils.py index e300a86d31..111556e1bc 100644 --- a/mmdet3d/core/bbox/structures/utils.py +++ b/mmdet3d/core/bbox/structures/utils.py @@ -311,9 +311,8 @@ def get_proj_mat_by_coord_type(img_meta, coord_type): def yaw2local(yaw, loc): - """Transform global yaw to local yaw in camera coordinates, ranging. - - [-pi..pi]. + """Transform global yaw to local yaw in camera coordinates, ranges from -pi + to pi. Args: yaw (torch.Tensor): A vector with local yaw of each box. From f923341f4f26ba823eede1964b1a50e68e645933 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 14:07:35 +0800 Subject: [PATCH 3/7] delete local yaw in base --- mmdet3d/core/bbox/structures/base_box3d.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/mmdet3d/core/bbox/structures/base_box3d.py b/mmdet3d/core/bbox/structures/base_box3d.py index 9a2a6b714c..ec182216b5 100644 --- a/mmdet3d/core/bbox/structures/base_box3d.py +++ b/mmdet3d/core/bbox/structures/base_box3d.py @@ -79,16 +79,9 @@ def dims(self): @property def yaw(self): - """torch.Tensor: A vector with global yaw of each box - in shape (N, ).""" + """torch.Tensor: A vector with yaw of each box in shape (N, ).""" return self.tensor[:, 6] - @property - def local_yaw(self): - """torch.Tensor: A vector with local yaw of each box - in shape (N, ).""" - pass - @property def height(self): """torch.Tensor: A vector with height of each box in shape (N, ).""" From 4d14e3e5eebcddb85fe959af2c76bcebcc11afde Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 15:11:32 +0800 Subject: [PATCH 4/7] change local yaw to alpha --- mmdet3d/core/bbox/structures/cam_box3d.py | 8 ++++---- mmdet3d/core/bbox/structures/utils.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mmdet3d/core/bbox/structures/cam_box3d.py b/mmdet3d/core/bbox/structures/cam_box3d.py index a03cf4c40d..54fb58b970 100644 --- a/mmdet3d/core/bbox/structures/cam_box3d.py +++ b/mmdet3d/core/bbox/structures/cam_box3d.py @@ -4,7 +4,7 @@ from ...points import BasePoints from .base_box3d import BaseInstance3DBoxes -from .utils import rotation_3d_in_axis, yaw2local +from .utils import rotation_3d_in_axis, yaw2alpha class CameraInstance3DBoxes(BaseInstance3DBoxes): @@ -91,13 +91,13 @@ def bottom_height(self): return self.tensor[:, 1] @property - def local_yaw(self): + def alpha(self): """torch.Tensor: A vector with local yaw of each box in shape (N, ).""" yaw = self.yaw loc = self.gravity_center - local_yaw = yaw2local(yaw, loc) + alpha = yaw2alpha(yaw, loc) - return local_yaw + return alpha @property def gravity_center(self): diff --git a/mmdet3d/core/bbox/structures/utils.py b/mmdet3d/core/bbox/structures/utils.py index 111556e1bc..b80a22a306 100644 --- a/mmdet3d/core/bbox/structures/utils.py +++ b/mmdet3d/core/bbox/structures/utils.py @@ -310,9 +310,9 @@ def get_proj_mat_by_coord_type(img_meta, coord_type): return img_meta[mapping[coord_type]] -def yaw2local(yaw, loc): - """Transform global yaw to local yaw in camera coordinates, ranges from -pi - to pi. +def yaw2alpha(yaw, loc): + """Transform global yaw to local yaw (alpha) in camera coordinates, ranges + from -pi to pi. Args: yaw (torch.Tensor): A vector with local yaw of each box. @@ -321,11 +321,11 @@ def yaw2local(yaw, loc): shape: (N, 3) Returns: - torch.Tensor: local yaw. + torch.Tensor: local yaw (alpha). """ - local_yaw = yaw - torch.atan2(loc[:, 0], loc[:, 2]) - while local_yaw > np.pi: - local_yaw -= np.pi * 2 - while local_yaw < -np.pi: - local_yaw += np.pi * 2 - return local_yaw + alpha = yaw - torch.atan2(loc[:, 0], loc[:, 2]) + while alpha > np.pi: + alpha -= np.pi * 2 + while alpha < -np.pi: + alpha += np.pi * 2 + return alpha From 50532f642a261916e9f53aab44c2b56c439f2fc1 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 15:27:42 +0800 Subject: [PATCH 5/7] change local yaw to alpha --- mmdet3d/core/bbox/structures/cam_box3d.py | 12 +++++++----- mmdet3d/core/bbox/structures/utils.py | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mmdet3d/core/bbox/structures/cam_box3d.py b/mmdet3d/core/bbox/structures/cam_box3d.py index 54fb58b970..f94b65aeac 100644 --- a/mmdet3d/core/bbox/structures/cam_box3d.py +++ b/mmdet3d/core/bbox/structures/cam_box3d.py @@ -4,7 +4,7 @@ from ...points import BasePoints from .base_box3d import BaseInstance3DBoxes -from .utils import rotation_3d_in_axis, yaw2alpha +from .utils import rotation_3d_in_axis, yaw2local class CameraInstance3DBoxes(BaseInstance3DBoxes): @@ -91,13 +91,15 @@ def bottom_height(self): return self.tensor[:, 1] @property - def alpha(self): - """torch.Tensor: A vector with local yaw of each box in shape (N, ).""" + def local_yaw(self): + """torch.Tensor: A vector with local yaw of each box in shape (N, ). + local_yaw equals to alpha in kitti. + """ yaw = self.yaw loc = self.gravity_center - alpha = yaw2alpha(yaw, loc) + local_yaw = yaw2local(yaw, loc) - return alpha + return local_yaw @property def gravity_center(self): diff --git a/mmdet3d/core/bbox/structures/utils.py b/mmdet3d/core/bbox/structures/utils.py index b80a22a306..e41fe9f134 100644 --- a/mmdet3d/core/bbox/structures/utils.py +++ b/mmdet3d/core/bbox/structures/utils.py @@ -310,9 +310,9 @@ def get_proj_mat_by_coord_type(img_meta, coord_type): return img_meta[mapping[coord_type]] -def yaw2alpha(yaw, loc): - """Transform global yaw to local yaw (alpha) in camera coordinates, ranges - from -pi to pi. +def yaw2local(yaw, loc): + """Transform global yaw to local yaw (alpha in kitti) in camera + coordinates, ranges from -pi to pi. Args: yaw (torch.Tensor): A vector with local yaw of each box. @@ -321,11 +321,11 @@ def yaw2alpha(yaw, loc): shape: (N, 3) Returns: - torch.Tensor: local yaw (alpha). + torch.Tensor: local yaw (alpha in kitti). """ - alpha = yaw - torch.atan2(loc[:, 0], loc[:, 2]) - while alpha > np.pi: - alpha -= np.pi * 2 - while alpha < -np.pi: - alpha += np.pi * 2 - return alpha + local_yaw = yaw - torch.atan2(loc[:, 0], loc[:, 2]) + while local_yaw > np.pi: + local_yaw -= np.pi * 2 + while local_yaw < -np.pi: + local_yaw += np.pi * 2 + return local_yaw From 4f217f3484de60c3108c22b79dbc06fed9a044b1 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 20:08:49 +0800 Subject: [PATCH 6/7] update docstring --- mmdet3d/core/bbox/structures/cam_box3d.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mmdet3d/core/bbox/structures/cam_box3d.py b/mmdet3d/core/bbox/structures/cam_box3d.py index f94b65aeac..6026919ee8 100644 --- a/mmdet3d/core/bbox/structures/cam_box3d.py +++ b/mmdet3d/core/bbox/structures/cam_box3d.py @@ -93,7 +93,9 @@ def bottom_height(self): @property def local_yaw(self): """torch.Tensor: A vector with local yaw of each box in shape (N, ). - local_yaw equals to alpha in kitti. + local_yaw equals to alpha in kitti, which is commonly used in + monocular 3D object detection task, so only CameraInstance3DBoxes + has the property. """ yaw = self.yaw loc = self.gravity_center From 6f4e4a7747c623b41e2adeaff26a28490fb83143 Mon Sep 17 00:00:00 2001 From: ChaimZhu Date: Wed, 22 Dec 2021 20:18:57 +0800 Subject: [PATCH 7/7] update docstring again --- mmdet3d/core/bbox/structures/cam_box3d.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mmdet3d/core/bbox/structures/cam_box3d.py b/mmdet3d/core/bbox/structures/cam_box3d.py index 6026919ee8..b708613441 100644 --- a/mmdet3d/core/bbox/structures/cam_box3d.py +++ b/mmdet3d/core/bbox/structures/cam_box3d.py @@ -92,10 +92,11 @@ def bottom_height(self): @property def local_yaw(self): - """torch.Tensor: A vector with local yaw of each box in shape (N, ). - local_yaw equals to alpha in kitti, which is commonly used in - monocular 3D object detection task, so only CameraInstance3DBoxes - has the property. + """torch.Tensor: + A vector with local yaw of each box in shape (N, ). + local_yaw equals to alpha in kitti, which is commonly + used in monocular 3D object detection task, so only + :obj:`CameraInstance3DBoxes` has the property. """ yaw = self.yaw loc = self.gravity_center