Downloads · 30 days
12
12% of all-time downloads
rokati/heterogen_focal_without_kpis
heterogen_focal_without_kpis is a machine learning model from rokati. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for pytorch.
This is a Heterogeneous Graph Neural Network (GNN) model trained to predict Expected Goals (xG) in football/soccer using graph-structured data.
Downloads · 30 days
12
12% of all-time downloads
All-time downloads
100
Public
Repo size
1.1 MB
Likes
1
Public
Click a slice to open those files.
.pth526 KB · 98%
From the Hugging Face model README
This is a Heterogeneous Graph Neural Network (GNN) model trained to predict Expected Goals (xG) in football/soccer using graph-structured data.
The model uses the following contextual features for each shot:
import torch
from torch_geometric.data import HeteroData
from huggingface_hub import hf_hub_download
import importlib.util
import json
# Download files
model_path = hf_hub_download(repo_id="rokati/heterogen_focal_without_kpis", filename="best_gnn_model.pth")
architecture_path = hf_hub_download(repo_id="rokati/heterogen_focal_without_kpis", filename="model_architecture.py")
config_path = hf_hub_download(repo_id="rokati/heterogen_focal_without_kpis", filename="config.json")
# Load configuration
with open(config_path, 'r') as f:
config = json.load(f)
# Load architecture
spec = importlib.util.spec_from_file_location("model_architecture", architecture_path)
model_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(model_module)
# Create model instance
model = model_module.XGNet(
num_players=config['num_players'],
hid=config['hidden_dim'],
p=config['dropout_rate'],
heads=config['num_heads'],
num_layers=config['num_layers'],
use_norm=config['use_norm'],
num_global_features=config['num_global_features']
)
# Load weights
model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
model.eval()
# Prepare graph data
graph = HeteroData()
# Add nodes
graph["shooter"].x = torch.tensor([[player_idx]], dtype=torch.long)
graph["goal"].x = torch.zeros((1, 1))
# Add edges with attributes
graph["goal", "distance", "shooter"].edge_index = torch.tensor([[0], [0]], dtype=torch.long)
graph["goal", "distance", "shooter"].edge_attr = torch.tensor([[distance_to_goal]], dtype=torch.float)
graph["goal", "angle_to_goal", "shooter"].edge_index = torch.tensor([[0], [0]], dtype=torch.long)
graph["goal", "angle_to_goal", "shooter"].edge_attr = torch.tensor([[angle_to_goal]], dtype=torch.float)
graph["goal", "dist_to_gk", "shooter"].edge_index = torch.tensor([[0], [0]], dtype=torch.long)
graph["goal", "dist_to_gk", "shooter"].edge_attr = torch.tensor([[dist_to_gk]], dtype=torch.float)
graph["goal", "angle_to_gk", "shooter"].edge_index = torch.tensor([[0], [0]], dtype=torch.long)
graph["goal", "angle_to_gk", "shooter"].edge_attr = torch.tensor([[angle_to_gk]], dtype=torch.float)
# Add global features (18 features)
graph.global_features = torch.tensor([global_feature_values], dtype=torch.float)
# Make prediction
with torch.no_grad():
logits = model(graph)
xg_prediction = torch.sigmoid(logits).item()
The model was trained with:
The heterogeneous GNN uses:
MIT