浏览代码
Multi-curriculum support added.
Multi-curriculum support added.
- New school module maps brains to curriculums./develop-generalizationTraining-TrainerController
Deric Pang
7 年前
当前提交
c6617b70
共有 9 个文件被更改,包括 137 次插入 和 56 次删除
-
8docs/Training-Curriculum-Learning.md
-
17python/curricula/push_curriculum.json
-
21python/tests/test_curriculum.py
-
1python/unitytrainers/__init__.py
-
10python/unitytrainers/curriculum.py
-
67python/unitytrainers/trainer_controller.py
-
4unity-environment/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
-
21python/tests/test_school.py
-
44python/unitytrainers/school.py
|
|||
{ |
|||
"measure" : "progress", |
|||
"thresholds" : [0.1], |
|||
"min_lesson_length" : 2, |
|||
"signal_smoothing" : true, |
|||
"parameters" : |
|||
"PushBlockBrain" : |
|||
"goal_width" : [25.0, 5.0], |
|||
"goal_length" : [5.0, 1.0] |
|||
"measure" : "progress", |
|||
"thresholds" : [0.1], |
|||
"min_lesson_length" : 2, |
|||
"signal_smoothing" : true, |
|||
"parameters" : |
|||
{ |
|||
"goal_width" : [25.0, 5.0], |
|||
"goal_length" : [5.0, 1.0] |
|||
} |
|||
} |
|||
} |
|
|||
import pytest |
|||
from unittest.mock import patch |
|||
|
|||
from unitytrainers import School |
|||
|
|||
|
|||
@pytest.fixture |
|||
def default_reset_parameters(): |
|||
return {"param1": 1, "param2": 1, "param3": 1} |
|||
|
|||
|
|||
@patch('unitytrainers.Curriculum.__init__', return_value=None) |
|||
@patch('os.listdir', return_value=['TestBrain1.json', 'TestBrain2.json']) |
|||
def test_init_school_happy_path(listdir, curriculum_mock, default_reset_parameters): |
|||
print(curriculum_mock) |
|||
school = School('test-school/', default_reset_parameters) |
|||
|
|||
assert len(school.brains_to_curriculums) == 2 |
|||
|
|||
assert 'TestBrain1' in school.brains_to_curriculums |
|||
assert 'TestBrain2' in school.brains_to_curriculums |
|
|||
""" |
|||
A School holds many curriculums. The School tracks which brains are following which curriculums. |
|||
""" |
|||
|
|||
import os |
|||
from unitytrainers import Curriculum |
|||
|
|||
class School: |
|||
def __init__(self, curriculum_folder, default_reset_parameters): |
|||
""" |
|||
Initializes a School object. |
|||
""" |
|||
if curriculum_folder is None: |
|||
self._brains_to_curriculums = None |
|||
else: |
|||
self._brains_to_curriculums = {} |
|||
for location in os.listdir(curriculum_folder): |
|||
brain_name = location.split('.')[0] |
|||
self._brains_to_curriculums[brain_name] = Curriculum(location, default_reset_parameters) |
|||
|
|||
@property |
|||
def brains_to_curriculums(self): |
|||
return self._brains_to_curriculums |
|||
|
|||
|
|||
def increment_lessons(self, progresses): |
|||
for brain_name, progress in progresses.items(): |
|||
self.brains_to_curriculums[brain_name].increment_lesson(progress) |
|||
|
|||
|
|||
def set_lesson_nums(self, lesson_nums): |
|||
for brain_name, lesson in lesson_nums.items(): |
|||
self.brains_to_curriculums[brain_name].lesson_number = lesson |
|||
|
|||
|
|||
def get_config(self): |
|||
config = {} |
|||
|
|||
for _, curriculum in self.brains_to_curriculums.items(): |
|||
parameters = curriculum.data["parameters"] |
|||
for key in parameters: |
|||
config[key] = parameters[key][curriculum.lesson_number] |
|||
|
|||
return config |
撰写
预览
正在加载...
取消
保存
Reference in new issue