- 23
- Netherlands
- bciartd
So, I've been doing Sagrinda™ for quite a while now, trying to collect all the cars. Since I've golded the whole game it's pretty much the only major goal left for me now.
After going through this event with different cars and setups, I stuck to Nissan R92CP with Turbodatsun's tune for the quickest time. And after several hundreds of races there it started to feel a little mechanical, you know.
Then this idea started to crawl into my mind: what if I could train a neural network to do this race for me? That would be a fun and impressive thing to do, isn't it?
Sure, training a full-blown racing AI is not a feasable thing unless you have a whole corporation backing you up with their resources and R&D for years. But I don't need a general-purpose racing agent, I just need to teach it to do one particular track on one particular car with a fixed tune and race strategy.
Unfortunately, I'm not a ML scientist and have zero expertise in building an AI. I just have a general understanding of what is needed to build and train it. And some free time.
Since we have a giant community of racing enthusiasts here, I would love to go through some sanity check before wasting a lot of time on something that is impossible.
Several aspects of training an AI and running it afterwards.
Training data
Since I'm already doing this race dozens of times daily it's possible to accumulate a dataset of 100-200 attempts in a month or so.
Learning process
The main trick is to teach the model to do the race not just in the clear laps (with no traffic), but also to be able to overtake the field, change the Fuel Map after the Pit Stop, do the Pit Stop itself.
The main goal of the model is to do the race in the minimum time possible while keeping the Clean Race bonus.
I'll have to manually map all the 15 laps in the training data for every attempt - this way the AI should understand the repetitive nature of the task + it will be possible to reinforce it for a better time for a particular lap.
The laps themselves are different within one race:
Plus comparing the overall race time, of course.
Pit Stop / menus navigation doesn't have any variations, so that part should be learned pretty quickly.
Having dataset with desired outputs (recorded from my plays) also should speed up the learning process significantly. Although there's got to be a way to mark some inputs as "mandatory" (Pit Stop / menus navigation), "desired" (faster laps) or "undesired" (crashes, going off track, ingnoring Yellow Flag and so on).
Output data
The trained AI should emulate controller inputs as a result of its work while being fed a live video of the game + live telemetry.
I imagine it to work the following way:
Turn on the game, pick the car and the event, put the cursor on the Start button. Connect video and telemetry to the computer, connect the emulated controller to the PS5. Start the model execution (and optionally the recording of the training data - we still want to improve the model behaviour, right?), wait through the race, stop execuition (and recording) when the game arrives at the starting position. Recalculate the model using the latest data. Rinse and repeat.
Open questions
Now that you've finally read all of this, here are the open questions that I have in mind:
My goal here is not to create a cheat to beat the game. Yes, I'm wildly frustrated with the necessity of grinding for days just to buy an overpriced virtual old car that is barely useful for in-game racing. But that's not the point.
The point is to make grinding fun and do something different while I am at it. And maybe, MAYBE, create something beautiful along the way.
Modern problems require modern solutions.
After going through this event with different cars and setups, I stuck to Nissan R92CP with Turbodatsun's tune for the quickest time. And after several hundreds of races there it started to feel a little mechanical, you know.
Then this idea started to crawl into my mind: what if I could train a neural network to do this race for me? That would be a fun and impressive thing to do, isn't it?
Sure, training a full-blown racing AI is not a feasable thing unless you have a whole corporation backing you up with their resources and R&D for years. But I don't need a general-purpose racing agent, I just need to teach it to do one particular track on one particular car with a fixed tune and race strategy.
Unfortunately, I'm not a ML scientist and have zero expertise in building an AI. I just have a general understanding of what is needed to build and train it. And some free time.
Since we have a giant community of racing enthusiasts here, I would love to go through some sanity check before wasting a lot of time on something that is impossible.
Several aspects of training an AI and running it afterwards.
Training data
Since I'm already doing this race dozens of times daily it's possible to accumulate a dataset of 100-200 attempts in a month or so.
- Video recording of the race.
Fixed view, no looking backwards / to the sides. No need for audio. 60 FPS is more than enough.
Also it should be safe to convert the frame size from 4k (3840 × 2160) to 720p (1280×720) to lower the size of the model (and its inputs) and improve the calculation/training speed. - Recording of the telemetry.
Since PD is generous enough to provide us with the precise telemetry it can be used for training, so no need to extract those values with some OCR from the video output.
The values that I see particularly useful: Speed, Engine RPM, Fuel Level, Current Lap, Best/Last Lap Time, some of the flags (Rev Limiter, Handbrake), Current Gear, Brake, Throttle.
Maybe some others too, but I do think the less inputs the simpler the training. - Recording of the controller inputs.
Since there's no steering data in the telemetry and I need the AI to be able to navigate through Pit Stop menu (plus post-race menus) and adjust the Fuel Map during the race, I have to record all the controller inputs as well.
Also these inputs will be used as a reference in training data (the AI will need to learn to produce similar inputs as a result of its work).
Learning process
The main trick is to teach the model to do the race not just in the clear laps (with no traffic), but also to be able to overtake the field, change the Fuel Map after the Pit Stop, do the Pit Stop itself.
The main goal of the model is to do the race in the minimum time possible while keeping the Clean Race bonus.
I'll have to manually map all the 15 laps in the training data for every attempt - this way the AI should understand the repetitive nature of the task + it will be possible to reinforce it for a better time for a particular lap.
The laps themselves are different within one race:
- Lots of overtaking on laps 1-2, 6-9 and 13-15, (almost) no traffic on other laps;
- Fuel Map 2 with shortshifting on laps 1-8, Fuel Map 1 with no shortshifting on laps 9-15;
- Mandatory Pit Stop at the end of lap 8.
Plus comparing the overall race time, of course.
Pit Stop / menus navigation doesn't have any variations, so that part should be learned pretty quickly.
Having dataset with desired outputs (recorded from my plays) also should speed up the learning process significantly. Although there's got to be a way to mark some inputs as "mandatory" (Pit Stop / menus navigation), "desired" (faster laps) or "undesired" (crashes, going off track, ingnoring Yellow Flag and so on).
Output data
The trained AI should emulate controller inputs as a result of its work while being fed a live video of the game + live telemetry.
I imagine it to work the following way:
Turn on the game, pick the car and the event, put the cursor on the Start button. Connect video and telemetry to the computer, connect the emulated controller to the PS5. Start the model execution (and optionally the recording of the training data - we still want to improve the model behaviour, right?), wait through the race, stop execuition (and recording) when the game arrives at the starting position. Recalculate the model using the latest data. Rinse and repeat.
Open questions
Now that you've finally read all of this, here are the open questions that I have in mind:
- Is there a way to reliably record video, telemetry and controller inputs at the same time as live playing the game?
I assume that it's possible since many streamers do that daily, but what's the easiest and simplest way to do that? I'm especially concerned with controller inputs being in sync with all the other data. - Is there a way to emulate controller inputs coming from a connected computer?
I don't need to emulate feedback or trigger effects, I just want the game to take the generated inputs and not to complain about it. - Do any of you have ML backgound so I can discuss the architecture of the model, the training / fine-tuming process and not waste months of my life blindly probing every variation possible?
My goal here is not to create a cheat to beat the game. Yes, I'm wildly frustrated with the necessity of grinding for days just to buy an overpriced virtual old car that is barely useful for in-game racing. But that's not the point.
The point is to make grinding fun and do something different while I am at it. And maybe, MAYBE, create something beautiful along the way.
Modern problems require modern solutions.