# What is the need of multiple Bounding Boxes per grid cell in YOLO v1?

This question is regarding YOLO v1 architecture as in here.

I am confused as to why authors have used 2 bounding boxes per grid cell for training. Assuming there can be only one object per grid cell. Would two boxes would be relevant?

If yes:

Then how would the target vector(y) for the grid cell containing the object centre look like? Wont this lead to repeated values of ground truth annotations for both bounding boxes?

else:

What is the exact rationale behind multiple bounding boxes?

• check this related question on another Stack Exchange site: Yolo v1 bounding boxes during training step, hope it will help you. Commented Apr 18, 2018 at 11:55
• Commented May 15, 2019 at 9:17

I think we need to have clear separation of training time and inference time.

## During training

At the training time, the responsible bounding box of the highest IOU at each cell plays the part in the loss function via $$1^{obj}_{ij}$$. So we may think why not use just one bounding box per cell.

However, let's not forget that both bounding box predictors of each cell are getting trained. YOLO train the model so that each bounding box predictor at a cell develops their own specializations. We never know which bounding box at a cell gives a better prediction at the inference time.

## During inference

At inference time, YOLO uses all the bounding boxes of all the cells to calculate class confidence scores.

Then apply non-max suppression to identify objects from all the bounding boxes of all the cells.

This steps are well explained in YOLO — ‘You only look once’ for Object Detection explained.

Next, we multiply all these class score with bounding box confidence and get class scores for different bounding boxes. We do this for all the grid cells. That is equal to 772 = 98. Now we have class scores for each bounding box(Tensor dimension=20*1). Now let us focus on the dog in the image. The dog score for the bounding boxes will be present in (1,1) of the tensor in all the bounding box scores. We will now set a threshold value of scores and sort them descendingly. Now we will use Non-max supression algorithm to set score to zero for redundant boxes.

Consider you have dog score for bounding box1 as 0.5 and let this be the highest score and for box47 as 0.3. We will take an Intersection over Union of these values and if the value is greater than 0.5, we will set the value for box2 as zero,otherwise, we will continue to the next box. We do this for all boxes.

Because each bounding box predictor at each cell has developed different specialization, we have more diverse capabilities in the YOLO model than having single bounding box per cell . The first (j=0) bounding box at cell (1, 1) may give a better confidence (IOU) for a dog but the second (j=1) bounding box may give a better one for a cat.

By using multiple bounding boxes (B > 1), YOLO gives better detection capabilities. I believe by increasing B, the capability would improve. However, because YOLO puts the importance on the real-time detection speed, B is set to 2, in my understanding.