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
decode_bboxes(bboxes, anchors)
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.OBB
Bases: Detect
YOLOv8 OBB detection head for detection with rotation models.
Source code in ultralytics/nn/modules/head.py
__init__(nc=80, ne=1, ch=())
Initialize OBB with number of classes nc
and layer channels ch
.
Source code in ultralytics/nn/modules/head.py
decode_bboxes(bboxes, anchors)
forward(x)
Concatenates and returns predicted bounding boxes and class probabilities.
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.WorldDetect
Bases: Detect
Source code in ultralytics/nn/modules/head.py
__init__(nc=80, embed=512, with_bn=False, ch=())
Initialize YOLOv8 detection layer with nc classes and layer channels ch.
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, text)
Concatenates and returns predicted bounding boxes and class probabilities.
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
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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
__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
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 |
|
forward(x, batch=None)
Runs the forward pass of the module, returning bounding box and classification scores for the input.