remydubois / lsnms

Large Scale Non maximum Suppression. This project implements a O(nlog(n)) approach for non max suppression, useful for object detection ran on very large images such as satellite or histology, when the number of instances to prune becomes very large.
63 stars 5 forks source link

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) #3

Closed fanweiya closed 2 years ago

fanweiya commented 2 years ago

I use lsnms postprocess my boxes, it run fail. my vesion: Requirement already satisfied: lsnms==0.1.2 in f:\anaconda\envs\tf2\lib\site-packages (0.1.2) Requirement already satisfied: numba==0.54.1 in f:\anaconda\envs\tf2\lib\site-packages (from lsnms==0.1.2) (0.54.1) Requirement already satisfied: numpy==1.19.5 in f:\anaconda\envs\tf2\lib\site-packages (from lsnms==0.1.2) (1.19.5) Requirement already satisfied: setuptools in f:\anaconda\envs\tf2\lib\site-packages (from numba==0.54.1->lsnms==0.1.2) (58.1.0) Requirement already satisfied: llvmlite<0.38,>=0.37.0rc1 in f:\anaconda\envs\tf2\lib\site-packages (from numba==0.54.1->lsnms==0.1.2) (0.37.0)

numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x0000011F89894108>.
Failed in nopython mode pipeline (step: native lowering)
Can only insert double* at [4] in {i8*, i8*, i64, i64, double*, [2 x i64], [2 x i64]}: got float*

File "F:\Anaconda\envs\tf2\lib\site-packages\lsnms\kdtree.py", line 56:
    def __init__(self, data, leaf_size=16, axis=0, indices=None):
        <source elided>
        # Stores the data
        self.data = data
        ^

During: lowering "(self).data = data" at F:\Anaconda\envs\tf2\lib\site-packages\lsnms\kdtree.py (56)
During: resolving callee type: jitclass.Node#11f7301c8c8<data:array(float64, 2d, A),bbox:array(float64, 1d, A),axis:int64,dimensionality:int64,indices:OptionalType(array(int64, 1d, A)) i.e. the type 'array(int64, 1d, A) or None',is_leaf:bool,leaf_size:int64,left:OptionalType(DeferredType#1234585073416) i.e. the type 'DeferredType#1234585073416 or None',right:OptionalType(DeferredType#1234585073416) i.e. the type 'DeferredType#1234585073416 or None'>
During: typing of call at F:\Anaconda\envs\tf2\lib\site-packages\lsnms\kdtree.py (260)

Enable logging at debug level for details.

File "F:\Anaconda\envs\tf2\lib\site-packages\lsnms\kdtree.py", line 260:
    def __init__(self, data, leaf_size=16):
        <source elided>
        axis = max_spread_axis(self.data)
        self._root = Node(data, leaf_size, axis, None)
        ^

During: resolving callee type: jitclass.KDTree#11f730239c8<_root:DeferredType#1234585073416,data:array(float64, 2d, A)>
During: typing of call at F:\Anaconda\envs\tf2\lib\site-packages\lsnms\nms.py (68)

During: resolving callee type: jitclass.KDTree#11f730239c8<_root:DeferredType#1234585073416,data:array(float64, 2d, A)>
During: typing of call at F:\Anaconda\envs\tf2\lib\site-packages\lsnms\nms.py (68)

During: resolving callee type: jitclass.KDTree#11f730239c8<_root:DeferredType#1234585073416,data:array(float64, 2d, A)>
During: typing of call at F:\Anaconda\envs\tf2\lib\site-packages\lsnms\nms.py (68)

File "F:\Anaconda\envs\tf2\lib\site-packages\lsnms\nms.py", line 68:
def nms(
    <source elided>
        if tree == "kdtree":
            kdtree = KDTree(boxes[:, :2], 32)
            ^
rdbs-oss commented 2 years ago

Hey, thanks for reporting. Numba is quite itchy with data types: Can only insert double* at [4] in {i8*, i8*, i64, i64, double*, [2 x i64], [2 x i64]}: got float* at the 5th line means that you gave bounding boxes as an array of float32 (I assume), while the tree is typed to support float64.

.astype(np.float64) should do the trick (?) Keep me posted. I will add safe checks to ensure this raises a clearer error, or enlarge data types compatibility.

fanweiya commented 2 years ago

Hey, thanks for reporting. Numba is quite itchy with data types: Can only insert double* at [4] in {i8*, i8*, i64, i64, double*, [2 x i64], [2 x i64]}: got float* at the 5th line means that you gave bounding boxes as an array of float32 (I assume), while the tree is typed to support float64.

.astype(np.float64) should do the trick (?) Keep me posted. I will add safe checks to ensure this raises a clearer error, or enlarge data types compatibility.

thanks,my data is actually float32 datatype, I switched to float64 and never made a mistake again.