edbeeching / godot_rl_agents_examples

Example Environments for the Godot RL Agents library
MIT License
37 stars 13 forks source link

Update examples #14

Closed metinc closed 8 months ago

metinc commented 9 months ago

Still a lot of work to do, some examples don't even run at this moment. I will fix these problems before adding the AIController nodes.

Closes #4

Ivan-267 commented 9 months ago

Nice work so far, regarding a non-working example, I'm not sure whether this is still relevant, linking here in case it is: https://github.com/edbeeching/godot_rl_agents_examples/issues/12

edbeeching commented 9 months ago

@metinc , thanks for looking at this. I just pushed a fix for the ships example on the main branch. If you rebase it should be working now. Let me know if you find any further examples that are broken.

metinc commented 9 months ago

@Ivan-267 @edbeeching I am stuck with the VirtualCamera example. I was able to fix the project so it can be played as a human. But when I run gdrl I get this error:

ValueError: cannot reshape array of size 384 into shape (16,16,4)

Any idea how to fix this? The image size is 16 16 3 = 768 bytes. Also I don't understand why hex_encode() is used in RGBCameraSensor3D.gd. Why not simply use the byte array without encoding?

Ivan-267 commented 9 months ago

I haven't previously tried working with the CameraSensor in GDRL.

After some experimenting it seems I was able to get it to work:

https://github.com/edbeeching/godot_rl_agents_examples/assets/61947090/9a00c310-a415-4222-ba0e-500d79804dcb

For testing purposes just to verify it's learning something, what's shown in the video above is without the shaped reward and with the rewards set to +10 and -10, where a mean of exactly 10 would mean it's going to the right location every time, without having to worry about speed, and the Action Repeat of sync node is set to 16 to potentially accelerate learning (these modifications are not needed other than for testing).

I'll check a bit more and if everything seems OK I'll make a PR to the env and to godot-rl as well, since a Python-side modification is needed as well.

As for hex_encode(), my assumption is that it's used to simplify sending the values from Godot to Python in a way that is smaller in size and simpler to parse. When sending the values, they first get converted to JSON. In case of a PackedByteArray, that becomes a string containing the color values, which is larger than a string containing the hex encoded values (where 2 characters represent a channel value for a pixel), and also slightly more complex to parse later (e.g. the first character you would get in Python is [). There are likely ways to send the data in a smaller format (I haven't looked into this), but for now, this seems to be working with just small modifications.

Ivan-267 commented 9 months ago

I've linked the two PRs needed above. If you apply the change to the environment and godot-rl, hopefully it should work as it does for me, but let me know if there are still some errors.

Ivan-267 commented 9 months ago

Thanks for all of the updates, I'll make a quick check of some of the envs, but before merging we'll need @edbeeching to take a look also because he made these envs.

Quick test with gdrl, run pretrained onnx in Godot Editor (where one exists), and take a glance at the AIController code:

I previously tested the ShipsExample and my AirHockey env, so just a quick check remaining:

metinc commented 8 months ago

@edbeeching Would you like to merge this? I don't have permission to do so.

edbeeching commented 8 months ago

@metinc Thanks for this. Let me review and load the examples tonight then I will add you as a contributor to the lib(s) so you can merge yourself :)