Skip to content
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] how to set Focal loss Parameters #14

Closed
vkherde opened this issue Apr 30, 2019 · 3 comments
Closed

[Question] how to set Focal loss Parameters #14

vkherde opened this issue Apr 30, 2019 · 3 comments

Comments

@vkherde
Copy link

vkherde commented Apr 30, 2019

Hi @mvoelk

I am trying to use focal loss in SSD model, as per the code in DSOD_train.ipynb, lines

  • loss = SSDFocalLoss(lambda_conf=10000, class_weights=class_weights)
  • class_weights = np.array([0.00007205, 1.3919328 , 1.43665262, 1.30902077, 1.36668928, 1.2391509 , 1.21337629, 0.41527107, 1.1458096 , 0.29150119, 1.25713104, 0.61941517, 1.03175604, 1.21542005, 1.01947561, 0.0542007 , 1.12664538, 1.14966073, 1.12464889, 1.49998021, 1.09218961])

I want to understand how these parameters were calculated for "lamba_conf" and "class_weights" please confirm if you got a chance. Many thanks indeed

Best Regards
Vaibhav

@mvoelk
Copy link
Owner

mvoelk commented Apr 30, 2019

I did not spend much time on the DSOD model.

The value for lambda is probably much too high. I took this value only for some experiments. A value of 100.0, as I used it for the SegLink models, should work find. I will also change that in the code.

The class_weight values were calculated using compute_class_weights method in the PriorUtility.

ssd_detectors/ssd_utils.py

Lines 552 to 561 in 3ef2c31

def compute_class_weights(self, gt_util, num_samples=np.inf):
"""Computes weighting factors for the classification loss by considering
the inverse frequency of class instance in local ground truth.
"""
s = np.zeros(gt_util.num_classes)
for i in tqdm(range(min(gt_util.num_samples, num_samples))):
egt = self.encode(gt_util.data[i])
s += np.sum(egt[:,-gt_util.num_classes:], axis=0)
si = 1/s
return si/np.sum(si) * len(s)

Roughly speaking, they are the normalized inverse of the class frequencies in the local ground truth.

@vkherde
Copy link
Author

vkherde commented May 2, 2019

Thanks for the explanation @mvoelk

@mvoelk
Copy link
Owner

mvoelk commented Jul 19, 2019

Just in case someone reads it... #18 may also be relevant.

@mvoelk mvoelk mentioned this issue Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants