# How to label training data for YOLO

I am having a question on how to label training data for YOLO algorithm.

Let's say that each label Y, we need to specify $$[P_c, b_x, b_y, b_h, b_w]$$, where $$P_c$$ is the indicator for presence (1=present, 0=not present), $$(b_x, b_y)$$ is the relative position of the center of the object-of-interest, and $$(b_h, b_w)$$ is the relative dimension of the bounding box containing the object.

Using picture below as an example, the cell (1,2), which contains a black car, should have a label $$Y = [1, 0.4, 0.3, 0.9, 0.5]$$. And for any cells without cars, they should have a label $$[0, ?, ?, ?, ?]$$ [Coursera Deep Learning Specialization Materials]

But if we have a finer grid like this, where the dimension of each cells is smaller than the ground truth bounding box.

Let's say that the ground truth bounding box for the car is the red box, and the ground truth center point is the red dot, which is in cell 2.

For cell 2 it will have label $$Y = [1, 0.9, 0.1, 2, 2]$$, is this correct? And for cell $$1, 3, 4$$ what kind of label will they have? Do they have $$P_c=1$$ or $$P_c = 0$$? And if $$P_c=1$$, how will the $$b_x$$ and $$b_y$$ be? (As I remember that $$b_x, b_y$$ should have value between $$0$$ and $$1$$. But in cell $$1,3,4$$ there is no center point of the object-of-interest)

In effect, the midpoint is contained in cell $$2$$. Cells $$1,3,4$$ will be shown at $$P_c=0$$ according to the YOLO algorithm, which only takes in count the cell that contains the midpoint and calculates the bounding box, as you mentioned, with $$b_y b_x, b_y, b_h, b_w$$. With the proposition of $$Y = [1, 0.9, 0.1, 2, 2]$$, I would think that if you take the point $$(0,0)$$ as the left-upper corner, $$Y$$ would be more likely to be $$Y = [1,0.2,0.57,0.21,0.15]$$, being calculated with a grid of $$19 \times 19$$.