ObjectDetector¶
Anchor-free object detector with timm backbones and Feature Pyramid Networks, supporting FCOS and YOLOX architectures.
Overview¶
ObjectDetector is a PyTorch Lightning module for object detection that combines:
- Any timm backbone for feature extraction
- Feature Pyramid Network (FPN) for multi-scale features
- FCOS or YOLOX detection head (configurable via
detection_arch) - Focal Loss, GIoU Loss, and Centerness Loss (FCOS) or YOLOX losses
- NMS post-processing for inference
- Configurable optimizer and scheduler
API Reference¶
autotimm.ObjectDetector ¶
Bases: PreprocessingMixin, LightningModule
End-to-end object detector supporting FCOS and YOLOX architectures.
Architecture: timm backbone → FPN → Detection Head (FCOS/YOLOX) → NMS
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone
|
str | FeatureBackboneConfig
|
A timm model name (str) or a :class: |
required |
num_classes
|
int
|
Number of object classes (excluding background). |
required |
detection_arch
|
str
|
Detection architecture to use. Options: |
'fcos'
|
cls_loss_fn
|
str | Module | None
|
Classification loss function. Can be: - A string from the loss registry (e.g., 'focal') - An instance of nn.Module (custom loss) - None (uses FocalLoss with focal_alpha and focal_gamma) |
None
|
reg_loss_fn
|
str | Module | None
|
Regression loss function. Can be: - A string from the loss registry (e.g., 'giou') - An instance of nn.Module (custom loss) - None (uses GIoULoss) |
None
|
metrics
|
MetricManager | list[MetricConfig] | None
|
A :class: |
None
|
logging_config
|
LoggingConfig | None
|
Optional :class: |
None
|
transform_config
|
TransformConfig | None
|
Optional :class: |
None
|
lr
|
float
|
Learning rate. |
0.0001
|
weight_decay
|
float
|
Weight decay for optimizer. |
0.0001
|
optimizer
|
str | dict[str, Any]
|
Optimizer name ( |
'adamw'
|
optimizer_kwargs
|
dict[str, Any] | None
|
Additional kwargs for the optimizer. |
None
|
scheduler
|
str | dict[str, Any] | None
|
Scheduler name ( |
'cosine'
|
scheduler_kwargs
|
dict[str, Any] | None
|
Extra kwargs forwarded to the LR scheduler. |
None
|
fpn_channels
|
int
|
Number of channels in FPN layers. |
256
|
head_num_convs
|
int
|
Number of conv layers in detection head branches. |
4
|
focal_alpha
|
float
|
Alpha parameter for focal loss. |
0.25
|
focal_gamma
|
float
|
Gamma parameter for focal loss. |
2.0
|
cls_loss_weight
|
float
|
Weight for classification loss. |
1.0
|
reg_loss_weight
|
float
|
Weight for regression loss. |
1.0
|
centerness_loss_weight
|
float
|
Weight for centerness loss (FCOS only). |
1.0
|
score_thresh
|
float
|
Score threshold for detections during inference. |
0.05
|
nms_thresh
|
float
|
IoU threshold for NMS. |
0.5
|
max_detections_per_image
|
int
|
Maximum detections to keep per image. |
100
|
freeze_backbone
|
bool
|
If |
False
|
strides
|
tuple[int, ...]
|
FPN output strides. Default (8, 16, 32, 64, 128) for P3-P7. |
(8, 16, 32, 64, 128)
|
regress_ranges
|
tuple[tuple[int, int], ...] | None
|
Regression ranges for each FPN level (FCOS only). |
None
|
compile_model
|
bool
|
If |
True
|
compile_kwargs
|
dict[str, Any] | None
|
Optional dict of kwargs to pass to |
None
|
seed
|
int | None
|
Random seed for reproducibility. If |
None
|
deterministic
|
bool
|
If |
True
|
Example
model = ObjectDetector( ... backbone="resnet50", ... num_classes=80, ... metrics=[ ... MetricConfig( ... name="mAP", ... backend="torchmetrics", ... metric_class="MeanAveragePrecision", ... params={}, ... stages=["val", "test"], ... ), ... ], ... lr=1e-4, ... )
Source code in src/autotimm/tasks/object_detection.py
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 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 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 | |
__init__ ¶
__init__(backbone: str | FeatureBackboneConfig, num_classes: int, detection_arch: str = 'fcos', cls_loss_fn: str | Module | None = None, reg_loss_fn: str | Module | None = None, metrics: MetricManager | list[MetricConfig] | None = None, logging_config: LoggingConfig | None = None, transform_config: TransformConfig | None = None, lr: float = 0.0001, weight_decay: float = 0.0001, optimizer: str | dict[str, Any] = 'adamw', optimizer_kwargs: dict[str, Any] | None = None, scheduler: str | dict[str, Any] | None = 'cosine', scheduler_kwargs: dict[str, Any] | None = None, fpn_channels: int = 256, head_num_convs: int = 4, focal_alpha: float = 0.25, focal_gamma: float = 2.0, cls_loss_weight: float = 1.0, reg_loss_weight: float = 1.0, centerness_loss_weight: float = 1.0, score_thresh: float = 0.05, nms_thresh: float = 0.5, max_detections_per_image: int = 100, freeze_backbone: bool = False, strides: tuple[int, ...] = (8, 16, 32, 64, 128), regress_ranges: tuple[tuple[int, int], ...] | None = None, compile_model: bool = True, compile_kwargs: dict[str, Any] | None = None, seed: int | None = None, deterministic: bool = True)
Source code in src/autotimm/tasks/object_detection.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 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 | |
forward ¶
Forward pass through the detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
Tensor
|
Input images [B, C, H, W]. |
required |
Returns:
| Type | Description |
|---|---|
list[Tensor]
|
Tuple of (cls_outputs, reg_outputs, centerness_outputs) per FPN level. |
list[Tensor]
|
For YOLOX, centerness_outputs is None. |
Source code in src/autotimm/tasks/object_detection.py
training_step ¶
Source code in src/autotimm/tasks/object_detection.py
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 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
validation_step ¶
Source code in src/autotimm/tasks/object_detection.py
test_step ¶
Source code in src/autotimm/tasks/object_detection.py
predict_step ¶
configure_optimizers ¶
Configure optimizer and learning rate scheduler.
Source code in src/autotimm/tasks/object_detection.py
to_onnx ¶
to_onnx(save_path: str | None = None, example_input: Tensor | None = None, opset_version: int = 17, dynamic_axes: dict[str, dict[int, str]] | None = None, **kwargs: Any) -> str
Export model to ONNX format.
Detection models flatten their list outputs into named tensors for ONNX compatibility (e.g., cls_l0..cls_l4, reg_l0..reg_l4, ctr_l0..ctr_l4).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_path
|
str | None
|
Path to save the ONNX model. If None, uses a temp file. |
None
|
example_input
|
Tensor | None
|
Example input tensor. If None, uses default shape (1, 3, 224, 224). |
None
|
opset_version
|
int
|
ONNX opset version. Default is 17. |
17
|
dynamic_axes
|
dict[str, dict[int, str]] | None
|
Dynamic axes specification. If None, batch dimension is dynamic. |
None
|
**kwargs
|
Any
|
Additional arguments passed to export_to_onnx. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the saved ONNX model. |
Example
model = ObjectDetector(backbone="resnet50", num_classes=80) path = model.to_onnx("detector.onnx")
Source code in src/autotimm/tasks/object_detection.py
Usage Examples¶
Basic Usage¶
import autotimm as at # recommended alias
from autotimm import ObjectDetector, MetricConfig
metrics = [
MetricConfig(
name="mAP",
backend="torchmetrics",
metric_class="MeanAveragePrecision",
params={"box_format": "xyxy", "iou_type": "bbox"},
stages=["val", "test"],
prog_bar=True,
),
]
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
lr=1e-4,
)
With FeatureBackboneConfig¶
from autotimm import FeatureBackboneConfig, ObjectDetector
cfg = FeatureBackboneConfig(
model_name="resnet50",
pretrained=True,
out_indices=(2, 3, 4), # C3, C4, C5
)
model = ObjectDetector(
backbone=cfg,
num_classes=80,
metrics=metrics,
)
With Transformer Backbone¶
model = ObjectDetector(
backbone="swin_tiny_patch4_window7_224",
num_classes=80,
metrics=metrics,
lr=1e-5, # Lower LR for transformers
fpn_channels=256,
)
Custom FPN and Head¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
fpn_channels=256, # FPN channels (128, 256, or 512)
head_num_convs=4, # Number of conv layers in head
)
Custom Loss Configuration¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
focal_alpha=0.25,
focal_gamma=2.0,
cls_loss_weight=1.0,
reg_loss_weight=1.0,
centerness_loss_weight=1.0,
)
Custom Inference Settings¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
score_thresh=0.05, # Confidence threshold
nms_thresh=0.5, # NMS IoU threshold
max_detections_per_image=100, # Max detections to keep
)
With TransformConfig (Preprocessing)¶
Enable inference-time preprocessing with model-specific normalization:
from autotimm import ObjectDetector, TransformConfig
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
transform_config=TransformConfig(), # Enable preprocess()
)
# Now you can preprocess raw images
from PIL import Image
image = Image.open("test.jpg")
tensor = model.preprocess(image) # Returns preprocessed tensor
output = model(tensor)
Get Model's Data Config¶
model = ObjectDetector(
backbone="swin_tiny_patch4_window7_224",
num_classes=80,
metrics=metrics,
transform_config=TransformConfig(),
)
# Get normalization config
config = model.get_data_config()
print(f"Mean: {config['mean']}")
print(f"Std: {config['std']}")
print(f"Input size: {config['input_size']}")
Frozen Backbone¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
freeze_backbone=True, # Only train FPN and head
lr=1e-3, # Higher LR when backbone frozen
)
With MultiStep Scheduler¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
lr=1e-4,
scheduler="multistep",
scheduler_kwargs={"milestones": [8, 11], "gamma": 0.1},
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
backbone |
str \| FeatureBackboneConfig |
Required | Model name or config |
num_classes |
int |
Required | Number of object classes |
detection_arch |
str |
"fcos" |
Detection architecture ("fcos" or "yolox") |
cls_loss_fn |
str \| nn.Module \| None |
None |
Classification loss function (string from registry, nn.Module, or None for default) |
reg_loss_fn |
str \| nn.Module \| None |
None |
Regression loss function (string from registry, nn.Module, or None for default) |
metrics |
MetricManager \| list[MetricConfig] |
None |
Metrics configuration |
logging_config |
LoggingConfig \| None |
None |
Enhanced logging options |
transform_config |
TransformConfig \| None |
None |
Transform config for preprocessing |
lr |
float |
1e-4 |
Learning rate |
weight_decay |
float |
1e-4 |
Weight decay |
optimizer |
str \| dict |
"adamw" |
Optimizer name or config |
optimizer_kwargs |
dict \| None |
None |
Extra optimizer kwargs |
scheduler |
str \| dict \| None |
"cosine" |
Scheduler name or config |
scheduler_kwargs |
dict \| None |
None |
Extra scheduler kwargs |
fpn_channels |
int |
256 |
Number of FPN channels |
head_num_convs |
int |
4 |
Conv layers in detection head |
focal_alpha |
float |
0.25 |
Focal loss alpha |
focal_gamma |
float |
2.0 |
Focal loss gamma |
cls_loss_weight |
float |
1.0 |
Classification loss weight |
reg_loss_weight |
float |
1.0 |
Regression loss weight |
centerness_loss_weight |
float |
1.0 |
Centerness loss weight |
score_thresh |
float |
0.05 |
Score threshold for detections |
nms_thresh |
float |
0.5 |
NMS IoU threshold |
max_detections_per_image |
int |
100 |
Max detections per image |
freeze_backbone |
bool |
False |
Freeze backbone weights |
strides |
tuple[int, ...] |
(8, 16, 32, 64, 128) |
FPN strides |
regress_ranges |
tuple \| None |
None |
Custom regression ranges (FCOS only) |
compile_model |
bool |
True |
Apply torch.compile() for faster training/inference (PyTorch 2.0+) |
compile_kwargs |
dict \| None |
None |
Kwargs for torch.compile() (e.g., mode, fullgraph, dynamic) |
seed |
int \| None |
None |
Random seed for reproducibility (None to disable seeding) |
deterministic |
bool |
True |
Enable deterministic algorithms (may impact performance) |
Model Architecture¶
ObjectDetector
├── backbone (timm feature extractor)
│ └── Multi-scale features: C3, C4, C5
├── fpn (Feature Pyramid Network)
│ └── Pyramid levels: P3, P4, P5, P6, P7
├── detection_head (DetectionHead)
│ ├── cls_subnet → classification logits
│ ├── bbox_subnet → bbox offsets (l, t, r, b)
│ └── centerness_subnet → centerness scores
└── loss_fn (FCOSLoss)
├── FocalLoss (classification)
├── GIoULoss (bbox regression)
└── CenternessLoss (center-ness)
FCOS Architecture¶
Feature Pyramid Network (FPN):
- Takes C3, C4, C5 features from backbone
- Builds pyramid levels P3-P7 via top-down and lateral connections
- Each pyramid level detects objects at different scales
Regression Ranges: Objects are assigned to FPN levels based on their size:
| Level | Stride | Default Range | Object Size |
|---|---|---|---|
| P3 | 8 | (-1, 64) | Very small |
| P4 | 16 | (64, 128) | Small |
| P5 | 32 | (128, 256) | Medium |
| P6 | 64 | (256, 512) | Large |
| P7 | 128 | (512, ∞) | Very large |
Detection Head:
- Shared across all FPN levels
- 3 branches: classification, bbox regression, centerness
- Each branch has 4 conv layers (configurable via
head_num_convs)
Loss Functions:
- Focal Loss: Handles class imbalance in one-stage detectors
- GIoU Loss: IoU-based metric for bbox regression
- Centerness Loss: Suppresses low-quality detections far from object centers
Backbone Selection¶
CNN Backbones¶
| Backbone | Speed | Accuracy | Use Case |
|---|---|---|---|
resnet18 |
Fast | Good | Quick experiments |
resnet50 |
Medium | Better | Standard baseline |
efficientnet_b3 |
Medium | Better | Efficiency |
convnext_tiny |
Medium | Best | Modern CNN |
resnet101 |
Slow | Best | High accuracy |
Transformer Backbones¶
| Backbone | Speed | Memory | Use Case |
|---|---|---|---|
swin_tiny_patch4_window7_224 |
Fast | Medium | Balanced |
swin_small_patch4_window7_224 |
Medium | Medium | Production |
swin_base_patch4_window7_224 |
Slow | High | Maximum accuracy |
vit_base_patch16_224 |
Slow | High | Research |
Notes:
- Swin Transformers work best for detection (hierarchical features)
- Use smaller batch sizes (8-16) with transformers
- Use lower learning rates (1e-5) with transformer backbones
Logged Metrics¶
| Metric | Stage | Condition |
|---|---|---|
{stage}/loss |
train, val, test | Always |
{stage}/cls_loss |
train, val, test | Always |
{stage}/reg_loss |
train, val, test | Always |
{stage}/centerness_loss |
train, val, test | Always |
{stage}/{metric_name} |
As configured | Per MetricConfig |
train/lr |
train | log_learning_rate=True |
train/grad_norm |
train | log_gradient_norm=True |
Training Tips¶
Standard COCO Training¶
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
lr=1e-4,
scheduler="multistep",
scheduler_kwargs={"milestones": [8, 11], "gamma": 0.1},
)
trainer = AutoTrainer(
max_epochs=12,
gradient_clip_val=1.0,
)
Two-Phase Training (Recommended)¶
# Phase 1: Train FPN and head only
model = ObjectDetector(
backbone="resnet50",
num_classes=80,
metrics=metrics,
freeze_backbone=True,
lr=1e-3,
)
trainer = AutoTrainer(max_epochs=3)
trainer.fit(model, datamodule=data)
# Phase 2: Fine-tune entire model
for param in model.backbone.parameters():
param.requires_grad = True
model._lr = 1e-4
trainer = AutoTrainer(max_epochs=12, gradient_clip_val=1.0)
trainer.fit(model, datamodule=data)
Small Object Detection¶
For better small object detection:
model = ObjectDetector(
backbone="resnet50",
num_classes=num_classes,
metrics=metrics,
fpn_channels=256, # More capacity
head_num_convs=4, # Deeper head
# Adjust regression ranges to emphasize smaller levels
regress_ranges=(
(-1, 32), # P3: extra small
(32, 64), # P4: very small
(64, 128), # P5: small
(128, 256), # P6: medium
(256, float("inf")), # P7: large
),
)