Unverified Commit 2abd9b1e authored by ChaimZhu's avatar ChaimZhu Committed by GitHub
Browse files

[Enhance] Update numba version (#1043)

* update numba

* update

* fix numba version in doc

* fix typo

* fix_typos
parent 71c79968
...@@ -19,12 +19,6 @@ We list some potential troubles encountered by users and developers, along with ...@@ -19,12 +19,6 @@ We list some potential troubles encountered by users and developers, along with
**NOTE**: We have migrated to use pycocotools in mmdet3d >= 0.13.0. **NOTE**: We have migrated to use pycocotools in mmdet3d >= 0.13.0.
- If you face the error shown below, and your environment contains numba == 0.48.0 with numpy >= 1.20.0:
``TypeError: expected dtype object, got 'numpy.dtype[bool_]'``
please downgrade numpy to < 1.20.0 or install numba == 0.48 from source, because in numpy == 1.20.0, `np.dtype` produces subclass due to API change. Please refer to [here](https://github.com/numba/numba/issues/6041) for more details.
- If you face the error shown below when importing pycocotools: - If you face the error shown below when importing pycocotools:
``ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject`` ``ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject``
...@@ -36,3 +30,4 @@ We list some potential troubles encountered by users and developers, along with ...@@ -36,3 +30,4 @@ We list some potential troubles encountered by users and developers, along with
or or
``pip install -e "git+https://github.com/ppwwyyxx/cocoapi#egg=pycocotools&subdirectory=PythonAPI"`` ``pip install -e "git+https://github.com/ppwwyyxx/cocoapi#egg=pycocotools&subdirectory=PythonAPI"``
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
**注意**: 我们已经在 0.13.0 及之后的版本中全面支持 pycocotools。 **注意**: 我们已经在 0.13.0 及之后的版本中全面支持 pycocotools。
- 如果您遇到下面的问题,并且您的环境包含 numba == 0.48.0 和 numpy >= 1.20.0:
``TypeError: expected dtype object, got 'numpy.dtype[bool_]'``
请将 numpy 的版本降级至 < 1.20.0,或者从源码安装 numba == 0.48,这是由于 numpy == 1.20.0 改变了 API,使得在调用 `np.dtype` 会产生子类。请参考 [这里](https://github.com/numba/numba/issues/6041) 获取更多细节。
- 如果您在导入 pycocotools 相关包时遇到下面的问题: - 如果您在导入 pycocotools 相关包时遇到下面的问题:
``ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject`` ``ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject``
...@@ -36,3 +30,4 @@ ...@@ -36,3 +30,4 @@
或者 或者
``pip install -e "git+https://github.com/ppwwyyxx/cocoapi#egg=pycocotools&subdirectory=PythonAPI"`` ``pip install -e "git+https://github.com/ppwwyyxx/cocoapi#egg=pycocotools&subdirectory=PythonAPI"``
...@@ -705,7 +705,7 @@ def points_in_convex_polygon_3d_jit(points, ...@@ -705,7 +705,7 @@ def points_in_convex_polygon_3d_jit(points,
normal_vec, d, num_surfaces) normal_vec, d, num_surfaces)
@numba.jit @numba.njit
def points_in_convex_polygon_jit(points, polygon, clockwise=False): def points_in_convex_polygon_jit(points, polygon, clockwise=False):
"""Check points is in 2d convex polygons. True when point in polygon. """Check points is in 2d convex polygons. True when point in polygon.
...@@ -723,14 +723,16 @@ def points_in_convex_polygon_jit(points, polygon, clockwise=False): ...@@ -723,14 +723,16 @@ def points_in_convex_polygon_jit(points, polygon, clockwise=False):
num_points_of_polygon = polygon.shape[1] num_points_of_polygon = polygon.shape[1]
num_points = points.shape[0] num_points = points.shape[0]
num_polygons = polygon.shape[0] num_polygons = polygon.shape[0]
# if clockwise: # vec for all the polygons
# vec1 = polygon - polygon[:, [num_points_of_polygon - 1] + if clockwise:
# list(range(num_points_of_polygon - 1)), :] vec1 = polygon - polygon[:,
# else: np.array([num_points_of_polygon - 1] + list(
# vec1 = polygon[:, [num_points_of_polygon - 1] + range(num_points_of_polygon - 1))), :]
# list(range(num_points_of_polygon - 1)), :] - polygon else:
# vec1: [num_polygon, num_points_of_polygon, 2] vec1 = polygon[:,
vec1 = np.zeros((2), dtype=polygon.dtype) np.array([num_points_of_polygon - 1] +
list(range(num_points_of_polygon -
1))), :] - polygon
ret = np.zeros((num_points, num_polygons), dtype=np.bool_) ret = np.zeros((num_points, num_polygons), dtype=np.bool_)
success = True success = True
cross = 0.0 cross = 0.0
...@@ -738,12 +740,9 @@ def points_in_convex_polygon_jit(points, polygon, clockwise=False): ...@@ -738,12 +740,9 @@ def points_in_convex_polygon_jit(points, polygon, clockwise=False):
for j in range(num_polygons): for j in range(num_polygons):
success = True success = True
for k in range(num_points_of_polygon): for k in range(num_points_of_polygon):
if clockwise: vec = vec1[j, k]
vec1 = polygon[j, k] - polygon[j, k - 1] cross = vec[1] * (polygon[j, k, 0] - points[i, 0])
else: cross -= vec[0] * (polygon[j, k, 1] - points[i, 1])
vec1 = polygon[j, k - 1] - polygon[j, k]
cross = vec1[1] * (polygon[j, k, 0] - points[i, 0])
cross -= vec1[0] * (polygon[j, k, 1] - points[i, 1])
if cross >= 0: if cross >= 0:
success = False success = False
break break
......
...@@ -15,13 +15,13 @@ def div_up(m, n): ...@@ -15,13 +15,13 @@ def div_up(m, n):
return m // n + (m % n > 0) return m // n + (m % n > 0)
@cuda.jit('(float32[:], float32[:], float32[:])', device=True, inline=True) @cuda.jit(device=True, inline=True)
def trangle_area(a, b, c): def trangle_area(a, b, c):
return ((a[0] - c[0]) * (b[1] - c[1]) - (a[1] - c[1]) * return ((a[0] - c[0]) * (b[1] - c[1]) - (a[1] - c[1]) *
(b[0] - c[0])) / 2.0 (b[0] - c[0])) / 2.0
@cuda.jit('(float32[:], int32)', device=True, inline=True) @cuda.jit(device=True, inline=True)
def area(int_pts, num_of_inter): def area(int_pts, num_of_inter):
area_val = 0.0 area_val = 0.0
for i in range(num_of_inter - 2): for i in range(num_of_inter - 2):
...@@ -31,7 +31,7 @@ def area(int_pts, num_of_inter): ...@@ -31,7 +31,7 @@ def area(int_pts, num_of_inter):
return area_val return area_val
@cuda.jit('(float32[:], int32)', device=True, inline=True) @cuda.jit(device=True, inline=True)
def sort_vertex_in_convex_polygon(int_pts, num_of_inter): def sort_vertex_in_convex_polygon(int_pts, num_of_inter):
if num_of_inter > 0: if num_of_inter > 0:
center = cuda.local.array((2, ), dtype=numba.float32) center = cuda.local.array((2, ), dtype=numba.float32)
...@@ -71,10 +71,7 @@ def sort_vertex_in_convex_polygon(int_pts, num_of_inter): ...@@ -71,10 +71,7 @@ def sort_vertex_in_convex_polygon(int_pts, num_of_inter):
int_pts[j * 2 + 1] = ty int_pts[j * 2 + 1] = ty
@cuda.jit( @cuda.jit(device=True, inline=True)
'(float32[:], float32[:], int32, int32, float32[:])',
device=True,
inline=True)
def line_segment_intersection(pts1, pts2, i, j, temp_pts): def line_segment_intersection(pts1, pts2, i, j, temp_pts):
A = cuda.local.array((2, ), dtype=numba.float32) A = cuda.local.array((2, ), dtype=numba.float32)
B = cuda.local.array((2, ), dtype=numba.float32) B = cuda.local.array((2, ), dtype=numba.float32)
...@@ -117,10 +114,7 @@ def line_segment_intersection(pts1, pts2, i, j, temp_pts): ...@@ -117,10 +114,7 @@ def line_segment_intersection(pts1, pts2, i, j, temp_pts):
return False return False
@cuda.jit( @cuda.jit(device=True, inline=True)
'(float32[:], float32[:], int32, int32, float32[:])',
device=True,
inline=True)
def line_segment_intersection_v1(pts1, pts2, i, j, temp_pts): def line_segment_intersection_v1(pts1, pts2, i, j, temp_pts):
a = cuda.local.array((2, ), dtype=numba.float32) a = cuda.local.array((2, ), dtype=numba.float32)
b = cuda.local.array((2, ), dtype=numba.float32) b = cuda.local.array((2, ), dtype=numba.float32)
...@@ -159,7 +153,7 @@ def line_segment_intersection_v1(pts1, pts2, i, j, temp_pts): ...@@ -159,7 +153,7 @@ def line_segment_intersection_v1(pts1, pts2, i, j, temp_pts):
return True return True
@cuda.jit('(float32, float32, float32[:])', device=True, inline=True) @cuda.jit(device=True, inline=True)
def point_in_quadrilateral(pt_x, pt_y, corners): def point_in_quadrilateral(pt_x, pt_y, corners):
ab0 = corners[2] - corners[0] ab0 = corners[2] - corners[0]
ab1 = corners[3] - corners[1] ab1 = corners[3] - corners[1]
...@@ -178,7 +172,7 @@ def point_in_quadrilateral(pt_x, pt_y, corners): ...@@ -178,7 +172,7 @@ def point_in_quadrilateral(pt_x, pt_y, corners):
return abab >= abap and abap >= 0 and adad >= adap and adap >= 0 return abab >= abap and abap >= 0 and adad >= adap and adap >= 0
@cuda.jit('(float32[:], float32[:], float32[:])', device=True, inline=True) @cuda.jit(device=True, inline=True)
def quadrilateral_intersection(pts1, pts2, int_pts): def quadrilateral_intersection(pts1, pts2, int_pts):
num_of_inter = 0 num_of_inter = 0
for i in range(4): for i in range(4):
...@@ -202,7 +196,7 @@ def quadrilateral_intersection(pts1, pts2, int_pts): ...@@ -202,7 +196,7 @@ def quadrilateral_intersection(pts1, pts2, int_pts):
return num_of_inter return num_of_inter
@cuda.jit('(float32[:], float32[:])', device=True, inline=True) @cuda.jit(device=True, inline=True)
def rbbox_to_corners(corners, rbbox): def rbbox_to_corners(corners, rbbox):
# generate clockwise corners and rotate it clockwise # generate clockwise corners and rotate it clockwise
angle = rbbox[4] angle = rbbox[4]
...@@ -228,7 +222,7 @@ def rbbox_to_corners(corners, rbbox): ...@@ -228,7 +222,7 @@ def rbbox_to_corners(corners, rbbox):
1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y 1] = -a_sin * corners_x[i] + a_cos * corners_y[i] + center_y
@cuda.jit('(float32[:], float32[:])', device=True, inline=True) @cuda.jit(device=True, inline=True)
def inter(rbbox1, rbbox2): def inter(rbbox1, rbbox2):
"""Compute intersection of two rotated boxes. """Compute intersection of two rotated boxes.
...@@ -254,7 +248,7 @@ def inter(rbbox1, rbbox2): ...@@ -254,7 +248,7 @@ def inter(rbbox1, rbbox2):
return area(intersection_corners, num_intersection) return area(intersection_corners, num_intersection)
@cuda.jit('(float32[:], float32[:], int32)', device=True, inline=True) @cuda.jit(device=True, inline=True)
def devRotateIoUEval(rbox1, rbox2, criterion=-1): def devRotateIoUEval(rbox1, rbox2, criterion=-1):
"""Compute rotated iou on device. """Compute rotated iou on device.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import numba import numba
import numpy as np import numpy as np
import warnings import warnings
from numba.errors import NumbaPerformanceWarning from numba.core.errors import NumbaPerformanceWarning
from mmdet3d.core.bbox import box_np_ops from mmdet3d.core.bbox import box_np_ops
......
lyft_dataset_sdk lyft_dataset_sdk
networkx>=2.2,<2.3 networkx>=2.2,<2.3
# we may unlock the version of numba in the future numba>0.52.1
numba==0.48.0 numpy
numpy<1.20.0
nuscenes-devkit nuscenes-devkit
plyfile plyfile
scikit-image scikit-image
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment