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

#468 Bug/sg 399 external checkpoints fix

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:bug/SG-399_external_checkpoints_fix
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
39
40
41
42
43
44
45
46
47
  1. import inspect
  2. from typing import Callable, Dict, Optional
  3. from super_gradients.training.dataloaders.dataloaders import ALL_DATALOADERS
  4. from super_gradients.training.models.all_architectures import ARCHITECTURES
  5. from super_gradients.training.metrics.all_metrics import METRICS
  6. from super_gradients.training.losses.all_losses import LOSSES
  7. from super_gradients.modules.detection_modules import ALL_DETECTION_MODULES
  8. def create_register_decorator(registry: Dict[str, Callable]) -> Callable:
  9. """
  10. Create a decorator that registers object of specified type (model, metric, ...)
  11. :param registry: The registry (maps name to object that you register)
  12. :return: Register function
  13. """
  14. def register(name: Optional[str] = None) -> Callable:
  15. """
  16. Set up a register decorator.
  17. :param name: If specified, the decorated object will be registered with this name.
  18. :return: Decorator that registers the callable.
  19. """
  20. def decorator(cls: Callable) -> Callable:
  21. """Register the decorated callable"""
  22. cls_name = name if name is not None else cls.__name__
  23. if cls_name in registry:
  24. ref = registry[cls_name]
  25. raise Exception(f"`{cls_name}` is already registered and points to `{inspect.getmodule(ref).__name__}.{ref.__name__}")
  26. registry[cls_name] = cls
  27. return cls
  28. return decorator
  29. return register
  30. register_model = create_register_decorator(registry=ARCHITECTURES)
  31. register_detection_module = create_register_decorator(registry=ALL_DETECTION_MODULES)
  32. register_metric = create_register_decorator(registry=METRICS)
  33. register_loss = create_register_decorator(registry=LOSSES)
  34. register_dataloader = create_register_decorator(registry=ALL_DATALOADERS)
Discard
Tip!

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