Skip to content

Commit

Permalink
Create json a bit faster and less memory intensive
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjoos committed Feb 26, 2024
1 parent 2daf968 commit 4d5a4de
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tracklab/wrappers/datasets/soccernet/soccernet_game_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import time
import zipfile
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -84,7 +85,6 @@ def save_for_eval(self,
@staticmethod
def soccernet_encoding(dataframe: pd.DataFrame, supercategory):
dataframe["supercategory"] = supercategory
dataframe = dataframe.map(lambda x: x.tolist() if isinstance(x, np.ndarray) else x)
dataframe = dataframe.replace({np.nan: None})
if supercategory == "object":
# Remove detections that don't have mandatory columns
Expand All @@ -100,10 +100,7 @@ def soccernet_encoding(dataframe: pd.DataFrame, supercategory):
)
dataframe = dataframe.rename(columns={"bbox_ltwh": "bbox_image", "jersey_number": "jersey"})
dataframe["track_id"] = dataframe["track_id"]
dataframe["attributes"] = dataframe.apply(
lambda x: x[x.index.intersection(["role", "jersey", "team"])].to_dict(),
axis=1
)
dataframe["attributes"] = [{"role": x.get("role"), "jersey": x.get("jersey"), "team": x.get("team")} for n, x in dataframe.iterrows()]
dataframe["id"] = dataframe.index
dataframe = dataframe[dataframe.columns.intersection(
["id", "image_id", "video_id", "track_id", "supercategory",
Expand All @@ -127,6 +124,8 @@ def soccernet_encoding(dataframe: pd.DataFrame, supercategory):
dataframe["video_id"] = dataframe["video_id"].apply(str)
dataframe["image_id"] = dataframe["image_id"].apply(str)
dataframe["id"] = dataframe["id"].apply(str)
dataframe = dataframe.map(
lambda x: x.tolist() if isinstance(x, np.ndarray) else x)
return dataframe


Expand Down

0 comments on commit 4d5a4de

Please sign in to comment.