浏览代码

Fixed to give lesson index parameter when start up (#179)

* fixed to give lesson parameter when start up

* applied to PPO.ipynb and modified ppo.py a bit
/develop-generalizationTraining-TrainerController
Arthur Juliani 7 年前
当前提交
216888ee
共有 4 个文件被更改,包括 9 次插入6 次删除
  1. 3
      python/PPO.ipynb
  2. 4
      python/ppo.py
  3. 4
      python/unityagents/curriculum.py
  4. 4
      python/unityagents/environment.py

3
python/PPO.ipynb


"save_freq = 50000 # Frequency at which to save model.\n",
"env_name = \"environment\" # Name of the training environment file.\n",
"curriculum_file = None\n",
"lesson = 0 # Start learning from this lesson\n",
"\n",
"### Algorithm-specific parameters for tuning\n",
"gamma = 0.99 # Reward discount rate.\n",

},
"outputs": [],
"source": [
"env = UnityEnvironment(file_name=env_name, curriculum=curriculum_file)\n",
"env = UnityEnvironment(file_name=env_name, curriculum=curriculum_file, lesson=lesson)\n",
"print(str(env))\n",
"brain_name = env.external_brain_names[0]"
]

4
python/ppo.py


--time-horizon=<n> How many steps to collect per agent before adding to buffer [default: 2048].
--train Whether to train model, or only run inference [default: False].
--worker-id=<n> Number to add to communication port (5005). Used for multi-environment [default: 0].
--lesson=<n> Start learning from this lesson [default: 0].
'''
options = docopt(_USAGE)

curriculum_file = str(options['--curriculum'])
if curriculum_file == "None":
curriculum_file = None
lesson = int(options['--lesson'])
# Algorithm-specific parameters for tuning
gamma = float(options['--gamma'])

batch_size = int(options['--batch-size'])
normalize = options['--normalize']
env = UnityEnvironment(file_name=env_name, worker_id=worker_id, curriculum=curriculum_file)
env = UnityEnvironment(file_name=env_name, worker_id=worker_id, curriculum=curriculum_file, lesson=lesson)
print(str(env))
brain_name = env.external_brain_names[0]

4
python/unityagents/curriculum.py


class Curriculum(object):
def __init__(self, location, default_reset_parameters):
def __init__(self, location, default_reset_parameters, lesson):
self.lesson_number = 0
self.lesson_length = 0
self.measure_type = None
if location is None:

"The parameter {0} in Curriculum {1} must have {2} values "
"but {3} were found".format(key, location,
self.max_lesson_number + 1, len(parameters[key])))
self.set_lesson_number(lesson)
@property
def measure(self):

4
python/unityagents/environment.py


class UnityEnvironment(object):
def __init__(self, file_name, worker_id=0,
base_port=5005, curriculum=None):
base_port=5005, curriculum=None, lesson=0):
"""
Starts a new unity environment and establishes a connection with the environment.
Notice: Currently communication between Unity and Python takes place over an open socket without authentication.

self._num_brains = len(self._brain_names)
self._num_external_brains = len(self._external_brain_names)
self._resetParameters = p["resetParameters"]
self._curriculum = Curriculum(curriculum, self._resetParameters)
self._curriculum = Curriculum(curriculum, self._resetParameters, lesson)
for i in range(self._num_brains):
self._brains[self._brain_names[i]] = BrainParameters(self._brain_names[i], p["brainParameters"][i])
self._loaded = True

正在加载...
取消
保存