Code Monkey home page Code Monkey logo

Comments (6)

buaacarzp avatar buaacarzp commented on September 26, 2024 6

hello,everybody, I have solved this problem. It just caused by the version of pytorch. most of all use the pytorch>=0.4,but this version of torch is 0.3 or lower.
here is the solution of nms:

def nms(bboxes,scores,threshold=0.5):
    '''
    bboxes(tensor) [N,4]
    scores(tensor) [N,]
    '''
    x1 = bboxes[:,0]
    y1 = bboxes[:,1]
    x2 = bboxes[:,2]
    y2 = bboxes[:,3]
    areas = (x2-x1) * (y2-y1)

    _,order = scores.sort(0,descending=True)
    # print("order1:",order)
    keep = []
    while order.numel() > 0:
        if order.numel()>1:
            i = order.tolist()[0]   
            keep.append(i)
        else:
            keep.append(order.item())
            break

        xx1 = x1[order[1:]].clamp(min=x1[i])
        yy1 = y1[order[1:]].clamp(min=y1[i])
        xx2 = x2[order[1:]].clamp(max=x2[i])
        yy2 = y2[order[1:]].clamp(max=y2[i])

        w = (xx2-xx1).clamp(min=0)
        h = (yy2-yy1).clamp(min=0)
        inter = w*h

        ovr = inter / (areas[i] + areas[order[1:]] - inter)
        ids = (ovr<=threshold).nonzero().squeeze()
        if ids.numel() == 0:
            break
        order = order[ids+1] 
    return torch.LongTensor(keep)

```_

from pytorch-yolo-v1.

vcvishal avatar vcvishal commented on September 26, 2024

I used
i = order.item()

but it doesn't work

from pytorch-yolo-v1.

yahsiuhsieh avatar yahsiuhsieh commented on September 26, 2024

Move this line of code if order.numel() == 1: break in front of i = order.item().

from pytorch-yolo-v1.

leiqing110 avatar leiqing110 commented on September 26, 2024

Move this line of code if order.numel() == 1: break in front of i = order.item().

i do this according to your reply ,but it does not work. would you tell me more info about it ?

from pytorch-yolo-v1.

leiqing110 avatar leiqing110 commented on September 26, 2024

你好 请问你这个问题解决了吗 我也同样的问题

from pytorch-yolo-v1.

doduythao avatar doduythao commented on September 26, 2024

order sometimes is list, sometime only 1 element. (it's order!), so when only 1 element --> use .item(), when it's a list. use .list()[0]

from pytorch-yolo-v1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.