Peterisfar / YOLOV3

yolov3 by pytorch
MIT License
195 stars 53 forks source link

some questions about the 'datasets' and 'yolo_loss' code #20

Closed wangren97 closed 4 years ago

wangren97 commented 4 years ago

Very thanks for your work. These days I am working on the implementation of YOLOv3 and find your work. I have some questions about the code. 1) random_crop function. In utils/data_augment.py, line 'crop_xmax = max(w_img, int(max_bbox[2] + random.uniform(0, max_r_trans)))' and 'crop_ymax = max(h_img, int(max_bbox[3] + random.uniform(0, max_d_trans)))' I think the 'max' function should be changed to 'min' because 'h_img' and 'w_img' are always the maximum ones. 2) mixup function: utils/datasets.py line 'item_mix = random.randint(0, len(self.__annotations)-1)'. when I test by myself, there exists a case that item_mix = item. I think it is better to add a if condition for this case to avoid 'bboxes = np.concatenate([bboxes_org, bboxes_mix])' 3) label_smooth: I read the paper 'Bag of Freebies' and in section 3.2, equation (3), the formula is different with your implementation. The one shown in the paper is 1 - delta if i=y else delta (K -1) and your code is 1 - delta + delta / K if i=y else delta / K. Is it correct? 4) loss function: I didn't understand 'bbox_loss_scale = 2.0 - 1.0 label_xywh[..., 2:3] label_xywh[..., 3:4] / (img_size * 2)' in giou loss. Is it shown in the GIOU paper? why the format is 2 minus the label box area / image area? For 'label_noobj_mask FOCAL(input=p_conf, target=label_obj_mask)' in confidence loss. I find in some other implementations, there is a scale factor for the balance of negative samples. see https://github.com/eriklindernoren/PyTorch-YOLOv3/issues/309. Then how to determine the scale value? Could you please explain them? Very thanks!

Peterisfar commented 4 years ago

Thank you so much, you are so careful, thanks again. 1、you are right , it's a bug. it should be min 2、i think this case is low probability,if it happens, i think no influence.but add a condition is better. 3、'Bag of Freebies' has three versions, this code follows v1 4、bbox_loss_scale follows the darknet, and GIOU don't have it.the reason for using it is to balance the impact of different scale boxes on the loss. this code only use one factor, no scale factor(alpha is 1.0) in the folcal loss, but worth to try as the paper.

wangren97 commented 4 years ago

thanks for your reply. I found the bbox_loss_scale code in the darknet https://github.com/pjreddie/darknet/blob/master/src/yolo_layer.c line 219. For confidence loss, I will check the balance problem.