You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: units/en/unitbonus3/godotrl.mdx
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,6 +201,51 @@ In this simple example, a reasonable policy is learned in several minutes. You m
201
201
202
202
Try setting this property up to 8 to speed up training. This can be a great benefit on more complex environments, like the multi-player FPS we will learn about in the next chapter.
Let's put aside the Godot editor for now. We'll need to use terminals to run some commands in order to save models we trained.
209
+
210
+
The latest version of the Godot RL library provides experimental support for onnx models with the Stable Baselines 3, rllib, and CleanRL training frameworks.
211
+
212
+
For example, let's use the Stable Baselines 3 as the framework. Train your agent using the [sb3 example](https://github.com/edbeeching/godot_rl_agents/blob/main/examples/stable_baselines3_example.py) ([instructions for using the script](https://github.com/edbeeching/godot_rl_agents/blob/main/docs/ADV_STABLE_BASELINES_3.md#train-a-model-from-scratch)), enabling the option `--onnx_export_path=model.onnx`
If things work correctly, you should see messages printed out in the terminal like below:
222
+
223
+
```
224
+
No game binary has been provided, please press PLAY in the Godot editor
225
+
waiting for remote GODOT connection on port 11008
226
+
```
227
+
228
+
> If you encounter failures about import error in stable_baselines3_example script: "ImportError: cannot import name 'export_model_as_onnx' from 'godot_rl.wrappers.onnx.stable_baselines_export'", follow the answer in [this issue](https://github.com/edbeeching/godot_rl_agents/issues/203) here.
229
+
230
+
Now it's time to switch back to the Godot editor, and hit PLAY on the top right corner. Once you hit that, the game scene will pop up showing AI training. In the meantime, the terminal will start to print out metrics. Wait for the training to finish, and if things work correctly, you should be able to find the file `model.onnx` in the Godot project directory.
231
+
232
+
### Apply AI in the game!
233
+
234
+
Now let's apply this trained model to the game!
235
+
236
+
In the Godot editor, find the Sync node in `train.tscn`:
237
+
238
+
* change the control mode to `Onnx Inference` from the dropdown
239
+
* set `Onnx Model Path` to the model file name, in our case here it's `model.onnx`
240
+
241
+
To run this game, we need the mono version (i.e., the .NET version) of the Godot editor, you can download it from the Godot official page. We need to install [.NET](https://dotnet.microsoft.com/en-us/download) as well.
242
+
243
+
Most likely you wil encounter errors in the first attempt. Below are the scenarios to help you resolve the errors.
244
+
245
+
1. issue about `Invalid Call. Nonexistent function 'new' in base 'CSharpScript'`: [solution](https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TROUBLESHOOTING.md)
246
+
2. errors about `onnxruntime` on MacOS: [solution](https://github.com/microsoft/onnxruntime/issues/9707)
247
+
248
+
204
249
### There’s more!
205
250
206
251
We have only scratched the surface of what can be achieved with Godot RL Agents, the library includes custom sensors and cameras to enrich the information available to the agent. Take a look at the [examples](https://github.com/edbeeching/godot_rl_agents_examples) to find out more!
0 commit comments