From 15b18973f1c6a0f3cab5d253ae86c8048b4db9ec Mon Sep 17 00:00:00 2001 From: littletomatodonkey <2120160898@bit.edu.cn> Date: Thu, 10 Dec 2020 23:45:58 +0800 Subject: [PATCH] fix eval script (#464) * fix eval script * fix dali shell --- ppcls/modeling/architectures/hrnet.py | 3 ++- ppcls/modeling/architectures/resnest.py | 1 + ppcls/utils/misc.py | 4 ++-- tools/eval.py | 6 +++--- tools/eval.sh | 10 +++++----- tools/program.py | 13 +++++++++++-- tools/run.sh | 4 ++-- tools/static/run_dali.sh | 2 +- tools/train.py | 5 +++-- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/ppcls/modeling/architectures/hrnet.py b/ppcls/modeling/architectures/hrnet.py index 4911a1d0..07fc765e 100644 --- a/ppcls/modeling/architectures/hrnet.py +++ b/ppcls/modeling/architectures/hrnet.py @@ -179,7 +179,8 @@ class Branches(nn.Layer): outs = [] for idx, input in enumerate(inputs): conv = input - for basic_block_func in self.basic_block_list[idx]: + basic_block_list = self.basic_block_list[idx] + for basic_block_func in basic_block_list: conv = basic_block_func(conv) outs.append(conv) return outs diff --git a/ppcls/modeling/architectures/resnest.py b/ppcls/modeling/architectures/resnest.py index 84d0452a..769b7637 100644 --- a/ppcls/modeling/architectures/resnest.py +++ b/ppcls/modeling/architectures/resnest.py @@ -165,6 +165,7 @@ class SplatConv(nn.Layer): atten = self.conv3(gap) atten = self.rsoftmax(atten) + atten = paddle.reshape(x=atten, shape=[-1, atten.shape[1], 1, 1]) if self.radix > 1: attens = paddle.split(atten, num_or_sections=self.radix, axis=1) diff --git a/ppcls/utils/misc.py b/ppcls/utils/misc.py index 5a950ef2..90dc47e9 100644 --- a/ppcls/utils/misc.py +++ b/ppcls/utils/misc.py @@ -48,12 +48,12 @@ class AverageMeter(object): @property def total_minute(self): - return '{self.name}_sum: {s:{self.fmt}}{self.postfix} min'.format( + return '{self.name} {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}}{self.postfix}'.format( + return '{self.name}: {self.avg:{self.fmt}}{self.postfix}'.format( self=self) if self.need_avg else '' @property diff --git a/tools/eval.py b/tools/eval.py index 0a9f7c62..b69e71dc 100644 --- a/tools/eval.py +++ b/tools/eval.py @@ -67,9 +67,9 @@ def main(args, return_dict={}): init_model(config, net, optimizer=None) valid_dataloader = Reader(config, 'valid', places=place)() net.eval() - - top1_acc = program.run(valid_dataloader, config, net, None, None, 0, - 'valid') + with paddle.no_grad(): + top1_acc = program.run(valid_dataloader, config, net, None, None, 0, + 'valid') return_dict["top1_acc"] = top1_acc return top1_acc diff --git a/tools/eval.sh b/tools/eval.sh index 42770cd5..f67ba9c9 100644 --- a/tools/eval.sh +++ b/tools/eval.sh @@ -1,6 +1,6 @@ -python -m paddle.distributed.launch \ - --selected_gpus="0" \ +python3.7 -m paddle.distributed.launch \ + --gpus="0,1,2,3" \ tools/eval.py \ - -c ./configs/eval.yaml \ - -o load_static_weights=True \ - -o use_gpu=False + -c ./configs/ResNet/ResNet50.yaml \ + -o pretrained_model="./ResNet50_pretrained" \ + -o use_gpu=True diff --git a/tools/program.py b/tools/program.py index f7c5a5ed..12dfcdcb 100644 --- a/tools/program.py +++ b/tools/program.py @@ -298,6 +298,11 @@ def run(dataloader, tic = time.time() for idx, batch in enumerate(dataloader()): + # avoid statistics from warmup time + if idx == 10: + metric_list["batch_time"].reset() + metric_list["reader_time"].reset() + metric_list['reader_time'].update(time.time() - tic) batch_size = len(batch[0]) feeds = create_feeds(batch, use_mix) @@ -327,11 +332,15 @@ def run(dataloader, metric_list["batch_time"].update(time.time() - tic) tic = time.time() - fetchs_str = ' '.join([str(m.value) for m in metric_list.values()]) + fetchs_str = ' '.join([ + str(metric_list[key].mean) + if "time" in key else str(metric_list[key].value) + for key in metric_list + ]) if idx % print_interval == 0: ips_info = "ips: {:.5f} images/sec.".format( - batch_size / metric_list["batch_time"].val) + batch_size / metric_list["batch_time"].avg) if mode == 'eval': logger.info("{:s} step:{:<4d}, {:s} {:s}".format( mode, idx, fetchs_str, ips_info)) diff --git a/tools/run.sh b/tools/run.sh index ad1e5448..be89623f 100755 --- a/tools/run.sh +++ b/tools/run.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -python -m paddle.distributed.launch \ - --selected_gpus="0,1,2,3" \ +python3.7 -m paddle.distributed.launch \ + --gpus="0,1,2,3" \ tools/train.py \ -c ./configs/ResNet/ResNet50.yaml \ -o print_interval=10 diff --git a/tools/static/run_dali.sh b/tools/static/run_dali.sh index 2bc29dfc..1ac48b3c 100644 --- a/tools/static/run_dali.sh +++ b/tools/static/run_dali.sh @@ -4,7 +4,7 @@ export CUDA_VISIBLE_DEVICES="0,1,2,3" export FLAGS_fraction_of_gpu_memory_to_use=0.80 python3.7 -m paddle.distributed.launch \ - --selected_gpus="0,1,2,3" \ + --gpus="0,1,2,3" \ tools/static/train.py \ -c ./configs/ResNet/ResNet50.yaml \ -o print_interval=10 \ diff --git a/tools/train.py b/tools/train.py index e4589f64..3cd9d459 100644 --- a/tools/train.py +++ b/tools/train.py @@ -92,8 +92,9 @@ def main(args): # 2. validate with validate dataset if config.validate and epoch_id % config.valid_interval == 0: net.eval() - top1_acc = program.run(valid_dataloader, config, net, None, None, - epoch_id, 'valid') + with paddle.no_grad(): + top1_acc = program.run(valid_dataloader, config, net, None, + None, epoch_id, 'valid') if top1_acc > best_top1_acc: best_top1_acc = top1_acc best_top1_epoch = epoch_id -- GitLab