diff --git a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/eval.py b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/eval.py index ac379e530ca1dfad74adf3857cb9b3decefac3b0..88ec8c8915ff1b94521a569b433626caa6705827 100644 --- a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/eval.py +++ b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/eval.py @@ -17,6 +17,7 @@ #!python3 import argparse import os +import sys import torch if torch.__version__ >= "1.8": import torch_npu @@ -192,6 +193,7 @@ class Eval: with torch.no_grad(): for _, data_loader in self.data_loaders.items(): raw_metrics = [] + time_cost = sys.maxsize for i, batch in tqdm(enumerate(data_loader.train_loader), total=len(data_loader.train_loader)): if self.args['test_speed']: time_cost = self.report_speed(model, batch, times=50) @@ -202,8 +204,7 @@ class Eval: if not os.path.isdir(self.args['result_dir']): os.mkdir(self.args['result_dir']) self.format_output(batch, output) - time_cost = (time.time() - start) - print("Time:",time_cost) + time_cost = min((time.time() - start), time_cost) raw_metric = self.structure.measurer.validate_measure(batch, output, is_output_polygon=self.args['polygon'], box_thresh=self.args['box_thresh']) raw_metrics.append(raw_metric) @@ -211,6 +212,8 @@ class Eval: vis_image = self.structure.visualizer.visualize(batch, output, pred) self.logger.save_image_dict(vis_image) vis_images.update(vis_image) + if i == len(data_loader.train_loader) - 1: + print("Time:", time_cost) metrics = self.structure.measurer.gather_measure(raw_metrics, self.logger) for key, metric in metrics.items(): self.logger.info('%s : %f (%d)' % (key, metric.avg, metric.count)) diff --git a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/test/eval.sh b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/test/eval.sh index 2be1e64ba71f2eb720a040fef35b0ea778f58fbe..2847075f3108b1d85b7229ec0c71f1f4d8d60b89 100644 --- a/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/test/eval.sh +++ b/PyTorch/built-in/cv/detection/DB_ID0706_for_PyTorch/test/eval.sh @@ -98,7 +98,7 @@ e2e_time=$(( $end_time - $start_time )) # 结果打印,不需要修改 echo "------------------ Final result ------------------" # 输出性能FPS,需要模型审视修改 -FPS=`grep -a 'Time' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/test_${ASCEND_DEVICE_ID}.log | tail -n 10 | awk '{print$2}' | awk '{sum+=$1} END {print ('$batch_size')/(sum/NR)}'` +FPS=`grep -a 'Time' ${test_path_dir}/output/${ASCEND_DEVICE_ID}/test_${ASCEND_DEVICE_ID}.log | tail -n 1 | awk '{print$2}' | awk '{sum+=$1} END {print ('$batch_size')/(sum/NR)}'` FPS=${FPS#* } # 去除前面的空格字符 # 打印,不需要修改 echo "Final Performance images/sec : $FPS"