diff --git a/deploy/python/infer.py b/deploy/python/infer.py index e7c22c76a07f647fd2cb4f1fc2df6d08f6098581..9b95abdda8078747745e4cf48e90bc3281723656 100644 --- a/deploy/python/infer.py +++ b/deploy/python/infer.py @@ -152,17 +152,11 @@ class Detector(object): def postprocess(self, inputs, result): # postprocess output of predictor np_boxes_num = result['boxes_num'] - out_result = {k: [] for k, v in result.items() if v is not None} - idx = 0 - for num_box in np_boxes_num: - for k, v in out_result.items(): - v.append(result[k][idx:idx + num_box]) - idx += num_box - if num_box == 0: - print('[WARNNING] No object detected.') - out_result = {k: np.concatenate(v) for k, v in out_result.items()} - out_result['boxes_num'] = result['boxes_num'] - return out_result + if sum(np_boxes_num) <= 0: + print('[WARNNING] No object detected.') + result = {'boxes': np.zeros([0, 6]), 'boxes_num': [0]} + result = {k: v for k, v in result.items() if v is not None} + return result def filter_box(self, result, threshold): np_boxes_num = result['boxes_num'] diff --git a/ppdet/data/source/coco.py b/ppdet/data/source/coco.py index 5c401de14398f72084d8acbd56c1a52325edbe54..1f7c9b7bb528ac26ee405947bdafd55909fd1d84 100644 --- a/ppdet/data/source/coco.py +++ b/ppdet/data/source/coco.py @@ -39,6 +39,7 @@ class COCODataSet(DetDataset): empty_ratio (float): the ratio of empty record number to total record's, if empty_ratio is out of [0. ,1.), do not sample the records and use all the empty entries. 1. as default + repeat (int): repeat times for dataset, use in benchmark. """ def __init__(self, @@ -49,9 +50,15 @@ class COCODataSet(DetDataset): sample_num=-1, load_crowd=False, allow_empty=False, - empty_ratio=1.): - super(COCODataSet, self).__init__(dataset_dir, image_dir, anno_path, - data_fields, sample_num) + empty_ratio=1., + repeat=1): + super(COCODataSet, self).__init__( + dataset_dir, + image_dir, + anno_path, + data_fields, + sample_num, + repeat=repeat) self.load_image_only = False self.load_semantic = False self.load_crowd = load_crowd diff --git a/ppdet/data/source/dataset.py b/ppdet/data/source/dataset.py index 9c8e5e647cdeee0df35789ddb89d78d1b96d1a86..631627b3c241687b7d0b0e1737e396211afc4e60 100644 --- a/ppdet/data/source/dataset.py +++ b/ppdet/data/source/dataset.py @@ -38,6 +38,7 @@ class DetDataset(Dataset): data_fields (list): key name of data dictionary, at least have 'image'. sample_num (int): number of samples to load, -1 means all. use_default_label (bool): whether to load default label list. + repeat (int): repeat times for dataset, use in benchmark. """ def __init__(self, @@ -47,6 +48,7 @@ class DetDataset(Dataset): data_fields=['image'], sample_num=-1, use_default_label=None, + repeat=1, **kwargs): super(DetDataset, self).__init__() self.dataset_dir = dataset_dir if dataset_dir is not None else '' @@ -55,16 +57,19 @@ class DetDataset(Dataset): self.data_fields = data_fields self.sample_num = sample_num self.use_default_label = use_default_label + self.repeat = repeat self._epoch = 0 self._curr_iter = 0 def __len__(self, ): - return len(self.roidbs) + return len(self.roidbs) * self.repeat def __call__(self, *args, **kwargs): return self def __getitem__(self, idx): + if self.repeat > 1: + idx %= self.repeat # data batch roidb = copy.deepcopy(self.roidbs[idx]) if self.mixup_epoch == 0 or self._epoch < self.mixup_epoch: diff --git a/ppdet/data/source/mot.py b/ppdet/data/source/mot.py index 1baadf570d13afe6f9c648fdff755ac314d1aa35..90a8a1fe88d70e1627623c1cc721f2c6eb9781e4 100644 --- a/ppdet/data/source/mot.py +++ b/ppdet/data/source/mot.py @@ -39,6 +39,7 @@ class MOTDataSet(DetDataset): image_lists (str|list): mot data image lists, muiti-source mot dataset. data_fields (list): key name of data dictionary, at least have 'image'. sample_num (int): number of samples to load, -1 means all. + repeat (int): repeat times for dataset, use in benchmark. Notes: MOT datasets root directory following this: @@ -77,11 +78,13 @@ class MOTDataSet(DetDataset): dataset_dir=None, image_lists=[], data_fields=['image'], - sample_num=-1): + sample_num=-1, + repeat=1): super(MOTDataSet, self).__init__( dataset_dir=dataset_dir, data_fields=data_fields, - sample_num=sample_num) + sample_num=sample_num, + repeat=repeat) self.dataset_dir = dataset_dir self.image_lists = image_lists if isinstance(self.image_lists, str): @@ -95,7 +98,8 @@ class MOTDataSet(DetDataset): # only used to get categories and metric # only check first data, but the label_list of all data should be same. first_mot_data = self.image_lists[0].split('.')[0] - anno_file = os.path.join(self.dataset_dir, first_mot_data, 'label_list.txt') + anno_file = os.path.join(self.dataset_dir, first_mot_data, + 'label_list.txt') return anno_file def parse_dataset(self): @@ -276,7 +280,8 @@ class MCMOTDataSet(DetDataset): # only used to get categories and metric # only check first data, but the label_list of all data should be same. first_mot_data = self.image_lists[0].split('.')[0] - anno_file = os.path.join(self.dataset_dir, first_mot_data, 'label_list.txt') + anno_file = os.path.join(self.dataset_dir, first_mot_data, + 'label_list.txt') return anno_file def parse_dataset(self): @@ -472,7 +477,7 @@ class MOTImageFolder(DetDataset): image_dir=None, sample_num=-1, keep_ori_im=False, - anno_path=None, + anno_path=None, **kwargs): super(MOTImageFolder, self).__init__( dataset_dir, image_dir, sample_num=sample_num) @@ -576,6 +581,7 @@ class MOTImageFolder(DetDataset): def get_anno(self): return self.anno_path + def _is_valid_video(f, extensions=('.mp4', '.avi', '.mov', '.rmvb', 'flv')): return f.lower().endswith(extensions) diff --git a/ppdet/data/source/voc.py b/ppdet/data/source/voc.py index 1c2a7ef98ccbac760430befc375a79cdebc51a7c..2f103588537c5499ef83133fe3f8d4ba7303e685 100644 --- a/ppdet/data/source/voc.py +++ b/ppdet/data/source/voc.py @@ -46,6 +46,7 @@ class VOCDataSet(DetDataset): empty_ratio (float): the ratio of empty record number to total record's, if empty_ratio is out of [0. ,1.), do not sample the records and use all the empty entries. 1. as default + repeat (int): repeat times for dataset, use in benchmark. """ def __init__(self, @@ -56,13 +57,15 @@ class VOCDataSet(DetDataset): sample_num=-1, label_list=None, allow_empty=False, - empty_ratio=1.): + empty_ratio=1., + repeat=1): super(VOCDataSet, self).__init__( dataset_dir=dataset_dir, image_dir=image_dir, anno_path=anno_path, data_fields=data_fields, - sample_num=sample_num) + sample_num=sample_num, + repeat=repeat) self.label_list = label_list self.allow_empty = allow_empty self.empty_ratio = empty_ratio diff --git a/test_tipc/benchmark_train.sh b/test_tipc/benchmark_train.sh index 794f2302db663297b82260e5d891719cd03a931e..3e5cb9efcac1f3907a476306806ff6836444d096 100644 --- a/test_tipc/benchmark_train.sh +++ b/test_tipc/benchmark_train.sh @@ -83,6 +83,9 @@ line_num=`expr $line_num + 1` fp_items=$(func_parser_value "${lines[line_num]}") line_num=`expr $line_num + 1` epoch=$(func_parser_value "${lines[line_num]}") +eval "sed -i '10i\ repeat: ${epoch}' configs/datasets/coco_detection.yml" +eval "sed -i '10i\ repeat: ${epoch}' configs/datasets/coco_instance.yml" +eval "sed -i '10i\ repeat: ${epoch}' configs/datasets/mot.yml" line_num=`expr $line_num + 1` profile_option_key=$(func_parser_key "${lines[line_num]}") @@ -157,7 +160,7 @@ for batch_size in ${batch_size_list[*]}; do # sed batchsize and precision func_sed_params "$FILENAME" "${line_precision}" "$precision" func_sed_params "$FILENAME" "${line_batchsize}" "$MODE=$batch_size" - func_sed_params "$FILENAME" "${line_epoch}" "$MODE=$epoch" + func_sed_params "$FILENAME" "${line_epoch}" "$MODE=1" gpu_id=$(set_gpu_id $device_num) if [ ${#gpu_id} -le 1 ];then diff --git a/test_tipc/configs/keypoint/tinypose_128x96_train_infer_python.txt b/test_tipc/configs/keypoint/tinypose_128x96_train_infer_python.txt index 34aade55d6f3e8ea6878b3af320f48998c6f964d..2ab30ea781bf77bac8be6beb0f384bc9da9d5171 100644 --- a/test_tipc/configs/keypoint/tinypose_128x96_train_infer_python.txt +++ b/test_tipc/configs/keypoint/tinypose_128x96_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/keypoint_infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -random_infer_input:[{float32,[3,128,96]}] \ No newline at end of file +random_infer_input:[{float32,[3,128,96]}] +===========================train_benchmark_params========================== +batch_size:512 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/picodet/picodet_lcnet_1_5x_416_coco_train_infer_python.txt b/test_tipc/configs/picodet/picodet_lcnet_1_5x_416_coco_train_infer_python.txt index d7a5022a442a9943ab84383095fa3f84439a1028..d59ca2a39f993377d24f3e47e899c5cadbfe26d6 100644 --- a/test_tipc/configs/picodet/picodet_lcnet_1_5x_416_coco_train_infer_python.txt +++ b/test_tipc/configs/picodet/picodet_lcnet_1_5x_416_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x416x416_2.npy \ No newline at end of file +numpy_infer_input:3x416x416_2.npy +===========================train_benchmark_params========================== +batch_size:80 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_linux_gpu_normal_normal_paddle2onnx_python_linux_gpu_cpu.txt b/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_linux_gpu_normal_normal_paddle2onnx_python_linux_gpu_cpu.txt deleted file mode 100644 index 35e625a566d0ab33a8112bc9b582c27d0b14fbf1..0000000000000000000000000000000000000000 --- a/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_linux_gpu_normal_normal_paddle2onnx_python_linux_gpu_cpu.txt +++ /dev/null @@ -1,28 +0,0 @@ -===========================paddle2onnx_params=========================== -model_name:picodet_s_320_coco_lcnet -python:python3.7 -filename:null -## ---output_dir:./output_inference -weights:https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams -norm_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml -o -quant_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --slim_config configs/picodet/picodet_s_320_coco_lcnet.yml -o -fpgm_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --slim_config configs/picodet/picodet_s_320_coco_lcnet.yml -o -distill_export:null -export1:null -export2:null -kl_quant_export:tools/post_quant.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --slim_config configs/picodet/picodet_s_320_coco_lcnet.yml -o -## -2onnx: paddle2onnx ---model_dir:./output_inference/picodet_s_320_coco_lcnet/ ---model_filename:model.pdmodel ---params_filename:model.pdiparams ---save_file:./deploy/third_engine/demo_onnxruntime/onnx_file/picodet_s_320_coco.onnx ---opset_version:11 -## -inference:infer_demo.py ---modelpath:./onnx_file/picodet_s_320_coco.onnx ---img_fold:./imgs ---result_fold:results -infer_mode:norm -null:null \ No newline at end of file diff --git a/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_model_linux_gpu_normal_normal_paddle2onnx_python_linux_cpu.txt b/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_model_linux_gpu_normal_normal_paddle2onnx_python_linux_cpu.txt new file mode 100644 index 0000000000000000000000000000000000000000..44d0554d85670ec89006e3ef05ec915b01e0cab4 --- /dev/null +++ b/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_model_linux_gpu_normal_normal_paddle2onnx_python_linux_cpu.txt @@ -0,0 +1,30 @@ +===========================paddle2onnx_params=========================== +model_name:picodet_s_320_coco_lcnet +python:python3.7 +filename:null +## +--output_dir:./output_inference +weights:https://paddledet.bj.bcebos.com/models/picodet_s_320_coco_lcnet.pdparams +norm_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml -o +quant_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --slim_config _template_pact -o +fpgm_export:tools/export_model.py -c configs/picodet/picodet_s_320_coco_lcnet.yml --slim_config _template_fpgm -o +distill_export:null +export1:null +export_param:null +kl_quant_export:tools/post_quant.py -c configs/picodet/yolov3_darknet53_270e_coco.yml --slim_config _template_kl_quant -o +## +infer_mode:norm +infer_quant:False +cmd:paddle2onnx +--model_dir:null +--model_filename:model.pdmodel +--params_filename:model.pdiparams +--save_file:model.onnx +--opset_version:11 +--enable_onnx_checker:True +paddle2onnx_param1:null +infer_py:./deploy/third_engine/onnx/infer.py +--infer_cfg:null +--onnx_file:null +--image_file:./demo/000000014439.jpg +infer_param1:null \ No newline at end of file diff --git a/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_train_infer_python.txt b/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_train_infer_python.txt index 7c9bb02b35e9664cb003708b260842e29273a4da..e603169a223928aff53dfa1b6024bfa8e3d6bd15 100644 --- a/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_train_infer_python.txt +++ b/test_tipc/configs/picodet/picodet_s_320_coco_lcnet_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x320x320_2.npy \ No newline at end of file +numpy_infer_input:3x320x320_2.npy +===========================train_benchmark_params========================== +batch_size:128 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/picodet/picodet_s_320_coco_train_infer_python.txt b/test_tipc/configs/picodet/picodet_s_320_coco_train_infer_python.txt index 0868ac53dd1be2f34dbaa57b0c0d2bdd86ba1f53..6745bcc527590b116556dff19fbadd3e6908013f 100644 --- a/test_tipc/configs/picodet/picodet_s_320_coco_train_infer_python.txt +++ b/test_tipc/configs/picodet/picodet_s_320_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x320x320_2.npy \ No newline at end of file +numpy_infer_input:3x320x320_2.npy +===========================train_benchmark_params========================== +batch_size:128 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/ppyolo/ppyolo_mbv3_large_coco_train_infer_python.txt b/test_tipc/configs/ppyolo/ppyolo_mbv3_large_coco_train_infer_python.txt index d1fc912d018da0277301c2340ab675d66786f3e0..801a2eaf2f1ee85922a7fba4c08180fc5cb47903 100644 --- a/test_tipc/configs/ppyolo/ppyolo_mbv3_large_coco_train_infer_python.txt +++ b/test_tipc/configs/ppyolo/ppyolo_mbv3_large_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x320x320.npy \ No newline at end of file +numpy_infer_input:3x320x320.npy +===========================train_benchmark_params========================== +batch_size:24 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/ppyolo/ppyolo_r50vd_dcn_1x_coco_train_infer_python.txt b/test_tipc/configs/ppyolo/ppyolo_r50vd_dcn_1x_coco_train_infer_python.txt index 33d1282ee2bb9c4d6b97801386a136071c22529e..331f649a8979471e9da5ac2da0cf97800f56d5c3 100644 --- a/test_tipc/configs/ppyolo/ppyolo_r50vd_dcn_1x_coco_train_infer_python.txt +++ b/test_tipc/configs/ppyolo/ppyolo_r50vd_dcn_1x_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x608x608.npy \ No newline at end of file +numpy_infer_input:3x608x608.npy +===========================train_benchmark_params========================== +batch_size:24 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/ppyolo/ppyolo_tiny_650e_coco_train_infer_python.txt b/test_tipc/configs/ppyolo/ppyolo_tiny_650e_coco_train_infer_python.txt index a3ff4f7ec2b6d96d3a1e41c4321cfc639b2cc5b1..3201bcd4374c6d3bb7149136d9e91b864498d7e8 100644 --- a/test_tipc/configs/ppyolo/ppyolo_tiny_650e_coco_train_infer_python.txt +++ b/test_tipc/configs/ppyolo/ppyolo_tiny_650e_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x320x320.npy \ No newline at end of file +numpy_infer_input:3x320x320.npy +===========================train_benchmark_params========================== +batch_size:32 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco_train_infer_python.txt b/test_tipc/configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco_train_infer_python.txt index a85d525d4c375dad7d68bad53f5e98aee65b415d..d767a3631aa173c0fb6226b7c7c9c2cf6dbff4c4 100644 --- a/test_tipc/configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco_train_infer_python.txt +++ b/test_tipc/configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False null:null ===========================infer_benchmark_params=========================== -numpy_infer_input:3x640x640.npy \ No newline at end of file +numpy_infer_input:3x640x640.npy +===========================train_benchmark_params========================== +batch_size:12 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file diff --git a/test_tipc/configs/ppyoloe/ppyoloe_crn_s_300e_coco_train_infer_python.txt b/test_tipc/configs/ppyoloe/ppyoloe_crn_s_300e_coco_train_infer_python.txt index 5e553badc694748517cad61f90b80119e64b0ddb..459f6e02cedd9e8939d4346cde70f5ba8df760af 100644 --- a/test_tipc/configs/ppyoloe/ppyoloe_crn_s_300e_coco_train_infer_python.txt +++ b/test_tipc/configs/ppyoloe/ppyoloe_crn_s_300e_coco_train_infer_python.txt @@ -50,4 +50,10 @@ inference:./deploy/python/infer.py --run_benchmark:False --trt_max_shape:1600 ===========================infer_benchmark_params=========================== -numpy_infer_input:3x640x640.npy \ No newline at end of file +numpy_infer_input:3x640x640.npy +===========================train_benchmark_params========================== +batch_size:32 +fp_items:fp32|fp16 +epoch:1 +--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile +flags:null \ No newline at end of file