Search Unity

Resolved GridSensor Training Error

Discussion in 'ML-Agents' started by Rany_AN, May 26, 2021.

  1. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    I have grid sensor for a top-down 2D game.
    However, the Y component for grid size automatically snaps to 1?
    When I rotate it around X-axis and check rotation with agent it's fixed.
    I get this error when I try to train as well:
    lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 310, in _step                                                                                         raise env_exception                                                                                                                                                                                            PIL.UnidentifiedImageError: cannot identify image file <mlagents_envs.rpc_utils.OffsetBytesIO object at 0x000001A444AE9108>   


    EDIT: Managed to fix the error.

    I ran into another problem: The GridSensor doesn't detect the detectable tags.
    upload_2021-5-26_14-24-45.png
     
    Last edited: May 26, 2021
  2. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    Hi!
    I am glad you were able to fix your first error. Could you post what the issue was and what you did to resolve it? It will help new users and help us make more explicit error messages.

    I am sorry, but it seems that the GridSensor does not work properly in 2D environments. It was only created for 3D. Maybe using Raycasts instead will be enough for your game?
     
  3. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    Thanks @vincentpierre for letting me know it doesn't work well with 2D environments.
    I ran into 2 issues:
    First:
    lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 310, in _step                                                                                         raise env_exception                                                                                                                                                                                            PIL.UnidentifiedImageError: cannot identify image file <mlagents_envs.rpc_utils.OffsetBytesIO object at 0x000001A444AE9108>

    Reason: I think it was because I had self-play training mode on
    Fix: Attach grid sensor to each agent

    Second:
    File "X\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 98, in recv                                                                                                                        raise env_exception                                                                                                 mlagents_envs.exception.UnityObservationException: Decompressed observation did not have the expected shape - decompressed had (16, 4, 2) but expected [4, 16, 2]     

    Reason: Different grid sizes on each grid sensor in self-play mode
    Fix: Keep grid sizes the same
     
  4. Tonsias

    Tonsias

    Joined:
    Mar 2, 2021
    Posts:
    5
    i got the second mistake too. in a 3d environment. is there a solution for unequal grid sizes? it was a (14, 6, 2) Grid
     
  5. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    Hi, the grid sizes must be the same between agents that have the same behavior (including in self play mode).
    There is no way around this as the convolutions of the trainer expect a constant input size.
     
    Rany_AN likes this.