Search Unity

Resolved ZeroDivisionError, what could the cause of this be?

Discussion in 'ML-Agents' started by CAREFiSH, Jun 4, 2021.

  1. CAREFiSH

    CAREFiSH

    Joined:
    May 28, 2013
    Posts:
    8
    Good day amazing Unity developers and fellow Unity users, I have a question that you may be able to help me with.

    I have a bunch of demonstration files recorded with the DemonstrationRecorder, and now I am trying to use these but I am getting a ZeroDivisionError. How do I go about solving this error?

    Github Gist with error output: https://gist.github.com/carefish/3e5193f94103c14707e925c3bf65977f

    Things I have tried:
    https://forum.unity.com/threads/zero-division-error-when-training.1112275/#post-7156048 - changing `vis_encode_type` to all available ones (nature_cnn, resnet, match3 - the fully_connected one wasn't available? found here: https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Training-Configuration-File.md), still keep getting the ZeroDivisionError

    I have not yet tried: https://forum.unity.com/threads/why-is-my-ml-agents-project-not-training.1105774/#post-7116421 - Am not sure if there is a version mismatch, if this is the case I'll be happy to correct those mismatches :). I have tried a different mix of ml-agents unity package and ml-agents python package before moving on to using the recommended ones at https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Installation.md (pytorch 1.7.1, mlagents 0.26.0).

    Thanks for this amazing plugin, keep training and learning!
     
  2. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    Hi @CAREFiSH

    Judging from the error output, it seems that the input or output size is zero. Does the agent have any sensors and are the fields of the behavior parameters component correct?
     
  3. CAREFiSH

    CAREFiSH

    Joined:
    May 28, 2013
    Posts:
    8
    Thank you for the reply @andrewcoh_unity, your suggestion made me look at the other examples.
    So I made some changes and I 'solved' the Zero Division Errors and got other ones in return. I solved the Zero Division errors by providing the agent with some continuous actions and discrete branches.

    I'll expand a bit on my set up:
    I am using the new Input System, and use that to replay inputs recorded previously to make the demonstration files as I need them to be. Now I can not find any sample or documentation pointing me in the right direction on how to use CollectObservations and OnActionReceived with the new input system.

    In my CollectObservations functions I `observe` my agents local position and my agents target local position.
    In OnActionReceived I have only set up an `AddReward(-1f / MaxStep)` according to examples provided. See the gist link attached.

    It seems that demonstrations recorded using the new Input System require some kind of policy set up on the agent which I am unsure how to set these up properly.
    I remade my demonstration files by manually creating them by hand instead of using recorded inputs.

    Unity Agent setup from inspector:


    Unity Agent Script: https://gist.github.com/carefish/2672de6e8f98a6640ab726c93c3b0b87
    Python errors:
    RuntimeError: The actions Continuous: 0, Discrete: () in demonstration do not match the policy's Continuous: 8, Discrete: (2, 2, 2).

    So I guess the question is, why does the demonstration file think it has `Continuous: 0, Discrete: ()` if the InputActuator component provides the agent with continuous actions and branch sizes?

    EDIT:
    I re-recorded a manual demonstration file, with the agents behaviour type set to Heuristic Only and set the agents Continuous Actions and Discrete Actions to 0. Then tried to start the training session again and now I got the following error: RuntimeError: The actions Continuous: 4, Discrete: (2,) in demonstration do not match the policy's Continuous: 4, Discrete: (2, 2).

    I am getting closer to a solution it seems.

    EDIT 2:

    It looks like I have it working the way I want it to work! Woohoo. Turns out you have to pass on the ActionSpec generated by the InputActuator to the BehaviourParameters, I thought it would do this for me but didn't. Am experiencing some other issues where the Game Window requires to be focused else it will not do anything, but that may be a question for the Input System guys/forum. Thanks @andrewcoh_unity for pointing out I was missing parameters, they were set properly in the inspector but somehow that was not being picked up properly.
     
    Last edited: Jun 7, 2021
  4. manuiaccarino

    manuiaccarino

    Joined:
    Nov 15, 2023
    Posts:
    3
    Sorry, can you post the updated Behavior Parameter? I'm trying to use demo for an already done model about Soccertwos but i'm having your same problem