- Currently the PinballAgent can only read the score when Windows is set to 100% scale when training.
- The Pinball Window must be in focus during training, with no windows overlapping it.
-
Open Unity, and open the 3DPinballAI project
-
In the Project pane, select Assets > Scenes > main
-
Build the project by selecting File > Build Settings > Build - ensuring the project builds correctly.
- When asked for a folder, select the folder where you placed the project.
-
Open your favourite terminal 1
-
Activate your virtual Python environment by running
.\python-envs\pinball-env\Scripts\activate
2 -
Start the training by running
mlagents-learn <PATH_TO_PROJECT>\Assets\Config\trainer_config.yaml --run-id=FirstRun --train
- the
trainer_config.yaml
specifies parameters the training algorithm will use. - the
run-id
parameter can be named anything you like, this is specified so you can save, and reload different training runs later.
- the
-
ml-agents will execute and prompt you to press play in Unity
INFO:mlagents.envs:Start training by pressing the Play button in the Unity Editor.
-
Press play the Play button in Unity
-
A new 3D Pinball game will start.
-
The 3D Pinball window needs to stay focused and in the foreground with no other windows overlapping it.
-
Sit back and watch as the Training attempts to figure out how to play.
You should end up with somthing that looks like this:
During a training session, the training program prints out and saves updates at
regular intervals (specified by the summary_freq
option). The saved statistics
are grouped by the run-id
value so you should assign a unique id to each
training run if you plan to view the statistics. You can view these statistics
using TensorBoard during or after training by running the following command:
tensorboard --logdir=summaries --port 6006
And then opening the URL: localhost:6006.
Note: The default port TensorBoard uses is 6006. If there is an existing session running on port 6006 a new session can be launched on an open port using the --port option.
When training is finished, you can find the saved model in the models
folder
under the assigned run-id — in the cats example, the path to the model would be
models/FirstRun/VisualPinball.nn
.
While this example used the default training hyperparameters, you can edit the training_config.yaml file with a text editor to set different values.
-See command-line-training-options
If you enable the --debug
flag in the command line, the trainer metrics are logged to a CSV file
stored in the summaries
directory. The metrics stored are:
- brain name
- time to update policy
- time since start of training
- time for last experience collection
- number of experiences used for training
- mean return
1: You can use the Command Prompt, [Powershell][powershell] or [Windows Terminal][windowsTerminal].
2: If you used different folder names in the Virtual Environment Setup, you'll need to use those instead.