Reference for ultralytics/nn/modules/head.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/head.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.nn.modules.head.Detect
Bases: Module
YOLOv8 Detect head for detection models.
Source code in ultralytics/nn/modules/head.py
__init__(nc=80, ch=())
Initializes the YOLOv8 detection layer with specified number of classes and channels.
Source code in ultralytics/nn/modules/head.py
bias_init()
Initialize Detect() biases, WARNING: requires stride availability.
Source code in ultralytics/nn/modules/head.py
forward(x)
Concatenates and returns predicted bounding boxes and class probabilities.
Source code in ultralytics/nn/modules/head.py
ultralytics.nn.modules.head.Segment
Bases: Detect
YOLOv8 Segment head for segmentation models.
Source code in ultralytics/nn/modules/head.py
__init__(nc=80, nm=32, npr=256, ch=())
Initialize the YOLO model attributes such as the number of masks, prototypes, and the convolution layers.
Source code in ultralytics/nn/modules/head.py
forward(x)
Return model outputs and mask coefficients if training, otherwise return outputs and mask coefficients.
Source code in ultralytics/nn/modules/head.py
ultralytics.nn.modules.head.Pose
Bases: Detect
YOLOv8 Pose head for keypoints models.
Source code in ultralytics/nn/modules/head.py
__init__(nc=80, kpt_shape=(17, 3), ch=())
Initialize YOLO network with default parameters and Convolutional Layers.
Source code in ultralytics/nn/modules/head.py
forward(x)
Perform forward pass through YOLO model and return predictions.
Source code in ultralytics/nn/modules/head.py
kpts_decode(bs, kpts)
Decodes keypoints.
Source code in ultralytics/nn/modules/head.py
ultralytics.nn.modules.head.Classify
Bases: Module
YOLOv8 classification head, i.e. x(b,c1,20,20) to x(b,c2).
Source code in ultralytics/nn/modules/head.py
__init__(c1, c2, k=1, s=1, p=None, g=1)
Initializes YOLOv8 classification head with specified input and output channels, kernel size, stride, padding, and groups.
Source code in ultralytics/nn/modules/head.py
forward(x)
Performs a forward pass of the YOLO model on input image data.
Source code in ultralytics/nn/modules/head.py
ultralytics.nn.modules.head.RTDETRDecoder
Bases: Module
Real-Time Deformable Transformer Decoder (RTDETRDecoder) module for object detection.
This decoder module utilizes Transformer architecture along with deformable convolutions to predict bounding boxes and class labels for objects in an image. It integrates features from multiple layers and runs through a series of Transformer decoder layers to output the final predictions.
Source code in ultralytics/nn/modules/head.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
__init__(nc=80, ch=(512, 1024, 2048), hd=256, nq=300, ndp=4, nh=8, ndl=6, d_ffn=1024, dropout=0.0, act=nn.ReLU(), eval_idx=-1, nd=100, label_noise_ratio=0.5, box_noise_scale=1.0, learnt_init_query=False)
Initializes the RTDETRDecoder module with the given parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nc |
int
|
Number of classes. Default is 80. |
80
|
ch |
tuple
|
Channels in the backbone feature maps. Default is (512, 1024, 2048). |
(512, 1024, 2048)
|
hd |
int
|
Dimension of hidden layers. Default is 256. |
256
|
nq |
int
|
Number of query points. Default is 300. |
300
|
ndp |
int
|
Number of decoder points. Default is 4. |
4
|
nh |
int
|
Number of heads in multi-head attention. Default is 8. |
8
|
ndl |
int
|
Number of decoder layers. Default is 6. |
6
|
d_ffn |
int
|
Dimension of the feed-forward networks. Default is 1024. |
1024
|
dropout |
float
|
Dropout rate. Default is 0. |
0.0
|
act |
Module
|
Activation function. Default is nn.ReLU. |
ReLU()
|
eval_idx |
int
|
Evaluation index. Default is -1. |
-1
|
nd |
int
|
Number of denoising. Default is 100. |
100
|
label_noise_ratio |
float
|
Label noise ratio. Default is 0.5. |
0.5
|
box_noise_scale |
float
|
Box noise scale. Default is 1.0. |
1.0
|
learnt_init_query |
bool
|
Whether to learn initial query embeddings. Default is False. |
False
|
Source code in ultralytics/nn/modules/head.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
forward(x, batch=None)
Runs the forward pass of the module, returning bounding box and classification scores for the input.