未验证 提交 ee102078 编写于 作者: L littletomatodonkey 提交者: GitHub

fix log benchmark (#369)

fix log benchmark
上级 d4b1f6af
......@@ -20,9 +20,10 @@ class AverageMeter(object):
Computes and stores the average and current value
"""
def __init__(self, name='', fmt='f', need_avg=True):
def __init__(self, name='', fmt='f', postfix="", need_avg=True):
self.name = name
self.fmt = fmt
self.postfix = postfix
self.need_avg = need_avg
self.reset()
......@@ -42,18 +43,20 @@ class AverageMeter(object):
@property
def total(self):
return '{self.name}_sum: {self.sum:{self.fmt}}'.format(self=self)
return '{self.name}_sum: {self.sum:{self.fmt}}{self.postfix}'.format(
self=self)
@property
def total_minute(self):
return '{self.name}_sum: {s:{self.fmt}} min'.format(
return '{self.name}_sum: {s:{self.fmt}}{self.postfix} min'.format(
s=self.sum / 60, self=self)
@property
def mean(self):
return '{self.name}_avg: {self.avg:{self.fmt}}'.format(
return '{self.name}_avg: {self.avg:{self.fmt}}{self.postfix}'.format(
self=self) if self.need_avg else ''
@property
def value(self):
return '{self.name}: {self.val:{self.fmt}}'.format(self=self)
return '{self.name}: {self.val:{self.fmt}}{self.postfix}'.format(
self=self)
......@@ -36,24 +36,6 @@ from ppcls.utils.misc import AverageMeter
from ppcls.utils import logger
def create_dataloader():
"""
Create a dataloader with model input variables
Args:
feeds(dict): dict of model input variables
Returns:
dataloader(paddle dataloader):
"""
trainer_num = int(os.environ.get('PADDLE_TRAINERS_NUM', 1))
capacity = 64 if trainer_num == 1 else 8
dataloader = paddle.io.DataLoader.from_generator(
capacity=capacity, use_double_buffer=True, iterable=True)
return dataloader
def create_model(architecture, classes_num):
"""
Create a model
......@@ -275,16 +257,23 @@ def run(dataloader,
use_mix = config.get("use_mix", False) and mode == "train"
metric_list = [
("loss", AverageMeter('loss', '7.5f')),
("loss", AverageMeter(
'loss', '7.5f', postfix=",")),
("lr", AverageMeter(
'lr', 'f', need_avg=False)),
("batch_time", AverageMeter('elapse', '.7f')),
("reader_time", AverageMeter('reader ', '.7f')),
'lr', 'f', postfix=",", need_avg=False)),
("batch_time", AverageMeter(
'batch_cost', '.5f', postfix=" s,")),
("reader_time", AverageMeter(
'reader_cost', '.5f', postfix=" s,")),
]
if not use_mix:
topk_name = 'top{}'.format(config.topk)
metric_list.insert(1, (topk_name, AverageMeter(topk_name, '.5f')))
metric_list.insert(1, ("top1", AverageMeter("top1", '.5f')))
metric_list.insert(
1, (topk_name, AverageMeter(
topk_name, '.5f', postfix=",")))
metric_list.insert(
1, ("top1", AverageMeter(
"top1", '.5f', postfix=",")))
metric_list = OrderedDict(metric_list)
......@@ -316,35 +305,43 @@ def run(dataloader,
for name, fetch in fetchs.items():
metric_list[name].update(fetch.numpy()[0], batch_size)
metric_list['batch_time'].update(time.time() - tic)
metric_list["batch_time"].update(time.time() - tic)
tic = time.time()
fetchs_str = ' '.join([str(m.value) for m in metric_list.values()])
if idx % print_interval == 0:
ips_info = "ips: {:.5f} images/sec.".format(
batch_size / metric_list["batch_time"].val)
if mode == 'eval':
logger.info("{:s} step:{:<4d} {:s}s".format(mode, idx,
fetchs_str))
logger.info("{:s} step:{:<4d}, {:s} {:s}".format(
mode, idx, fetchs_str, ips_info))
else:
epoch_str = "epoch:{:<3d}".format(epoch)
step_str = "{:s} step:{:<4d}".format(mode, idx)
logger.info("{:s} {:s} {:s}s".format(
logger.info("{:s}, {:s}, {:s} {:s}".format(
logger.coloring(epoch_str, "HEADER")
if idx == 0 else epoch_str,
logger.coloring(step_str, "PURPLE"),
logger.coloring(fetchs_str, 'OKGREEN')))
logger.coloring(fetchs_str, 'OKGREEN'),
logger.coloring(ips_info, 'OKGREEN')))
end_str = ' '.join([str(m.mean) for m in metric_list.values()] +
[metric_list['batch_time'].total])
ips_info = "ips: {:.5f} images/sec.".format(
batch_size * metric_list["batch_time"].count /
metric_list["batch_time"].sum)
if mode == 'eval':
logger.info("END {:s} {:s}s".format(mode, end_str))
logger.info("END {:s} {:s} {:s}".format(mode, end_str, ips_info))
else:
end_epoch_str = "END epoch:{:<3d}".format(epoch)
logger.info("{:s} {:s} {:s}s".format(
logger.info("{:s} {:s} {:s} {:s}".format(
logger.coloring(end_epoch_str, "RED"),
logger.coloring(mode, "PURPLE"),
logger.coloring(end_str, "OKGREEN")))
logger.coloring(end_str, "OKGREEN"),
logger.coloring(ips_info, "OKGREEN"), ))
# return top1_acc in order to save the best model
if mode == 'valid':
......
......@@ -60,7 +60,8 @@ def main(args):
place = 'gpu:{}'.format(ParallelEnv().dev_id) if use_gpu else 'cpu'
place = paddle.set_device(place)
use_data_parallel = int(os.getenv("PADDLE_TRAINERS_NUM", 1)) != 1
trainer_num = int(os.getenv("PADDLE_TRAINERS_NUM", 1))
use_data_parallel = trainer_num != 1
config["use_data_parallel"] = use_data_parallel
if config["use_data_parallel"]:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册