Answers.Body: <p>I might be able to help with the theory, but the coding... it is a non standard API such as Tensorflow or Pytorch (it might be custom code for what I can tell).</p>
  <p><em><strong>The key element here is that the bouding boxes are removed only if they hold a prediciton for the same class that the box that is overlapping with</strong></em> (but with less confidence, that is why it gets removed).</p>
  <p>Here is an example, where we have:</p>
  <ul>
  <li>Two classes <span class="math-container">$c \in [c_1, c_2] = [$</span> &quot;star&quot;<span class="math-container">$, $</span> &quot;moon&quot; <span class="math-container">$]$</span></li>
  <li>Three bounding boxes</li>
  </ul>
  <p>The blue bounding boxes holds prediction for the class <span class="math-container">$c_1$</span> so their predictions are <span class="math-container">$p(c_1)_{box1} = 0.8$</span> and <span class="math-container">$ p(c_1)_{box2} = 0.9$</span>. On the other hand, the green box holds a prediction for the class <span class="math-container">$c_2$</span>.</p>
  <p>The three boxes are highly overlaping so the overlap between any box <span class="math-container">$x$</span> with any box <span class="math-container">$y$</span> will be above the IoU threshold: <span class="math-container">$IoU(box_x, box_y) &gt; 0.5$</span>. So in principle all boxes are suceptible to be removed.</p>
  <p>However the NMS only applies for boxes predicting the same class (in the case the blue one). So the NMS algorihtm is: if the boxes are overlapping, <span class="math-container">$IoU(box_1, box_2) &gt; 0.5$</span>, which is true, remove all non maximal class probability boxes. Said differently, take just the box with highest <span class="math-container">$p(c_1)$</span> and remove the rest. So the <span class="math-container">$box_1$</span> with class probability <span class="math-container">$p(c_1) = 0.8$</span> would be removed.</p>
  <p>So what happens with green box? Isn't it overlapping as well? Yes, but consider that the green box is not trying to predict the same object, is trying to predict another object, <span class="math-container">$c_2$</span>, which happens to be very close to the first object, <span class="math-container">$c_1$</span>. This way object detectors support detection of different overlapping objects.</p>
  <p><a href="https://i.sstatic.net/6MJ1l.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6MJ1l.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-13T16:19:46.153Z
Answers.LastActivityDate: 2020-08-13T16:19:46.153Z
Answers.UserDisplayName: JVGD
Body: <p>My understanding of how non-max suppression works is that it suppresses all overlapping boxes that have a Jaccard overlap smaller than a threshold (e.g. 0.5). The boxes to be considered are on a confident score (may be 0.2 or something). So, if there are boxes that have a score over 0.2 (e.g. the score is 0.3 and overlap is 0.4) the boxes won't be suppressed.</p>
  <p>In this way, one object will be predicted by many boxes, one high score box, and many low confident score boxes, but I found that the model predicts only one box for one object. Can someone enlighten me?</p>
  <p>I currently viewing the ssd from  <a href="https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Object-Detection" rel="nofollow noreferrer">https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Object-Detection</a></p>
  <p>Here is the code.</p>
  <pre><code>#Finding Jaccap Overlap and sorting scotes
  class_scores, sort_ind = class_scores.sort(dim=0, descending=True)
  class_decoded_locs = class_decoded_locs[sort_ind]  # (n_min_score, 4)
  overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs)  
  suppress = torch.zeros((n_above_min_score), dtype=torch.uint8).to(device)  
  
  for box in range(class_decoded_locs.size(0)):
  # If this box is already marked for suppression
      if suppress[box] == 1:
      continue
      suppress = torch.max(suppress, overlap[box] &gt; max_overlap)
      suppress[box] = 0
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-01-16T22:40:58.370Z
Comments.Text: Hello welcome to AI.SE!
Comments.UserDisplayName: Michael Hearn
Tags: <computer-vision><object-detection><non-max-suppression>
Title: How does non-max suppression work when one or multiple bounding boxes are predicted for the same object?
UserDisplayName: Moe Kaung Kin
ThreadText: # How does non-max suppression work when one or multiple bounding boxes are predicted for the same object?
  
  (Asked by: username_0 on 2020-01-16)
  
  My understanding of how non-max suppression works is that it suppresses all overlapping boxes that have a Jaccard overlap smaller than a threshold (e.g. 0.5). The boxes to be considered are on a confident score (may be 0.2 or something). So, if there are boxes that have a score over 0.2 (e.g. the score is 0.3 and overlap is 0.4) the boxes won't be suppressed.
  In this way, one object will be predicted by many boxes, one high score box, and many low confident score boxes, but I found that the model predicts only one box for one object. Can someone enlighten me?
  I currently viewing the ssd from  https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Object-Detection
  Here is the code.
  #Finding Jaccap Overlap and sorting scotes
  class_scores, sort_ind = class_scores.sort(dim=0, descending=True)
  class_decoded_locs = class_decoded_locs[sort_ind]  # (n_min_score, 4)
  overlap = find_jaccard_overlap(class_decoded_locs, class_decoded_locs)  
  suppress = torch.zeros((n_above_min_score), dtype=torch.uint8).to(device)  
  
  for box in range(class_decoded_locs.size(0)):
  # If this box is already marked for suppression
      if suppress[box] == 1:
      continue
      suppress = torch.max(suppress, overlap[box] > max_overlap)
      suppress[box] = 0
  
  **Tags:** computer-vision, object-detection, non-max-suppression
  > **Comments:**
  > **username_1**: Hello welcome to AI.SE!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-08-13. Score: 2
  
  I might be able to help with the theory, but the coding... it is a non standard API such as Tensorflow or Pytorch (it might be custom code for what I can tell).
  
  ***The key element here is that the bouding boxes are removed only if they hold a prediciton for the same class that the box that is overlapping with*** (but with less confidence, that is why it gets removed).
  
  Here is an example, where we have:
  
  * Two classes $c \in [c\_1, c\_2] = [$ "star"$, $ "moon" $]$
  * Three bounding boxes
  
  The blue bounding boxes holds prediction for the class $c\_1$ so their predictions are $p(c\_1)\_{box1} = 0.8$ and $ p(c\_1)\_{box2} = 0.9$. On the other hand, the green box holds a prediction for the class $c\_2$.
  
  The three boxes are highly overlaping so the overlap between any box $x$ with any box $y$ will be above the IoU threshold: $IoU(box\_x, box\_y) > 0.5$. So in principle all boxes are suceptible to be removed.
  
  However the NMS only applies for boxes predicting the same class (in the case the blue one). So the NMS algorihtm is: if the boxes are overlapping, $IoU(box\_1, box\_2) > 0.5$, which is true, remove all non maximal class probability boxes. Said differently, take just the box with highest $p(c\_1)$ and remove the rest. So the $box\_1$ with class probability $p(c\_1) = 0.8$ would be removed.
  
  So what happens with green box? Isn't it overlapping as well? Yes, but consider that the green box is not trying to predict the same object, is trying to predict another object, $c\_2$, which happens to be very close to the first object, $c\_1$. This way object detectors support detection of different overlapping objects.
  
  [![enter image description here](https://i.sstatic.net/6MJ1l.png)](https://i.sstatic.net/6MJ1l.png)
  
  
  ---
  
  