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

#869 Add DagsHub Logger to Super Gradients

Merged
Ghost merged 1 commits into Deci-AI:master from timho102003:dagshub_logger
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
27
28
29
30
31
32
33
34
35
36
37
38
  1. import torch
  2. from super_gradients.common.object_names import Losses
  3. from super_gradients.common.registry.registry import register_loss
  4. from super_gradients.training.losses.ohem_ce_loss import OhemCELoss
  5. @register_loss(Losses.SHELFNET_OHEM_LOSS)
  6. class ShelfNetOHEMLoss(OhemCELoss):
  7. def __init__(self, threshold: float = 0.7, mining_percent: float = 1e-4, ignore_lb: int = 255):
  8. """
  9. This loss is an extension of the Ohem (Online Hard Example Mining Cross Entropy) Loss.
  10. :param threshold: threshold to th hard example mining algorithm
  11. :param mining_percent: minimum percentage of total pixels for the hard example mining algorithm
  12. (taking only the largest) losses.
  13. Default is 1e-4, according to legacy settings, number of 400 pixels for typical input of (512x512) and batch of
  14. 16.
  15. :param ignore_lb: targets label to be ignored
  16. """
  17. super().__init__(threshold=threshold, mining_percent=mining_percent, ignore_lb=ignore_lb)
  18. def forward(self, predictions_list: list, targets):
  19. losses = []
  20. for predictions in predictions_list:
  21. losses.append(super().forward(predictions, targets))
  22. total_loss = sum(losses)
  23. losses.append(total_loss)
  24. return total_loss, torch.stack(losses, dim=0).detach()
  25. @property
  26. def component_names(self):
  27. """
  28. Component names for logging during training.
  29. These correspond to 2nd item in the tuple returned in self.forward(...).
  30. See super_gradients.Trainer.train() docs for more info.
  31. """
  32. return ["Loss1/4", "Loss1/8", "Loss1/16", "Loss"]
Discard
Tip!

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