# Does Intersection over Union filter out good detections when using instance segmentation?

**URL:** <https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654>\
**Category:** 🤝  Community Help\
**Tags:** segmentation\
**Created:** [February 18, 2025, 4:46pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654 "2025-02-18T16:46:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reinier\_Zeldenrust](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/reinier_zeldenrust/32/5052_2.png) [@Reinier\_Zeldenrust](https://discuss.roboflow.com/u/Reinier_Zeldenrust)\
**Post date:** [February 18, 2025, 4:46pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654/1 "2025-02-18T16:46:51Z")

</div>

We have a trained instance segmentation that we’re using via hosted inference, using workflows. In workflows, you can set IoU, but it’s not clear how it works. The documentation points to this: [How to Code Non-Maximum Suppression (NMS) in Plain NumPy](https://blog.roboflow.com/how-to-code-non-maximum-suppression-nms-in-plain-numpy/) seems to refer to object detection specifically.

However I’m seeing a few cases where my model is missing a really obvious roof face, while the adjacent roof face is well detected. I wonder if the IoU setting uses bounding boxes, or the pixel masks themselves.

Especially when the roof faces are diagonal on the image, the bounding boxes of the detection may overlap quite a lot even when the detections themselves do not overlap at all, and this setting may filter out too many real, valid detections!

 ![Screenshot 2025-02-18 at 16.41.13](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/2X/3/3df1bdb5bb65aa9d3fc486318a33a87b5f6094a0.jpeg)

I have experimented with setting the IoU value to be high (e.g. 0.95) but then we do get quite a few more genuinely overlapping detections. I’m hoping the model can be smart enough to actually compare the masks rather than the bounding boxes.

---

<div class="post-metadata">

**Author:** ![Reinier\_Zeldenrust](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/reinier_zeldenrust/32/5052_2.png) [@Reinier\_Zeldenrust](https://discuss.roboflow.com/u/Reinier_Zeldenrust)\
**Post date:** [February 18, 2025, 4:49pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654/2 "2025-02-18T16:49:19Z")

</div>

This is the screenshot in the workflow mode:

 ![Screenshot 2025-02-18 at 16.47.18](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/2X/f/f5d5c2e993a4b4c88f33fb62d245b8c71e955c21.png)

and the link goes [here](https://blog.roboflow.com/how-to-code-non-maximum-suppression-nms-in-plain-numpy/) again - and the [workflows documentation](https://inference.roboflow.com/workflows/blocks/instance_segmentation_model/#properties) also takes you there.

---

<div class="post-metadata">

**Author:** ![Thomas\_Hansen](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/thomas_hansen/32/5153_2.png) [@Thomas\_Hansen](https://discuss.roboflow.com/u/Thomas_Hansen)\
**Post date:** [February 24, 2025, 8:58pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654/3 "2025-02-24T20:58:02Z")

</div>

Hi Reiner,

Yes it looks like the NMS is only using axis aligned bounding boxes as far as I can tell. I think this is the code that does NMS post processing on instance segmentation in inference here: [inference/inference/core/models/instance\_segmentation\_base.py at main · roboflow/inference · GitHub](https://github.com/roboflow/inference/blob/main/inference/core/models/instance_segmentation_base.py#L123)

I think it’s be possible to implement NMS using actual polygon overlapp calculations. I don’t know if it should be default in this code given potential speed implications. But I it being optional and have an flag on the Workflow block e.g ([inference/inference/core/workflows/core\_steps/models/roboflow/instance\_segmentation/v2.py at main · roboflow/inference · GitHub](https://github.com/roboflow/inference/blob/main/inference/core/workflows/core_steps/models/roboflow/instance_segmentation/v2.py))

The overlap calculation of the NMS function itself is here: [inference/inference/core/nms.py at main · roboflow/inference · GitHub](https://github.com/roboflow/inference/blob/main/inference/core/nms.py#L156)

I understand that doesn’t solve your problem, but hopefully confirming at least is somewhat helpful?

We don’t have this on the roadmap right now at roboflow, but I’ll note it as a feature request in the backlog. Since inference is open source, we’d be happy to have you make a PR if it’s something you want to implement yourself.

---

<div class="post-metadata">

**Author:** ![Reinier\_Zeldenrust](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/reinier_zeldenrust/32/5052_2.png) [@Reinier\_Zeldenrust](https://discuss.roboflow.com/u/Reinier_Zeldenrust)\
**Post date:** [February 25, 2025, 2:01pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654/4 "2025-02-25T14:01:16Z")

</div>

Hi Thomas, thanks for the response, definitely helpful. I guess we can set the value to 0.99 (1 seems to error for some reason) and then do the filtering on our end afterwards. We’ll take a look at doing a PR too.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [March 18, 2025, 2:01pm UTC](https://discuss.roboflow.com/t/does-intersection-over-union-filter-out-good-detections-when-using-instance-segmentation/8654/5 "2025-03-18T14:01:40Z")

</div>

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
