Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
16.93k stars 4.14k forks source link

Trying to train with curricula causes a JsonDecodeError #2113

Closed DanAmador closed 4 years ago

DanAmador commented 5 years ago

I have a Curriculum file which supposedly helps to teach my agent how to tackle some other objects in the scene.

It uses a brain called SumoTackleLearn and I tried loading it by using the command

MLAgents/Config/trainer_config.yaml --debug --train --curriculum=MLAgents/Config/curricula/Tackle --run-id=tackle-curriculum

This at first gave me an error stating that a reset parameter was expecting more values than it actually had, this in turn showed me that the file was being correctly loaded, but I had just misread the documentation.

After fixing that mistake I tried training with said curriculum again but I've bumped into this:

image

The tackle folder contains a file called "SumoTackleLearn.json" with the following content:

{
  "measure": "reward",
  "thresholds": [5, 5, 6, 7],
  "min_lesson_length": 100,
  "signal_smoothing": false,
  "parameters": {
    "EnemySpawnVariance": [0, 5.0, 10.0, 15.0, 20.0]
  }
}

And my Academy object, which trains the SumoTackleLearn brain has the EnemySpawnVariance as a Reset Parameter.

I've tried following what the documentation said or what the few tutorials online showed, but I can't seem to get it running.

I know for a fact that the file gets correctly loaded because of my previous issue which leads me to believe that this might be caused by some sort of bug. If not what's wrong with my configuration?

harperj commented 5 years ago

Hi @DanAmador -- I'm able to load the JSON file as pasted here, so I'm not sure why you're running into an issue. Perhaps it could be related to Windows.

Maybe you could try just parsing the file via the Python REPL:

>>> import json
>>> with open("path/to/your/curriculum.json") as data_file:
...     json.load(data_file)
{'measure': 'reward', 'thresholds': [5, 5, 6, 7], 'min_lesson_length': 100, 'signal_smoothing': False, 'parameters': {'EnemySpawnVariance': [0, 5.0, 10.0, 15.0, 20.0]}}

If this works then we'll need to figure out why the Curriculum class isn't loading the correct file or how it differs.

DanAmador commented 5 years ago

Everything works as expected while loading it with the repl

image

Tonidor commented 5 years ago

I'm also having the same issue.

harperj commented 5 years ago

Hi again @DanAmador @Tonidor -- I've attempted on both Mac and Windows machines to reproduce this issue but can't seem to do so. One think I can suggest to double check is that your curriculum .json file has the same name as the brain name in your environment.

If you're running from source you could use a debugger to check whether the file name being opened is correct for your environment.

Our team has limited ability to help debug custom environment setups, so other than this general advice I can't help unless you can reproduce this issue with one of our curriculum examples (e.g. WallJump). If you can reproduce this please share and I'll give another go at reproducing.

MentalGear commented 5 years ago

Stuck with the exact same JSON.decode error. Has anyone already figured this out ?

DanAmador commented 5 years ago

I've found more about this problem.

I thought this issue would be solved in version 9 and decided to retry it.

At first I got excited as the trainer loaded the curriculum and said how a parameter was not present in the environment. I edited the json file and tried to reload it and still had the same JsonDecode

This is the trace when it reads the extra param:

Traceback (most recent call last): File "c:\users\anton\anaconda3\envs\unity9\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\anton\anaconda3\envs\unity9\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\anton\Anaconda3\envs\unity9\Scripts\mlagents-learn.exe\__main__.py", line 9, in <module> File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 337, in main run_training(0, run_seed, options, Queue()) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 94, in run_training maybe_meta_curriculum = try_create_meta_curriculum(curriculum_folder, env, lesson) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 163, in try_create_meta_curriculum meta_curriculum = MetaCurriculum(curriculum_folder, env.reset_parameters) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\meta_curriculum.py", line 37, in __init__ curriculum = Curriculum(curriculum_filepath, default_reset_parameters) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\curriculum.py", line 56, in __init__ "the Environment".format(key, location) mlagents.trainers.exception.CurriculumError: The parameter extra_param in Curriculum ML-Agents/Config/curricula/Run\WalkerLearning.json is not present in the Environment

And without it:

Traceback (most recent call last): File "c:\users\anton\anaconda3\envs\unity9\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\anton\anaconda3\envs\unity9\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\anton\Anaconda3\envs\unity9\Scripts\mlagents-learn.exe\__main__.py", line 9, in <module> File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 337, in main run_training(0, run_seed, options, Queue()) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 94, in run_training maybe_meta_curriculum = try_create_meta_curriculum(curriculum_folder, env, lesson) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\learn.py", line 163, in try_create_meta_curriculum meta_curriculum = MetaCurriculum(curriculum_folder, env.reset_parameters) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\meta_curriculum.py", line 37, in __init__ curriculum = Curriculum(curriculum_filepath, default_reset_parameters) File "c:\users\anton\anaconda3\envs\unity9\lib\site-packages\mlagents\trainers\curriculum.py", line 29, in __init__ self.data = json.load(data_file) File "c:\users\anton\anaconda3\envs\unity9\lib\json\__init__.py", line 299, in load parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File "c:\users\anton\anaconda3\envs\unity9\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s) File "c:\users\anton\anaconda3\envs\unity9\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "c:\users\anton\anaconda3\envs\unity9\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Vaspra commented 4 years ago

As @DanAmador referenced, please use my fix #2651 mine used to fail but this will sort it.

harperj commented 4 years ago

It looks like this issue has been resolved by #265 (thanks for the contribution @DanAmador). I'm going to close the issue for now but if this doesn't resolve the problem feel free to reopen it.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.