Search Unity

Unexpected ToReadOnlyArray() size from output Tensor

Discussion in 'ML-Agents' started by ivan_unity77, May 28, 2021.

  1. ivan_unity77

    ivan_unity77

    Joined:
    Apr 22, 2021
    Posts:
    2
    I'm playing around with a network I trained using the ML-Agents and I'm using Barracuda to take a look at the input/output Tensors.
    I use the following code to read all the output tensors after I've propagated some random input.

    Code (CSharp):
    1. foreach (string name in _runtimeModel.outputs) {
    2.             Tensor output = _worker.PeekOutput(name);
    3.             Debug.Log($"name: {name}\n" +
    4.             $"shape:[{string.Join(", ", output.shape.ToArray())}]\n" +
    5.             $"values:[{string.Join(",", output.ToReadOnlyArray())}]");
    6. }
    It all makes sense up until I inspect the continuous_actions Tensor where I get the output below, the shape doesn't match the size of the ToReadOnlyArray().

    name: continuous_actions
    shape:[1, 1, 1, 1, 1, 1, 1, 4]
    values:[0.1156273,-1,-0.9141262,-0.1325357,0.8688275,0.8440998,-1.733,2.479572,-1.629915,1.056483,2.080409,0.9630347,1.416127,-4.703472,1.340752,0.9655838,1.777658,3.831296,1.676966,4.660925,2.97469,1.283623,-4.332521,-1.59838,2.090659,0.4194155,-0.4820561,0.837211,0.4300392,-1.655783,0.4295818,1.273943,0.5760217,-0.02087674,-1.228398,2.373877,-0.6333808,-2.146893,2.877553,-3.410499,0.8597594,4.478225,-3.272307,-0.5468621,0.5830808,0.3875606,2.67083,1.105596,1.001739,-5.086424,-0.3662632,0.7757202,-3.256629,0.2554953,4.946887,-0.2961233,2.917093,3.687653,-1.788513,-0.9519644,-2.951114,-0.6920433,-1.780857,4.391388,-0.2063182,-1.112427,-1.402477,-0.2442079,4.097916,-2.828585,-0.5184602,2.065983,-2.000575,1.177458,-2.286689,-2.948756,0.1624968,2.702826,3.887595,0.9407495,-4.065562,3.149174,3.629395,0.2566599,0.4580555,-0.454669,-0.5754454,-1.0499,0.6522522,-4.183906,3.813012,1.601692,2.264779,1.312585,-3.550067,-1.6202,-0.3782642,1.347933,-3.296545,3.051929,2.206869,2.245427,-0.4319859,-2.161755,3.874439,-4.171382,5.675072,-4.172846,-2.00458,0.9803899,-3.115294,-3.563,3.975834,0.3370307,-1.994925,-7.028366,-2.014729,2.823181,3.286783,0.6972361,-6.691628,0.6603691,3.531862,-0.1034166,4.013782,3.720714,-3.541944,2.644315]


    Am I doing something wrong? Should I be aware of something I'm missing?
    The same happens for the discrete_actions Tensor too.
     
  2. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    I suspect that you have 32 agents in the scene. Since each has 4 continuous actions, you get a tensor of 32 x 4 = 128 elements at each decision point. I do not know why the batch size does not appear in the shape of the output but I suspect it is because batch size can change depending on the input and is not a constant of the model.
     
  3. ivan_unity77

    ivan_unity77

    Joined:
    Apr 22, 2021
    Posts:
    2
    Thanks for your reply ✌️

    That is definitely not the case, my player GameObject is unique and it is the owner of the only Agent component in the scene. Plus I thought the size of the action tensors was basically defined in the Agent component. ‍‍

    I've noticed two Tensor called discrete_action_output_shape and discrete_action_output_shape with shape [1, 1, 1, 1, 1, 1, 1, 1]. They seem to contain the "size" of the values that should actually be read in the continuous_actions and discrete_action output tensors.

    Could this be a valid interpretation?
     
    Last edited: Jun 2, 2021
  4. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    discrete_action_output_shape contains a single value of the size of the discrete action (same with continuous). We use this number to validate the model (make sure expected and actual tensor size are identical). These values should not influence the shape of the tensors at all.
    I do not know why your continuous_actions has 128 values instead of 4. What inputs did you pass to the model?