A Python library to create and use machine learning TrackMania AIs.
Project description
TMLearning
TMLearning is a Python library for training and deploying custom TrackMania AIs using machine learning. It works with any TrackMania version—or any game that uses only arrow keys—by training a convolutional neural network (CNN) to imitate your driving style from screenshots and predict the next key presses.
Note: To capture keyboard input when TrackMania is not in focus, you must run the application running
TMLearningwith administrator privileges.
Features
| Feature | Status |
|---|---|
| Digital Inputs / Outputs | ✅ Supported |
| Analog Inputs / Outputs | ❌ Not supported |
| Car Data (rotation, speed, position) | 🟨 Coming soon (TMNF only) |
| Convolutional Neural Network architecture | ✅ Supported |
Installation
pip install tmlearning
Quickstart
-
Input Testing
from tmlearning import wasd_key_test, arrow_key_test # Test WASD input wasd_key_test() # Test arrow-key input arrow_key_test()
Press your chosen keys to confirm they’re detected correctly.
-
Initialize the Bot
from tmlearning import GeneralTMLearning bot = GeneralTMLearning( name="my_bot", keys="ARROW", # or "WASD" data_capture_interval=0.1, exec_capture_interval=0.1, save_frequency=None, img_size=(160, 120), cnn_test_percentage=0.2, cnn_epochs=10, cnn_batch_size=32, verbose=True )
-
Create a Dataset
bot.create_database()
- Press Enter to start.
- After a 5‑second countdown, drive in TrackMania.
- Hold your stop key (default
z) for ~2×data_capture_intervalseconds to stop and save.
-
Train the Model
bot.train_model()
-
Run the Model
bot.run_model()
- Press Enter, switch to TrackMania within 5 seconds, and let it drive for you.
- Use Ctrl+C to stop.
File Structure
When you instantiate GeneralTMLearning(name="my_bot"), a folder named my_bot_bot/ is created containing:
| File Name | Description |
|---|---|
my_bot_data.pkl |
Pickled dataset (screenshots + key labels). |
my_bot_cnn.keras |
Saved CNN model weights. |
my_bot_config.pkl |
Pickled configuration parameters. |
Configuration
- On first initialization,
my_bot_config.pklrecords all parameters. - Re-initializing with the same
nameloads existing settings. - Changing any attribute (e.g.
bot.img_size = (200,150)) automatically updates the config file.
File Management
| Method | Deletes |
|---|---|
bot.delete_dataset_file() |
my_bot_data.pkl |
bot.delete_config_file() |
my_bot_config.pkl |
bot.delete_all_files() |
Entire my_bot_bot/ folder |
CNN Architecture (v1.2.0)
Currently fixed; customization coming in v1.3.
| Layer | Parameters |
|---|---|
| Conv1 | kernel=3×3, stride=1 |
| BatchNorm | — |
| Conv2 | kernel=3×3, stride=1 |
| BatchNorm | — |
| Conv3 | kernel=3×3, stride=1 |
| BatchNorm | — |
| MaxPooling | kernel=2×2, stride=2 |
| Dense (FC1) | 256 units |
| Dropout | p=0.3 |
| Dense (FC2) | 4 units (output classes) |
Version History
-
1.2.0
- Switched to CNN architecture.
- Added file‑deletion methods (
delete_all_files,delete_config_file,delete_dataset_file). - Renamed main class to
GeneralTMLearningin preparation forTMNFLearning.
-
1.1.0
- Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tmlearning-1.2.0.tar.gz.
File metadata
- Download URL: tmlearning-1.2.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0a81e23d11de87e83c46d252832dcdbbe272d3aa480a70df7ea9c86281413f
|
|
| MD5 |
38cd88667722ea5e210322f87f7c5ab4
|
|
| BLAKE2b-256 |
27c764cb6ae42a91b68b803f71562da054dc2a5a06ba01004858444ae40693f7
|
File details
Details for the file tmlearning-1.2.0-py3-none-any.whl.
File metadata
- Download URL: tmlearning-1.2.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a83b4fbd3be5e19b9cd7a4e71c2d8b4164b82150472ece9db78b935e1cf66f
|
|
| MD5 |
8c82d06ab6d6da9d553e4c013498c6c9
|
|
| BLAKE2b-256 |
f13bcfcb1fd41f40fe691c8be3ff3bcab6b0552d6b624f3c3ad7877ed22f8b09
|