LogoLogo
  • 🐟An Introduction to Bluetang
  • Features
    • 📔Overview
  • Deepseek Integration
    • 😃What are the benefits?
  • How To Use
    • â„šī¸Important Information
    • 🔗Important Links
    • 📖Wiki
      • 💾Installation
        • đŸ’ŋLinux
        • đŸĒŸWindows
      • 🔃Update
      • đŸ’ģBluetang CLI Tool
      • 👨‍đŸ’ģClasses
        • GameAgent Class
        • Game Class
        • GameFrame Class
        • InputController Class
      • 🔌Plugins
        • GameAgent Plugin
        • Game Plugin
        • Training a Context Classifier
  • 📑Whitepaper
Powered by GitBook
On this page
  • Analyzing the Game
  • Launch the Game
  • Capture Context Frames
  • Train the Context Classifier
  • Using the Context Classifier at Runtime
  1. How To Use
  2. Wiki
  3. Plugins

Training a Context Classifier

PreviousGame PluginNextWhitepaper

Last updated 4 months ago

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 .

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.

  1. Manually bring the game to the area that represents the main_menu context.

  2. Start a context frame capture: bluetang capture context SuperHexagon 0.5 main_menu

  3. 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.

  4. 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.

  5. If you browse to datasets/collect_frames_for_context/main_menu you should see the captured frames.

  6. 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

context = self.machine_learning_models["context_classifier"].predict(game_frame.frame)
📖
🔌
Super Hexagon