MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam3_nms

Function sam3_nms

sam3.cpp:9591–9614  ·  view source on GitHub ↗

Non-maximum suppression on detections, sorted by score descending. Returns indices of kept detections.

Source from the content-addressed store, hash-verified

9589// Non-maximum suppression on detections, sorted by score descending.
9590// Returns indices of kept detections.
9591static std::vector<int> sam3_nms(const std::vector<sam3_detection>& dets, float iou_thresh) {
9592 // Sort indices by score descending
9593 std::vector<int> indices(dets.size());
9594 for (int i = 0; i < (int)dets.size(); ++i) indices[i] = i;
9595 std::sort(indices.begin(), indices.end(), [&](int a, int b) {
9596 return dets[a].score > dets[b].score;
9597 });
9598
9599 std::vector<bool> suppressed(dets.size(), false);
9600 std::vector<int> keep;
9601
9602 for (int idx : indices) {
9603 if (suppressed[idx]) continue;
9604 keep.push_back(idx);
9605 for (int j : indices) {
9606 if (suppressed[j] || j == idx) continue;
9607 if (sam3_box_iou(dets[idx].box, dets[j].box) > iou_thresh) {
9608 suppressed[j] = true;
9609 }
9610 }
9611 }
9612
9613 return keep;
9614}
9615
9616// Bilinear interpolation of a flat mask [H_in * W_in] to [H_out * W_out].
9617// Uses double for coordinate math to match PyTorch F.interpolate precision.

Callers 1

sam3_segment_pcsFunction · 0.85

Calls 1

sam3_box_iouFunction · 0.85

Tested by

no test coverage detected