Data Extension API¶
Extension point. Dataset dispatch is task-owned. Preserve the output contract expected by the matching trainer when adding modality support.
Routes and classes¶
| Module | Route/classes | Role |
|---|---|---|
datasets.builder |
build_dataset |
Routes classification, localization, and vqa tasks. |
datasets.classification_dataset |
build, ClassificationDataset, VideoDataset, TrackingDataset, HFTrackingDataset, H5TrackingDataset |
Classification modalities. |
datasets.localization_dataset |
LocalizationDataset and concrete spotting/feature/SoccerNet classes |
Localization dataset selection and sampling. |
datasets.vqa_dataset |
VQADataset |
VQA manifest rows and answer references. |
datasets.utils.tracking / utils.h5_tracking |
tracking transforms, graph helpers, and HDF5 reader/manifest helpers | Tracking and HDF5 data support. |
datasets.hf_json, datasets.hf_tracking |
prepared-split types and prepare_*_split |
Optional Hub-backed split staging. |
Dataset classes are internal implementations; the dispatch path is the extension point. The following sections document all non-private local dataset classes before the optional Hugging Face integration.
build_dataset(config, annotation_file=None, processor=None, split='train')
¶
Return a dataset instance based on model type
Source code in opensportslib/datasets/builder.py
Classification datasets¶
classification_dataset.build(...) chooses the configured classification
modality. VideoDataset handles video/frames-style inputs; TrackingDataset
handles tracking data; HFTrackingDataset and H5TrackingDataset are concrete
tracking specializations. These classes are consumed by
Trainer_Classification, so a new dataset must preserve the batch fields that
its selected trainer reads.
classification dataset implmentations for video and tracking modalities.
provides three concrete dataset classes:
- VideoDataset (MVFoul, SN-GAR video)
- TrackingDataset (SN-GAR tracking / parquet)
both inherit from ClassificationDataset, which handles annotation loading, label mapping, and class-weight computation.
ClassificationDataset
¶
Bases: Dataset
shared base for all classification datasets.
loads annotations, builds a label map, and exposes helpers for computing sample-level and class-level weights (useful for balanced sampling and weighted loss respectively).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
the loaded YAML configuration. |
required | |
annotations_path
|
path to the annotation JSON file. |
required | |
split
|
one of "train", "valid", "test". |
'train'
|
Source code in opensportslib/datasets/classification_dataset.py
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 | |
get_class_weights(num_classes=None, normalize=True, sqrt=False)
¶
per-class inverse-frequency weights for WeightedRandomSampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_classes
|
if None, inferred from the label tensor. |
None
|
|
normalize
|
if True, weights are scaled so they sum to num_classes. |
True
|
|
sqrt
|
if True, use inverse square-root frequency instead of raw counts. |
False
|
Returns:
| Type | Description |
|---|---|
|
torch.Tensor of shape (num_classes,). |
Source code in opensportslib/datasets/classification_dataset.py
get_sample_weights()
¶
per-sample inverse-frequency weights for WeightedRandomSampler.
Returns:
| Type | Description |
|---|---|
|
torch.Tensor of length len(self) with one weight per sample. |
Source code in opensportslib/datasets/classification_dataset.py
VideoDataset
¶
Bases: ClassificationDataset
frame-sampled video clips for classification.
for MVFoul: supports single-view and multi-view modes. In multi-view training, two views are randomly sampled per clip; at test time all available views are returned and stacked along a view dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
the loaded YAML configuration. |
required | |
annotations_path
|
path to the annotation JSON file. |
required | |
processor
|
HuggingFace image processor (used only for HuggingFace models). |
required | |
split
|
one of "train", "valid", "test". |
'train'
|
Source code in opensportslib/datasets/classification_dataset.py
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 | |
TrackingDataset
¶
Bases: ClassificationDataset
graph-based classification dataset built from player tracking data.
each sample is a temporal sequence of per-frame graphs where nodes represent the ball and 22 players, and edges encode spatial or tactical relationships (see build_edge_index).
supports optional preloading of all clips into memory and training-time augmentation (horizontal/vertical/team flip).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
the loaded YAML configuration. |
required | |
annotations_path
|
path to the annotation JSON file. |
required | |
split
|
one of "train", "valid", "test". |
'train'
|
Source code in opensportslib/datasets/classification_dataset.py
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 | |
HFTrackingDataset
¶
Bases: TrackingDataset
Tracking graphs backed by indexed Hugging Face WebDataset TAR shards.
Source code in opensportslib/datasets/classification_dataset.py
H5TrackingDataset
¶
Bases: ClassificationDataset
Graph-based classification dataset for UTC-indexed player/ball H5 files.
Source code in opensportslib/datasets/classification_dataset.py
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 | |
build(config, annotations_path, processor=None, split='train')
¶
construct the appropriate dataset for the configured modality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
the loaded YAML configuration. |
required | |
annotations_path
|
path to the annotation JSON file. |
required | |
processor
|
HuggingFace image processor (video modality only). |
None
|
|
split
|
one of "train", "valid", "test". |
'train'
|
Returns:
| Type | Description |
|---|---|
|
a Dataset instance (VideoDataset or TrackingDataset). |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the data_modality is not recognized. |
Source code in opensportslib/datasets/classification_dataset.py
Localization datasets¶
LocalizationDataset is the top-level localization entry point. It selects
video, tracking, feature, and SoccerNet-oriented concrete datasets based on
the configured split type and input modality. FrameReader and
DatasetVideoSharedMethods are shared implementation support for video routes.
| Dataset group | Concrete classes |
|---|---|
| Spotting/video | ActionSpotDataset, ActionSpotVideoDataset |
| Tracking spotting | TrackingActionSpotDataset, TrackingActionSpotVideoDataset |
| Feature JSON | FeaturefromJson, FeatureClipsfromJSON, FeatureClipChunksfromJson |
| SoccerNet | SoccerNetGame, SoccerNetGameClips, SoccerNetGameClipsChunks, SoccerNet, SoccerNetClips, SoccerNetClipsChunks |
LocalizationDataset
¶
Bases: Dataset
Source code in opensportslib/datasets/localization_dataset.py
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 | |
building_dataloader(dataset, cfg, gpu, dali)
¶
Build a dataloader from config dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
dict
|
Config dict. It should at least contain the key "type". |
required |
default_args
|
dict | None
|
Default initialization arguments. Default: None. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dataloader |
The constructed dataloader. |
Source code in opensportslib/datasets/localization_dataset.py
FrameReader
¶
Class used to read a video and create a clip of frames by applying some transformations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modality
|
string
|
Modality of the frames. |
required |
crop_transform
|
Transformations that apply to frame for cropping. |
required | |
img_transform
|
Transformations that apply to frame like GaussianBlur and Normalization. |
required | |
same_transform
|
bool
|
Whether to apply same trasnforms to every frame of a same clip. |
required |
sample_fps
|
int
|
Fps at which we want to extract frames from the video. |
2
|
Source code in opensportslib/datasets/localization_dataset.py
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 | |
adapt_frame_ocv(frame)
¶
Apply some modifications to the frame to have the expected shape and format.
Returns:
| Type | Description |
|---|---|
|
img (torch.tensor). |
Source code in opensportslib/datasets/localization_dataset.py
load_frames_ocv(video_name, start, end, pad=False, source_start_frame=None, source_end_frame=None)
¶
Load frames from a video to create a clip of frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_name
|
string
|
The path of the video. This is the full path of the file if we infer a single video |
required |
start
|
int
|
Start frame at which we load the clip. |
required |
end
|
int
|
End frame at which we finish the clip. |
required |
pad
|
bool
|
Whether to apply padding to the clip or not. |
False
|
source_start_frame
|
int | None
|
First physical frame of a logical interval. Both source bounds must be provided together. |
None
|
source_end_frame
|
int | None
|
Exclusive physical end frame of a logical interval. |
None
|
Source code in opensportslib/datasets/localization_dataset.py
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 | |
ActionSpotDataset
¶
Bases: Dataset
Class that overrides Dataset class. This class is to prepare training data using opencv. Training data consists of frames, associated labels and a boolean indicating if the clip of frames contains an event. A training sample can be mixed up with another one if mixup is used or not. In particular, a training sample contains the following informations without mixup: "frame": The frames. "contains_event": True if event occurs within these frames, False otherwise. "label": The labels associated to the frames. and the following informations with mixup: "frame": A combination of the frames of the first video and the second one. "contains_event": True if event occurs within these frames, False otherwise. "label": Rearrangement of the labels of each video. "mix_frame": Frames of the second video. "mix_weight": The weight that have been used for mixing frames and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
dict
|
dict of class names to idx. |
required |
label_file
|
list[string] | string
|
Path to label json files. Can be a single file or a list or a json files. |
required |
video_dir
|
list[string] | string
|
Path to folders where videos are located. Can be a single folder or a list of folders. Must match the number of json files. |
required |
modality
|
string
|
[rgb] Modality of the frame. |
required |
clip_len
|
int
|
Length of a clip of frames. |
required |
input_fps
|
int
|
Fps of the input videos. |
required |
extract_fps
|
int
|
Fps at which we want to extract frames. |
required |
dataset_len
|
int
|
Number of clips. |
required |
is_eval
|
bool
|
Disable random augmentation Default: True. |
True
|
crop_dim
|
int
|
The dimension for cropping frames. Default: None. |
None
|
same_transform
|
bool
|
Apply the same random augmentation to each frame in a clip. Default: True. |
True
|
dilate_len
|
int
|
Dilate ground truth labels. Default: 0. |
0
|
mixup
|
bool
|
Whether to mixup clips of two videos or not. Default: False. |
False
|
pad_len
|
int
|
Number of frames to pad the start and end of videos. Default: DEFAULT_PAD_LEN. |
5
|
fg_upsample
|
Sample foreground explicitly. Default: -1. |
-1
|
Source code in opensportslib/datasets/localization_dataset.py
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 | |
__getitem__(unused)
¶
Get a training sample based on one video without mixup, two otherwise.
Source code in opensportslib/datasets/localization_dataset.py
load_frame_gpu(batch, device)
¶
Load frame to gpu by appliyng some transformations or not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Batch containing data. |
required | |
device
|
The device on which to load the frames. |
required |
Source code in opensportslib/datasets/localization_dataset.py
ActionSpotVideoDataset
¶
Bases: Dataset, DatasetVideoSharedMethods
Class that overrides Dataset class. This class is to prepare testing data. Testing data consists of frames, the name of the video and index of the first frame in the video. This class can process as input a json file containing metadatas of video or just a video. Args: classes (dict): dict of class names to idx. label_file (string): Can be path to label json or path of a video. video_dir (string): path to folder where videos are located. modality (string): [rgb] Modality of the frame. clip_len (int): Length of a clip of frames. input_fps (int): Fps of the input videos. extract_fps (int): Fps at which we want to extract frames. overlap_len (int): The number of overlapping frames between consecutive clips. crop_dim (int): The dimension for cropping frames. Default: None. flip (bool): Whether to flip or not the frames. Default: False. multi_crop (bool): Whether multi croping or not Default: False. skip_partial_end (bool): Whether to skip a partial number of clips at the end. Default: True. pad_len (int): Number of frames to pad the start and end of videos. Default: DEFAULT_PAD_LEN.
Source code in opensportslib/datasets/localization_dataset.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 | |
__getitem__(idx)
¶
Get a dict of metadata containing the name of the video, the index of the first frame and the clip of frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
The index of the clip in the list of clips. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
{"video","start","frame"}. |
Source code in opensportslib/datasets/localization_dataset.py
TrackingActionSpotDataset
¶
Bases: Dataset, _TrackingGraphWindowMixin
Training dataset for tracking-based action spotting.
Mirrors ActionSpotDataset (random clip_len-frame windows, dense dilated per-frame labels, uniform/foreground-weighted sampling) but slices per-frame graphs out of a cached whole-match tracking parquet (see datasets.utils.tracking.load_or_build_game_cache) instead of decoding video frames. Mixup is not supported (mixing raw node features across two differently-structured graphs is not well-defined).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
dict
|
dict of class names to idx. |
required |
label_file
|
str | list[str]
|
Path to annotation JSON file(s). |
required |
video_dir
|
str | list[str]
|
Root dir(s) containing the tracking parquets referenced by the annotations. |
required |
clip_len
|
int
|
Length of a clip, in decimated (extract_fps) frames. |
required |
extract_fps
|
float
|
Target fps to decimate the native stream to. |
required |
dataset_len
|
int
|
Number of clips per epoch. |
required |
edge_type
|
str
|
Graph edge-building strategy (see build_edge_index). |
'positional'
|
k
|
int
|
neighbour count for knn-style edge strategies. |
8
|
r
|
float
|
distance threshold (metres) for distance-style strategies. |
15.0
|
is_eval
|
bool
|
Disable augmentation (mirrors ActionSpotDataset). |
True
|
dilate_len
|
int
|
Dilate ground-truth labels. |
0
|
pad_len
|
int
|
Frames to pad the start/end of a game. |
5
|
fg_upsample
|
float
|
Sample foreground explicitly. |
-1
|
augmentations
|
list
|
tracking augmentation transforms. |
None
|
normalize
|
bool
|
whether to normalize spatial features. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 | |
TrackingActionSpotVideoDataset
¶
Bases: Dataset, _TrackingGraphWindowMixin, DatasetVideoSharedMethods
Sliding-window evaluation dataset for tracking-based action spotting.
Mirrors ActionSpotVideoDataset/DatasetVideoSharedMethods - same (path, video, start) sliding-clip list with overlap_len for full-match coverage, and the same get_labels/videos/labels properties the mAP evaluator relies on - but each clip is a window of per-frame graphs sliced out of a cached whole-match tracking parquet instead of decoded video frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classes
|
dict
|
dict of class names to idx. |
required |
label_file
|
str
|
Path to annotation JSON file. |
required |
video_dir
|
str
|
Root dir containing the tracking parquets. |
required |
clip_len
|
int
|
Length of a clip, in decimated (extract_fps) frames. |
required |
extract_fps
|
float
|
Target fps to decimate the native stream to. |
required |
edge_type
|
str
|
Graph edge-building strategy (see build_edge_index). |
'positional'
|
k
|
int
|
neighbour count for knn-style edge strategies. |
8
|
r
|
float
|
distance threshold (metres) for distance-style strategies. |
15.0
|
overlap_len
|
int
|
Overlapping frames between consecutive clips. |
0
|
pad_len
|
int
|
Frames to pad the start/end of a game. |
5
|
skip_partial_end
|
bool
|
Whether to skip a partial clip at the end. |
True
|
normalize
|
bool
|
whether to normalize spatial features. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 | |
frame_times
property
¶
Map each video to the absolute match clock (ms) of its decimated frames.
Unlike a decoded video, a tracking parquet's frame index is not a multiple of the frame period: recording starts mid-broadcast (row 0 can be ~80 s into the clock) and the clock jumps ~60-90 s across half-time. process_frame_predictions uses this to report predictions on the same clock the annotations' position_ms uses; without it every prediction lands tens of seconds away from its ground truth.
__getitem__(idx)
¶
Get a dict of metadata containing the name of the game, the index of the first frame, and the clip's per-frame graphs.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
{"video", "start", "graphs"}. |
Source code in opensportslib/datasets/localization_dataset.py
FeaturefromJson
¶
Bases: Dataset
Parent class that is used to modularise common operations between the classes that prepare features data. In particular, this class loads the input, creates dictionnaries of classes and has a method to process the annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | List(str)
|
Path of the input. Can be a json file, a features file or a list of json files (list only for training purposes). |
required |
features_dir
|
str | List(str)
|
Path where the features are located. Must match the number of input paths. |
required |
classes
|
path
|
Path of the file containing the classes. Only used if input is feature file, otherwise list of classes is in the json file. |
required |
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
Source code in opensportslib/datasets/localization_dataset.py
2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 | |
annotation(annotation)
¶
Process an annotation to derive the frame number, the class index and a boolean. Args: annotation (dict): It must contains the keys "gameTime" and "label".
Returns:
| Name | Type | Description |
|---|---|---|
label |
int
|
The index of the class. |
frame |
int
|
The index of the frame. |
cont |
bool
|
Whether to continue in the loop or not. |
Source code in opensportslib/datasets/localization_dataset.py
FeatureClipsfromJSON
¶
Bases: FeaturefromJson
Class that inherits from FeaturefromJson to prepare features data as clips of features. This class is used for the pooling methods. The class has 2 behaviours for processing the data depending if it is for training or testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | List(str)
|
Path of the input. Can be a json file, a features file or a list of json files (list only for training purposes). |
required |
features_dir
|
str | List(str)
|
Path where the features are located. Must match the number of input paths. |
required |
classes
|
path
|
Path of the file containing the classes. Only used if input is feature file, otherwise list of classes is in the json file. |
required |
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
window_size
|
int
|
The length of the window that will be used for the length of the clips. Default: 15. |
15
|
train
|
bool
|
Whether we prepare data for training or for testing purposes. Default: True. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 | |
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: If training: clip_feat (np.array): clip of features. clip_labels (np.array): clip of labels. If testing: Name of the feature file. features (np.array): clip of features. labels (np.array): clip of labels.
Source code in opensportslib/datasets/localization_dataset.py
FeatureClipChunksfromJson
¶
Bases: FeaturefromJson
Class that inherits from FeaturefromJson to prepare features data as clips of features based on a chunk approach. This class is used for the CALF method. The class has 2 behaviours for processing the data depending if it is for training or testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | List(str)
|
Path of the input. Can be a json file, a features file or a list of json files (list only for training purposes). |
required |
features_dir
|
str | List(str)
|
Path where the features are located. Must match the number of input paths. |
required |
classes
|
path
|
Path of the file containing the classes. Only used if input is feature file, otherwise list of classes is in the json file. |
required |
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
chunk_size
|
int
|
Size of the chunk. Default: 240. |
240
|
receptive_field
|
int
|
temporal receptive field of x seconds on both sides of the central frame in the temporal dimension of the 3D convolutions Default: 80. |
80
|
chunks_per_epoch
|
int
|
Number of chunks per epoch. Default: 6000. |
6000
|
gpu
|
bool
|
Whether gpu is used or not. Default: True. |
True
|
train
|
bool
|
Whether we prepare data for training or for testing purposes. Default: True. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 | |
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: If training: clip_feat (np.array): clip of features. clip_labels (np.array): clip of labels. clip_targets (np.array): clip of targets. If testing: features (np.array): clip of features. labels (np.array): clip of labels.
Source code in opensportslib/datasets/localization_dataset.py
2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 | |
SoccerNetGame
¶
Bases: Dataset
Parent class that is used to modularise common operations between the classes that prepare features of a single game of the soccernet dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
string
|
Path of the game. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
version
|
int
|
Version of the dataset. Default: 1. |
1
|
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
Source code in opensportslib/datasets/localization_dataset.py
SoccerNetGameClips
¶
Bases: SoccerNetGame
Class that inherits from SoccerNetGame to prepare features data of a single game as clips of features. This class is used for the pooling methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
string
|
Path of the game. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
version
|
int
|
Version of the dataset. Default: 1. |
1
|
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
window_size
|
int
|
The length of the window that will be used for the length of the clips. Default: 15. |
15
|
Source code in opensportslib/datasets/localization_dataset.py
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: path: path of the game. clip_feat_1 (np.array): clip of features for the first half. clip_feat_2 (np.array): clip of features for the second half. empty list empty list
Source code in opensportslib/datasets/localization_dataset.py
SoccerNetGameClipsChunks
¶
Bases: SoccerNetGame
Class that inherits from SoccerNetGame to prepare features data of a single game as clips of features based on a chunk approach. This class is used for the CALF method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
string
|
Path of the game. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
version
|
int
|
Version of the dataset. Default: 1. |
required |
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
chunk_size
|
int
|
Size of the chunk. Default: 240. |
240
|
receptive_field
|
int
|
temporal receptive field of x seconds on both sides of the central frame in the temporal dimension of the 3D convolutions Default: 80. |
80
|
Source code in opensportslib/datasets/localization_dataset.py
2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 | |
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: clip_feat_1 (np.array): clip of features for the first half. clip_feat_2 (np.array): clip of features for the second half. clip_label_1 (np.array): clip of labels for the first half. clip_label_2 (np.array): clip of labels for the second half.
Source code in opensportslib/datasets/localization_dataset.py
SoccerNet
¶
Bases: Dataset
Parent class that is used to modularise common operations between the classes that prepare features of a split of a soccernet dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
string
|
Data root of the feature files. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
split
|
List(string)
|
List of splits. Default: ["train"]. |
['train']
|
version
|
int
|
Version of the dataset. Default: 1. |
1
|
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
Source code in opensportslib/datasets/localization_dataset.py
2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 | |
annotation(annotation)
¶
Process an annotation to derive the frame number, the class index and a boolean. Args: annotation (dict): It must contains the keys "gameTime" and "label".
Returns:
| Name | Type | Description |
|---|---|---|
label |
int
|
The index of the class. |
half |
int
|
Which half of the game. |
frame |
int
|
The index of the frame. |
cont |
bool
|
Whether to continue in the loop or not. |
Source code in opensportslib/datasets/localization_dataset.py
load_features(index=0, game='')
¶
Load features from files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Used for testing purpose to retrieve the game based on the index. Default: 0. |
0
|
game
|
string
|
Used for training purpose, this is the name of the game. Default: "". |
''
|
Source code in opensportslib/datasets/localization_dataset.py
SoccerNetClips
¶
Bases: SoccerNet
Class that inherits from SoccerNetGame to prepare features data of a split as clips of features. This class is used for the pooling methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
string
|
Data root of the feature files. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
split
|
List(string)
|
List of splits. Default: ["train"]. |
['train']
|
version
|
int
|
Version of the dataset. Default: 1. |
1
|
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
window_size
|
int
|
The length of the window that will be used for the length of the clips. Default: 15. |
15
|
train
|
bool
|
Whether training or testing. Default: True. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 | |
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: if train : clip_feat (np.array): clip of features. clip_labels (np.array): clip of labels for the segmentation. if testing: name of the game. clip_feat_1 (np.array): clip of features for the first half. clip_feat_2 (np.array): clip of features for the second half. clip_label_1 (np.array): clip of labels for the first half. clip_label_2 (np.array): clip of labels for the second half.
Source code in opensportslib/datasets/localization_dataset.py
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 | |
SoccerNetClipsChunks
¶
Bases: SoccerNet
Class that inherits from SoccerNetGame to prepare features data of a split as clips of features with a chunk approach. This class is used for the CALF method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Data root of the feature files. |
required |
features
|
str
|
Name of the features. Default: ResNET_PCA512.npy. |
'ResNET_PCA512.npy'
|
split
|
string
|
split. Default: "train". |
'train'
|
version
|
int
|
Version of the dataset. Default: 1. |
required |
framerate
|
int
|
The framerate at which the features have been extracted. Default: 2. |
2
|
chunk_size
|
int
|
Size of the chunk. Default: 240. |
240
|
receptive_field
|
int
|
temporal receptive field of x seconds on both sides of the central frame in the temporal dimension of the 3D convolutions Default: 80. |
80
|
chunks_per_epoch
|
int
|
Number of chunks per epoch. Default: 6000. |
6000
|
gpu
|
bool
|
Whether gpu is used or not. Default: True. |
True
|
train
|
bool
|
Whether we prepare data for training or for testing purposes. Default: True. |
True
|
Source code in opensportslib/datasets/localization_dataset.py
3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 | |
__getitem__(index)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Index |
required |
Returns: If training: clip_feat (np.array): clip of features. clip_labels (np.array): clip of labels. clip_targets (np.array): clip of targets. If testing: clip_feat_1 (np.array): clip of features for the first half. clip_feat_2 (np.array): clip of features for the second half. clip_labels_1 (np.array): clip of labels for the first half. clip_labels_2 (np.array): clip of labels for the second half.
Source code in opensportslib/datasets/localization_dataset.py
3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 | |
VQA datasets¶
VQADataset converts an OSL JSON VQA split into rows used by the configured
VQA trainer and evaluator. It requires question/reference-answer data in the
manifest; model-specific feature generation belongs to the VQA model/trainer,
not this dataset route.
VQA dataset adapter for canonical OpenSportsLib JSON annotations.
VQADataset
¶
Bases: Dataset
Flatten VQA annotations into single question-answer training samples.
Source code in opensportslib/datasets/vqa_dataset.py
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 | |
Tracking and HDF5 utilities¶
Tracking utilities normalize positions, build graph edge indices, cache games,
and apply spatial transforms. HDF5 utilities read timestamped tracking rows,
normalize their features, discover games, and write manifests. write_h5_manifest
writes a file; readers and cache builders perform local filesystem I/O.
tracking utilities for player-position graph data.
provides constants, edge-building strategies, spatial augmentations, and frame-level feature extraction for the SN-GAR tracking modality.
feature vector layout (per object, per frame)::
Index Field
----- ----------------------------------
0 x (pitch coordinates)
1 y
2 is_ball (one-hot entity type)
3 is_home
4 is_away
5 dx (velocity delta, computed across consecutive frames)
6 dy
7 z (ball height; MISSING_VALUE for players)
HorizontalFlip
¶
randomly negate x-coordinates and dx-velocities (pitch length axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probability
|
chance of applying the flip per call. |
0.5
|
Source code in opensportslib/datasets/utils/tracking.py
__call__(features)
¶
apply the transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
numpy.ndarray of shape (num_frames, NUM_OBJECTS, FEATURE_DIM). |
required |
Returns:
| Type | Description |
|---|---|
|
the (possibly flipped) feature array. a copy is made when |
|
|
the flip is applied; the input is never modified. |
Source code in opensportslib/datasets/utils/tracking.py
VerticalFlip
¶
randomly negate y-coordinates and dy-velocities (pitch width axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probability
|
chance of applying the flip per call. |
0.5
|
Source code in opensportslib/datasets/utils/tracking.py
__call__(features)
¶
apply the transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
numpy.ndarray of shape (num_frames, NUM_OBJECTS, FEATURE_DIM). |
required |
Returns:
| Type | Description |
|---|---|
|
the (possibly flipped) feature array. |
Source code in opensportslib/datasets/utils/tracking.py
TeamFlip
¶
randomly swap the home and away one-hot team flags.
this is a label-preserving augmentation: swapping team identity does not change the group activity class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
probability
|
chance of applying the swap per call. |
0.5
|
Source code in opensportslib/datasets/utils/tracking.py
__call__(features)
¶
apply the transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
numpy.ndarray of shape (num_frames, NUM_OBJECTS, FEATURE_DIM). |
required |
Returns:
| Type | Description |
|---|---|
|
the (possibly swapped) feature array. |
Source code in opensportslib/datasets/utils/tracking.py
parse_frame(row, num_objects=NUM_OBJECTS, feature_dim=FEATURE_DIM)
¶
parse a single parquet row into per-object features and positions.
Each row is expected to contain JSON-encoded columns balls, homePlayers, and awayPlayers following the SN-GAR tracking format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
A single row (pandas.Series) from a tracking parquet file. |
required |
Returns:
| Type | Description |
|---|---|
|
A tuple (features, positions) where features is a |
|
|
numpy.ndarray of shape (num_objects, feature_dim) and |
|
|
positions is a list of position-group strings (e.g. |
|
|
"GK", "DEF"). Unobserved slots are filled with |
|
|
MISSING_VALUE and an empty string respectively. |
Source code in opensportslib/datasets/utils/tracking.py
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 | |
compute_deltas(all_features, num_objects=NUM_OBJECTS)
¶
compute per-object velocity deltas across consecutive frames.
For each object that is observed in both frame t and frame t - 1, the displacement (dx, dy) is written into feature indices 5 and 6. frame 0 retains zero deltas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_features
|
numpy.ndarray of shape (num_frames, NUM_OBJECTS, FEATURE_DIM). |
required |
Returns:
| Type | Description |
|---|---|
|
the same array, modified in-place, with velocity deltas |
|
|
populated. |
Source code in opensportslib/datasets/utils/tracking.py
normalize_features(features, pitch_half_length=PITCH_HALF_LENGTH, pitch_half_width=PITCH_HALF_WIDTH, max_displacement=MAX_DISPLACEMENT, max_ball_height=MAX_BALL_HEIGHT)
¶
normalize spatial features to roughly [-1, 1].
observed coordinates are divided by the known pitch / displacement bounds. unobserved slots are set to MISSING_VALUE_NORMALIZED so the model receives a distinct, out-of-range sentinel that cannot be confused with a valid normalized value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
numpy.ndarray of shape (num_frames, NUM_OBJECTS, FEATURE_DIM). |
required |
Returns:
| Type | Description |
|---|---|
|
a new array with the same shape containing normalized values. |
|
|
the input is not modified. |
Source code in opensportslib/datasets/utils/tracking.py
build_edge_index(node_features, node_positions, edge_type, k=8, r=15.0)
¶
build a graph edge index for a single frame.
supports several connectivity strategies that trade off density against spatial or tactical priors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
numpy.ndarray of shape (NUM_OBJECTS, FEATURE_DIM). |
required | |
node_positions
|
List of position-group strings (length NUM_OBJECTS). |
required | |
edge_type
|
One of "none", "full", "knn", "distance", "ball_knn", "ball_distance", or "positional". |
required | |
k
|
Number of neighbours for knn / ball_knn strategies. |
8
|
|
r
|
Distance threshold (metres) for distance / ball_distance strategies. |
15.0
|
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray of shape (2, num_edges) in COO format, |
|
|
compatible with PyTorch Geometric. |
Source code in opensportslib/datasets/utils/tracking.py
build_game_cache(parquet_path)
¶
parse a whole-match tracking parquet once and cache compact arrays.
writes three sidecar files next to parquet_path:
velocity deltas (dx, dy) are intentionally left at zero here rather than computed on this native-rate array: a training/eval window may subsample the native stream down to a lower extract_fps, and deltas must reflect the gap between sampled frames, not between raw native rows. callers should slice a window out of the cached array first, then run compute_deltas on that (already-decimated) subsequence. the array is not normalized and has no augmentation applied either - both also happen per-window at train/eval time so they stay config-dependent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parquet_path
|
path to the whole-match tracking parquet. |
required |
Returns:
| Type | Description |
|---|---|
|
a tuple (features, times, positions); see load_or_build_game_cache. |
Source code in opensportslib/datasets/utils/tracking.py
load_or_build_game_cache(parquet_path, mmap=True)
¶
load the cached per-frame features/times/positions for a game, building the cache (see build_game_cache) on first access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parquet_path
|
path to the whole-match tracking parquet. |
required | |
mmap
|
if True, load cached arrays memory-mapped (cheap random window slicing without pulling the whole game into RAM). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
features |
numpy.ndarray (num_frames, NUM_OBJECTS, FEATURE_DIM) float32, raw (no velocity deltas, unnormalized) - callers compute deltas after slicing/decimating a window. |
|
times |
numpy.ndarray (num_frames,) float64, videoTimeMs per row. |
|
positions |
numpy.ndarray (num_frames, NUM_OBJECTS) int8 position codes (see _POSITION_CODES / positions_to_strings). |
Source code in opensportslib/datasets/utils/tracking.py
positions_to_strings(position_codes)
¶
decode a (NUM_OBJECTS,) array of int position codes back to strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position_codes
|
iterable of int codes (see _POSITION_CODES). |
required |
Returns:
| Type | Description |
|---|---|
|
list of position-group strings, e.g. ["BALL", "GK", "DEF", ...]. |
Source code in opensportslib/datasets/utils/tracking.py
slice_window(features_cache, positions_cache, base_idx, clip_len, stride)
¶
slice one decimated feature window out of a whole-match cache.
Picks clip_len frames starting at decimated index base_idx, taking
every stride-th native row (native_idx = (base_idx + i) * stride).
base_idx may be negative or run past the end of the match (start/end
padding, as ActionSpotDataset does for video); out-of-range frames are
left as MISSING_VALUE sentinels, which the edge-building / normalization
utilities already treat as absent nodes. Velocity deltas are computed
after this decimation (see compute_deltas) so dx/dy reflect the gap
between sampled frames, not raw native rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features_cache
|
(native_num_frames, NUM_OBJECTS, FEATURE_DIM) array from load_or_build_game_cache (raw, no deltas, unnormalized). |
required | |
positions_cache
|
(native_num_frames, NUM_OBJECTS) int8 position codes from the same cache. |
required | |
base_idx
|
window start, in decimated (extract_fps) frame units. |
required | |
clip_len
|
number of decimated frames in the window. |
required | |
stride
|
native rows per decimated frame (from the game's metadata). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
window |
(clip_len, NUM_OBJECTS, FEATURE_DIM) float32 array with velocity deltas filled in. |
|
positions |
list of |
Source code in opensportslib/datasets/utils/tracking.py
Utilities for UTC-indexed H5 player and ball tracking inputs.
H5Frame
dataclass
¶
H5TrackingReader
¶
Lazy reader for columnar player tracking H5 files keyed by UTC.
Source code in opensportslib/datasets/utils/h5_tracking.py
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 | |
parse_utc(value)
¶
Parse UTC-ish H5/JSON timestamp values into microsecond datetime64.
Source code in opensportslib/datasets/utils/h5_tracking.py
normalize_h5_features(features, *, pitch_half_length=85.0, pitch_half_width=50.0, max_height=30.0, max_displacement=110.0, missing_value=MISSING_VALUE)
¶
Normalize H5 XYZ graph features without mutating the input.
Source code in opensportslib/datasets/utils/h5_tracking.py
find_h5_games(path, joints_filename=JOINTS_FILENAME, ball_filename=BALL_FILENAME)
¶
List game directories holding both tracking files.
path is either one game directory or a directory of game directories.
Source code in opensportslib/datasets/utils/h5_tracking.py
write_h5_manifest(path, games, label='header', head_name='action', joints_filename=JOINTS_FILENAME, ball_filename=BALL_FILENAME)
¶
Write the OSL JSON manifest a rule-based H5 spotter reads its inputs from.
Input paths are absolute, so a config published without the data beside it still resolves.
Source code in opensportslib/datasets/utils/h5_tracking.py
Hugging Face-backed inputs¶
Hub preparation is optional. It can download or materialize local files and therefore requires a configured source, network access, and authentication for gated repositories.
Stage OSL JSON manifests and their selected media from a Hugging Face dataset.
PreparedHFJsonSplit
dataclass
¶
hf_json_source(config)
¶
prepare_hf_json_split(config, split)
¶
Download one split's selected media, then publish its local manifest.
The localization video and tracking loaders inspect each file during construction. Stage only the configured input type while keeping its manifest type and other metadata intact. Hub blobs are linked into a small split directory.
Source code in opensportslib/datasets/hf_json.py
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 | |
Metadata and TAR staging for Hugging Face tracking datasets.
PreparedTrackingSplit
dataclass
¶
HFTarTrackingReader
¶
Read one Parquet member without extracting it to the filesystem.
Source code in opensportslib/datasets/hf_tracking.py
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 | |
hf_tracking_source(config)
¶
prepare_hf_tracking_split(config, split)
¶
Index metadata and cache all required TAR shards for one split.
Source code in opensportslib/datasets/hf_tracking.py
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 | |