facebookresearch / detr

End-to-End Object Detection with Transformers
Apache License 2.0
13.69k stars 2.47k forks source link

Applying focal loss (masks) for bbox detection does not work. why? #453

Open amirhesamyazdi opened 3 years ago

amirhesamyazdi commented 3 years ago

I am wondering why loss_masks and in particular focal_loss only works with segmentation and not bbox prediction?

This is quite unexpected as focal loss can help class imbalance for bbox prediction too. Is there a reason why focal loss was not implemented for bbox? And what was the alternative to focal loss? is it eos_coef?

if args.masks: model = DETRsegm(model, freeze_detr=(args.frozen_weights is not None)) matcher = build_matcher(args) weight_dict = {'loss_ce': 1, 'loss_bbox': args.bbox_loss_coef} weight_dict['loss_giou'] = args.giou_loss_coef if args.masks: weight_dict["loss_mask"] = args.mask_loss_coef weight_dict["loss_dice"] = args.dice_loss_coef

TODO this is a hack

if args.aux_loss:
    aux_weight_dict = {}
    for i in range(args.dec_layers - 1):
        aux_weight_dict.update({k + f'_{i}': v for k, v in weight_dict.items()})
    weight_dict.update(aux_weight_dict)

losses = ['labels', 'boxes', 'cardinality']
if args.masks:
    losses += ["masks"]
criterion = SetCriterion(num_classes, matcher=matcher, weight_dict=weight_dict,
                         eos_coef=args.eos_coef, losses=losses)

what if I want to do masks without segmentation, just bbox. I tried masks with bbox data but it did not work

HuihanYang-Arya commented 1 year ago

hi did you solve this problem?