S3FD.pytorch icon indicating copy to clipboard operation
S3FD.pytorch copied to clipboard

a bug in nms

Open njustymk opened this issue 5 years ago • 2 comments

def nms(boxes, scores, overlap=0.5, top_k=200): keep = scores.new(scores.size(0)).zero_().long() if boxes.numel() == 0: return keep x1 = boxes[:, 0] y1 = boxes[:, 1] x2 = boxes[:, 2] y2 = boxes[:, 3] area = torch.mul(x2 - x1, y2 - y1) v, idx = scores.sort(0) # sort in ascending order # I = I[v >= 0.01] idx = idx[-top_k:] # indices of the top-k largest vals xx1 = boxes.new() yy1 = boxes.new() xx2 = boxes.new() yy2 = boxes.new() w = boxes.new() h = boxes.new()

# keep = torch.Tensor()
count = 0
while idx.numel() > 0:
    i = idx[-1]  # index of current largest val
    # keep.append(i)
    keep[count] = i
    count += 1
    if idx.size(0) == 1:
        break
    idx = idx[:-1]  # remove kept element from view
    # load bboxes of next highest vals
    torch.index_select(x1, 0, idx, out=xx1)
    torch.index_select(y1, 0, idx, out=yy1)
    torch.index_select(x2, 0, idx, out=xx2)
    torch.index_select(y2, 0, idx, out=yy2)
    # store element-wise max with next highest score
    xx1 = torch.clamp(xx1, min=x1[i])
    yy1 = torch.clamp(yy1, min=y1[i])
    xx2 = torch.clamp(xx2, max=x2[i])
    yy2 = torch.clamp(yy2, max=y2[i])
    w.resize_as_(xx2)
    h.resize_as_(yy2)
    w = xx2 - xx1
    h = yy2 - yy1
    # check sizes of xx1 and xx2.. after each iteration
    w = torch.clamp(w, min=0.0)
    h = torch.clamp(h, min=0.0)
    inter = w * h
    # IoU = i / (area(a) + area(b) - i)
    rem_areas = torch.index_select(area, 0, idx)  # load remaining areas)
    union = (rem_areas - inter) + area[i]
    IoU = inter / union  # store result in iou
    # keep only elements with an IoU <= overlap
    idx = idx[IoU.le(overlap)]
**_return keep, count_**

the two return are not same ,it may take error: layers/functions/detection.py", line 67, in forward ValueError: not enough values to unpack (expected 2, got 0)

njustymk avatar Jul 12 '20 01:07 njustymk

Hello, I also find this problem, my resolution is change the code 'if boxes.numel()==0 return keep' to '... ... return keep, 0'. Because the count means the kept boxes number, if boxes' num is 0, then the keep's num also should be 0.

Rui-coder avatar Apr 13 '22 13:04 Rui-coder

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

yxlijun avatar Apr 13 '22 13:04 yxlijun