Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nms for a motivational example of Record Dot Syntax #630

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

junjihashimoto
Copy link
Member

@junjihashimoto junjihashimoto commented Dec 9, 2021

Is it possible to combine Record Dot Syntax and named tensor?
I make a motivational example for that.
The python code of nms below is concise enough, but I'm wondering if Record Dot Syntax would make it even easier for users to write codes.

# https://github.com/rbgirshick/fast-rcnn/blob/master/lib/utils/nms.py#L8-L37
def nms(dets, thresh):
    x1 = dets[:, 0]
    y1 = dets[:, 1]
    x2 = dets[:, 2]
    y2 = dets[:, 3]
    scores = dets[:, 4]

    areas = (x2 - x1 + 1) * (y2 - y1 + 1)
    order = scores.argsort()[::-1]

    keep = []
    while order.size > 0:
        i = order[0]
        keep.append(i)
        xx1 = np.maximum(x1[i], x1[order[1:]])
        yy1 = np.maximum(y1[i], y1[order[1:]])
        xx2 = np.minimum(x2[i], x2[order[1:]])
        yy2 = np.minimum(y2[i], y2[order[1:]])

        w = np.maximum(0.0, xx2 - xx1 + 1)
        h = np.maximum(0.0, yy2 - yy1 + 1)
        inter = w * h
        ovr = inter / (areas[i] + areas[order[1:]] - inter)

        inds = np.where(ovr <= thresh)[0]
        order = order[inds + 1]

    return keep

@austinvhuang
Copy link
Member

I think any ADT in the NN.hs files would be a motivating example for the overloaded field names aspect at least. Many of them should really be sharing field names (eg "bias") but end up relying on awkward prefix conventions instead.

In spite of the improvement though, I would give the compiler team a long period of bugfixing time before cutting over considering our past issues with bleeding edge GHC versions (particularly with GHC 9+).

@junjihashimoto
Copy link
Member Author

junjihashimoto commented Dec 9, 2021

@austinvhuang
When we apply Record Dot Syntax to NN, we will not be able to support anything less than ghc-9.2.
So will it be used around next year or year after that?
However, using Hasfield like genericNms of this PR will allow us to create more generic functions without using explicit numeric indexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants