-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about GIoU #302
Comments
@lyx190 ah this is very interesting, I had not heard about GIoU before. I read the paper, and it seems like you may need to do some regularization of the new GIoU loss to balance it's magnitude with the existing losses (conf and class). Independently of this, I'd advise you to test the default repo first so you have a proper way to test the difference, otherwise your metrics mean nothing by themselves. |
@glenn-jocher thank you for your reply. I have trained on my own dataset with the default repo before. The result looks good, with 88% recall and 78% precision. What's more, I am trying to finetune the values of 'cls', 'conf', 'iou_t' on the Hyperparameters. As for my problem with the high recall(90) and low precision(20), my idea is, that it perhaps caused by the maldistribution of True and False samples during training phase. How do you think of it? Edited: Besides, because of the range of the GIoU loss value is among 0 ~ 2, so I have also normalized it into 0 to 1 to fit the cls_loss and conf_loss value. |
@lyx190 ah ok. Hmm, those are very high numbers indeed you got before, and now the precision has dropped a lot. class loss in single-class datasets is always zero (if you've configured your *.cfg for 1 class), so in your case |
@glenn-jocher ah I forgot to tell before that hyp['giou'] and hyp['conf'] I set was 2.4 and 4.3. And also in the training phase, if I wanna map the prediction values to the size of feature map, is it correct that:
for wh: |
Oh, you should probably make hyp = {'xy': 0.2, # xy loss gain
'wh': 0.1, # wh loss gain
'cls': 0.04, # cls loss gain
'conf': 4.5, # conf loss gain
'iou_t': 0.5, # iou target-anchor training threshold
'lr0': 0.001, # initial learning rate
'lrf': -4., # final learning rate = lr0 * (10 ** lrf)
'momentum': 0.90, # SGD momentum
'weight_decay': 0.0005} # optimizer weight decay I think the IOU metric should not be affected by the units used, so the IOUs could be in grid units or pixels. Off the top of my head the equations seem right, but you should be careful because i and j may be swapped for x and y, i.e. its possible the xy gridpoints are ji and not ij. |
@glenn-jocher thanks for your remind. I would check again the xy gridpoints. |
@lyx190 I started looking into a GIoU implementation. The code to export the bounding boxes is already present in models.py (for inference). This will create the boxes in units of pixels. If you want the output in grid units you simply skip the line 164 Lines 157 to 167 in 9cf5ab0
Have you had any luck with your implementation? |
@lyx190 BTW you should be extremely careful about building your own Lines 247 to 250 in 9cf5ab0
Note that in grid_xy the vertical dimension (y ) comes first, before the horizontal (x ) dimension. This is in maintaining with typical pytorch image dimension standards.
|
@lyx190 ok, this doesn't seem too hard. I think the fastest way to try is to output models.py raw values along with inference values. The target boxes are in xywh (normalized), while the inference outputs are in xywh (pixels). So we simply multiply the target boxes by the img_size, (target-anchor matches are already made so no new work needed there), and then simply pass the matched boxes to the existing |
@lyx190 I implemented giou loss in a new giou branch: I tuned the weighting hyperparameters manually a bit to |
@glenn-jocher ah it's nice. I am gonna check the new branch now. Yesterday I have print the values of |
@glenn-jocher BTW, I am gonna take a look the code you implemented. Your result looks much better than mine. I think maybe there is something wrong with my implementation. My modified with GIoU is below:
|
@glenn-jocher Now I am using your code to train on my own dataset, but I have a question about the calculation of GIoU: Lines 297 to 298 in 243344a
These two lines here, the xy coordinates of ground truth are resized based on the size of feature maps, so it isn't necessary to map the torch.sigmoid([pi[..., :2]]) to the size of feature map? |
@lyx190 inference operates completely well, as you can see from mAP comparisons to published results in the README. The predicted and target boxes will always have a common origin, adding the grid location is redundant since it will be removed in the IoU calculation. i.e. there's no point in adding the same constant to both xy values. |
@glenn-jocher Yes you are right. But I am confused that why if I added the grid_xy to predicted xy coordinate, the result would go down. Besides, I have trained on my own dataset with the new giou branch, below are the results between with giou and without giou: Both results are trained on my own dataset. The blue line with default hyp[] setting. The orange line with hyp[] which you set on the 'giou' branch. |
@lyx190 grid_xy is a constant offset. You can add it to both boxes you pass to giou, or add it to none, but you can not add it to only one. Your results look similar to mine above, the giou results are worse unfortunately. In my example the difference is minimal though, only a few percent lower. |
Your second run looks a little more promising though (the area between 220 to 300 I assume is a new run). |
@glenn-jocher I don't know what happened between epoch 220 to 300, all things went down automatically from 220. So I shut it down at 300 epoch. |
I don't know. It's a very nice idea, its too bad we can't reproduce the paper results yet. I suppose the conclusions one might draw from these results are that:
|
@glenn-jocher thank you for your idea, I would keep working on it. If I got a better result would come back here again. |
@its a very appealing idea to wrap all of the regression losses into one. Hopefully we can get it to work better. I'll leave the branch open, and if you make any discoveries let me know! |
@glenn-jocher ok! |
@glenn-jocher Hello, I am still struggling for the implementation now. I have found two things:
|
Can you provide an exact line number of which
I haven't observed this when training COCO or any of the smaller COCO datasets like |
|
@lyx190 hey I think you are right!! That line should read like this instead, because both the targets and prediction boxes are in giou = bbox_iou(pbox.t(), tbox[i], GIoU=True, x1y1x2y2=False) Your #2 is a pretty well known issue with the YOLO layer, which is that UPDATE1: I re-ran coco_64img.data to compare to my previous results. The updated results incorporating the |
@glenn-jocher I have tried the new on my own dataset, it also, unfortunately, had a little improvement. I am trying now with the loss format: lgiou = -log((1 + giou) / 2). If I get better result, I would tell you again. And about my second problem, the very high value of predicted |
@lyx190 we trained yolov3-spp fully with giou for 68 epochs and ended up at 0.464 mAP, about the same as regular xy and wh implementation. Any luck on your side? |
@glenn-jocher hello, I have trained on my own dataset, got the same result of regular yolov3. On which dataset did you trained with giou? I am going to test it on the same dataset as yours. |
@lyx190 I trained coco for one epoch. Also got same results as default. I've integrated giou into the main branch now, you can train with it using python3 train.py --data data/coco.data --img-size 320 --epochs 1 --giou |
@glenn-jocher Okay, thank you. I would train it on coco 64 image dataset and then post the result here |
@lyx190 GIoU is now integrated as the default regression loss for this repository, so simply running the default training command will use GIoU. Closing this issue as resolved. |
@glenn-jocher |
@developer0hye yes GIoU is a definite improvement over the individual xywh MSE losses. It stabilizes the wh loss, and since it merges 4 losses into 1 it is much easier to work with and tune hyperparameters with. |
@glenn-jocher Ah, one more! have you tried optimize the model with DIoU or CIoU? |
@developer0hye hmm, interesting. I suppose results will vary across datasets. The ultralytics results in https://github.com/ultralytics/yolov3#map were all trained from scratch using this repo with GIoU. |
@glenn-jocher Thank you very much for your code.
I am attempting to using GIoU loss with yolov3 on my own dataset with single class. I am confused about some relative problems. So I wanna ask you guys, if anyone achieved to replace lxy, lwy with GIoU loss to train the net?
I have mapped x, y, w, h of prediction and targets to the size of feature map and then calculated the GIoU loss value in the training phase. But after training, the recall can reach a high value like 90%, precision stay always very low at 25%. I don't know which part causes this problem.
Have anyone idea or managed to modified the GIoU loss on yolov3?
The text was updated successfully, but these errors were encountered: