Training a Context Classifier
A Context Classifier is a specialized machine learning model that can be trained using tools included with the Bluetang framework. Having a properly trained Context Classifier is essential for managing gameplay flows in your game agents. In this guide, we'll build a Context Classifier from scratch using Super Hexagon.
Analyzing the Game
To build a great Context Classifier, you need to spend some time playing/studying the game; breaking it down in different sections (i.e. contexts). With Super Hexagon, we will want our game agent to be able to differentiate between 4 contexts: main_menu, level_select, game and game_over.
Launch the Game
bluetang launch SuperHexagon
Capture Context Frames
Pretend we want to capture frames for main_menu.
Manually bring the game to the area that represents the main_menu context.
Start a context frame capture:
bluetang capture context SuperHexagon 0.5 main_menu
While the capture is running, interact with the game to generate as much visual variety as possible without leaving what you would consider the current context.
Wait until you have at least 200 frames captured (more is better!) and click the terminal, let it save everything to disk, and press Ctrl-C.
If you browse to datasets/collect_frames_for_context/main_menu you should see the captured frames.
Repeat until you have all other contexts captured. (You need at least two contexts to start training)
Train the Context Classifier
Next up is the easiest machine learning training operation you will ever perform in your life:
bluetang train context 15
This will split your collected frames for every context in training and validation sets and train a model over 15 epochs. The training operation will take a few minutes if you are using the GPU-accelerated version of Tensorflow. Otherwise, be prepared to wait a long time.
When the training is over, you will have to analyze the terminal output. First, look at the accuracy scores of every epoch, we are looking for a few epochs above 0.9. If all your values are under 0.9, you likely need to collect more frames for every context. Otherwise, you have successfully trained a model!
Using the Context Classifier at Runtime
Last updated