未验证 提交 9d200f0e 编写于 作者: 走神的阿圆's avatar 走神的阿圆 提交者: GitHub

add vdl to replace tb_paddle (#570)

上级 fe44893b
......@@ -22,7 +22,7 @@ import os
import six
import time
from tb_paddle import SummaryWriter
from visualdl import LogWriter
from paddlehub.common.logger import logger
from paddlehub.common.utils import mkdir
from paddlehub.autofinetune.evaluator import REWARD_SUM, TMP_HOME
......@@ -67,12 +67,12 @@ class BaseTuningStrategy(object):
self._output_dir = output_dir
# record the information for the whole auto finetune
self.writer = SummaryWriter(logdir=self._output_dir + '/visualization')
self.writer = LogWriter(logdir=self._output_dir + '/visualization')
# record the information for per population in all round
self.writer_pop_trails = []
for i in range(self.popsize):
writer_pop_trail = SummaryWriter(
writer_pop_trail = LogWriter(
logdir=self._output_dir + '/visualization/pop_{}'.format(i))
self.writer_pop_trails.append(writer_pop_trail)
......@@ -285,23 +285,23 @@ class HAZero(BaseTuningStrategy):
for index, name in enumerate(self.hparams_name_list):
self.writer.add_scalar(
tag="hyperparameter_tuning/" + name,
scalar_value=best_hparams[index],
global_step=self.round)
value=best_hparams[index],
step=self.round)
self.writer.add_scalar(
tag="hyperparameter_tuning/best_eval_value",
scalar_value=self.get_best_eval_value(),
global_step=self.round)
value=self.get_best_eval_value(),
step=self.round)
for pop_num in range(self.popsize):
params = self.evaluator.convert_params(params_list[pop_num])
for index, name in enumerate(self.hparams_name_list):
self.writer_pop_trails[pop_num].add_scalar(
tag="population_transformation/" + name,
scalar_value=params[index],
global_step=self.round)
value=params[index],
step=self.round)
self.writer_pop_trails[pop_num].add_scalar(
tag="population_transformation/eval_value",
scalar_value=(REWARD_SUM - reward_list[pop_num]),
global_step=self.round)
value=(REWARD_SUM - reward_list[pop_num]),
step=self.round)
self.evolution_stratefy.tell(params_list, reward_list)
self.evolution_stratefy.disp()
......@@ -422,23 +422,23 @@ class PSHE2(BaseTuningStrategy):
for index, name in enumerate(self.hparams_name_list):
self.writer.add_scalar(
tag="hyperparameter_tuning/" + name,
scalar_value=best_hparams[index],
global_step=self.round)
value=best_hparams[index],
step=self.round)
self.writer.add_scalar(
tag="hyperparameter_tuning/best_eval_value",
scalar_value=self.get_best_eval_value(),
global_step=self.round)
value=self.get_best_eval_value(),
step=self.round)
for pop_num in range(self.popsize):
params = self.evaluator.convert_params(params_list[pop_num])
for index, name in enumerate(self.hparams_name_list):
self.writer_pop_trails[pop_num].add_scalar(
tag="population_transformation/" + name,
scalar_value=params[index],
global_step=self.round)
value=params[index],
step=self.round)
self.writer_pop_trails[pop_num].add_scalar(
tag="population_transformation/eval_value",
scalar_value=(REWARD_SUM - reward_list[pop_num]),
global_step=self.round)
value=(REWARD_SUM - reward_list[pop_num]),
step=self.round)
self.estimate_momemtum()
for i in range(self.popsize):
......
......@@ -32,7 +32,7 @@ else:
import numpy as np
import paddle
import paddle.fluid as fluid
from tb_paddle import SummaryWriter
from visualdl import LogWriter
import paddlehub as hub
from paddlehub.common.paddle_helper import dtype_map, clone_program
......@@ -327,7 +327,7 @@ class BaseTask(object):
self._phases = []
self._envs = {}
self._predict_data = None
self._tb_writer = None
self._vdl_writer = None
# event hooks
self._hooks = TaskHooks()
......@@ -602,16 +602,16 @@ class BaseTask(object):
return [vars[varname] for varname in self.fetch_list]
@property
def tb_writer(self):
def vdl_writer(self):
"""
get tb_writer for visualization.
get vdl_writer for visualization.
"""
if not os.path.exists(self.config.checkpoint_dir):
mkdir(self.config.checkpoint_dir)
tb_log_dir = os.path.join(self.config.checkpoint_dir, "visualization")
if not self._tb_writer:
self._tb_writer = SummaryWriter(tb_log_dir)
return self._tb_writer
if not self._vdl_writer:
self._vdl_writer = LogWriter(tb_log_dir)
return self._vdl_writer
def create_event_function(self, hook_type):
"""
......@@ -718,18 +718,19 @@ class BaseTask(object):
"""
eval_scores, eval_loss, run_speed = self._calculate_metrics(run_states)
if 'train' in self._envs:
self.tb_writer.add_scalar(
self.vdl_writer.add_scalar(
tag="Loss_{}".format(self.phase),
scalar_value=eval_loss,
global_step=self._envs['train'].current_step)
value=eval_loss,
step=self._envs['train'].current_step)
log_scores = ""
for metric in eval_scores:
if 'train' in self._envs:
self.tb_writer.add_scalar(
self.vdl_writer.add_scalar(
tag="{}_{}".format(metric, self.phase),
scalar_value=eval_scores[metric],
global_step=self._envs['train'].current_step)
value=eval_scores[metric],
step=self._envs['train'].current_step)
log_scores += "%s=%.5f " % (metric, eval_scores[metric])
logger.eval(
"[%s dataset evaluation result] loss=%.5f %s[step/sec: %.2f]" %
......@@ -761,16 +762,16 @@ class BaseTask(object):
run_states (object): the results in train phase
"""
scores, avg_loss, run_speed = self._calculate_metrics(run_states)
self.tb_writer.add_scalar(
self.vdl_writer.add_scalar(
tag="Loss_{}".format(self.phase),
scalar_value=avg_loss,
global_step=self._envs['train'].current_step)
value=avg_loss,
step=self._envs['train'].current_step)
log_scores = ""
for metric in scores:
self.tb_writer.add_scalar(
self.vdl_writer.add_scalar(
tag="{}_{}".format(metric, self.phase),
scalar_value=scores[metric],
global_step=self._envs['train'].current_step)
value=scores[metric],
step=self._envs['train'].current_step)
log_scores += "%s=%.5f " % (metric, scores[metric])
logger.train("step %d / %d: loss=%.5f %s[step/sec: %.2f]" %
(self.current_step, self.max_train_steps, avg_loss,
......
......@@ -8,8 +8,7 @@ chardet == 3.0.4
requests
flask >= 1.1.0
flake8
tb-paddle
tensorboard >= 1.15
visualdl == 2.0.0a0
cma == 2.7.0
sentencepiece
nltk
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册