Skip to content

Commit d4df1d6

Browse files
committed
Group data also over game phase
1 parent bc5da31 commit d4df1d6

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

tools/machine-learning/fall_detection/data_loading/load_data.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
from datetime import datetime
2+
from itertools import batched
13
from pathlib import Path
24
from typing import Any
3-
from mcap.reader import make_reader, McapReader
5+
46
import polars as pl
7+
from mcap.reader import McapReader, make_reader
58
from msgpack import unpackb
6-
from datetime import datetime
7-
from itertools import batched
8-
from tqdm import tqdm
99
from scipy.spatial.transform import Rotation
10+
from tqdm import tqdm
11+
1012
from .unnest_structs import unnest_column
1113

1214

@@ -111,13 +113,15 @@ def iter_mcap(reader: McapReader, topics: list[str]):
111113

112114
def read_mcap(mcap_path: Path) -> pl.DataFrame:
113115
robot_identifier = mcap_path.parts[-3]
116+
game_phase_identifier = mcap_path.parts[-4]
114117
match_identifier = mcap_path.parts[-5]
115118

116119
print(mcap_path)
117120
with open(mcap_path, "rb") as mcap_data:
118121
reader = make_reader(mcap_data)
119122
dataframe = pl.from_dicts(iter_mcap(reader, OUTPUTS)).with_columns(
120123
pl.lit(robot_identifier).alias("robot_identifier"),
124+
pl.lit(game_phase_identifier).alias("game_phase_identifier"),
121125
pl.lit(match_identifier).alias("match_identifier"),
122126
)
123127
return dataframe
@@ -139,7 +143,7 @@ def convert_mcaps(mcaps: list[str]) -> pl.DataFrame:
139143
def load(path: str):
140144
df = pl.read_parquet(path).with_columns(
141145
(pl.col("time") - pl.col("time").min())
142-
.over("robot_identifier", "match_identifier")
146+
.over("robot_identifier", "game_phase_identifier", "match_identifier")
143147
.dt.total_seconds()
144148
.alias("time_in_game"),
145149
)

tools/machine-learning/fall_detection/scripts/inspect-data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def main():
1414
df,
1515
group_keys=[
1616
pl.col("robot_identifier"),
17+
pl.col("game_phase_identifier"),
1718
pl.col("match_identifier"),
1819
],
1920
features=[

tools/machine-learning/fall_detection/scripts/train.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ def train(model_type: ModelType, data_path: str) -> None:
230230
df = load(data_path)
231231
dataset = FallenDataset(
232232
df,
233-
group_keys=[pl.col("robot_identifier"), pl.col("match_identifier")],
233+
group_keys=[
234+
pl.col("robot_identifier"),
235+
pl.col("game_phase_identifier"),
236+
pl.col("match_identifier"),
237+
],
234238
features=[
235239
pl.col(
236240
"Control.main_outputs.sensor_data.inertial_measurement_unit.linear_acceleration.x"

0 commit comments

Comments
 (0)