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.
Metadata
Release files for tmlearning 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tmlearning-1.2.0.tar.gz | 10.3 kB | Without provenance | Details for tmlearning-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tmlearning-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for tmlearning-1.2.0-py3-none-any.whl |
Total release size: 22.6 kB
Release files / tmlearning-1.2.0.tar.gz
| Download URL | tmlearning-1.2.0.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee0a81e23d11de87e83c46d252832dcdbbe272d3aa480a70df7ea9c86281413f
|
|
BLAKE2b-256 checksum How to use checksums |
27c764cb6ae42a91b68b803f71562da054dc2a5a06ba01004858444ae40693f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Release files / tmlearning-1.2.0-py3-none-any.whl
| Download URL | tmlearning-1.2.0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5a83b4fbd3be5e19b9cd7a4e71c2d8b4164b82150472ece9db78b935e1cf66f
|
|
BLAKE2b-256 checksum How to use checksums |
f13bcfcb1fd41f40fe691c8be3ff3bcab6b0552d6b624f3c3ad7877ed22f8b09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Security for tmlearning 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.