Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Best configuration for touch input training?

Discussion in 'ML-Agents' started by Saaskun, Feb 18, 2020.

  1. Saaskun

    Saaskun

    Joined:
    Nov 29, 2019
    Posts:
    49
    Hi, I'm triying to do an AI that analize hand gestures for a "touch wall" and give the correct answer, like: right, left, up, down, right circle, etc.
    My problem is that the brain isn't learning :( and I think that the code is quite well

    For the inputs I made a json that store all the touch inputs that I record myself previously ... the first value always will be 0,0. The code get a random input when the desition finished
    X = time
    Y = x Pos
    Z = y Pos

    Example:
    Code (CSharp):
    1. {
    2.     "Direction": "Left",
    3.     "TimePos": {
    4.         "0": "0, 0, 0",
    5.         "1": "0.0139613, 0, 0",
    6.         "2": "0.0262996, -0.04159969, 0.008319868",
    7.         "3": "0.0398894, -0.07903878, 0.01247977",
    8.         "4": "0.0528541, -0.1372779, 0.02079964",
    9.         "5": "0.0660014, -0.2038375, 0.02911958",
    10.         "6": "0.079783, -0.2953562, 0.03743952",
    11.         "7": "0.0927471, -0.3910351, 0.04159942",
    12.         "8": "0.1057109, -0.5075134, 0.04575932",
    13.         "9": "0.1189348, -0.6364714, 0.04575932",
    14.         "10": "0.1326411, -0.7820694, 0.04575932",
    15.         "11": "0.1453997, -0.9401475, 0.04159942",
    16.         "12": "0.1586328, -1.056626, 0.03743952",
    17.         "13": "0.1718672, -1.156465, 0.03327948",
    18.         "14": "0.1850997, -1.202224, 0.02911958",
    19.         "15": "0.1984685, -1.210544, 0.02911958",
    20.         "16": "0.2115677, -1.210544, 0.02495961",
    21.         "17": "0.2253915, -1.210544, 0.02495961"
    22.     }

    The program reads the gesture values in every frame, when it finished it calls "RequestDecision();"
    Code:
    Code (CSharp):
    1.     private void Update()
    2.     {
    3.    
    4.         data = new Vector3 (jsonValues.timePos[indexData].x, jsonValues.timePos[indexData].y, jsonValues.timePos[indexData].z);
    5.  
    6.         CollectObservations();
    7.         indexData++;
    8.  
    9.         if (indexData >= numberData)
    10.         {
    11.             RequestDecision();
    12.             GetRandomValues();
    13.         }
    14.     }
    The Agent Action code:

    Code (CSharp):
    1.     public override void AgentAction(float[] act)
    2.     {
    3.         string dataMove = "";
    4.  
    5.         switch (act[0])
    6.         {
    7.             case 0:
    8.                 dataMove = "Right";
    9.                 break;
    10.             case 1:
    11.                 dataMove = "Left";
    12.                 break;
    13.         }
    14.  
    15.         realText.text = jsonValues.direction;
    16.         AItext.text = dataMove;
    17.  
    18.         if (dataMove == jsonValues.direction)
    19.         {
    20.             AddReward(0.1f);
    21.           //  goodOrBadTxt.text = "Good";
    22.            // GetRandomValues();
    23.            // Done();
    24.         }
    25.         else
    26.         {
    27.             AddReward(-0.05f);
    28.          //   goodOrBadTxt.text = "Bad";
    29.             Done();
    30.         }
    31.  
    32.  
    33.     }
    Vector Obs code:
    Code (CSharp):
    1.     public override void CollectObservations()
    2.     {
    3.         AddVectorObs(data.y);
    4.         AddVectorObs(data.z);
    5.         //    Debug.Log("Obs " + data + " index data " + indexData);
    6.  
    7.     }
    Other functions;
    Code (CSharp):
    1. void GetRandomValues()
    2.     {
    3.         indexData = 0;
    4.         int ran = Random.Range(0, jsonValuesArray.Length);
    5.  
    6.         jsonValues = jsonValuesArray[ran];
    7.         numberData = jsonValues.timePos.Length;
    8.     }
    9.  
    10.  
    11.     public override void AgentReset()
    12.     {
    13.         SetResetParameters();
    14.     }
    15.  
    16.     public void SetResetParameters()
    17.     {
    18.         indexData = 0;
    19.     }
    Also I enabled the "On Demand Decisions" checkbox

    Any idea?
    Greetings
     
    Last edited: Feb 18, 2020
  2. Saaskun

    Saaskun

    Joined:
    Nov 29, 2019
    Posts:
    49
    My bad, I change Update to FixedUpdate and now is learning