Skip to content

Commit bafa98d

Browse files
Merge pull request #17 from UnravelSports/feat/pressing-intensity
Feat/pressing intensity
2 parents 7359b4a + d37dd4d commit bafa98d

File tree

6 files changed

+253
-117
lines changed

6 files changed

+253
-117
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ This package currently supports:
3030
```python
3131
from unravel.soccer import KloppyPolarsDataset
3232

33-
from kloppy import skillcorner
33+
from kloppy import sportec
3434

35-
kloppy_dataset = skillcorner.load_open_data(
36-
match_id=2068,
37-
include_empty_frames=False,
38-
limit=500,
39-
)
35+
kloppy_dataset = sportec.load_open_tracking_data()
4036
kloppy_polars_dataset = KloppyPolarsDataset(
41-
kloppy_dataset=kloppy_dataset,
42-
ball_carrier_threshold=25.0
37+
kloppy_dataset=kloppy_dataset
4338
)
4439
```
40+
| | period_id | timestamp | frame_id | ball_state | id | x | y | z | team_id | position_name | game_id | vx | vy | vz | v | ax | ay | az | a | ball_owning_team_id | is_ball_carrier |
41+
|---:|------------:|:----------------|-----------:|:-------------|:---------------|-------:|------:|----:|:---------------|:----------------|:---------------|-------:|-------:|-----:|------:|-----:|-----:|-----:|----:|:----------------------|:------------------|
42+
| 0 | 1 | 0 days 00:00:00 | 10000 | alive | DFL-OBJ-00008F | -20.67 | -4.56 | 0 | DFL-CLU-000005 | RCB | DFL-MAT-J03WPY | 0.393 | -0.214 | 0 | 0.447 | 0 | 0 | 0 | 0 | DFL-CLU-00000P | False |
43+
| 1 | 1 | 0 days 00:00:00 | 10000 | alive | DFL-OBJ-0000EJ | -8.86 | -0.94 | 0 | DFL-CLU-000005 | UNK | DFL-MAT-J03WPY | -0.009 | 0.018 | 0 | 0.02 | 0 | 0 | 0 | 0 | DFL-CLU-00000P | False |
44+
| 2 | 1 | 0 days 00:00:00 | 10000 | alive | DFL-OBJ-0000F8 | -2.12 | 9.85 | 0 | DFL-CLU-00000P | RM | DFL-MAT-J03WPY | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | DFL-CLU-00000P | False |
45+
| 3 | 1 | 0 days 00:00:00 | 10000 | alive | DFL-OBJ-0000NZ | 0.57 | 23.23 | 0 | DFL-CLU-00000P | RB | DFL-MAT-J03WPY | 0.179 | -0.134 | 0 | 0.223 | 0 | 0 | 0 | 0 | DFL-CLU-00000P | False |
46+
| 4 | 1 | 0 days 00:00:00 | 10000 | alive | DFL-OBJ-0001HW | -46.26 | 0.08 | 0 | DFL-CLU-000005 | GK | DFL-MAT-J03WPY | 0.357 | 0.071 | 0 | 0.364 | 0 | 0 | 0 | 0 | DFL-CLU-00000P | False |
47+
4548

4649
$^1$ <small>Open data available through kloppy.</small>
4750

