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

#970 Update YoloNASQuickstart.md

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:bugfix/SG-000_fix_readme_yolonas_snippets
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  1. from typing import Callable
  2. from torch import nn
  3. from typing_extensions import Protocol, runtime_checkable
  4. @runtime_checkable
  5. class HasPreprocessingParams(Protocol):
  6. """
  7. Protocol interface for torch datasets that support getting preprocessing params, later to be passed to a model
  8. that obeys NeedsPreprocessingParams. This interface class serves a purpose of explicitly indicating whether a torch dataset has
  9. get_dataset_preprocessing_params implemented.
  10. """
  11. def get_dataset_preprocessing_params(self):
  12. ...
  13. @runtime_checkable
  14. class HasPredict(Protocol):
  15. """
  16. Protocol class serves a purpose of explicitly indicating whether a torch model has the functionality of ".predict"
  17. as defined in SG.
  18. """
  19. def set_dataset_processing_params(self, *args, **kwargs):
  20. """Set the processing parameters for the dataset."""
  21. ...
  22. def predict(self, images, *args, **kwargs):
  23. ...
  24. def predict_webcam(self, *args, **kwargs):
  25. ...
  26. @runtime_checkable
  27. class SupportsReplaceNumClasses(Protocol):
  28. """
  29. Protocol interface for modules that support replacing the number of classes.
  30. Derived classes should implement the `replace_num_classes` method.
  31. This interface class serves a purpose of explicitly indicating whether a class supports optimized head replacement:
  32. >>> class PredictionHead(nn.Module, SupportsReplaceNumClasses):
  33. >>> def replace_num_classes(self, num_classes: int, compute_new_weights_fn: Callable[[nn.Module, int], nn.Module] = None):
  34. >>> ...
  35. """
  36. def replace_num_classes(self, num_classes: int, compute_new_weights_fn: Callable[[nn.Module, int], nn.Module]):
  37. """
  38. Replace the number of classes in the module.
  39. :param num_classes: New number of classes.
  40. :param compute_new_weights_fn: (callable) An optional function that computes the new weights for the new classes.
  41. It takes existing nn.Module and returns a new one.
  42. :return: None
  43. """
  44. ...
Discard
Tip!

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