Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#378 Feature/sg 281 add kd notebook

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-281-add_kd_notebook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  1. import torch
  2. from super_gradients.training.losses.ohem_ce_loss import OhemCELoss
  3. class ShelfNetOHEMLoss(OhemCELoss):
  4. def __init__(self, threshold: float = 0.7, mining_percent: float = 1e-4, ignore_lb: int = 255):
  5. """
  6. This loss is an extension of the Ohem (Online Hard Example Mining Cross Entropy) Loss.
  7. :param threshold: threshold to th hard example mining algorithm
  8. :param mining_percent: minimum percentage of total pixels for the hard example mining algorithm
  9. (taking only the largest) losses.
  10. Default is 1e-4, according to legacy settings, number of 400 pixels for typical input of (512x512) and batch of
  11. 16.
  12. :param ignore_lb: targets label to be ignored
  13. """
  14. super().__init__(threshold=threshold, mining_percent=mining_percent, ignore_lb=ignore_lb)
  15. def forward(self, predictions_list: list, targets):
  16. losses = []
  17. for predictions in predictions_list:
  18. losses.append(super().forward(predictions, targets))
  19. total_loss = sum(losses)
  20. losses.append(total_loss)
  21. return total_loss, torch.stack(losses, dim=0).detach()
Discard
Tip!

Press p or to see the previous file or, n or to see the next file