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