Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inference when action names are not alphabetic #27

Conversation

Ivan-267
Copy link
Collaborator

@Ivan-267 Ivan-267 commented Dec 1, 2023

This is a quick fix that should enable onnx inference to work for environments where the actions are not defined in an alphabetical order by name.

Only briefly tested, I have tried to quickly start training using gdrl and play in Editor.

To do:

  • Testing [Failed]
  • Quick testing after added changes to godot_env.py [Passed]

For an example action space that is not sorted:

With the applied fix, the action space as Printed from Python was:

action space {'acceleration': {'size': 1, 'action_type': 'continuous'}, '2': {'size': 1, 'action_type': 'continuous'}, '1': {'size': 1, 'action_type': 'continuous'}}
observation space {'obs': {'size': [12], 'space': 'box'}}

(same as the order written in AIController in gdscript)

Without the fix, the order of actions is changed before it reaches Python:

action space {'1': {'action_type': 'continuous', 'size': 1}, '2': {'action_type': 'continuous', 'size': 1}, 'acceleration': {'action_type': 'continuous', 'size': 1}}
observation space {'obs': {'size': [12], 'space': 'box'}}

More info on the issue itself is described in the linked issue.

Disables `sort_keys` for `stringify`
@Ivan-267 Ivan-267 linked an issue Dec 1, 2023 that may be closed by this pull request
@Ivan-267 Ivan-267 marked this pull request as draft December 1, 2023 17:42
@Ivan-267
Copy link
Collaborator Author

Ivan-267 commented Dec 1, 2023

Initial test failed, it seems that the received string from var message = stream.get_string() also has alphabetic order of actions rather than the defined order (that may be fine though). Will look into the cause of the issue more closely later.

Edit: It seems that the order of the actions is changed in Python regardless of how Godot sends it on conversion to spaces.Dict. Will experiment a bit with this when I get some time.

Edit2: Added the fix on godot_env side as well, now it should work.

Copy link
Owner

@edbeeching edbeeching left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean fix. LGTM

@Ivan-267 Ivan-267 merged commit b4c3f22 into main Dec 4, 2023
@Ivan-267 Ivan-267 deleted the fix-action-names-must-be-alphabetically-ordered-for-onnx-inference-to-work branch December 4, 2023 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Action names must be alphabetically ordered for ONNX inference to work.
2 participants