Update README.md
Browse files
README.md
CHANGED
|
@@ -6,30 +6,181 @@ tags:
|
|
| 6 |
- reinforcement-learning
|
| 7 |
- ML-Agents-SnowballTarget
|
| 8 |
---
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
This is a trained model of a **ppo** agent playing **SnowballTarget**
|
| 12 |
-
using the [Unity ML-Agents Library](https://github.com/Unity-Technologies/ml-agents).
|
| 13 |
|
| 14 |
-
|
| 15 |
-
The Documentation: https://unity-technologies.github.io/ml-agents/ML-Agents-Toolkit-Documentation/
|
| 16 |
|
| 17 |
-
|
| 18 |
-
- A *short tutorial* where you teach Huggy the Dog πΆ to fetch the stick and then play with him directly in your
|
| 19 |
-
browser: https://huggingface.co/learn/deep-rl-course/unitbonus1/introduction
|
| 20 |
-
- A *longer tutorial* to understand how works ML-Agents:
|
| 21 |
-
https://huggingface.co/learn/deep-rl-course/unit5/introduction
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
You can watch your agent **playing directly in your browser**
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
| 6 |
- reinforcement-learning
|
| 7 |
- ML-Agents-SnowballTarget
|
| 8 |
---
|
| 9 |
+
# PPO-SnowballTarget Reinforcement Learning Model
|
| 10 |
|
| 11 |
+
## Model Description
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
This model is a Proximal Policy Optimization (PPO) agent trained to play the SnowballTarget environment from Unity ML-Agents. The agent, named Julien the Bear π», learns to accurately throw snowballs at spawning targets to maximize rewards.
|
|
|
|
| 14 |
|
| 15 |
+
## Model Details
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
### Model Architecture
|
| 18 |
+
- **Algorithm**: Proximal Policy Optimization (PPO)
|
| 19 |
+
- **Framework**: Unity ML-Agents with PyTorch backend
|
| 20 |
+
- **Agent**: Julien the Bear (3D character)
|
| 21 |
+
- **Policy Network**: Actor-Critic architecture
|
| 22 |
+
- Actor: Outputs action probabilities
|
| 23 |
+
- Critic: Estimates state values for advantage calculation
|
| 24 |
|
| 25 |
+
### Environment: SnowballTarget
|
|
|
|
| 26 |
|
| 27 |
+
SnowballTarget is an environment created at Hugging Face using assets from Kay Lousberg where you train an agent called Julien the bear π» that learns to hit targets with snowballs.
|
| 28 |
+
|
| 29 |
+
**Environment Details:**
|
| 30 |
+
- **Objective**: Train Julien the Bear to accurately throw snowballs at targets
|
| 31 |
+
- **Setting**: 3D winter environment with spawning targets
|
| 32 |
+
- **Agent**: Single agent (Julien the Bear)
|
| 33 |
+
- **Targets**: Dynamically spawning targets that need to be hit with snowballs
|
| 34 |
+
|
| 35 |
+
### Observation Space
|
| 36 |
+
The agent observes:
|
| 37 |
+
- Agent's position and rotation
|
| 38 |
+
- Target positions and states
|
| 39 |
+
- Snowball trajectory information
|
| 40 |
+
- Environmental spatial relationships
|
| 41 |
+
- Ray-cast sensors for spatial awareness
|
| 42 |
+
|
| 43 |
+
### Action Space
|
| 44 |
+
- **Continuous Actions**: Aiming direction and throw force
|
| 45 |
+
- **Action Dimensions**: Typically 2-3 continuous values
|
| 46 |
+
- Horizontal aiming angle
|
| 47 |
+
- Vertical aiming angle
|
| 48 |
+
- Throw force/power
|
| 49 |
+
|
| 50 |
+
### Reward Structure
|
| 51 |
+
- **Positive Rewards**:
|
| 52 |
+
- +1.0 for hitting a target
|
| 53 |
+
- Distance-based reward bonuses for accurate shots
|
| 54 |
+
- **Negative Rewards**:
|
| 55 |
+
- Small time penalty to encourage efficiency
|
| 56 |
+
- Penalty for missing targets
|
| 57 |
+
|
| 58 |
+
## Training Configuration
|
| 59 |
+
|
| 60 |
+
### PPO Hyperparameters
|
| 61 |
+
- **Algorithm**: Proximal Policy Optimization (PPO)
|
| 62 |
+
- **Training Framework**: Unity ML-Agents
|
| 63 |
+
- **Batch Size**: Typical ML-Agents default (1024-2048)
|
| 64 |
+
- **Learning Rate**: Adaptive (typically 3e-4)
|
| 65 |
+
- **Entropy Coefficient**: Encourages exploration
|
| 66 |
+
- **Value Function Coefficient**: Balances actor-critic training
|
| 67 |
+
- **PPO Clipping**: Ξ΅ = 0.2 (standard PPO clipping range)
|
| 68 |
+
|
| 69 |
+
### Training Process
|
| 70 |
+
- **Environment**: Unity ML-Agents SnowballTarget
|
| 71 |
+
- **Training Method**: Parallel environment instances
|
| 72 |
+
- **Episode Length**: Variable (until all targets hit or timeout)
|
| 73 |
+
- **Success Criteria**: Consistent target hitting accuracy
|
| 74 |
+
|
| 75 |
+
## Performance Metrics
|
| 76 |
+
|
| 77 |
+
The model is evaluated based on:
|
| 78 |
+
- **Hit Accuracy**: Percentage of targets successfully hit
|
| 79 |
+
- **Average Reward**: Cumulative reward per episode
|
| 80 |
+
- **Training Stability**: Consistent improvement over training steps
|
| 81 |
+
- **Efficiency**: Time to hit targets (faster is better)
|
| 82 |
+
|
| 83 |
+
### Expected Performance
|
| 84 |
+
- **Target Hit Rate**: >80% accuracy on target hitting
|
| 85 |
+
- **Convergence**: Stable policy after sufficient training episodes
|
| 86 |
+
- **Generalization**: Ability to hit targets in various positions
|
| 87 |
+
|
| 88 |
+
## Usage
|
| 89 |
+
|
| 90 |
+
### Loading the Model
|
| 91 |
+
```python
|
| 92 |
+
from mlagents_envs import UnityToPythonWrapper
|
| 93 |
+
from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
|
| 94 |
+
|
| 95 |
+
# Load the trained model
|
| 96 |
+
# Model files should include .onnx policy file and configuration
|
| 97 |
+
```
|
| 98 |
+
### Resume the training
|
| 99 |
+
```bash
|
| 100 |
+
mlagents-learn <your_configuration_file_path.yaml> --run-id=<run_id> --resume
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Running Inference
|
| 104 |
+
```python
|
| 105 |
+
# The model can be used directly in Unity ML-Agents environments
|
| 106 |
+
# or deployed to Unity builds for real-time inference
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Technical Implementation
|
| 110 |
+
|
| 111 |
+
### PPO Algorithm Features
|
| 112 |
+
- **Policy Clipping**: Prevents large policy updates
|
| 113 |
+
- **Advantage Estimation**: GAE (Generalized Advantage Estimation)
|
| 114 |
+
- **Value Function**: Shared network with actor for efficiency
|
| 115 |
+
- **Batch Training**: Multiple parallel environments for sample efficiency
|
| 116 |
+
|
| 117 |
+
### Unity ML-Agents Integration
|
| 118 |
+
- **Python API**: Training through Python interface
|
| 119 |
+
- **Unity Side**: Real-time environment simulation
|
| 120 |
+
- **Observation Collection**: Automated sensor data gathering
|
| 121 |
+
- **Action Execution**: Smooth character animation and physics
|
| 122 |
+
|
| 123 |
+
## Files Structure
|
| 124 |
+
|
| 125 |
+
```
|
| 126 |
+
βββ SnowballTarget.onnx # Trained policy network
|
| 127 |
+
βββ configuration.yaml # Training configuration
|
| 128 |
+
βββ run_logs/ # Training metrics and logs
|
| 129 |
+
βββ results/ # Training results and statistics
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Limitations and Considerations
|
| 133 |
+
|
| 134 |
+
1. **Environment Specific**: Model is trained specifically for SnowballTarget environment
|
| 135 |
+
2. **Unity Dependency**: Requires Unity ML-Agents framework for deployment
|
| 136 |
+
3. **Physics Sensitivity**: Performance may vary with different physics settings
|
| 137 |
+
4. **Target Patterns**: May not generalize to significantly different target spawn patterns
|
| 138 |
+
|
| 139 |
+
## Applications
|
| 140 |
+
|
| 141 |
+
- **Game AI**: Can be integrated into Unity games as intelligent NPC behavior
|
| 142 |
+
- **Educational**: Demonstrates reinforcement learning in 3D environments
|
| 143 |
+
- **Research**: Benchmark for continuous control and aiming tasks
|
| 144 |
+
- **Interactive Demos**: Can be deployed in web builds for demonstrations
|
| 145 |
+
|
| 146 |
+
## Ethical Considerations
|
| 147 |
+
|
| 148 |
+
This model represents a benign gaming scenario with no ethical concerns:
|
| 149 |
+
- **Content**: Family-friendly winter sports theme
|
| 150 |
+
- **Violence**: Non-violent snowball throwing activity
|
| 151 |
+
- **Educational Value**: Suitable for learning about AI and reinforcement learning
|
| 152 |
+
|
| 153 |
+
## Unity ML-Agents Version Compatibility
|
| 154 |
+
|
| 155 |
+
- **ML-Agents**: Compatible with Unity ML-Agents toolkit
|
| 156 |
+
- **Unity Version**: Works with Unity 2021.3+ LTS
|
| 157 |
+
- **Python Package**: Requires `mlagents` Python package
|
| 158 |
+
|
| 159 |
+
## Training Environment
|
| 160 |
+
|
| 161 |
+
- **Unity Editor**: 3D environment simulation
|
| 162 |
+
- **ML-Agents**: Python training interface
|
| 163 |
+
- **Hardware**: GPU-accelerated training recommended
|
| 164 |
+
- **Parallel Environments**: Multiple instances for efficient training
|
| 165 |
+
|
| 166 |
+
## Citation
|
| 167 |
+
|
| 168 |
+
If you use this model, please cite:
|
| 169 |
+
|
| 170 |
+
```bibtex
|
| 171 |
+
@misc{ppo-snowballtarget-2024,
|
| 172 |
+
title={PPO-SnowballTarget: Reinforcement Learning Agent for Unity ML-Agents},
|
| 173 |
+
author={Adilbai},
|
| 174 |
+
year={2024},
|
| 175 |
+
publisher={Hugging Face Hub},
|
| 176 |
+
url={https://huggingface.co/Adilbai/ppo-SnowballTarget}
|
| 177 |
+
}
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
## References
|
| 181 |
+
|
| 182 |
+
- Schulman, J., et al. (2017). Proximal Policy Optimization Algorithms. arXiv preprint arXiv:1707.06347.
|
| 183 |
+
- Unity Technologies. Unity ML-Agents Toolkit. https://github.com/Unity-Technologies/ml-agents
|
| 184 |
+
- Hugging Face Deep RL Course: https://huggingface.co/learn/deep-rl-course
|
| 185 |
+
- Kay Lousberg (Environment Assets): https://www.kaylousberg.com/
|
| 186 |
|