In this README we will guide you through the setup process of TMRL, how to train and how to perform inference.
We have provided pre-trained models for all our agents in the model_weights folder, but if you want to train the model yourself, follow the steps below.
Provided in our repository is a custom track that we have created for you to train and perform inference on. The tracks
is called tmrl-test-track-1 and can be found in the train_files folder in the root directory of the project.
We have also provided a reward pickle file that is specifically tailored towards our own track,
so it is important that you have this file in the correct directory.
The reward file is located in the reward pickle file folder in the root directory of the project.
The project is structured as follows:
README.md: The README file that you are currently reading.configs: Contains theconfig.jsonfiles for each implemented algorithmtrain_files: Contains the custom track and reward pickle file used for training an agent with TMRL.data: Contains the results from training the agents.model_weights: Contains the pre-trained models for all our agents.pipelines: Contains the code for the agents and the pipeline to train and perform inference.
As mentioned before, we have provided pre-trained models for all our agents in the model weights folder,
but if you want to train the model yourself, follow the steps below.
Before any work can be done, a few things need to be installed and set up.
- Unzip the provided zip file, navigate to the root directory of the project and open it in your IDE of choice (PyCharm recommended).
- Read through the TMRL instructions on installing TMRL and OpenPlanet. Following
these instructions, I recommend running
pip install pywin32in a venv instead ofconda install pywin32. - Follow the instructions to see if everything is installed correctly by following the provided 'Getting started' guide.
- We recommend re-installing PyTorch after the previous steps are completed and verified. This is in case you want to train yourself. Please run the following command for venv users:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
and for conda users:
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
After these steps are completed, you should have TMRL installed and OpenPlanet working within Trackmania. Also, optionally, you have re-installed PyTorch.
To make training and inference work with our own track, a few files need to be copied to the correct directories.
- Open the
train_filesfolder in the root directory of the project, containingreward.pklandtmrl-test-track-1.Map.Gbx. - Copy the
reward.pklfile and navigate to theC:\Users\USERNAME\TmrlData\rewarddirectory. - Delete the existing
reward.pklfile and paste the new one in its place. - Copy the
tmrl-test-track-1.Map.Gbxfile and navigate to theC:\Users\USERNAME\Documents\Trackmania\Maps\My Mapsdirectory. - Paste the copied track in the directory.
Following these steps, you should have the reward.pkl file in the correct directory and the custom track in the correct directory.
This reward.pkl file is specifically tailored towards our own track, so it will not work for other tracks. More
information on how to create your own reward function can be found in the tmrl repository (see: 'Getting started')
Now we move on to training the model. We have provided pre-trained models for all our agents in the model weights folder, but if you want to train the model yourself, follow these steps:
- Choose a model you want to train, which is either a Pixel or LIDAR-based agent.
- Navigate to the
configsdirectory, dependent on if you want to train LIDAR or Pixel agents, navigate to the corresponding sub-directory. - Copy the
config.jsonfile from the chosen directory. - Navigate to the
C:\Users\USERNAME\TmrlData\configdirectory and paste the copiedconfig.jsonfile in the directory. - Open the
config.jsonfile and change theRUN_NAMEto a name of your choosing. Everything else is setup for you. Note: if you do not change theRUN_NAMEand you have trained before using the sameRUN_NAMEthe checkpoint file inC:\Users\USERNAME\TmrlData\checkpointswill be used to continue training, so changing theRUN_NAMEis important if you want to start training from scratch or if you want to train different agents. - Optional: If you are training on a CPU set the
CUDA_TRAININGflag tofalsein theconfig.jsonfile - Optional: If you want the model weights to be saved every
xsteps, change theSAVE_MODEL_EVERYflag to the desired amount of steps, with0meaning no saving.
Now that we are set-up for training we can start the training process:
- Open Trackmania, navigate to
Createin the main menu, thenTrack Editor->Edit Track->My Local tracks->My Mapsand you should see thetmrl-test-track-1track1. - Click on
tmrl-test-track-1and click theGreen Flagin the bottom right corner. Now you should see the car on the track. Make sure you followed theGetting startedguidestep 3because depending on Pixel or LIDAR-based agent, you need to change the camera view and the ghost needs to be turned off for all agents. - Take note of your chosen agent you want to train, either Pixel or LIDAR variant of DDPG, PPO, SAC-DC, SAC-SC.
- Open three separate terminals (make sure you are in your venv or conda env) and navigate to the
pipelines\<YOUR AGENT YOU WANT TO TRAIN>in all three terminals.- In the first terminal run the following command:
py pipeline.py --serverorpython pipeline.py --server(depending on if the first one did not work). You should see three lines in the terminal - In the second terminal run the following command:
py pipeline.py --trainerorpython pipeline.py --trainer(depending on if the first one did not work). After a few seconds you should see that an empty replay buffer is initialized - In the third terminal run the following command:
py pipeline.py --workerorpython pipeline.py --worker(depending on if the first one did not work) You should here a dinging noise once and now if you move to the Trackmania screen you can see that the car is moving. In the console you should see it's collecting samples etc.
- In the first terminal run the following command:
- Move back to the second terminal with the
trainerrunning. After a while it will show a round is completed and it has logged some values for you. - From here you can sit back and wait until the training process is finished, which is 10 epochs. You can stop the training process at any time by pressing
CTRL + Cin the terminal with thetrainerrunning. The model weights will be saved in theC:\Users\USERNAME\TmrlData\weightsdirectory (if set.)
Now that we have trained the model, we can perform inference on the model. We have provided a pre-trained models for all our agents in the model_weights folder, but if you want to perform inference on the model you trained yourself the process will be comparable:
- Choose the sensory (LIDAR or pixel data) you want to perform inference on.
- Navigate to the
configsdirectory and to the chosen sensory sub-directory. - Now choose if you want to perform inference on either the SAC-SC, SAC-DC, DDPG or PPO agent. Copy the
config.jsonfile from the chosen directory. - Navigate to the
C:\Users\USERNAME\TmrlData\configdirectory. and paste the copiedconfig.jsonfile in the directory. - Navigate to the
model_weightsdirectory. Choose the agent corresponding to the chosenconfig.jsonfile. Copy the.tmodfile from the chosen directory. - Navigate to the
C:\Users\USERNAME\TmrlData\weightsdirectory. and paste the copied.tmodfile in the directory. - Open a terminal and navigate to the
pipelines\<YOUR AGENT YOU WANT TO PERFORM INFERENCE ON>directory. - Have Trackmania open and the
tmrl-test-track-1track loaded in the editor. (As described inTrainingstep 1,2 and 3) - Open a terminal and run the following command:
py pipeline.py --testorpython pipeline.py --test(depending on if the first one did not work). The car should start performing actions.
Performing inference on the model you trained yourself:
- After training has finished you can quit the
server,trainerandworkerterminals. - Use one of the terminals you used before or open a new terminal and navigate to the
pipelines\<YOUR AGENT YOU WANT TO PERFORM INFERENCE ON>directory. (this has to be the one you finished training - Have Trackmania open and the
tmrl-test-track-1track loaded in the editor. (As described inTrainingstep 1,2 and 3) - In the open terminal run the following command:
py pipeline.py --testorpython pipeline.py --test(depending on if the first one did not work) The car should start doing stuff
IMPORTANT NOTICE
Inference on the Pixel-based agents is somewhat broken in our TMRL environment. You can perform inference for one round and than the package throws an error. this might not
happen for you, but if it happens please just restart the inference process by repeating the last command in the terminal.
Footnotes
-
If you don't see it, make sure the file in
train_fileshas correctly been copied toC:\Users\USERNAME\Documents\Trackmania\Maps\My Maps) ↩