日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【算法】非极大值抑制原理、流程和代码

發布時間:2025/3/15 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【算法】非极大值抑制原理、流程和代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.




代碼如下:

# -------------------------------------------------------- # Fast R-CNN # Copyright (c) 2015 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Ross Girshick # --------------------------------------------------------import numpy as npdef py_cpu_nms(dets, thresh):"""Pure Python NMS baseline."""x1 = dets[:, 0] # pred bbox top_xy1 = dets[:, 1] # pred bbox top_yx2 = dets[:, 2] # pred bbox bottom_xy2 = dets[:, 3] # pred bbox bottom_yscores = dets[:, 4] # pred bbox cls scoreareas = (x2 - x1 + 1) * (y2 - y1 + 1) # pred bbox areasorder = scores.argsort()[::-1] # 對pred bbox按score做降序排序,對應step-2keep = [] # NMS后,保留的pred bboxwhile order.size > 0:i = order[0] # top-1 score bboxkeep.append(i) # top-1 score的話,自然就保留了xx1 = np.maximum(x1[i], x1[order[1:]]) # top-1 bbox(score最大)與order中剩余bbox計算NMSyy1 = 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 * hovr = inter / (areas[i] + areas[order[1:]] - inter) # 無處不在的IoU計算~~~inds = np.where(ovr <= thresh)[0] # 這個操作可以對代碼斷點調試理解下,結合step-3,我們希望剔除所有與當前top-1 bbox IoU > thresh的冗余bbox,那么保留下來的bbox,自然就是ovr <= thresh的非冗余bbox,其inds保留下來,作進一步篩選order = order[inds + 1] # 保留有效bbox,就是這輪NMS未被抑制掉的幸運兒,為什么 + 1?因為ind = 0就是這輪NMS的top-1,剩余有效bbox在IoU計算中與top-1做的計算,inds對應回原數組,自然要做 +1 的映射,接下來就是step-4的循環return keep # 最終NMS結果返回if __name__ == '__main__':dets = np.array([[100,120,170,200,0.98],[20,40,80,90,0.99],[20,38,82,88,0.96],[200,380,282,488,0.9],[19,38,75,91, 0.8]])py_cpu_nms(dets, 0.5)

參考資料:https://zhuanlan.zhihu.com/p/49481833

猜你喜歡:👇🏻
?【算法】ROI Align 原理
?【算法】anchor free 和 anchor based 目標檢測模型
?【算法】交叉熵損失和KL散度

總結

以上是生活随笔為你收集整理的【算法】非极大值抑制原理、流程和代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。