浏览代码

Will now print summaries even when not training or when training is over (#1020)

* [Initial Commit]

* [Addressed comments]

* [Now using global step to write the summaries]
/develop-generalizationTraining-TrainerController
Arthur Juliani 6 年前
当前提交
9e8049f0
共有 2 个文件被更改,包括 16 次插入14 次删除
  1. 21
      python/unitytrainers/trainer.py
  2. 9
      python/unitytrainers/trainer_controller.py

21
python/unitytrainers/trainer.py


@property
def get_step(self):
"""
Returns the number of steps the trainer has performed
Returns the number of training steps the trainer has performed
:return: the step count of the trainer
"""
raise UnityTrainerException("The get_step property was not implemented.")

"""
raise UnityTrainerException("The update_model method was not implemented.")
def write_summary(self, lesson_num=0):
def write_summary(self, global_step, lesson_num=0):
:param lesson_num: The lesson the trainer is at.
:param global_step: The number of steps the simulation has been going for
:param lesson_number: The lesson the trainer is at.
if (self.get_step % self.trainer_parameters['summary_freq'] == 0 and self.get_step != 0 and
self.is_training and self.get_step <= self.get_max_steps):
if global_step % self.trainer_parameters['summary_freq'] == 0 and global_step != 0:
is_training = "Training." if self.is_training and self.get_step <= self.get_max_steps else "Not Training."
logger.info("{}: {}: Step: {}. Mean Reward: {:0.3f}. Std of Reward: {:0.3f}."
.format(self.run_id, self.brain_name, self.get_step,
mean_reward, np.std(self.stats['cumulative_reward'])))
logger.info(" {}: {}: Step: {}. Mean Reward: {:0.3f}. Std of Reward: {:0.3f}. {}"
.format(self.run_id, self.brain_name, min(self.get_step, self.get_max_steps),
mean_reward, np.std(self.stats['cumulative_reward']), is_training))
logger.info("{}: {}: Step: {}. No episode was completed since last summary."
.format(self.run_id, self.brain_name, self.get_step))
logger.info(" {}: {}: Step: {}. No episode was completed since last summary. {}"
.format(self.run_id, self.brain_name, self.get_step, is_training))
summary = tf.Summary()
for key in self.stats:
if len(self.stats[key]) > 0:

9
python/unitytrainers/trainer_controller.py


trainer.update_model()
# Write training statistics to Tensorboard.
if self.meta_curriculum is not None:
trainer.write_summary(lesson=self.meta_curriculum.brains_to_curriculums[brain_name].lesson_num)
trainer.write_summary(
global_step,
lesson=self.meta_curriculum.brains_to_curriculums[brain_name].lesson_num)
trainer.write_summary()
trainer.write_summary(global_step)
if self.train_model:
global_step += 1
global_step += 1
if global_step % self.save_freq == 0 and global_step != 0 and self.train_model:
# Save Tensorflow model
self._save_model(sess, steps=global_step, saver=saver)

正在加载...
取消
保存