0

I'm a starter on Halide, I'm trying to use it to accelerate maskrcnn.

By now, the performance is really excellent comparing to c version. Then, I've run into a problem which has bothered me for several days: Non maximum suppression(nms), it is a classic algorithm but I have not found any similar example for this in halide, the summary is:

Sort an array box first, then for every i in box, from i+1 to the end of this array, compute the overlap with box[i], then either keep it or delete it according to overlap. Is it possible to realize it in halide? Do I have to use an define::extern? Appeciate a lot if anyone could reply.


update:

Sorry that I didn't explain this problem very well. The Non maximum suppression in MaskRcnn is a little different from the one in Canny Edge Detector, You can refer to this:

https://www.pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/

where the python code is the realization of this kind of algorithm.

If it's too long, think about this simple question:

For an array a[10]= {1, 2, 3, 4, 5 ,6 , 7 , 8, 9, 10}, we need to compute the product between a[i] and a[j](i+1<=j < 10), if this product value is smaller than 6(for example), then we delete the a[j], iterates this operation for all i in range [0, 9]. Thank you.

Francois
  • 21
  • 2

1 Answers1

0

WRT non-maximum suppression: A quick look in Wikipedia and this presentation (http://www.inf.u-szeged.hu/ssip/2003/lectures/chetverikov/edge_detection.pdf) gives me some idea of what the algorithm does. I've no idea how to determine the edge direction, but I thing this might help:

Assuming a simple filter (x +/- 1, y +/- 1), Halide can find the maximum of the set of values using an RDom. Call that result MAX. Create a filter of coefficients using MAX - a filter of ones and zeros. Multiply the coefficients by the original matrix, and you should have non-minimum suppression.

The filter of coefficients can be created by using max((signed)(pixel - (MAX - 1)), 0), where the pixel values are unsigned. Essentially, subtract MAX-1 from the original values using unsigned subtract-and-saturate. The results of the filter is an array of ones and zeros.

As you can see, it's not particularly difficult to create this sort of algorithm in Halide; it's actually more difficult to sort out the meaning of terms like "overlap". Hopefully, this will give you some idea how to proceed.

Best of luck, -Phil

  • Thanks for your kindly reply, the kind of method you propose is really nice for Canny Edge Detector Algorithm, however, it's a little different from what I want to do. I have updated more details for this nms algorithm in Object Detection, the way to realize it in Halide has bothered me and our group for a long time. Thanks if you have more excellent ideas. – Francois Nov 01 '17 at 02:35