Data API Reference¶
oriented_det.data
¶
Data loading, tiling, transforms, and evaluation for oriented detection.
APCalculator
¶
Calculate Average Precision (AP) for oriented object detection.
Source code in oriented_det/data/evaluation.py
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 | |
compute_ap(detections, ground_truths, *, class_name=None, show_progress=False, progress_stream=None, max_iou_calculations=None, min_box_size=1.0)
¶
Compute Average Precision for a single class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detections
|
Sequence[Detection]
|
List of detections |
required |
ground_truths
|
Sequence[GroundTruth]
|
List of ground truths |
required |
class_name
|
Optional[str]
|
Optional class name |
None
|
show_progress
|
bool
|
Whether to show progress bar |
False
|
max_iou_calculations
|
Optional[int]
|
Maximum number of IoU calculations to allow. If exceeded, will use approximate method or return 0.0. |
None
|
min_box_size
|
float
|
Minimum box size (width/height) in pixels to consider valid. Boxes smaller than this will be filtered out (default: 1.0). |
1.0
|
Source code in oriented_det/data/evaluation.py
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 | |
compute_map(all_detections, all_ground_truths, show_progress=True, progress_stream=None, max_iou_calculations_per_class=10000000, min_box_size=1.0)
¶
Compute mAP across all classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_detections
|
Dict[str, List[Detection]]
|
Dictionary mapping image_id -> list of Detection objects |
required |
all_ground_truths
|
Dict[str, List[GroundTruth]]
|
Dictionary mapping image_id -> list of GroundTruth objects |
required |
show_progress
|
bool
|
Whether to show progress bars |
True
|
max_iou_calculations_per_class
|
int
|
Maximum IoU calculations per class before optimization |
10000000
|
min_box_size
|
float
|
Minimum box size (width/height) in pixels to consider valid. Boxes smaller than this will be filtered out (default: 1.0). |
1.0
|
Returns:
| Type | Description |
|---|---|
Tuple[Dict[str, float], Dict[str, ClassEvalMetrics]]
|
|
Source code in oriented_det/data/evaluation.py
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 | |
AirbusPlaygroundCSVDataset
¶
CSV-backed Airbus Playground dataset yielding DOTASample objects.
Source code in oriented_det/data/airbus_playground.py
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 | |
empty_gt_filtered_count
property
¶
Tiles removed by filter_empty_gt at init.
tiles_discovered_count
property
¶
Tiles in split CSV before filter_empty_gt (if enabled).
get_raw_class_names_from_csv()
¶
Return unique class_name values in the CSV for the current split (before map_labels/ignore_labels). Useful to verify CSV content and that map_labels keys match.
Source code in oriented_det/data/airbus_playground.py
AlbumentationsTransform
¶
Wrapper for albumentations transforms that only apply non-geometric augmentations.
This transform applies albumentations augmentations that do not modify the spatial layout of the image (no rotation, scaling, translation, etc.) since albumentations does not support oriented bounding boxes. Only color, contrast, blur, noise, and similar augmentations are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
An albumentations Compose transform containing only non-geometric augmentations. The transform should work on numpy arrays (H, W, C). |
required | |
p
|
float
|
Probability of applying the transform (default: 1.0) |
1.0
|
Example
import albumentations as A from oriented_det.data import AlbumentationsTransform
Create non-geometric augmentation pipeline¶
aug = A.Compose([ ... A.RandomBrightnessContrast(p=0.5), ... A.RandomGamma(p=0.3), ... A.GaussNoise(p=0.2), ... A.GaussianBlur(p=0.2), ... A.CLAHE(p=0.3), ... ])
transform = AlbumentationsTransform(aug) augmented_image = transform(image) # PIL Image or numpy array
Source code in oriented_det/data/transforms.py
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 | |
__call__(image)
¶
Apply albumentations transform to image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
PIL Image or numpy array (H, W, C) in RGB format |
required |
Returns:
| Type | Description |
|---|---|
any
|
Transformed image in the same format as input |
Source code in oriented_det/data/transforms.py
ClassEvalMetrics
dataclass
¶
ClassGtBestIouMetrics
dataclass
¶
Per-class GT alignment: max IoU vs raw detections (before score filter).
Source code in oriented_det/data/evaluation.py
Compose
¶
Compose multiple transforms.
Source code in oriented_det/data/transforms.py
DOTAAnnotation
dataclass
¶
Single DOTA annotation entry.
Source code in oriented_det/data/dota.py
from_line(line, *, class_map=None)
classmethod
¶
Parse a single DOTA annotation line.
DOTA Polygon Format (official default):¶
Official DOTA (captain-whu.github.io) uses comma-separated: "x1, y1, x2, y2, x3, y3, x4, y4, category, difficult" We produce this format by default (see format_dota_line, to_line). For reading, we also accept space-separated: "x1 y1 x2 y2 x3 y3 x4 y4 class_name difficult" (class = parts[8:-1] for multi-word names).
Corner Order Convention: - The 4 corners are ordered sequentially around the polygon perimeter - Typically, corners follow a consistent winding order (clockwise or counter-clockwise) - The first corner (x1, y1) is usually the top-left or top-most point - Subsequent corners follow the polygon boundary
Conversion to QBox/RBox: - The polygon is first converted to a QBox, which normalizes the point order - QBox ensures counter-clockwise orientation and orders points starting from top-most - RBox is then derived from QBox, computing center, dimensions, and angle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
DOTA annotation line |
required |
class_map
|
Optional[Dict[str, int]]
|
Optional mapping from class names to IDs |
None
|
Returns:
| Type | Description |
|---|---|
'DOTAAnnotation'
|
DOTAAnnotation with parsed polygon and RBox |
Example
line = "100 200 300 200 300 400 100 400 plane 0" ann = DOTAAnnotation.from_line(line)
Creates a rectangle with corners at (100,200), (300,200), (300,400), (100,400)¶
Source code in oriented_det/data/dota.py
to_line()
¶
Serialize to official DOTA format (comma-separated).
DOTADataset
¶
Efficient DOTA dataset loader with lazy parsing.
Source code in oriented_det/data/dota.py
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 | |
annotation_files_discovered_count
property
¶
Label files found before filter_empty_gt (if enabled).
empty_gt_filtered_count
property
¶
Tiles removed by filter_empty_gt at init.
__init__(root_dir, *, split='train', split_file=None, label_dir=None, image_dir=None, class_map=None, allowed_classes=None, ignore_labels=None, difficult_strategy='drop', filter_empty_gt=False)
¶
Initialize DOTA dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_dir
|
str | Path
|
Root directory of DOTA dataset (used as base if label_dir/image_dir not specified) |
required |
split
|
str
|
Split name ("train", "val", "test") - used for pattern matching |
'train'
|
split_file
|
Optional[str | Path]
|
Optional path to a file listing image names (one per line). If provided, only images listed in this file will be used. This follows the official DOTA dataset convention where train.txt, val.txt, test.txt list the image names. |
None
|
label_dir
|
Optional[str | Path]
|
Optional custom path to label directory. If None, uses root_dir/labelTxt. This allows having train/val/test in separate folders. Can be the same as image_dir to read images and annotations from one folder. |
None
|
image_dir
|
Optional[str | Path]
|
Optional custom path to image directory. If None, uses root_dir/images. This allows having train/val/test in separate folders. Can be the same as label_dir to read images and annotations from one folder. |
None
|
class_map
|
Optional[Dict[str, int]]
|
Optional mapping from class names to numeric IDs |
None
|
allowed_classes
|
Optional[Sequence[str]]
|
Optional list of allowed class names (whitelist) |
None
|
ignore_labels
|
Optional[Sequence[str]]
|
Optional list of class names to exclude (blacklist) |
None
|
difficult_strategy
|
str
|
How to handle difficult annotations: drop | ignore | keep. |
'drop'
|
filter_empty_gt
|
bool
|
If True, drop tiles whose effective GT count is zero after difficult_strategy, allowed_classes, and ignore_labels (MMRotate DOTADataset parity). |
False
|
Source code in oriented_det/data/dota.py
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 | |
get_class_names()
¶
Extract unique class names from all annotations.
DOTASample
dataclass
¶
Single DOTA image sample with annotations.
Source code in oriented_det/data/dota.py
filter_by_class(allowed_classes=None, ignore_labels=None, drop_difficult=False)
¶
Return a filtered copy of this sample.
Source code in oriented_det/data/dota.py
Detection
dataclass
¶
Single detection result.
Source code in oriented_det/data/evaluation.py
DiagonalFlip
¶
Bases: OrientedTransform
Diagonal flip (MMRotate direction='diagonal', le90 angle π − θ).
Source code in oriented_det/data/transforms.py
GroundTruth
dataclass
¶
Single ground truth annotation.
Source code in oriented_det/data/evaluation.py
GtBestIouAlignmentMetrics
dataclass
¶
Global and per-class mean best IoU (per-GT max over raw detections).
Source code in oriented_det/data/evaluation.py
HorizontalFlip
¶
Bases: OrientedTransform
Horizontal flip transform for oriented boxes.
Source code in oriented_det/data/transforms.py
ImageTiler
¶
Efficient tiler for splitting large images into overlapping patches.
The tiler supports configurable overlap and minimum overlap thresholds for keeping annotations that cross tile boundaries.
Source code in oriented_det/data/tiling.py
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 | |
__init__(tile_size=1024, overlap=0.2, *, min_box_area=16.0, min_overlap_ratio=0.0, edge_handling='clip')
¶
Initialize ImageTiler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile_size
|
int
|
Size of each tile (width and height in pixels) |
1024
|
overlap
|
float
|
Overlap ratio between adjacent tiles [0, 1). overlap=0.2 means 20% overlap, so stride = tile_size * 0.8 |
0.2
|
min_box_area
|
float
|
Minimum area (in pixels²) for a box to be kept in a tile. Boxes smaller than this are filtered out. |
16.0
|
min_overlap_ratio
|
float
|
Minimum ratio of box area that must overlap with tile to keep the box. Range [0, 1]. - 0.0: Keep box if any part overlaps (default) - 0.5: Keep box only if >= 50% of its area is in tile - 1.0: Keep box only if fully inside tile |
0.0
|
edge_handling
|
str
|
Strategy for boxes crossing tile boundaries: - "clip": Keep boxes that overlap tile (default) - "ignore": Only keep boxes fully inside tile - "keep": Same as "clip" (kept for backward compatibility) |
'clip'
|
Example
tiler = ImageTiler( ... tile_size=1024, ... overlap=0.2, # 20% overlap between tiles ... min_box_area=64, # Filter boxes < 64 pixels² ... min_overlap_ratio=0.3, # Keep box if >= 30% overlaps tile ... )
Source code in oriented_det/data/tiling.py
assign_boxes_to_tile(tile, rboxes, class_names, difficult_flags=None)
¶
Assign boxes to a tile, applying edge handling and overlap thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Target tile |
required |
rboxes
|
Sequence[RBox]
|
Sequence of RBox annotations |
required |
class_names
|
Sequence[str]
|
Class names corresponding to rboxes |
required |
difficult_flags
|
Optional[Sequence[int]]
|
Optional difficulty flags |
None
|
Returns:
| Type | Description |
|---|---|
TiledSample
|
TiledSample with boxes assigned to the tile |
Source code in oriented_det/data/tiling.py
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 | |
generate_tiles(image_width, image_height, *, prefix='tile')
¶
Generate tile grid for an image of given dimensions.
Source code in oriented_det/data/tiling.py
tile_image(image_path, image_width, image_height, rboxes, class_names, difficult_flags=None)
¶
Generate tiled samples from an image and its annotations.
Source code in oriented_det/data/tiling.py
OrientedTransform
dataclass
¶
Base class for transforms that modify both image and oriented boxes.
Source code in oriented_det/data/transforms.py
Rotate
¶
Bases: OrientedTransform
Rotation transform for oriented boxes.
Source code in oriented_det/data/transforms.py
apply_to_rbox(rbox, image_width, image_height)
¶
Rotate RBox around image center.
Source code in oriented_det/data/transforms.py
Tile
dataclass
¶
Represents a single tile/patch from a larger image.
Source code in oriented_det/data/tiling.py
bounds
property
¶
Returns (x, y, x + width, y + height).
clip_box(rbox)
¶
Clip an RBox to this tile's bounds, returning None if fully outside.
Source code in oriented_det/data/tiling.py
TiledSample
dataclass
¶
A sample with its annotations clipped to a specific tile.
Source code in oriented_det/data/tiling.py
VerticalFlip
¶
Bases: OrientedTransform
Vertical flip transform for oriented boxes.
Source code in oriented_det/data/transforms.py
apply_random_train_flips(image, rboxes, *, image_width, image_height, enable_horizontal=True, enable_vertical=True, enable_diagonal=False)
¶
Pick at most one random flip (MMRotate DOTA-style 25% per enabled mode).
When horizontal, vertical, and diagonal are all enabled, each has probability
0.25 and there is a 0.25 chance of no flip — matching
RRandomFlip(flip_ratio=[0.25, 0.25, 0.25],
direction=['horizontal', 'vertical', 'diagonal']).
With only horizontal and vertical enabled (no diagonal), uses 0.5 per enabled mode and no no-flip bucket (legacy two-flip behavior).
Source code in oriented_det/data/flips.py
build_dota_loader(root_dir, *, split='train', split_file=None, label_dir=None, image_dir=None, batch_size=1, shuffle=False, num_workers=0, class_map=None, allowed_classes=None, ignore_labels=None, difficult_strategy='drop', filter_empty_gt=False, collate_fn=None)
¶
Build a PyTorch DataLoader for DOTA dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_dir
|
str | Path
|
Root directory of DOTA dataset (used as base if label_dir/image_dir not specified) |
required |
split
|
str
|
Split name ("train", "val", "test") |
'train'
|
split_file
|
Optional[str | Path]
|
Optional path to a file listing image names (one per line). If provided, only images listed in this file will be used. This follows the official DOTA dataset convention. |
None
|
label_dir
|
Optional[str | Path]
|
Optional custom path to label directory. If None, uses root_dir/labelTxt. This allows having train/val/test in separate folders. |
None
|
image_dir
|
Optional[str | Path]
|
Optional custom path to image directory. If None, uses root_dir/images. This allows having train/val/test in separate folders. |
None
|
batch_size
|
int
|
Batch size for DataLoader |
1
|
shuffle
|
bool
|
Whether to shuffle the dataset |
False
|
num_workers
|
int
|
Number of worker processes for data loading |
0
|
class_map
|
Optional[Dict[str, int]]
|
Optional mapping from class names to numeric IDs |
None
|
allowed_classes
|
Optional[Sequence[str]]
|
Optional list of allowed class names (whitelist) |
None
|
ignore_labels
|
Optional[Sequence[str]]
|
Optional list of class names to exclude (blacklist) |
None
|
difficult_strategy
|
str
|
drop | ignore | keep (same as DOTADataset) |
'drop'
|
filter_empty_gt
|
bool
|
Drop tiles with no effective GT (same as DOTADataset) |
False
|
collate_fn
|
Optional[Callable]
|
Optional custom collate function. If None, uses collate_dota_samples from oriented_det.train.utils which converts DOTASample objects to (images, targets) format expected by training engines. |
None
|
Returns:
| Type | Description |
|---|---|
'DataLoader'
|
DataLoader that yields batches in format determined by collate_fn. |
'DataLoader'
|
Default collate_fn returns (images, targets) tuple for training. |
Source code in oriented_det/data/dota.py
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 | |
build_dota_split_dataset(tile_roots, *, split, same_folder=False, difficult_strategy='drop', allowed_classes=None, ignore_labels=None, filter_empty_gt=False)
¶
Build one DOTADataset or ConcatDataset over multiple tile roots.
Source code in oriented_det/data/dota.py
collect_dota_image_paths(tile_roots, *, same_folder=False)
¶
Collect image paths from one or more DOTA tile directories.
Source code in oriented_det/data/dota.py
collect_dota_split_image_paths(tile_roots, *, split, same_folder=False, difficult_strategy='drop', allowed_classes=None, ignore_labels=None, filter_empty_gt=False, log_filter_empty_gt=False)
¶
Collect image paths using the same tile set as :func:build_dota_split_dataset.
When filter_empty_gt is True, skips tiles with no effective GT after
difficult_strategy, allowed_classes, and ignore_labels (training parity).
Set log_filter_empty_gt to print the same summary as training startup.
Source code in oriented_det/data/dota.py
compute_gt_best_iou_alignment_metrics(all_detections, all_ground_truths, *, class_names=None, skip_difficult=False, use_exact_rotated_iou=True, device=None, show_progress=False, progress_stream=None)
¶
Per-GT max rotated IoU vs raw detections (global + per-class means).
For each non-skipped GT, best_any is the max IoU over all detections on the
same image; best_same restricts to same-class detections. Uses exact polygon
IoU on CPU when use_exact_rotated_iou is true (same as mAP matching).
Source code in oriented_det/data/evaluation.py
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 | |
create_albumentations_augmentation(brightness_limit=0.2, contrast_limit=0.2, gamma_limit=(80, 120), gauss_noise_var_limit=(10.0, 50.0), blur_limit=3, clahe_clip_limit=4.0, p_brightness_contrast=0.5, p_gamma=0.3, p_noise=0.2, p_blur=0.2, p_clahe=0.3)
¶
Create a default albumentations augmentation pipeline with non-geometric transforms.
This function creates a sensible default augmentation pipeline using only non-geometric transforms that are safe for oriented bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
brightness_limit
|
float
|
Range for brightness adjustment (-limit to +limit) |
0.2
|
contrast_limit
|
float
|
Range for contrast adjustment (-limit to +limit) |
0.2
|
gamma_limit
|
tuple
|
Range for gamma correction (as percentage, e.g., (80, 120)) |
(80, 120)
|
gauss_noise_var_limit
|
tuple
|
Variance range for Gaussian noise (will be converted to std_range internally) |
(10.0, 50.0)
|
blur_limit
|
int
|
Maximum kernel size for Gaussian blur (must be odd) |
3
|
clahe_clip_limit
|
float
|
Clip limit for CLAHE (Contrast Limited Adaptive Histogram Equalization) |
4.0
|
p_brightness_contrast
|
float
|
Probability of applying brightness/contrast |
0.5
|
p_gamma
|
float
|
Probability of applying gamma correction |
0.3
|
p_noise
|
float
|
Probability of adding Gaussian noise |
0.2
|
p_blur
|
float
|
Probability of applying Gaussian blur |
0.2
|
p_clahe
|
float
|
Probability of applying CLAHE |
0.3
|
Returns:
| Type | Description |
|---|---|
AlbumentationsTransform
|
AlbumentationsTransform instance with the configured augmentation pipeline |
Example
from oriented_det.data import create_albumentations_augmentation
Create default augmentation¶
aug = create_albumentations_augmentation()
Apply to image¶
augmented_image = aug(image)
Source code in oriented_det/data/transforms.py
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 | |
detect_airbus_split_csv_format(split_values)
¶
Infer whether split.csv uses legacy train/val strings or integer fold ids.
Fold mode: every non-empty value must parse as a non-negative int. Training code treats
fold val_split_id (default 0) as validation and all other folds as training, unless
train_includes_val is enabled (train on all folds; val fold for monitoring only).
Source code in oriented_det/data/airbus_playground.py
dota_dataset_class_names(dataset)
¶
Union class names from DOTADataset, ConcatDataset, or Subset.
Source code in oriented_det/data/dota.py
dota_label_path_for_image(image_path, *, same_folder=False)
¶
Resolve the DOTA annotation .txt path for an image file.
Source code in oriented_det/data/dota.py
format_airbus_empty_gt_filter_log(dataset, *, split)
¶
One-line summary for train logs when filter_empty_gt is enabled.
Source code in oriented_det/data/airbus_playground.py
format_dota_empty_gt_filter_log(dataset, *, split)
¶
One-line summary for train logs when filter_empty_gt is enabled.
Source code in oriented_det/data/dota.py
format_dota_line(x1, y1, x2, y2, x3, y3, x4, y4, category, difficult)
¶
Format a single annotation line in official DOTA format (comma-separated).
See https://captain-whu.github.io/DOTA/dataset.html
Source code in oriented_det/data/dota.py
format_gt_best_iou_alignment_table(metrics, class_names=None, *, markdown=False)
¶
Format per-class mean best IoU (same class) table.
Source code in oriented_det/data/evaluation.py
format_gt_best_iou_alignment_table_from_dict(data, class_names=None, *, markdown=False)
¶
Format table from :func:gt_best_iou_alignment_metrics_to_dict output.
Source code in oriented_det/data/evaluation.py
generate_airbus_playground_csvs(data_root, *, annotations_file='annotations.csv', split_file='split.csv', num_splits=10, seed=42, ignore_labels=None, map_labels=None, include_stats=False)
¶
Generate annotations.csv and split.csv from Airbus export folders.
Each image group (dataset_id, zone_id, image_id) is assigned an integer fold id in
0 .. num_splits-1 (balanced round-robin on a shuffled group list). The split column
stores that integer as text. By convention fold 0 is the default validation fold; set
dataset.val_split_id in the training config to use another fold as validation.
Source code in oriented_det/data/airbus_playground.py
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 | |
gt_best_iou_alignment_metrics_to_dict(metrics)
¶
JSON-serializable view of :class:GtBestIouAlignmentMetrics.
Source code in oriented_det/data/evaluation.py
resolve_dota_tile_roots(*, tiles_dirs=None, tiles_dir=None, split_label='split')
¶
Resolve one or more DOTA tile roots from singular/plural config fields.
Source code in oriented_det/data/dota.py
visualize_tiles(image_path, image_width, image_height, tiles, rboxes=None, class_names=None, *, output_path=None, tile_color=(255, 0, 0), box_color=(0, 255, 0), tile_width=2, box_width=2)
¶
Visualize tiles and annotations for debugging tiling operations.
This function helps debug tiling by drawing: - Tile boundaries in red (by default) - Annotations in green (by default) - Tile IDs as labels
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path
|
Path to the image file |
required |
image_width
|
int
|
Width of the image |
required |
image_height
|
int
|
Height of the image |
required |
tiles
|
Sequence[Tile]
|
Sequence of Tile objects to visualize |
required |
rboxes
|
Optional[Sequence[RBox]]
|
Optional sequence of RBox annotations |
None
|
class_names
|
Optional[Sequence[str]]
|
Optional class names for annotations |
None
|
output_path
|
Optional[Path]
|
Optional path to save visualization |
None
|
tile_color
|
Tuple[int, int, int]
|
RGB color for tile boundaries (default: red) |
(255, 0, 0)
|
box_color
|
Tuple[int, int, int]
|
RGB color for annotation boxes (default: green) |
(0, 255, 0)
|
tile_width
|
int
|
Line width for tile boundaries |
2
|
box_width
|
int
|
Line width for annotation boxes |
2
|
Returns:
| Type | Description |
|---|---|
any
|
PIL Image with visualization (or numpy array if PIL unavailable) |
Example
tiler = ImageTiler(tile_size=512, overlap=0.2) tiles = tiler.generate_tiles(2000, 2000) visualize_tiles( ... image_path=Path("image.png"), ... image_width=2000, ... image_height=2000, ... tiles=tiles, ... rboxes=annotations, ... output_path=Path("tiles_vis.png"), ... )
Source code in oriented_det/data/tiling.py
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 | |
Important Notes¶
DOTA Dataset Loading Modes¶
The DOTA loader supports three modes for organizing your dataset:
- Pattern matching (default): Matches annotation files by split pattern (e.g.,
*_train.txt) - Split file (official DOTA convention): Uses a file listing image names (e.g.,
train.txt) - Separate folders: Train/val/test in different directories
DOTA Polygon Format¶
- DOTA uses 8 coordinates:
x1 y1 x2 y2 x3 y3 x4 y4 class_name difficult - Corners are ordered sequentially around the polygon perimeter
- The loader converts polygons to
QBox(which normalizes point order) and then toRBox QBoxensures counter-clockwise orientation and orders points starting from top-most
Data Augmentation¶
OrientedDet supports two types of data augmentation:
- Geometric Transforms (Oriented Bounding Box Aware):
HorizontalFlip,VerticalFlip,Rotate,Compose - These transforms modify both the image and oriented bounding boxes
-
Angle information is preserved correctly
-
Albumentations (Non-Geometric Only):
create_albumentations_augmentation,AlbumentationsTransform - Only non-geometric augmentations are supported (color, contrast, blur, noise, etc.)
- Note: Albumentations does not support oriented bounding boxes, so only non-geometric transforms can be used
Examples¶
DOTA Dataset Loading¶
from oriented_det.data import DOTADataset, build_dota_loader
# Mode 1: Pattern matching (backward compatible)
dataset = DOTADataset(
root_dir="/path/to/dota",
split="train",
allowed_classes=["plane", "ship", "vehicle"],
difficult_strategy="drop"
)
# Mode 2: Using split file (official DOTA convention)
dataset = DOTADataset(
root_dir="/path/to/dota",
split="train",
split_file="train.txt", # Lists image names, one per line
allowed_classes=["plane", "ship", "vehicle"],
difficult_strategy="drop"
)
# Mode 3: Separate folders for each split
train_dataset = DOTADataset(
root_dir="/path/to/data_root",
split="train",
label_dir="/path/to/data_root/train/labelTxt",
image_dir="/path/to/data_root/train/images",
difficult_strategy="drop"
)
# Or use PyTorch DataLoader
loader = build_dota_loader(
root_dir="/path/to/dota",
split="train",
split_file="train.txt", # Optional
batch_size=4,
shuffle=True
)
Image Tiling¶
from oriented_det.data import ImageTiler, visualize_tiles
from pathlib import Path
# Configure tiler with overlap and filtering options
tiler = ImageTiler(
tile_size=1024,
overlap=0.2, # 20% overlap between tiles
min_box_area=64, # Filter boxes < 64 pixels²
min_overlap_ratio=0.3, # Keep box only if >= 30% overlaps tile
edge_handling="clip" # "clip", "ignore", or "keep"
)
# Generate tiles and process
for tiled_sample in tiler.tile_image(
image_path=Path("large_image.png"),
image_width=4000,
image_height=4000,
rboxes=annotations,
class_names=classes
):
# Process each tile
process_tile(tiled_sample)
# Visualize tiles for debugging
tiles = tiler.generate_tiles(4000, 4000)
visualize_tiles(
image_path=Path("large_image.png"),
image_width=4000,
image_height=4000,
tiles=tiles,
rboxes=annotations,
class_names=classes,
output_path=Path("tiles_vis.png")
)
Data Augmentation¶
from oriented_det.data import HorizontalFlip, Rotate, Compose, create_albumentations_augmentation
# Geometric transforms (oriented bounding box aware)
aug = Compose([
HorizontalFlip(p=0.5),
Rotate(degrees=90, p=0.3),
])
augmented_image, augmented_boxes = aug(image, rboxes, image_width, image_height)
# Albumentations (non-geometric only)
aug = create_albumentations_augmentation(
brightness_limit=0.2,
contrast_limit=0.2,
gamma_limit=(80, 120),
gauss_noise_var_limit=(10.0, 50.0),
blur_limit=3,
clahe_clip_limit=4.0,
p_brightness_contrast=0.5,
p_gamma=0.3,
p_noise=0.2,
p_blur=0.2,
p_clahe=0.3,
)
augmented_image = aug(image) # Returns PIL Image
Oriented mAP Evaluation¶
from oriented_det.data import Detection, GroundTruth, compute_oriented_map
from oriented_det.geometry import RBox
detections = {
"img1": [Detection(rbox=..., score=0.9, class_id=0, class_name="plane")],
}
ground_truths = {
"img1": [GroundTruth(rbox=..., class_id=0, class_name="plane")],
}
mean_ap, class_aps = compute_oriented_map(
detections, ground_truths, iou_threshold=0.5
)