3

In summary, I have a pair of legs that have rotation-axis-points and want to be able to allow the computer to figure out which way the legs should rotate to allow itself to balance and keep the 'waist' game-object greater than a certain height (Essentially self-balancing). If the waist falls under a certain height, (IE, falling over) the agent gets a reward-reduction. When I run the Anaconda prompt and run Unity when it asks me to, Unity freezes and Anaconda displays the error code shown below. It's hard to find up-to-date tutorials so I would really appreciate some support. What's going on? Thank you. (:

Agent environment

                        ▄▄▄▓▓▓▓
                   ╓▓▓▓▓▓▓█▓▓▓▓▓
              ,▄▄▄m▀▀▀'  ,▓▓▓▀▓▓▄                           ▓▓▓  ▓▓▌
            ▄▓▓▓▀'      ▄▓▓▀  ▓▓▓      ▄▄     ▄▄ ,▄▄ ▄▄▄▄   ,▄▄ ▄▓▓▌▄ ▄▄▄    ,▄▄
          ▄▓▓▓▀        ▄▓▓▀   ▐▓▓▌     ▓▓▌   ▐▓▓ ▐▓▓▓▀▀▀▓▓▌ ▓▓▓ ▀▓▓▌▀ ^▓▓▌  ╒▓▓▌
        ▄▓▓▓▓▓▄▄▄▄▄▄▄▄▓▓▓      ▓▀      ▓▓▌   ▐▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▌   ▐▓▓▄ ▓▓▌
        ▀▓▓▓▓▀▀▀▀▀▀▀▀▀▀▓▓▄     ▓▓      ▓▓▌   ▐▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▌    ▐▓▓▐▓▓
          ^█▓▓▓        ▀▓▓▄   ▐▓▓▌     ▓▓▓▓▄▓▓▓▓ ▐▓▓    ▓▓▓ ▓▓▓  ▓▓▓▄    ▓▓▓▓`
            '▀▓▓▓▄      ^▓▓▓  ▓▓▓       └▀▀▀▀ ▀▀ ^▀▀    `▀▀ `▀▀   '▀▀    ▐▓▓▌
               ▀▀▀▀▓▄▄▄   ▓▓▓▓▓▓,                                      ▓▓▓▓▀
                   `▀█▓▓▓▓▓▓▓▓▓▌
                        ¬`▀▀▀█▓


INFO:mlagents.trainers:CommandLineOptions(debug=False, num_runs=1, seed=-1, env_path=None, run_id='testRun1', load_model=False, train_model=False, save_freq=50000, keep_checkpoints=5, base_port=5005, num_envs=1, curriculum_folder='config/curricula/Balance/', lesson=0, slow=False, no_graphics=False, multi_gpu=False, trainer_config_path='config/trainer_config.yaml', sampler_file_path=None, docker_target_name=None, env_args=None, cpu=False)
INFO:mlagents.envs:Start training by pressing the Play button in the Unity Editor.
INFO:mlagents.envs:
'BalanceAcademy' started successfully!
Unity Academy name: BalanceAcademy
        Reset Parameters : {}
Traceback (most recent call last):
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\curriculum.py", line 132, in _load_curriculum
    return json.load(fp)
  File "C:\Users\Jaden Williams\.conda\envs\ml_Balance01\lib\json\__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Users\Jaden Williams\.conda\envs\ml_Balance01\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Jaden Williams\.conda\envs\ml_Balance01\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Jaden Williams\.conda\envs\ml_Balance01\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 6 column 1 (char 112)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Jaden Williams\.conda\envs\ml_Balance01\Scripts\mlagents-learn-script.py", line 11, in <module>
    load_entry_point('mlagents', 'console_scripts', 'mlagents-learn')()
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\learn.py", line 422, in main
    run_training(0, run_seed, options, Queue())
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\learn.py", line 232, in run_training
    curriculum_folder, env, options.lesson
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\learn.py", line 300, in try_create_meta_curriculum
    meta_curriculum = MetaCurriculum(curriculum_folder, env.reset_parameters)
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\meta_curriculum.py", line 43, in __init__
    curriculum = Curriculum(curriculum_filepath, default_reset_parameters)
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\curriculum.py", line 26, in __init__
    self.data = Curriculum.load_curriculum_file(location)
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\curriculum.py", line 119, in load_curriculum_file
    return Curriculum._load_curriculum(data_file)
  File "c:\users\jaden williams\dropbox\documents\ml-agents-0.12.0\ml-agents\mlagents\trainers\curriculum.py", line 137, in _load_curriculum
    ) from e
mlagents.trainers.exception.CurriculumLoadingError: Error parsing JSON file. Please check for formatting errors. A tool such as https://jsonlint.com/ can be helpful with this.

And here is my code for the agent:

using MLAgents;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BalanceAgent : Agent
{
    private BalancingArea area;
    public GameObject waist;
    public GameObject buttR;
    public GameObject buttL;
    public GameObject thighR;
    public GameObject thighL;
    public GameObject legR;
    public GameObject legL;
    public GameObject footR;
    public GameObject footL;
    public GameObject goal;
    // private float buttR = 0f;


    public override void InitializeAgent() {
        base.InitializeAgent();
        area = GetComponentInParent<BalancingArea>();

    }

    public override void AgentAction(float[] vectorAction) {

        int buttRDir = 0;
        int buttRVec = (int)vectorAction[0];
        switch (buttRVec) {
            case 3:
                buttRDir = 0;
                break;
            case 1:
                buttRDir = -1;
                break;
            case 2:
                buttRDir = 1;
                break;
        }
        buttR.transform.Rotate(0, buttRDir, 0);

        int buttLDir = 0;
        int buttLVec = (int)vectorAction[1];
        switch (buttLVec) {
            case 3:
                buttLDir = 0;
                break;
            case 1:
                buttLDir = -1;
                break;
            case 2:
                buttLDir = 1;
                break;
        }
        buttL.transform.Rotate(0, buttLDir, 0);

        int thighRDir = 0;
        int thighRVec = (int)vectorAction[2];
        switch (thighRVec) {
            case 3:
                thighRDir = 0;
                break;
            case 1:
                thighRDir = -1;
                break;
            case 2:
                thighRDir = 1;
                break;
        }
        thighR.transform.Rotate(0, thighRDir, 0);

        int thighLDir = 0;
        int thighLVec = (int)vectorAction[3];
        switch (thighLVec) {
            case 3:
                thighLDir = 0;
                break;
            case 1:
                thighLDir = -1;
                break;
            case 2:
                thighLDir = 1;
                break;
        }
        thighL.transform.Rotate(0, thighLDir, 0);

        int legRDir = 0;
        int legRVec = (int)vectorAction[4];
        switch (legRVec) {
            case 3:
                legRDir = 0;
                break;
            case 1:
                legRDir = -1;
                break;
            case 2:
                legRDir = 1;
                break;
        }
        legR.transform.Rotate(0, legRDir, 0);

        int legLDir = 0;
        int legLVec = (int)vectorAction[5];
        switch (legLVec) {
            case 3:
                legLDir = 0;
                break;
            case 1:
                legLDir = -1;
                break;
            case 2:
                legLDir = 1;
                break;
        }
        legL.transform.Rotate(0, legLDir, 0);

        int footRDir = 0;
        int footRVec = (int)vectorAction[6];
        switch (footRVec) {
            case 3:
                footRDir = 0;
                break;
            case 1:
                footRDir = -1;
                break;
            case 2:
                footRDir = 1;
                break;
        }
        footR.transform.Rotate(0, footRDir, 0);

        int footLDir = 0;
        int footLVec = (int)vectorAction[7];
        switch (footLVec) {
            case 3:
                footLDir = 0;
                break;
            case 1:
                footLDir = -1;
                break;
            case 2:
                footLDir = 1;
                break;
        }
        footL.transform.Rotate(0, footLDir, 0);




        //buttR = vectorAction[0]; //Right or none
        //if (buttR == 2) buttR = -1f; //Left

        if (waist.transform.position.y > -1.3) {
            AddReward(.1f);
        }
        else {
            AddReward(-.02f);
        }

        if(waist.transform.position.y <= -3) {
            AddReward(-.1f);
            Done();
        }

    }

    public override void CollectObservations() {
        AddVectorObs(waist.transform.localRotation.y);
        AddVectorObs(buttR.transform.localRotation.x);
        AddVectorObs(buttL.transform.localRotation.x);
        AddVectorObs(thighR.transform.localRotation.y);
        AddVectorObs(thighL.transform.localRotation.y);
        AddVectorObs(legR.transform.localRotation.y);
        AddVectorObs(legL.transform.localRotation.y);
        AddVectorObs(footR.transform.localRotation.y);
        AddVectorObs(footL.transform.localRotation.y);

        AddVectorObs(waist.GetComponent<Rigidbody>().freezeRotation);
    }
}
Ruzihm
  • 19,749
  • 5
  • 36
  • 48
  • 1
    So what exactly is your question here? Also, please don't include images of code. These make finding questions harder to search for and make copying code into answers absurdly inconvenient, not to mention make the information inaccessible to people who use screen readers. You should rather include any code as text in the body of the question. – Ruzihm Dec 11 '19 at 22:21
  • 1
    @Ruzihm Thanks for the reply! Yes, you're right, I'll add the code. I just want to know how well I'm writing my code to train my balancing agent. Because, when I try to train the agent using Anaconda, the prompt fails and Unity crashes. Thanks. – Jaden Williams Dec 11 '19 at 22:54
  • Aha, that's a very important thing to include in the question! When does Unity crash? As soon as learning begins? – Ruzihm Dec 11 '19 at 23:12
  • 1
    @Ruzihm Unity freezes/crashes right when I press play after Anaconda is set up. I added the anaconda error text. Thanks. – Jaden Williams Dec 11 '19 at 23:18
  • Looks like it's having trouble loading curricula. I can only guess that you don't have any in the directory you've given it, since you haven't mentioned them. Try running the command without the `curriculum_folder` parameter. I'm also voting to re-open this question – Ruzihm Dec 11 '19 at 23:21
  • @Ruzihm Removing that parameter did help it. I also had my vector branch size 1 too short. I'm not fully sure what that param. did anyways. Still learning! But now, the person won't reset when he falls over. Shouldn't line 166 in my code accomplish that with "Done()"? Doesn't that method reset everything? – Jaden Williams Dec 11 '19 at 23:52
  • You need to make/edit the [Academy](https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Learning-Environment-Design-Academy.md) with a `AcademyReset` method that resets the environment (including the state of the joints that the agent is controlling). But, I think the solution to the problem in the question has been found so I'm going to write it up as an answer. If you need more help beyond that, you should ask a new question. – Ruzihm Dec 12 '19 at 04:33

1 Answers1

2

It is having trouble finding and loading the curriculua in the specified curriculum_folder parameter. Because you don't need curricula, you can remove the curriculum_folder parameter and it will proceed without trying to load any of them.

Ruzihm
  • 19,749
  • 5
  • 36
  • 48