From 05bf280c43922ba2b401dd78bcd28c65b5aaa5f5 Mon Sep 17 00:00:00 2001 From: Li Bin Date: Fri, 26 May 2023 10:28:45 +0800 Subject: [PATCH 1/4] Fix bug: AttributeError: 'LineString' object has no attribute 'exterior' --- mmdet3d/datasets/convert_utils.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mmdet3d/datasets/convert_utils.py b/mmdet3d/datasets/convert_utils.py index fcc70723e..a253ccd80 100644 --- a/mmdet3d/datasets/convert_utils.py +++ b/mmdet3d/datasets/convert_utils.py @@ -7,6 +7,7 @@ from nuscenes.utils.geometry_utils import view_points from pyquaternion import Quaternion from shapely.geometry import MultiPoint, box +from shapely.geometry.polygon import Polygon from mmdet3d.structures import Box3DMode, CameraInstance3DBoxes, points_cam2img from mmdet3d.structures.ops import box_np_ops @@ -358,18 +359,20 @@ def post_process_coords( if polygon_from_2d_box.intersects(img_canvas): img_intersection = polygon_from_2d_box.intersection(img_canvas) - intersection_coords = np.array( + if isinstance(img_intersection, Polygon): + intersection_coords = np.array( [coord for coord in img_intersection.exterior.coords]) - - min_x = min(intersection_coords[:, 0]) - min_y = min(intersection_coords[:, 1]) - max_x = max(intersection_coords[:, 0]) - max_y = max(intersection_coords[:, 1]) - - return min_x, min_y, max_x, max_y - else: + min_x = min(intersection_coords[:, 0]) + min_y = min(intersection_coords[:, 1]) + max_x = max(intersection_coords[:, 0]) + max_y = max(intersection_coords[:, 1]) + return min_x, min_y, max_x, max_y + else: + warnings.warn('img_intersection is not an object of Polygon.') + return None + else: return None - + def generate_record(ann_rec: dict, x1: float, y1: float, x2: float, y2: float, dataset: str) -> Union[dict, None]: From 205656335f765e9f6d0e6e72cc0e5f794dd61899 Mon Sep 17 00:00:00 2001 From: Li Bin Date: Fri, 26 May 2023 10:36:20 +0800 Subject: [PATCH 2/4] fixed linter --- mmdet3d/datasets/convert_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mmdet3d/datasets/convert_utils.py b/mmdet3d/datasets/convert_utils.py index a253ccd80..1d2dda777 100644 --- a/mmdet3d/datasets/convert_utils.py +++ b/mmdet3d/datasets/convert_utils.py @@ -370,9 +370,9 @@ def post_process_coords( else: warnings.warn('img_intersection is not an object of Polygon.') return None - else: - return None - + else: + return None + def generate_record(ann_rec: dict, x1: float, y1: float, x2: float, y2: float, dataset: str) -> Union[dict, None]: From b00ab5c658c1b06c8d9aacab34a750ea134c0ba0 Mon Sep 17 00:00:00 2001 From: Li Bin Date: Fri, 26 May 2023 10:43:38 +0800 Subject: [PATCH 3/4] fixed linter --- mmdet3d/datasets/convert_utils.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mmdet3d/datasets/convert_utils.py b/mmdet3d/datasets/convert_utils.py index 1d2dda777..2f765fc64 100644 --- a/mmdet3d/datasets/convert_utils.py +++ b/mmdet3d/datasets/convert_utils.py @@ -1,6 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. import copy from typing import List, Optional, Tuple, Union +import warnings import numpy as np from nuscenes import NuScenes @@ -360,18 +361,18 @@ def post_process_coords( if polygon_from_2d_box.intersects(img_canvas): img_intersection = polygon_from_2d_box.intersection(img_canvas) if isinstance(img_intersection, Polygon): - intersection_coords = np.array( - [coord for coord in img_intersection.exterior.coords]) - min_x = min(intersection_coords[:, 0]) - min_y = min(intersection_coords[:, 1]) - max_x = max(intersection_coords[:, 0]) - max_y = max(intersection_coords[:, 1]) - return min_x, min_y, max_x, max_y + intersection_coords = np.array( + [coord for coord in img_intersection.exterior.coords]) + min_x = min(intersection_coords[:, 0]) + min_y = min(intersection_coords[:, 1]) + max_x = max(intersection_coords[:, 0]) + max_y = max(intersection_coords[:, 1]) + return min_x, min_y, max_x, max_y else: - warnings.warn('img_intersection is not an object of Polygon.') - return None + warnings.warn('img_intersection is not an object of Polygon.') + return None else: - return None + return None def generate_record(ann_rec: dict, x1: float, y1: float, x2: float, y2: float, From e666e01f10b348ee3b2feca22d76f92834fea5ad Mon Sep 17 00:00:00 2001 From: Li Bin Date: Fri, 26 May 2023 10:49:41 +0800 Subject: [PATCH 4/4] fix linter issue wit isort --- mmdet3d/datasets/convert_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmdet3d/datasets/convert_utils.py b/mmdet3d/datasets/convert_utils.py index 2f765fc64..cb4d97e13 100644 --- a/mmdet3d/datasets/convert_utils.py +++ b/mmdet3d/datasets/convert_utils.py @@ -1,7 +1,7 @@ # Copyright (c) OpenMMLab. All rights reserved. import copy -from typing import List, Optional, Tuple, Union import warnings +from typing import List, Optional, Tuple, Union import numpy as np from nuscenes import NuScenes