dgenerate-ultralytics-headless 8.3.137__py3-none-any.whl → 8.3.224__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/METADATA +41 -34
  2. dgenerate_ultralytics_headless-8.3.224.dist-info/RECORD +285 -0
  3. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/WHEEL +1 -1
  4. tests/__init__.py +7 -6
  5. tests/conftest.py +15 -39
  6. tests/test_cli.py +17 -17
  7. tests/test_cuda.py +17 -8
  8. tests/test_engine.py +36 -10
  9. tests/test_exports.py +98 -37
  10. tests/test_integrations.py +12 -15
  11. tests/test_python.py +126 -82
  12. tests/test_solutions.py +319 -135
  13. ultralytics/__init__.py +27 -9
  14. ultralytics/cfg/__init__.py +83 -87
  15. ultralytics/cfg/datasets/Argoverse.yaml +4 -4
  16. ultralytics/cfg/datasets/DOTAv1.5.yaml +2 -2
  17. ultralytics/cfg/datasets/DOTAv1.yaml +2 -2
  18. ultralytics/cfg/datasets/GlobalWheat2020.yaml +2 -2
  19. ultralytics/cfg/datasets/HomeObjects-3K.yaml +4 -5
  20. ultralytics/cfg/datasets/ImageNet.yaml +3 -3
  21. ultralytics/cfg/datasets/Objects365.yaml +24 -20
  22. ultralytics/cfg/datasets/SKU-110K.yaml +9 -9
  23. ultralytics/cfg/datasets/VOC.yaml +10 -13
  24. ultralytics/cfg/datasets/VisDrone.yaml +43 -33
  25. ultralytics/cfg/datasets/african-wildlife.yaml +5 -5
  26. ultralytics/cfg/datasets/brain-tumor.yaml +4 -5
  27. ultralytics/cfg/datasets/carparts-seg.yaml +5 -5
  28. ultralytics/cfg/datasets/coco-pose.yaml +26 -4
  29. ultralytics/cfg/datasets/coco.yaml +4 -4
  30. ultralytics/cfg/datasets/coco128-seg.yaml +2 -2
  31. ultralytics/cfg/datasets/coco128.yaml +2 -2
  32. ultralytics/cfg/datasets/coco8-grayscale.yaml +103 -0
  33. ultralytics/cfg/datasets/coco8-multispectral.yaml +2 -2
  34. ultralytics/cfg/datasets/coco8-pose.yaml +23 -2
  35. ultralytics/cfg/datasets/coco8-seg.yaml +2 -2
  36. ultralytics/cfg/datasets/coco8.yaml +2 -2
  37. ultralytics/cfg/datasets/construction-ppe.yaml +32 -0
  38. ultralytics/cfg/datasets/crack-seg.yaml +5 -5
  39. ultralytics/cfg/datasets/dog-pose.yaml +32 -4
  40. ultralytics/cfg/datasets/dota8-multispectral.yaml +2 -2
  41. ultralytics/cfg/datasets/dota8.yaml +2 -2
  42. ultralytics/cfg/datasets/hand-keypoints.yaml +29 -4
  43. ultralytics/cfg/datasets/lvis.yaml +9 -9
  44. ultralytics/cfg/datasets/medical-pills.yaml +4 -5
  45. ultralytics/cfg/datasets/open-images-v7.yaml +7 -10
  46. ultralytics/cfg/datasets/package-seg.yaml +5 -5
  47. ultralytics/cfg/datasets/signature.yaml +4 -4
  48. ultralytics/cfg/datasets/tiger-pose.yaml +20 -4
  49. ultralytics/cfg/datasets/xView.yaml +5 -5
  50. ultralytics/cfg/default.yaml +96 -93
  51. ultralytics/cfg/trackers/botsort.yaml +16 -17
  52. ultralytics/cfg/trackers/bytetrack.yaml +9 -11
  53. ultralytics/data/__init__.py +4 -4
  54. ultralytics/data/annotator.py +12 -12
  55. ultralytics/data/augment.py +531 -564
  56. ultralytics/data/base.py +76 -81
  57. ultralytics/data/build.py +206 -42
  58. ultralytics/data/converter.py +179 -78
  59. ultralytics/data/dataset.py +121 -121
  60. ultralytics/data/loaders.py +114 -91
  61. ultralytics/data/split.py +28 -15
  62. ultralytics/data/split_dota.py +67 -48
  63. ultralytics/data/utils.py +110 -89
  64. ultralytics/engine/exporter.py +422 -460
  65. ultralytics/engine/model.py +224 -252
  66. ultralytics/engine/predictor.py +94 -89
  67. ultralytics/engine/results.py +345 -595
  68. ultralytics/engine/trainer.py +231 -134
  69. ultralytics/engine/tuner.py +279 -73
  70. ultralytics/engine/validator.py +53 -46
  71. ultralytics/hub/__init__.py +26 -28
  72. ultralytics/hub/auth.py +30 -16
  73. ultralytics/hub/google/__init__.py +34 -36
  74. ultralytics/hub/session.py +53 -77
  75. ultralytics/hub/utils.py +23 -109
  76. ultralytics/models/__init__.py +1 -1
  77. ultralytics/models/fastsam/__init__.py +1 -1
  78. ultralytics/models/fastsam/model.py +36 -18
  79. ultralytics/models/fastsam/predict.py +33 -44
  80. ultralytics/models/fastsam/utils.py +4 -5
  81. ultralytics/models/fastsam/val.py +12 -14
  82. ultralytics/models/nas/__init__.py +1 -1
  83. ultralytics/models/nas/model.py +16 -20
  84. ultralytics/models/nas/predict.py +12 -14
  85. ultralytics/models/nas/val.py +4 -5
  86. ultralytics/models/rtdetr/__init__.py +1 -1
  87. ultralytics/models/rtdetr/model.py +9 -9
  88. ultralytics/models/rtdetr/predict.py +22 -17
  89. ultralytics/models/rtdetr/train.py +20 -16
  90. ultralytics/models/rtdetr/val.py +79 -59
  91. ultralytics/models/sam/__init__.py +8 -2
  92. ultralytics/models/sam/amg.py +53 -38
  93. ultralytics/models/sam/build.py +29 -31
  94. ultralytics/models/sam/model.py +33 -38
  95. ultralytics/models/sam/modules/blocks.py +159 -182
  96. ultralytics/models/sam/modules/decoders.py +38 -47
  97. ultralytics/models/sam/modules/encoders.py +114 -133
  98. ultralytics/models/sam/modules/memory_attention.py +38 -31
  99. ultralytics/models/sam/modules/sam.py +114 -93
  100. ultralytics/models/sam/modules/tiny_encoder.py +268 -291
  101. ultralytics/models/sam/modules/transformer.py +59 -66
  102. ultralytics/models/sam/modules/utils.py +55 -72
  103. ultralytics/models/sam/predict.py +745 -341
  104. ultralytics/models/utils/loss.py +118 -107
  105. ultralytics/models/utils/ops.py +118 -71
  106. ultralytics/models/yolo/__init__.py +1 -1
  107. ultralytics/models/yolo/classify/predict.py +28 -26
  108. ultralytics/models/yolo/classify/train.py +50 -81
  109. ultralytics/models/yolo/classify/val.py +68 -61
  110. ultralytics/models/yolo/detect/predict.py +12 -15
  111. ultralytics/models/yolo/detect/train.py +56 -46
  112. ultralytics/models/yolo/detect/val.py +279 -223
  113. ultralytics/models/yolo/model.py +167 -86
  114. ultralytics/models/yolo/obb/predict.py +7 -11
  115. ultralytics/models/yolo/obb/train.py +23 -25
  116. ultralytics/models/yolo/obb/val.py +107 -99
  117. ultralytics/models/yolo/pose/__init__.py +1 -1
  118. ultralytics/models/yolo/pose/predict.py +12 -14
  119. ultralytics/models/yolo/pose/train.py +31 -69
  120. ultralytics/models/yolo/pose/val.py +119 -254
  121. ultralytics/models/yolo/segment/predict.py +21 -25
  122. ultralytics/models/yolo/segment/train.py +12 -66
  123. ultralytics/models/yolo/segment/val.py +126 -305
  124. ultralytics/models/yolo/world/train.py +53 -45
  125. ultralytics/models/yolo/world/train_world.py +51 -32
  126. ultralytics/models/yolo/yoloe/__init__.py +7 -7
  127. ultralytics/models/yolo/yoloe/predict.py +30 -37
  128. ultralytics/models/yolo/yoloe/train.py +89 -71
  129. ultralytics/models/yolo/yoloe/train_seg.py +15 -17
  130. ultralytics/models/yolo/yoloe/val.py +56 -41
  131. ultralytics/nn/__init__.py +9 -11
  132. ultralytics/nn/autobackend.py +179 -107
  133. ultralytics/nn/modules/__init__.py +67 -67
  134. ultralytics/nn/modules/activation.py +8 -7
  135. ultralytics/nn/modules/block.py +302 -323
  136. ultralytics/nn/modules/conv.py +61 -104
  137. ultralytics/nn/modules/head.py +488 -186
  138. ultralytics/nn/modules/transformer.py +183 -123
  139. ultralytics/nn/modules/utils.py +15 -20
  140. ultralytics/nn/tasks.py +327 -203
  141. ultralytics/nn/text_model.py +81 -65
  142. ultralytics/py.typed +1 -0
  143. ultralytics/solutions/__init__.py +12 -12
  144. ultralytics/solutions/ai_gym.py +19 -27
  145. ultralytics/solutions/analytics.py +36 -26
  146. ultralytics/solutions/config.py +29 -28
  147. ultralytics/solutions/distance_calculation.py +23 -24
  148. ultralytics/solutions/heatmap.py +17 -19
  149. ultralytics/solutions/instance_segmentation.py +21 -19
  150. ultralytics/solutions/object_blurrer.py +16 -17
  151. ultralytics/solutions/object_counter.py +48 -53
  152. ultralytics/solutions/object_cropper.py +22 -16
  153. ultralytics/solutions/parking_management.py +61 -58
  154. ultralytics/solutions/queue_management.py +19 -19
  155. ultralytics/solutions/region_counter.py +63 -50
  156. ultralytics/solutions/security_alarm.py +22 -25
  157. ultralytics/solutions/similarity_search.py +107 -60
  158. ultralytics/solutions/solutions.py +343 -262
  159. ultralytics/solutions/speed_estimation.py +35 -31
  160. ultralytics/solutions/streamlit_inference.py +104 -40
  161. ultralytics/solutions/templates/similarity-search.html +31 -24
  162. ultralytics/solutions/trackzone.py +24 -24
  163. ultralytics/solutions/vision_eye.py +11 -12
  164. ultralytics/trackers/__init__.py +1 -1
  165. ultralytics/trackers/basetrack.py +18 -27
  166. ultralytics/trackers/bot_sort.py +48 -39
  167. ultralytics/trackers/byte_tracker.py +94 -94
  168. ultralytics/trackers/track.py +7 -16
  169. ultralytics/trackers/utils/gmc.py +37 -69
  170. ultralytics/trackers/utils/kalman_filter.py +68 -76
  171. ultralytics/trackers/utils/matching.py +13 -17
  172. ultralytics/utils/__init__.py +251 -275
  173. ultralytics/utils/autobatch.py +19 -7
  174. ultralytics/utils/autodevice.py +68 -38
  175. ultralytics/utils/benchmarks.py +169 -130
  176. ultralytics/utils/callbacks/base.py +12 -13
  177. ultralytics/utils/callbacks/clearml.py +14 -15
  178. ultralytics/utils/callbacks/comet.py +139 -66
  179. ultralytics/utils/callbacks/dvc.py +19 -27
  180. ultralytics/utils/callbacks/hub.py +8 -6
  181. ultralytics/utils/callbacks/mlflow.py +6 -10
  182. ultralytics/utils/callbacks/neptune.py +11 -19
  183. ultralytics/utils/callbacks/platform.py +73 -0
  184. ultralytics/utils/callbacks/raytune.py +3 -4
  185. ultralytics/utils/callbacks/tensorboard.py +9 -12
  186. ultralytics/utils/callbacks/wb.py +33 -30
  187. ultralytics/utils/checks.py +163 -114
  188. ultralytics/utils/cpu.py +89 -0
  189. ultralytics/utils/dist.py +24 -20
  190. ultralytics/utils/downloads.py +176 -146
  191. ultralytics/utils/errors.py +11 -13
  192. ultralytics/utils/events.py +113 -0
  193. ultralytics/utils/export/__init__.py +7 -0
  194. ultralytics/utils/{export.py → export/engine.py} +81 -63
  195. ultralytics/utils/export/imx.py +294 -0
  196. ultralytics/utils/export/tensorflow.py +217 -0
  197. ultralytics/utils/files.py +33 -36
  198. ultralytics/utils/git.py +137 -0
  199. ultralytics/utils/instance.py +105 -120
  200. ultralytics/utils/logger.py +404 -0
  201. ultralytics/utils/loss.py +99 -61
  202. ultralytics/utils/metrics.py +649 -478
  203. ultralytics/utils/nms.py +337 -0
  204. ultralytics/utils/ops.py +263 -451
  205. ultralytics/utils/patches.py +70 -31
  206. ultralytics/utils/plotting.py +253 -223
  207. ultralytics/utils/tal.py +48 -61
  208. ultralytics/utils/torch_utils.py +244 -251
  209. ultralytics/utils/tqdm.py +438 -0
  210. ultralytics/utils/triton.py +22 -23
  211. ultralytics/utils/tuner.py +11 -10
  212. dgenerate_ultralytics_headless-8.3.137.dist-info/RECORD +0 -272
  213. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/entry_points.txt +0 -0
  214. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/licenses/LICENSE +0 -0
  215. {dgenerate_ultralytics_headless-8.3.137.dist-info → dgenerate_ultralytics_headless-8.3.224.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,8 @@
1
1
  # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2
2
  """Convolution modules."""
3
3
 
4
+ from __future__ import annotations
5
+
4
6
  import math
5
7
 
6
8
  import numpy as np
@@ -8,20 +10,20 @@ import torch
8
10
  import torch.nn as nn
9
11
 
10
12
  __all__ = (
13
+ "CBAM",
14
+ "ChannelAttention",
15
+ "Concat",
11
16
  "Conv",
12
17
  "Conv2",
13
- "LightConv",
18
+ "ConvTranspose",
14
19
  "DWConv",
15
20
  "DWConvTranspose2d",
16
- "ConvTranspose",
17
21
  "Focus",
18
22
  "GhostConv",
19
- "ChannelAttention",
20
- "SpatialAttention",
21
- "CBAM",
22
- "Concat",
23
- "RepConv",
24
23
  "Index",
24
+ "LightConv",
25
+ "RepConv",
26
+ "SpatialAttention",
25
27
  )
26
28
 
27
29
 
@@ -35,8 +37,7 @@ def autopad(k, p=None, d=1): # kernel, padding, dilation
35
37
 
36
38
 
37
39
  class Conv(nn.Module):
38
- """
39
- Standard convolution module with batch normalization and activation.
40
+ """Standard convolution module with batch normalization and activation.
40
41
 
41
42
  Attributes:
42
43
  conv (nn.Conv2d): Convolutional layer.
@@ -48,8 +49,7 @@ class Conv(nn.Module):
48
49
  default_act = nn.SiLU() # default activation
49
50
 
50
51
  def __init__(self, c1, c2, k=1, s=1, p=None, g=1, d=1, act=True):
51
- """
52
- Initialize Conv layer with given parameters.
52
+ """Initialize Conv layer with given parameters.
53
53
 
54
54
  Args:
55
55
  c1 (int): Number of input channels.
@@ -67,8 +67,7 @@ class Conv(nn.Module):
67
67
  self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
68
68
 
69
69
  def forward(self, x):
70
- """
71
- Apply convolution, batch normalization and activation to input tensor.
70
+ """Apply convolution, batch normalization and activation to input tensor.
72
71
 
73
72
  Args:
74
73
  x (torch.Tensor): Input tensor.
@@ -79,8 +78,7 @@ class Conv(nn.Module):
79
78
  return self.act(self.bn(self.conv(x)))
80
79
 
81
80
  def forward_fuse(self, x):
82
- """
83
- Apply convolution and activation without batch normalization.
81
+ """Apply convolution and activation without batch normalization.
84
82
 
85
83
  Args:
86
84
  x (torch.Tensor): Input tensor.
@@ -92,8 +90,7 @@ class Conv(nn.Module):
92
90
 
93
91
 
94
92
  class Conv2(Conv):
95
- """
96
- Simplified RepConv module with Conv fusing.
93
+ """Simplified RepConv module with Conv fusing.
97
94
 
98
95
  Attributes:
99
96
  conv (nn.Conv2d): Main 3x3 convolutional layer.
@@ -103,8 +100,7 @@ class Conv2(Conv):
103
100
  """
104
101
 
105
102
  def __init__(self, c1, c2, k=3, s=1, p=None, g=1, d=1, act=True):
106
- """
107
- Initialize Conv2 layer with given parameters.
103
+ """Initialize Conv2 layer with given parameters.
108
104
 
109
105
  Args:
110
106
  c1 (int): Number of input channels.
@@ -120,8 +116,7 @@ class Conv2(Conv):
120
116
  self.cv2 = nn.Conv2d(c1, c2, 1, s, autopad(1, p, d), groups=g, dilation=d, bias=False) # add 1x1 conv
121
117
 
122
118
  def forward(self, x):
123
- """
124
- Apply convolution, batch normalization and activation to input tensor.
119
+ """Apply convolution, batch normalization and activation to input tensor.
125
120
 
126
121
  Args:
127
122
  x (torch.Tensor): Input tensor.
@@ -132,8 +127,7 @@ class Conv2(Conv):
132
127
  return self.act(self.bn(self.conv(x) + self.cv2(x)))
133
128
 
134
129
  def forward_fuse(self, x):
135
- """
136
- Apply fused convolution, batch normalization and activation to input tensor.
130
+ """Apply fused convolution, batch normalization and activation to input tensor.
137
131
 
138
132
  Args:
139
133
  x (torch.Tensor): Input tensor.
@@ -154,8 +148,7 @@ class Conv2(Conv):
154
148
 
155
149
 
156
150
  class LightConv(nn.Module):
157
- """
158
- Light convolution module with 1x1 and depthwise convolutions.
151
+ """Light convolution module with 1x1 and depthwise convolutions.
159
152
 
160
153
  This implementation is based on the PaddleDetection HGNetV2 backbone.
161
154
 
@@ -165,8 +158,7 @@ class LightConv(nn.Module):
165
158
  """
166
159
 
167
160
  def __init__(self, c1, c2, k=1, act=nn.ReLU()):
168
- """
169
- Initialize LightConv layer with given parameters.
161
+ """Initialize LightConv layer with given parameters.
170
162
 
171
163
  Args:
172
164
  c1 (int): Number of input channels.
@@ -179,8 +171,7 @@ class LightConv(nn.Module):
179
171
  self.conv2 = DWConv(c2, c2, k, act=act)
180
172
 
181
173
  def forward(self, x):
182
- """
183
- Apply 2 convolutions to input tensor.
174
+ """Apply 2 convolutions to input tensor.
184
175
 
185
176
  Args:
186
177
  x (torch.Tensor): Input tensor.
@@ -195,8 +186,7 @@ class DWConv(Conv):
195
186
  """Depth-wise convolution module."""
196
187
 
197
188
  def __init__(self, c1, c2, k=1, s=1, d=1, act=True):
198
- """
199
- Initialize depth-wise convolution with given parameters.
189
+ """Initialize depth-wise convolution with given parameters.
200
190
 
201
191
  Args:
202
192
  c1 (int): Number of input channels.
@@ -213,8 +203,7 @@ class DWConvTranspose2d(nn.ConvTranspose2d):
213
203
  """Depth-wise transpose convolution module."""
214
204
 
215
205
  def __init__(self, c1, c2, k=1, s=1, p1=0, p2=0):
216
- """
217
- Initialize depth-wise transpose convolution with given parameters.
206
+ """Initialize depth-wise transpose convolution with given parameters.
218
207
 
219
208
  Args:
220
209
  c1 (int): Number of input channels.
@@ -228,8 +217,7 @@ class DWConvTranspose2d(nn.ConvTranspose2d):
228
217
 
229
218
 
230
219
  class ConvTranspose(nn.Module):
231
- """
232
- Convolution transpose module with optional batch normalization and activation.
220
+ """Convolution transpose module with optional batch normalization and activation.
233
221
 
234
222
  Attributes:
235
223
  conv_transpose (nn.ConvTranspose2d): Transposed convolution layer.
@@ -241,8 +229,7 @@ class ConvTranspose(nn.Module):
241
229
  default_act = nn.SiLU() # default activation
242
230
 
243
231
  def __init__(self, c1, c2, k=2, s=2, p=0, bn=True, act=True):
244
- """
245
- Initialize ConvTranspose layer with given parameters.
232
+ """Initialize ConvTranspose layer with given parameters.
246
233
 
247
234
  Args:
248
235
  c1 (int): Number of input channels.
@@ -259,8 +246,7 @@ class ConvTranspose(nn.Module):
259
246
  self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
260
247
 
261
248
  def forward(self, x):
262
- """
263
- Apply transposed convolution, batch normalization and activation to input.
249
+ """Apply transposed convolution, batch normalization and activation to input.
264
250
 
265
251
  Args:
266
252
  x (torch.Tensor): Input tensor.
@@ -271,8 +257,7 @@ class ConvTranspose(nn.Module):
271
257
  return self.act(self.bn(self.conv_transpose(x)))
272
258
 
273
259
  def forward_fuse(self, x):
274
- """
275
- Apply activation and convolution transpose operation to input.
260
+ """Apply activation and convolution transpose operation to input.
276
261
 
277
262
  Args:
278
263
  x (torch.Tensor): Input tensor.
@@ -284,8 +269,7 @@ class ConvTranspose(nn.Module):
284
269
 
285
270
 
286
271
  class Focus(nn.Module):
287
- """
288
- Focus module for concentrating feature information.
272
+ """Focus module for concentrating feature information.
289
273
 
290
274
  Slices input tensor into 4 parts and concatenates them in the channel dimension.
291
275
 
@@ -294,8 +278,7 @@ class Focus(nn.Module):
294
278
  """
295
279
 
296
280
  def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):
297
- """
298
- Initialize Focus module with given parameters.
281
+ """Initialize Focus module with given parameters.
299
282
 
300
283
  Args:
301
284
  c1 (int): Number of input channels.
@@ -311,10 +294,9 @@ class Focus(nn.Module):
311
294
  # self.contract = Contract(gain=2)
312
295
 
313
296
  def forward(self, x):
314
- """
315
- Apply Focus operation and convolution to input tensor.
297
+ """Apply Focus operation and convolution to input tensor.
316
298
 
317
- Input shape is (b,c,w,h) and output shape is (b,4c,w/2,h/2).
299
+ Input shape is (B, C, W, H) and output shape is (B, 4C, W/2, H/2).
318
300
 
319
301
  Args:
320
302
  x (torch.Tensor): Input tensor.
@@ -327,8 +309,7 @@ class Focus(nn.Module):
327
309
 
328
310
 
329
311
  class GhostConv(nn.Module):
330
- """
331
- Ghost Convolution module.
312
+ """Ghost Convolution module.
332
313
 
333
314
  Generates more features with fewer parameters by using cheap operations.
334
315
 
@@ -341,8 +322,7 @@ class GhostConv(nn.Module):
341
322
  """
342
323
 
343
324
  def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
344
- """
345
- Initialize Ghost Convolution module with given parameters.
325
+ """Initialize Ghost Convolution module with given parameters.
346
326
 
347
327
  Args:
348
328
  c1 (int): Number of input channels.
@@ -358,8 +338,7 @@ class GhostConv(nn.Module):
358
338
  self.cv2 = Conv(c_, c_, 5, 1, None, c_, act=act)
359
339
 
360
340
  def forward(self, x):
361
- """
362
- Apply Ghost Convolution to input tensor.
341
+ """Apply Ghost Convolution to input tensor.
363
342
 
364
343
  Args:
365
344
  x (torch.Tensor): Input tensor.
@@ -372,8 +351,7 @@ class GhostConv(nn.Module):
372
351
 
373
352
 
374
353
  class RepConv(nn.Module):
375
- """
376
- RepConv module with training and deploy modes.
354
+ """RepConv module with training and deploy modes.
377
355
 
378
356
  This module is used in RT-DETR and can fuse convolutions during inference for efficiency.
379
357
 
@@ -391,8 +369,7 @@ class RepConv(nn.Module):
391
369
  default_act = nn.SiLU() # default activation
392
370
 
393
371
  def __init__(self, c1, c2, k=3, s=1, p=1, g=1, d=1, act=True, bn=False, deploy=False):
394
- """
395
- Initialize RepConv module with given parameters.
372
+ """Initialize RepConv module with given parameters.
396
373
 
397
374
  Args:
398
375
  c1 (int): Number of input channels.
@@ -418,8 +395,7 @@ class RepConv(nn.Module):
418
395
  self.conv2 = Conv(c1, c2, 1, s, p=(p - k // 2), g=g, act=False)
419
396
 
420
397
  def forward_fuse(self, x):
421
- """
422
- Forward pass for deploy mode.
398
+ """Forward pass for deploy mode.
423
399
 
424
400
  Args:
425
401
  x (torch.Tensor): Input tensor.
@@ -430,8 +406,7 @@ class RepConv(nn.Module):
430
406
  return self.act(self.conv(x))
431
407
 
432
408
  def forward(self, x):
433
- """
434
- Forward pass for training mode.
409
+ """Forward pass for training mode.
435
410
 
436
411
  Args:
437
412
  x (torch.Tensor): Input tensor.
@@ -443,8 +418,7 @@ class RepConv(nn.Module):
443
418
  return self.act(self.conv1(x) + self.conv2(x) + id_out)
444
419
 
445
420
  def get_equivalent_kernel_bias(self):
446
- """
447
- Calculate equivalent kernel and bias by fusing convolutions.
421
+ """Calculate equivalent kernel and bias by fusing convolutions.
448
422
 
449
423
  Returns:
450
424
  (torch.Tensor): Equivalent kernel
@@ -457,8 +431,7 @@ class RepConv(nn.Module):
457
431
 
458
432
  @staticmethod
459
433
  def _pad_1x1_to_3x3_tensor(kernel1x1):
460
- """
461
- Pad a 1x1 kernel to 3x3 size.
434
+ """Pad a 1x1 kernel to 3x3 size.
462
435
 
463
436
  Args:
464
437
  kernel1x1 (torch.Tensor): 1x1 convolution kernel.
@@ -472,15 +445,14 @@ class RepConv(nn.Module):
472
445
  return torch.nn.functional.pad(kernel1x1, [1, 1, 1, 1])
473
446
 
474
447
  def _fuse_bn_tensor(self, branch):
475
- """
476
- Fuse batch normalization with convolution weights.
448
+ """Fuse batch normalization with convolution weights.
477
449
 
478
450
  Args:
479
451
  branch (Conv | nn.BatchNorm2d | None): Branch to fuse.
480
452
 
481
453
  Returns:
482
- (torch.Tensor): Fused kernel
483
- (torch.Tensor): Fused bias
454
+ kernel (torch.Tensor): Fused kernel.
455
+ bias (torch.Tensor): Fused bias.
484
456
  """
485
457
  if branch is None:
486
458
  return 0, 0
@@ -538,8 +510,7 @@ class RepConv(nn.Module):
538
510
 
539
511
 
540
512
  class ChannelAttention(nn.Module):
541
- """
542
- Channel-attention module for feature recalibration.
513
+ """Channel-attention module for feature recalibration.
543
514
 
544
515
  Applies attention weights to channels based on global average pooling.
545
516
 
@@ -553,8 +524,7 @@ class ChannelAttention(nn.Module):
553
524
  """
554
525
 
555
526
  def __init__(self, channels: int) -> None:
556
- """
557
- Initialize Channel-attention module.
527
+ """Initialize Channel-attention module.
558
528
 
559
529
  Args:
560
530
  channels (int): Number of input channels.
@@ -565,8 +535,7 @@ class ChannelAttention(nn.Module):
565
535
  self.act = nn.Sigmoid()
566
536
 
567
537
  def forward(self, x: torch.Tensor) -> torch.Tensor:
568
- """
569
- Apply channel attention to input tensor.
538
+ """Apply channel attention to input tensor.
570
539
 
571
540
  Args:
572
541
  x (torch.Tensor): Input tensor.
@@ -578,8 +547,7 @@ class ChannelAttention(nn.Module):
578
547
 
579
548
 
580
549
  class SpatialAttention(nn.Module):
581
- """
582
- Spatial-attention module for feature recalibration.
550
+ """Spatial-attention module for feature recalibration.
583
551
 
584
552
  Applies attention weights to spatial dimensions based on channel statistics.
585
553
 
@@ -589,8 +557,7 @@ class SpatialAttention(nn.Module):
589
557
  """
590
558
 
591
559
  def __init__(self, kernel_size=7):
592
- """
593
- Initialize Spatial-attention module.
560
+ """Initialize Spatial-attention module.
594
561
 
595
562
  Args:
596
563
  kernel_size (int): Size of the convolutional kernel (3 or 7).
@@ -602,8 +569,7 @@ class SpatialAttention(nn.Module):
602
569
  self.act = nn.Sigmoid()
603
570
 
604
571
  def forward(self, x):
605
- """
606
- Apply spatial attention to input tensor.
572
+ """Apply spatial attention to input tensor.
607
573
 
608
574
  Args:
609
575
  x (torch.Tensor): Input tensor.
@@ -615,8 +581,7 @@ class SpatialAttention(nn.Module):
615
581
 
616
582
 
617
583
  class CBAM(nn.Module):
618
- """
619
- Convolutional Block Attention Module.
584
+ """Convolutional Block Attention Module.
620
585
 
621
586
  Combines channel and spatial attention mechanisms for comprehensive feature refinement.
622
587
 
@@ -626,8 +591,7 @@ class CBAM(nn.Module):
626
591
  """
627
592
 
628
593
  def __init__(self, c1, kernel_size=7):
629
- """
630
- Initialize CBAM with given parameters.
594
+ """Initialize CBAM with given parameters.
631
595
 
632
596
  Args:
633
597
  c1 (int): Number of input channels.
@@ -638,8 +602,7 @@ class CBAM(nn.Module):
638
602
  self.spatial_attention = SpatialAttention(kernel_size)
639
603
 
640
604
  def forward(self, x):
641
- """
642
- Apply channel and spatial attention sequentially to input tensor.
605
+ """Apply channel and spatial attention sequentially to input tensor.
643
606
 
644
607
  Args:
645
608
  x (torch.Tensor): Input tensor.
@@ -651,16 +614,14 @@ class CBAM(nn.Module):
651
614
 
652
615
 
653
616
  class Concat(nn.Module):
654
- """
655
- Concatenate a list of tensors along specified dimension.
617
+ """Concatenate a list of tensors along specified dimension.
656
618
 
657
619
  Attributes:
658
620
  d (int): Dimension along which to concatenate tensors.
659
621
  """
660
622
 
661
623
  def __init__(self, dimension=1):
662
- """
663
- Initialize Concat module.
624
+ """Initialize Concat module.
664
625
 
665
626
  Args:
666
627
  dimension (int): Dimension along which to concatenate tensors.
@@ -668,12 +629,11 @@ class Concat(nn.Module):
668
629
  super().__init__()
669
630
  self.d = dimension
670
631
 
671
- def forward(self, x):
672
- """
673
- Concatenate input tensors along specified dimension.
632
+ def forward(self, x: list[torch.Tensor]):
633
+ """Concatenate input tensors along specified dimension.
674
634
 
675
635
  Args:
676
- x (List[torch.Tensor]): List of input tensors.
636
+ x (list[torch.Tensor]): List of input tensors.
677
637
 
678
638
  Returns:
679
639
  (torch.Tensor): Concatenated tensor.
@@ -682,16 +642,14 @@ class Concat(nn.Module):
682
642
 
683
643
 
684
644
  class Index(nn.Module):
685
- """
686
- Returns a particular index of the input.
645
+ """Returns a particular index of the input.
687
646
 
688
647
  Attributes:
689
648
  index (int): Index to select from input.
690
649
  """
691
650
 
692
651
  def __init__(self, index=0):
693
- """
694
- Initialize Index module.
652
+ """Initialize Index module.
695
653
 
696
654
  Args:
697
655
  index (int): Index to select from input.
@@ -699,12 +657,11 @@ class Index(nn.Module):
699
657
  super().__init__()
700
658
  self.index = index
701
659
 
702
- def forward(self, x):
703
- """
704
- Select and return a particular index from input.
660
+ def forward(self, x: list[torch.Tensor]):
661
+ """Select and return a particular index from input.
705
662
 
706
663
  Args:
707
- x (List[torch.Tensor]): List of input tensors.
664
+ x (list[torch.Tensor]): List of input tensors.
708
665
 
709
666
  Returns:
710
667
  (torch.Tensor): Selected tensor.