This is a project for automating driving in Forza Horizon 4 Game. It records input images and preferred driving commands using record.py, then trains a model on this data using various libraries and tools. Trained models can then be used to drive the car within the game using drive.py
- To train a model, we first have to create a dataset with the input images and preferred driving commands. To do so we have to use the
record.py - The data is recorded using a
controller, so keyboard inputs aren't supported yet. - The
MONITOR_REGIONvariable stores the location of the screen, current it is set to record the left screen in a dual screen setup, this can be changed as needed - The
OUTPUT_DIRvariable defines the location where the recorded data is stored - The
RECORD_FPS_CAPvariable defines the frame rate at which the data is recorded RESIZE_DIMSdefines the size of the recorded images/frames- Run the record script
python record.pyto start recording the game's output. - Press
qto stop the recording process. - Each run is stored as a sequence.
- Run the record script
- Once you have recorded data, you can use various models (e.g.,
forza-convnext-lstm) to train and optimize performance. - The training process uses the PyTorch Lightning framework for easy experiment tracking and logging.
- You can customize hyperparameters in the
config.jsonfile, such as batch size, sequence length, and learning rate.
- We use a combination of ConvNeXt Tiny and LSTM models to predict driving commands from game images.
- The training process involves the following steps:
- Data loading: Load recorded data sequences into memory using
ForzaDatasetorForzaLSTMDataset. - Model initialization: Initialize the model with either ConvNeXt Tiny or ConvNext Tiny LSTM architecture, depending on the
config.jsonsettings. - Training loop: Train the model on the loaded data for a specified number of epochs using PyTorch Lightning's
Trainer.
- Data loading: Load recorded data sequences into memory using
README.md- Description of the project/repositorydrive.py- Program to drive the car in forzagamepad.py- Implements classes and relevant methods to record inputs from the controller and to write commands as the controllerrecord.py- Code to record and create a sequence for the forza datasettrain_model.py- Model trainer script