experiencor / keras-yolo2

Easy training on custom dataset. Various backends (MobileNet and SqueezeNet) supported. A YOLO demo to detect raccoon run entirely in brower is accessible at https://git.io/vF7vI (not on Windows).
MIT License
1.73k stars 787 forks source link

is bounding box correct? #408

Closed hokim72 closed 5 years ago

hokim72 commented 5 years ago

Hi I'm trying to understand yolo algorithm through your code I found something wrong(?) in calculating bonding box in preprocessing.py

box = [center_x, center_y, center_w, center_h] at line 197

The above center_x, center_y seem not to be the relative values to grid They should be center_x-grid_x, center_y-grid_y?

rodrigo2019 commented 5 years ago

The bound boxes values are between values between 0 and 1, and these values are normalized in relation to the grid, so the network doesn't need to know where is that object, just need to know that object are inside in the grid cell. in this line the value are normalized between 0 and 1, also it is referenced in which grid this coordinate are locate, it is necessary because the network doesn't need to know where is the object in the image, just in the grid, but the loss function need to know where this object are in the image, so with this normalization we can do it. And here we also normalize the predicted values in order to compare with the ground truth normalized in that way

hokim72 commented 5 years ago

Thanks for your reply center_x, center_y are normalized to 0 ~ GRID_W, 0 ~ GRID_H respectively. this and this x, y coordinate of box is not 0~1 but 0 ~ GRID_W(H)

But I understand what you mean As you said, y value of model has grid_x, grid_y but ground true box doesn't have such information So, x, y use absolute values ( 0~ GRID_W(H) ) instead of the relative values(0~1) for x,y coordinates

rodrigo2019 commented 5 years ago

x,y are not between 0~1 because they have the grid index added into them