@@ -67,8 +70,6 @@ bdb = BigDataBowlDataset(
6770
```python
6871
converter = SoccerGraphConverterPolars(
6972
dataset=kloppy_polars_dataset,
70-
max_player_speed=12.0,
71-
max_ball_speed=28.0,
7273
self_loop_ball=True,
7374
adjacency_matrix_connect_type="ball",
7475
adjacency_matrix_type="split_by_team",

examples/0_quick_start_guide.ipynb

Lines changed: 125 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,20 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": null,
39+
"execution_count": 1,
4040
"metadata": {},
41-
"outputs": [],
41+
"outputs": [
42+
{
43+
"name": "stdout",
44+
"output_type": "stream",
45+
"text": [
46+
"\n",
47+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.0.1\u001b[0m\n",
48+
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
49+
"Note: you may need to restart the kernel to use updated packages.\n"
50+
]
51+
}
52+
],
4253
"source": [
4354
"%pip install unravelsports --quiet"
4455
]
@@ -51,35 +62,32 @@
5162
"\n",
5263
"1. Load [Kloppy](https://github.com/PySport/kloppy) dataset. \n",
5364
" See [in-depth Tutorial](1_kloppy_gnn_train.ipynb) on how do processes multiple match files, and to see an overview of all possible settings.\n",
54-
"2. Convert to Graph format using `SoccerGraphConverter`\n",
65+
"2. Convert to Graph format using `SoccerGraphConverterPolars`\n",
5566
"3. Create dataset for easy processing with [Spektral](https://graphneural.network/) using `CustomSpektralDataset`"
5667
]
5768
},
5869
{
5970
"cell_type": "code",
60-
"execution_count": null,
71+
"execution_count": 2,
6172
"metadata": {},
6273
"outputs": [],
6374
"source": [
64-
"from unravel.soccer import SoccerGraphConverter\n",
75+
"from unravel.soccer import SoccerGraphConverterPolars, KloppyPolarsDataset\n",
6576
"from unravel.utils import CustomSpektralDataset\n",
6677
"\n",
67-
"from kloppy import skillcorner\n",
68-
"\n",
69-
"from unravel.utils import dummy_labels\n",
78+
"from kloppy import sportec\n",
7079
"\n",
7180
"# Load Kloppy dataset\n",
72-
"kloppy_dataset = skillcorner.load_open_data(\n",
73-
" match_id=4039,\n",
74-
" include_empty_frames=False,\n",
75-
" limit=500, # limit to 500 frames in this example\n",
81+
"kloppy_dataset = sportec.load_open_tracking_data(only_alive=True, limit=500)\n",
82+
"kloppy_polars_dataset = KloppyPolarsDataset(\n",
83+
" kloppy_dataset=kloppy_dataset,\n",
7684
")\n",
85+
"kloppy_polars_dataset.add_dummy_labels()\n",
86+
"kloppy_polars_dataset.add_graph_ids(by=[\"frame_id\"])\n",
7787
"\n",
78-
"# Initialize the Graph Converter, with dataset and labels\n",
88+
"# Initialize the Graph Converter with dataset\n",
7989
"# Here we use the default settings\n",
80-
"converter = SoccerGraphConverter(\n",
81-
" dataset=kloppy_dataset, labels=dummy_labels(kloppy_dataset)\n",
82-
")\n",
90+
"converter = SoccerGraphConverterPolars(dataset=kloppy_polars_dataset)\n",
8391
"\n",
8492
"# Compute the graphs and add them to the CustomSpektralDataset\n",
8593
"dataset = CustomSpektralDataset(graphs=converter.to_spektral_graphs())"
@@ -96,14 +104,14 @@
96104
},
97105
{
98106
"cell_type": "code",
99-
"execution_count": null,
107+
"execution_count": 3,
100108
"metadata": {},
101109
"outputs": [],
102110
"source": [
103111
"from spektral.data import DisjointLoader\n",
104112
"\n",
105113
"train, test, val = dataset.split_test_train_validation(\n",
106-
" split_train=4, split_test=1, split_validation=1, random_seed=42\n",
114+
" split_train=4, split_test=1, split_validation=1, random_seed=43\n",
107115
")"
108116
]
109117
},
@@ -121,9 +129,17 @@
121129
},
122130
{
123131
"cell_type": "code",
124-
"execution_count": null,
132+
"execution_count": 4,
125133
"metadata": {},
126-
"outputs": [],
134+
"outputs": [
135+
{
136+
"name": "stderr",
137+
"output_type": "stream",
138+
"text": [
139+
"WARNING:absl:At this time, the v2.11+ optimizer `tf.keras.optimizers.Adam` runs slowly on M1/M2 Macs, please use the legacy Keras optimizer instead, located at `tf.keras.optimizers.legacy.Adam`.\n"
140+
]
141+
}
142+
],
127143
"source": [
128144
"from unravel.classifiers import CrystalGraphClassifier\n",
129145
"\n",
@@ -150,9 +166,74 @@
150166
},
151167
{
152168
"cell_type": "code",
153-
"execution_count": null,
169+
"execution_count": 5,
154170
"metadata": {},
155-
"outputs": [],
171+
"outputs": [
172+
{
173+
"name": "stdout",
174+
"output_type": "stream",
175+
"text": [
176+
"Epoch 1/10\n"
177+
]
178+
},
179+
{
180+
"name": "stderr",
181+
"output_type": "stream",
182+
"text": [
183+
"/Users/jbekkers/PycharmProjects/unravelsports/.venv311/lib/python3.11/site-packages/keras/src/initializers/initializers.py:120: UserWarning: The initializer GlorotUniform is unseeded and being called multiple times, which will return identical values each time (even if the initializer is unseeded). Please update your code to provide a seed to the initializer, or avoid using the same initializer instance more than once.\n",
184+
" warnings.warn(\n"
185+
]
186+
},
187+
{
188+
"name": "stdout",
189+
"output_type": "stream",
190+
"text": [
191+
"11/11 [==============================] - 1s 16ms/step - loss: 21.7806 - auc: 0.5278 - binary_accuracy: 0.5419 - val_loss: 5.1682 - val_auc: 0.5000 - val_binary_accuracy: 0.5000\n",
192+
"Epoch 2/10\n",
193+
" 1/11 [=>............................] - ETA: 0s - loss: 9.2846 - auc: 0.3651 - binary_accuracy: 0.5000WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 3 batches). You may need to use the repeat() function when building your dataset.\n"
194+
]
195+
},
196+
{
197+
"name": "stderr",
198+
"output_type": "stream",
199+
"text": [
200+
"WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 3 batches). You may need to use the repeat() function when building your dataset.\n"
201+
]
202+
},
203+
{
204+
"name": "stdout",
205+
"output_type": "stream",
206+
"text": [
207+
"11/11 [==============================] - 0s 6ms/step - loss: 4.5155 - auc: 0.5366 - binary_accuracy: 0.5449\n",
208+
"Epoch 3/10\n",
209+
"11/11 [==============================] - 0s 4ms/step - loss: 2.0773 - auc: 0.4515 - binary_accuracy: 0.4731\n",
210+
"Epoch 4/10\n",
211+
"11/11 [==============================] - 0s 5ms/step - loss: 1.1006 - auc: 0.5205 - binary_accuracy: 0.5150\n",
212+
"Epoch 5/10\n",
213+
"11/11 [==============================] - 0s 4ms/step - loss: 0.9159 - auc: 0.4915 - binary_accuracy: 0.5180\n",
214+
"Epoch 6/10\n",
215+
"11/11 [==============================] - 0s 5ms/step - loss: 0.8020 - auc: 0.4873 - binary_accuracy: 0.5060\n",
216+
"Epoch 7/10\n",
217+
"11/11 [==============================] - 0s 4ms/step - loss: 0.8067 - auc: 0.4960 - binary_accuracy: 0.5299\n",
218+
"Epoch 8/10\n",
219+
"11/11 [==============================] - 0s 6ms/step - loss: 0.7808 - auc: 0.5055 - binary_accuracy: 0.5299\n",
220+
"Epoch 9/10\n",
221+
"11/11 [==============================] - 0s 4ms/step - loss: 0.7661 - auc: 0.4937 - binary_accuracy: 0.5060\n",
222+
"Epoch 10/10\n",
223+
"11/11 [==============================] - 0s 5ms/step - loss: 0.7406 - auc: 0.5098 - binary_accuracy: 0.5329\n"
224+
]
225+
},
226+
{
227+
"data": {
228+
"text/plain": [
229+
"<keras.src.callbacks.History at 0x39fe49d10>"
230+
]
231+
},
232+
"execution_count": 5,
233+
"metadata": {},
234+
"output_type": "execute_result"
235+
}
236+
],
156237
"source": [
157238
"from tensorflow.keras.callbacks import EarlyStopping\n",
158239
"\n",
@@ -186,9 +267,17 @@
186267
},
187268
{
188269
"cell_type": "code",
189-
"execution_count": null,
270+
"execution_count": 6,
190271
"metadata": {},
191-
"outputs": [],
272+
"outputs": [
273+
{
274+
"name": "stdout",
275+
"output_type": "stream",
276+
"text": [
277+
"3/3 [==============================] - 0s 6ms/step - loss: 0.7001 - auc: 0.5000 - binary_accuracy: 0.4819\n"
278+
]
279+
}
280+
],
192281
"source": [
193282
"loader_te = DisjointLoader(test, epochs=1, shuffle=False, batch_size=batch_size)\n",
194283
"results = model.evaluate(loader_te.load())"
@@ -207,9 +296,17 @@
207296
},
208297
{
209298
"cell_type": "code",
210-
"execution_count": null,
299+
"execution_count": 7,
211300
"metadata": {},
212-
"outputs": [],
301+
"outputs": [
302+
{
303+
"name": "stdout",
304+
"output_type": "stream",
305+
"text": [
306+
"3/3 [==============================] - 0s 5ms/step\n"
307+
]
308+
}
309+
],
213310
"source": [
214311
"loader_te = DisjointLoader(test, batch_size=batch_size, epochs=1, shuffle=False)\n",
215312
"loaded_pred = model.predict(loader_te.load(), use_multiprocessing=True)"
@@ -218,7 +315,7 @@
218315
],
219316
"metadata": {
220317
"kernelspec": {
221-
"display_name": "venv",
318+
"display_name": ".venv311",
222319
"language": "python",
223320
"name": "python3"
224321
},
@@ -232,7 +329,7 @@
232329
"name": "python",
233330
"nbconvert_exporter": "python",
234331
"pygments_lexer": "ipython3",
235-
"version": "3.12.2"
332+
"version": "3.11.11"
236333
}
237334
},
238335
"nbformat": 4,

0 commit comments

Comments
 (0)