edbeeching / godot_rl_agents

An Open Source package that allows video game creators, AI researchers and hobbyists the opportunity to learn complex behaviors for their Non Player Characters or agents
MIT License
924 stars 65 forks source link

Exporting A Game. How it works? #1

Open nonunknown opened 2 years ago

nonunknown commented 2 years ago

So, First of all, this is an awesome project, thanks for that!

Did you tested on exported games? I took some read and seems to exist pre-trained models, so how is the approach to have an exported game which doesnt need dependencies (like python or so)?

edbeeching commented 2 years ago

Thanks for such a positive comment and first issue.

Regarding model export, currently the model is always hosted in python, which means python is a dependency. But this is one of the key changes that will be made in v0.2.0 (in around 1 month, see the roadmap for other changes due).

I am currently testing using the C# library TorchSharp for loading and running the trained model inside Godot, which will remove the python dependency (once the model is trained).

araffin commented 2 years ago

I am currently testing using the C# library TorchSharp for loading and running the trained model inside Godot, which will remove the python dependency (once the model is trained).

You may also take a look at ONNX export: https://stable-baselines3.readthedocs.io/en/master/guide/export.html#export-to-onnx

nonunknown commented 2 years ago

hmm thanks for the response! Wel When I was looking for How to implement Reiforcement Learning, I was looking for a C++ implementation, because then I could make as a GDExtension (for godot 4) then this would not require any dependencies for end-users, I found some here on gitrhub but no documentation others abandoned! I really want to use this in my project but at the end it needs to be exported, so I can help in the project, (like porting to godot 4) I just wanted a way to do it in c++...

edbeeching commented 2 years ago

hmm thanks for the response! Wel When I was looking for How to implement Reiforcement Learning, I was looking for a C++ implementation, because then I could make as a GDExtension (for godot 4) then this would not require any dependencies for end-users, I found some here on gitrhub but no documentation others abandoned! I really want to use this in my project but at the end it needs to be exported, so I can help in the project, (like porting to godot 4) I just wanted a way to do it in c++...

Do you need to perform the training inside Godot, or just the model inference?

A word of caution from someone who has learned this the hard way, implementing (Deep) RL algorithms can be a good learning experience, but is challenging, slow, frustrating and hard to debug. In additional I am not sure if there is a GDNative Neural Network library available, so that would need implementating as well. This is the reason I have chosen to perform training on the python side and eventually inference will be available inside Godot. There is also the benefit of running several parallel executables to speed up training.

nonunknown commented 2 years ago

Nope I dont want to implement it! I was just looking for a library, the thing is that seems that python is the only way out. The problem now is: how can we export a game with pre-trained models?

GeorgeS2019 commented 2 years ago

@edbeeching

I am currently testing using the C# library TorchSharp for loading and running the trained model inside Godot, which will remove the python dependency (once the model is trained).

Currently Microsoft is organizing a hackathon for 1 week starting NOW!!!!. They need someone to introduce Godot and Machine learning. If you have some example, please join and share at least one Godot RL example.

If you can give us some help, please check this

Basically, we are trying to use this Godot RL example, but attempting to remove python dependency

KeithKeyes commented 2 years ago

I am currently testing using the C# library TorchSharp for loading and running the trained model inside Godot, which will remove the python dependency (once the model is trained).

looking forward to your great work! gdrl is already an amazing tool, potentially providing endless possibilities of game enviroments for testing varing RL algorithms. But, integrating the trained model into Godot engine for inference is much more attractive to us game developers anyway ^_^.

indiejames commented 11 months ago

Is there any progress on this? Would be great to be able to use a trained model to do inferencing on a mobile device.

Ivan-267 commented 11 months ago

Is there any progress on this? Would be great to be able to use a trained model to do inferencing on a mobile device.

Hello, it is possible to export to onnx and run inference in Godot: https://github.com/edbeeching/godot_rl_agents?tab=readme-ov-file#exporting-and-loading-your-trained-agent-in-onnx-format

There's some more info about using the sb3 example file: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/ADV_STABLE_BASELINES_3.md#train-a-model-in-editor

However, I have only tested this on Windows so far. An additional note is to make sure to copy the onnx file to the same relative path from the exported .exe file as specified in the sync node in Inspector.

In Godot 4.1.2, if I try to select the Android export template, I get an error message that says: Exporting to Android is currently not supported in Godot 4 when using C#/.NET, and we are using C# for inference.

edbeeching commented 11 months ago

Hi. Yes I think in Godot 4 C# is not supported yet for mobile and web export. It works for 3.5 and is it on the 4.x roadmap. So we are waiting for Godot on this one.

I will leave this open until they add the support.

edbeeching commented 3 months ago

Experimental support for web exports is available in this repo: https://github.com/TechnoLukas/godotrl-web/tree/main We will try to include this in our next release.