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

#868 Draw fix

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:hotfix/SG-000-fix_draw
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  1. from typing import Union, Tuple, Type
  2. from torch import nn
  3. from super_gradients.modules.utils import autopad
  4. class ConvBNAct(nn.Module):
  5. """
  6. Class for Convolution2d-Batchnorm2d-Activation layer.
  7. Default behaviour is Conv-BN-Act. To exclude Batchnorm module use
  8. `use_normalization=False`, to exclude activation use `activation_type=None`.
  9. For convolution arguments documentation see `nn.Conv2d`.
  10. For batchnorm arguments documentation see `nn.BatchNorm2d`.
  11. """
  12. def __init__(
  13. self,
  14. in_channels: int,
  15. out_channels: int,
  16. kernel_size: Union[int, Tuple[int, int]],
  17. padding: Union[int, Tuple[int, int]],
  18. activation_type: Type[nn.Module],
  19. stride: Union[int, Tuple[int, int]] = 1,
  20. dilation: Union[int, Tuple[int, int]] = 1,
  21. groups: int = 1,
  22. bias: bool = True,
  23. padding_mode: str = "zeros",
  24. use_normalization: bool = True,
  25. eps: float = 1e-5,
  26. momentum: float = 0.1,
  27. affine: bool = True,
  28. track_running_stats: bool = True,
  29. device=None,
  30. dtype=None,
  31. activation_kwargs=None,
  32. ):
  33. super().__init__()
  34. if activation_kwargs is None:
  35. activation_kwargs = {}
  36. self.seq = nn.Sequential()
  37. self.seq.add_module(
  38. "conv",
  39. nn.Conv2d(
  40. in_channels,
  41. out_channels,
  42. kernel_size=kernel_size,
  43. stride=stride,
  44. padding=padding,
  45. dilation=dilation,
  46. groups=groups,
  47. bias=bias,
  48. padding_mode=padding_mode,
  49. ),
  50. )
  51. if use_normalization:
  52. self.seq.add_module(
  53. "bn",
  54. nn.BatchNorm2d(out_channels, eps=eps, momentum=momentum, affine=affine, track_running_stats=track_running_stats, device=device, dtype=dtype),
  55. )
  56. if activation_type is not None:
  57. self.seq.add_module("act", activation_type(**activation_kwargs))
  58. def forward(self, x):
  59. return self.seq(x)
  60. class Conv(nn.Module):
  61. # STANDARD CONVOLUTION
  62. # TODO: This class is illegaly similar to ConvBNAct, and the only reason it exists is due to fact that some models were using it
  63. # previosly and one have to find a bulletproof way drop this class but still be able to load models that were using it. Perhaps
  64. # it is possible through load_state_dict / save_state_dict magic.
  65. def __init__(self, input_channels, output_channels, kernel, stride, activation_type: Type[nn.Module], padding: int = None, groups: int = None):
  66. super().__init__()
  67. self.conv = nn.Conv2d(input_channels, output_channels, kernel, stride, autopad(kernel, padding), groups=groups or 1, bias=False)
  68. self.bn = nn.BatchNorm2d(output_channels)
  69. self.act = activation_type()
  70. def forward(self, x):
  71. return self.act(self.bn(self.conv(x)))
  72. def fuseforward(self, x):
  73. return self.act(self.conv(x))
Discard
Tip!

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