Downloads · 30 days
7
15% of all-time downloads
CharithAnupama/ML-Agents-SoccerTwos
ML-Agents-SoccerTwos is a reinforcement learning model from CharithAnupama. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. It is set up for ml-agents.
[](https://github.com/Unity-Technologies/ml-agents) [](https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Learning-Environment-Examples.mdsoccer-twos) [](https://opensource.org/licenses/Apache-2.0)
Downloads · 30 days
7
15% of all-time downloads
All-time downloads
48
Public
Repo size
1.8 MB
Likes
0
Public
Click a slice to open those files.
.onnx1.8 MB · 99%
From the Hugging Face model README
A sophisticated multi-agent reinforcement learning model trained on the Unity ML-Agents SoccerTwos environment. This model demonstrates advanced cooperative and competitive behaviors in a 2v2 soccer simulation, showcasing emergent team strategies and individual skill development.
The SoccerTwos model represents a breakthrough in multi-agent reinforcement learning, where four AI agents (two teams of two players each) learn to play soccer through self-play and competitive training. The model exhibits complex behaviors including:
Game Setup:
Physics & Mechanics:
Each agent receives:
# Core PPO Settings
batch_size: 2048
buffer_size: 20480
learning_rate: 3e-4
learning_rate_schedule: linear
epsilon: 0.2
beta: 5e-4
lambd: 0.95
num_epoch: 3
# Network Architecture
hidden_units: 512
num_layers: 2
normalize: true
vis_encode_type: simple
# Training Schedule
max_steps: 50000000
time_horizon: 1000
summary_freq: 12000
import onnxruntime as ort
import numpy as np
# Load the ONNX model
model_path = "SoccerTwos.onnx"
session = ort.InferenceSession(model_path)
# Get input/output names
input_name = session.get_inputs()[0].name
output_names = [output.name for output in session.get_outputs()]
# Run inference
def predict_action(observation):
observation = np.array(observation, dtype=np.float32)
observation = observation.reshape(1, -1) # Batch dimension
outputs = session.run(output_names, {input_name: observation})
actions = outputs[0][0] # Extract actions from batch
return actions
// Unity C# script example
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
public class SoccerAgent : Agent
{
[SerializeField] private string modelPath = "SoccerTwos.onnx";
public override void OnActionReceived(ActionBuffers actionBuffers)
{
// Extract continuous actions
float moveX = actionBuffers.ContinuousActions[0];
float moveZ = actionBuffers.ContinuousActions[1];
float rotate = actionBuffers.ContinuousActions[2];
// Apply actions to agent
ApplyMovement(moveX, moveZ, rotate);
}
}
# Evaluation with metrics tracking
class SoccerEvaluator:
def __init__(self, model_path):
self.session = ort.InferenceSession(model_path)
self.reset_metrics()
def reset_metrics(self):
self.goals_scored = 0
self.goals_conceded = 0
self.ball_touches = 0
self.episode_length = 0
def evaluate_episode(self, observations, actions, rewards):
# Run full episode evaluation
total_reward = sum(rewards)
win_rate = 1.0 if self.goals_scored > self.goals_conceded else 0.0
return {
'total_reward': total_reward,
'goals_scored': self.goals_scored,
'goals_conceded': self.goals_conceded,
'win_rate': win_rate,
'ball_touches': self.ball_touches
}
Offensive Strategies:
Defensive Strategies:
Minimum:
Recommended:
# Multi-episode evaluation
def evaluate_model(model_path, num_episodes=100):
evaluator = SoccerEvaluator(model_path)
results = []
for episode in range(num_episodes):
# Run episode
episode_result = evaluator.run_episode()
results.append(episode_result)
# Aggregate results
avg_reward = np.mean([r['total_reward'] for r in results])
win_rate = np.mean([r['win_rate'] for r in results])
avg_goals = np.mean([r['goals_scored'] for r in results])
return {
'average_reward': avg_reward,
'win_rate': win_rate,
'average_goals_per_episode': avg_goals,
'total_episodes': num_episodes
}
# Custom training configuration
from mlagents_envs.environment import UnityEnvironment
from mlagents.trainers.settings import TrainerSettings
# Environment setup
env = UnityEnvironment(file_name="SoccerTwos")
trainer_config = TrainerSettings(
trainer_type="ppo",
hyperparameters={
"batch_size": 2048,
"buffer_size": 20480,
"learning_rate": 3e-4,
"beta": 5e-4,
"epsilon": 0.2,
"lambd": 0.95,
"num_epoch": 3,
"learning_rate_schedule": "linear"
}
)
We welcome contributions to improve the model and documentation:
Areas for Contribution:
@misc{ml_agents_soccer_twos_2025,
title={ML-Agents SoccerTwos: Multi-Agent Soccer AI},
author={Adilbai},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/Adilbai/ML-Agents-SoccerTwos},
note={Unity ML-Agents trained model for 2v2 soccer simulation}
}
This model is released under the Apache 2.0 License, consistent with Unity ML-Agents framework licensing.
multi-agent reinforcement-learning unity-ml-agents soccer cooperative-ai competitive-ai onnx game-ai emergent-behavior team-coordination
Note: This model represents advanced multi-agent AI capabilities and serves as an excellent example of emergent team behaviors in competitive environments. The model is suitable for research, education, and game development applications.