diff --git a/paddlecv/configs/single_op/PP-HGNet.yml b/paddlecv/configs/single_op/PP-HGNet.yml index 9e462c67847666feb95d25461ca01fdb860c21f2..020206399327273346e0f5bfe50cea9695189a73 100644 --- a/paddlecv/configs/single_op/PP-HGNet.yml +++ b/paddlecv/configs/single_op/PP-HGNet.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-HumanSegV2.yml b/paddlecv/configs/single_op/PP-HumanSegV2.yml index e65ab3867c48f577eb5c593df78f8ce348516574..c50883de083e1a347ff78b67439dad15dee7ccd0 100644 --- a/paddlecv/configs/single_op/PP-HumanSegV2.yml +++ b/paddlecv/configs/single_op/PP-HumanSegV2.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-LCNet.yml b/paddlecv/configs/single_op/PP-LCNet.yml index 655e38c4e611894677cd7d8d7933a9091fde7987..86f91c4b6710a08f0bb9bd7978123b768d80c386 100644 --- a/paddlecv/configs/single_op/PP-LCNet.yml +++ b/paddlecv/configs/single_op/PP-LCNet.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-LCNetV2.yml b/paddlecv/configs/single_op/PP-LCNetV2.yml index 1eb58fff6356720f6465a44fe0d3d05c13c93a46..771f8f57608865ae8eb414f70ddd4259e17417aa 100644 --- a/paddlecv/configs/single_op/PP-LCNetV2.yml +++ b/paddlecv/configs/single_op/PP-LCNetV2.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-LiteSeg.yml b/paddlecv/configs/single_op/PP-LiteSeg.yml index 3e54c3cc364f14e3945c7b8bb11684e617cba887..64f8e88396109addc2f4231b6a5b7dbb6df7b7c3 100644 --- a/paddlecv/configs/single_op/PP-LiteSeg.yml +++ b/paddlecv/configs/single_op/PP-LiteSeg.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-MattingV1.yml b/paddlecv/configs/single_op/PP-MattingV1.yml index 047e77c44406301a413ef0f784df5117fc9aff59..736f0b111c9c501b43a080dd6458894c595cc3b1 100644 --- a/paddlecv/configs/single_op/PP-MattingV1.yml +++ b/paddlecv/configs/single_op/PP-MattingV1.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-PicoDet.yml b/paddlecv/configs/single_op/PP-PicoDet.yml index 79e5315c0685101abf2c35c0445d1e3d13e5e37e..77c86e3cd996f9548e86cc001709fd0f5cd0917c 100644 --- a/paddlecv/configs/single_op/PP-PicoDet.yml +++ b/paddlecv/configs/single_op/PP-PicoDet.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 320 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-YOLO.yml b/paddlecv/configs/single_op/PP-YOLO.yml index 883cb21a5ae0809f4a28b3933d6473285d6ed46d..7b5fb1b6cba107ad8a296e72044eed4a35748432 100644 --- a/paddlecv/configs/single_op/PP-YOLO.yml +++ b/paddlecv/configs/single_op/PP-YOLO.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 608 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-YOLOE+.yml b/paddlecv/configs/single_op/PP-YOLOE+.yml index 3b08b63d06ec13e0c13466617c3d3865a76fa064..73608d73709f31b96700b311ba78b339924f1835 100644 --- a/paddlecv/configs/single_op/PP-YOLOE+.yml +++ b/paddlecv/configs/single_op/PP-YOLOE+.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 640 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-YOLOE.yml b/paddlecv/configs/single_op/PP-YOLOE.yml index 1f34b220f370717e76dd7d0336508e8712c120d5..a52447639a74990634def50c52e00123ea23fd63 100644 --- a/paddlecv/configs/single_op/PP-YOLOE.yml +++ b/paddlecv/configs/single_op/PP-YOLOE.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 640 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/single_op/PP-YOLOv2.yml b/paddlecv/configs/single_op/PP-YOLOv2.yml index dc9cf698dc75822eb629c79ec7ff7fc43d1900e3..d426882664d6848ad347bbd527ad9a77ade4f93b 100644 --- a/paddlecv/configs/single_op/PP-YOLOv2.yml +++ b/paddlecv/configs/single_op/PP-YOLOv2.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 640 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/Face-Detection-Attr.yml b/paddlecv/configs/system/Face-Detection-Attr.yml new file mode 100644 index 0000000000000000000000000000000000000000..341bc3dbf8d11888c2eabb53e6aa62382b6efddc --- /dev/null +++ b/paddlecv/configs/system/Face-Detection-Attr.yml @@ -0,0 +1,66 @@ +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: True + return_res: True + +MODEL: + - DetectionOp: + name: det + param_path: paddlecv://models/face_detection/inference.pdiparams + model_path: paddlecv://models/face_detection/inference.pdmodel + batch_size: 1 + PreProcess: + - NormalizeImage: + is_scale: false + mean: [123, 117, 104] + std: [127.502231, 127.502231, 127.502231] + - Permute: + PostProcess: + - ParserDetResults: + label_list: + - face + threshold: 0.5 + Inputs: + - input.image + - BboxCropOp: + name: bbox_crop + Inputs: + - input.image + - det.dt_bboxes + - ClassificationOp: + name: cls + param_path: paddlecv://models/face_attribute/inference.pdiparams + model_path: paddlecv://models/face_attribute/inference.pdmodel + batch_size: 8 + PreProcess: + - ResizeImage: + size: [ 224, 224 ] + - NormalizeImage: + scale: 0.00392157 + mean: [ 0.485, 0.456, 0.406 ] + std: [ 0.229, 0.224, 0.225 ] + order: '' + channel_num: 3 + - ToCHWImage: + - ExpandDim: + axis: 0 + PostProcess: + - FaceAttribute: + Inputs: + - bbox_crop.crop_image + - DetOutput: + name: vis + Inputs: + - input.fn + - input.image + - det.dt_bboxes + - det.dt_scores + - det.dt_cls_names + - cls.class_ids + - cls.scores + - cls.label_names + diff --git a/paddlecv/configs/system/PP-Human-Attr.yml b/paddlecv/configs/system/PP-Human-Attr.yml new file mode 100644 index 0000000000000000000000000000000000000000..022836b6672c7fde2bc42f49e6945e662ab89f89 --- /dev/null +++ b/paddlecv/configs/system/PP-Human-Attr.yml @@ -0,0 +1,93 @@ +image_shape: &image_shape 640 + +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: False + return_res: True + + +MODEL: + - DetectionOp: + name: det + param_path: paddlecv://models/mot_ppyoloe_l_36e_pphuman/model.pdiparams + model_path: paddlecv://models/mot_ppyoloe_l_36e_pphuman/model.pdmodel + batch_size: 1 + image_shape: [3, *image_shape, *image_shape] + PreProcess: + - Resize: + interp: 2 + keep_ratio: false + target_size: [*image_shape, *image_shape] + - Permute: + PostProcess: + - ParserDetResults: + label_list: + - pedestrian + threshold: 0.1 + Inputs: + - input.image + + - TrackerOP: + name: tracker + type: OCSORTTracker + tracker_configs: + det_thresh: 0.4 + max_age: 30 + min_hits: 3 + iou_threshold: 0.3 + delta_t: 3 + inertia: 0.2 + vertical_ratio: 0 + min_box_area: 0 + use_byte: False + PostProcess: + - ParserTrackerResults: + label_list: + - pedestrian + Inputs: + - det.dt_bboxes + - det.dt_scores + - det.dt_class_ids + - BboxCropOp: + name: bbox_crop + Inputs: + - input.image + - tracker.tk_bboxes + - ClassificationOp: + name: cls + param_path: paddlecv://models/person_attribute/inference.pdiparams + model_path: paddlecv://models/person_attribute/inference.pdmodel + batch_size: 8 + PreProcess: + - ResizeImage: + size: [256, 192] + - NormalizeImage: + scale: 0.00392157 + mean: [ 0.485, 0.456, 0.406 ] + std: [ 0.229, 0.224, 0.225 ] + order: '' + channel_num: 3 + - ToCHWImage: + - ExpandDim: + axis: 0 + PostProcess: + - PersonAttribute: + Inputs: + - bbox_crop.crop_image + - TrackerOutput: + name: vis + Inputs: + - input.fn + - input.image + - tracker.tk_bboxes + - tracker.tk_scores + - tracker.tk_ids + - tracker.tk_cls_ids + - tracker.tk_cls_names + - cls.class_ids + - cls.scores + - cls.label_names diff --git a/paddlecv/configs/system/PP-Human.yml b/paddlecv/configs/system/PP-Human.yml index 9e01fe7c94c4eaf746913239d193febd375aecc5..5192c940086b216a6ad8eb20403f2f7f068fe635 100644 --- a/paddlecv/configs/system/PP-Human.yml +++ b/paddlecv/configs/system/PP-Human.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 640 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-OCRv2.yml b/paddlecv/configs/system/PP-OCRv2.yml index 93cf5e2cb266dcc47d8ab74374dde581fa120050..77cc76593d755b688680fa59466a61bd0b341575 100644 --- a/paddlecv/configs/system/PP-OCRv2.yml +++ b/paddlecv/configs/system/PP-OCRv2.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-OCRv3-IE.yml b/paddlecv/configs/system/PP-OCRv3-IE.yml new file mode 100644 index 0000000000000000000000000000000000000000..96df4ffa99a9faf3692396cfc52f03343d2cd260 --- /dev/null +++ b/paddlecv/configs/system/PP-OCRv3-IE.yml @@ -0,0 +1,80 @@ +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: True + return_res: True + +MODEL: + - OcrDbDetOp: + name: det + param_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdmodel + batch_size: 1 + PreProcess: + - RGB2BGR: + - DetResizeForTest: + limit_side_len: 960 + limit_type: "max" + - NormalizeImage: + std: [0.229, 0.224, 0.225] + mean: [0.485, 0.456, 0.406] + scale: '1./255.' + order: 'hwc' + - ToCHWImage: + - ExpandDim: + axis: 0 + - KeepKeys: + keep_keys: ['image', 'shape'] + PostProcess: + - DBPostProcess: + thresh: 0.3 + box_thresh: 0.6 + max_candidates: 1000 + unclip_ratio: 1.5 + use_dilation: False + score_mode: "fast" + box_type: "quad" + Inputs: + - input.image + - PolyCropOp: + name: crop + Inputs: + - input.image + - det.dt_polys + - OcrCrnnRecOp: + name: rec + param_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdmodel + batch_size: 6 + PreProcess: + - RGB2BGR: + - ReisizeNormImg: + rec_image_shape: [3, 48, 320] + PostProcess: + - CTCLabelDecode: + character_dict_path: "paddlecv://dict/ocr/ch_dict.txt" + use_space_char: true + Inputs: + - crop.crop_image + - InformationExtractionOp: + name: nlp + schema: ['时间', '始发站', '终点站'] + batch_size: 1 + PostProcess: + - InformationExtractionDecode: + Inputs: + - rec.rec_text + - OCROutput: + name: vis + font_path: paddlecv://fonts/simfang.ttf + Inputs: + - input.fn + - input.image + - det.dt_polys + - rec.rec_text + - rec.rec_score + - nlp.text + - nlp.type diff --git a/paddlecv/configs/system/PP-OCRv3-SA.yml b/paddlecv/configs/system/PP-OCRv3-SA.yml new file mode 100644 index 0000000000000000000000000000000000000000..f171cc96ee21b6054cfda7254efc62f6de7c4ee2 --- /dev/null +++ b/paddlecv/configs/system/PP-OCRv3-SA.yml @@ -0,0 +1,78 @@ +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: True + return_res: True + +MODEL: + - OcrDbDetOp: + name: det + param_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdmodel + batch_size: 1 + PreProcess: + - RGB2BGR: + - DetResizeForTest: + limit_side_len: 960 + limit_type: "max" + - NormalizeImage: + std: [0.229, 0.224, 0.225] + mean: [0.485, 0.456, 0.406] + scale: '1./255.' + order: 'hwc' + - ToCHWImage: + - ExpandDim: + axis: 0 + - KeepKeys: + keep_keys: ['image', 'shape'] + PostProcess: + - DBPostProcess: + thresh: 0.3 + box_thresh: 0.6 + max_candidates: 1000 + unclip_ratio: 1.5 + use_dilation: False + score_mode: "fast" + box_type: "quad" + Inputs: + - input.image + - PolyCropOp: + name: crop + Inputs: + - input.image + - det.dt_polys + - OcrCrnnRecOp: + name: rec + param_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdmodel + batch_size: 6 + PreProcess: + - RGB2BGR: + - ReisizeNormImg: + rec_image_shape: [3, 48, 320] + PostProcess: + - CTCLabelDecode: + character_dict_path: "paddlecv://dict/ocr/ch_dict.txt" + use_space_char: true + Inputs: + - crop.crop_image + - SentimentAnalysisOp: + name: nlp + batch_size: 1 + PostProcess: + - SentimentAnalysisDecode: + Inputs: + - rec.rec_text + - OCROutput: + name: vis + font_path: paddlecv://fonts/simfang.ttf + Inputs: + - input.fn + - input.image + - det.dt_polys + - rec.rec_text + - rec.rec_score + - nlp.label diff --git a/paddlecv/configs/system/PP-OCRv3-TTS.yml b/paddlecv/configs/system/PP-OCRv3-TTS.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ff63c2b0469b40830dc00ba553adc088ba8bcd4 --- /dev/null +++ b/paddlecv/configs/system/PP-OCRv3-TTS.yml @@ -0,0 +1,76 @@ +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: True + return_res: True + +MODEL: + - OcrDbDetOp: + name: det + param_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_det_infer/inference.pdmodel + batch_size: 1 + PreProcess: + - RGB2BGR: + - DetResizeForTest: + limit_side_len: 960 + limit_type: "max" + - NormalizeImage: + std: [0.229, 0.224, 0.225] + mean: [0.485, 0.456, 0.406] + scale: '1./255.' + order: 'hwc' + - ToCHWImage: + - ExpandDim: + axis: 0 + - KeepKeys: + keep_keys: ['image', 'shape'] + PostProcess: + - DBPostProcess: + thresh: 0.3 + box_thresh: 0.6 + max_candidates: 1000 + unclip_ratio: 1.5 + use_dilation: False + score_mode: "fast" + box_type: "quad" + Inputs: + - input.image + - PolyCropOp: + name: crop + Inputs: + - input.image + - det.dt_polys + - OcrCrnnRecOp: + name: rec + param_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdiparams + model_path: paddlecv://models/ch_PP-OCRv3_rec_infer/inference.pdmodel + batch_size: 6 + PreProcess: + - RGB2BGR: + - ReisizeNormImg: + rec_image_shape: [3, 48, 320] + PostProcess: + - CTCLabelDecode: + character_dict_path: "paddlecv://dict/ocr/ch_dict.txt" + use_space_char: true + Inputs: + - crop.crop_image + - TTSOp: + name: tts + Inputs: + - input.fn + - rec.rec_text + - OCROutput: + name: vis + font_path: paddlecv://fonts/simfang.ttf + Inputs: + - input.fn + - input.image + - det.dt_polys + - rec.rec_text + - rec.rec_score + - tts.fn diff --git a/paddlecv/configs/system/PP-OCRv3.yml b/paddlecv/configs/system/PP-OCRv3.yml index 6b3894c8dd0a28d3d14c955a28b324a425f4046f..8642e9c9b106e554e46037158b42112534cb27ae 100644 --- a/paddlecv/configs/system/PP-OCRv3.yml +++ b/paddlecv/configs/system/PP-OCRv3.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-ShiTu.yml b/paddlecv/configs/system/PP-ShiTu.yml index b2234965ed5786ee9081a38a8e9e208b8c41335f..772c3bfcfb28d7f0833ef221e9318f031b2eebc6 100644 --- a/paddlecv/configs/system/PP-ShiTu.yml +++ b/paddlecv/configs/system/PP-ShiTu.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-ShiTuV2.yml b/paddlecv/configs/system/PP-ShiTuV2.yml index 4d7ca863b1084abd35a5d3cd492e28579750bba3..275decce82bf2168a073c1689daf038be1cfd6fa 100644 --- a/paddlecv/configs/system/PP-ShiTuV2.yml +++ b/paddlecv/configs/system/PP-ShiTuV2.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Structure-layout-table.yml b/paddlecv/configs/system/PP-Structure-layout-table.yml index 2c0434a3466e1689d6aa629a73cff743264efdbd..96c2d00d14d3f88509bcd63d7c8087ccb5e7a13f 100644 --- a/paddlecv/configs/system/PP-Structure-layout-table.yml +++ b/paddlecv/configs/system/PP-Structure-layout-table.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Structure-re.yml b/paddlecv/configs/system/PP-Structure-re.yml index 7daa504d4e12e1b7749ca2c312fc8772a7b11fb6..68e74573d8099027238af705b483e6d2ae7eabcf 100644 --- a/paddlecv/configs/system/PP-Structure-re.yml +++ b/paddlecv/configs/system/PP-Structure-re.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Structure-ser.yml b/paddlecv/configs/system/PP-Structure-ser.yml index 380c42c8b63586004ffe1fde014c4b2f093912c3..b9ba29b0a9133d3dd4a0a147d07eaef783c5876e 100644 --- a/paddlecv/configs/system/PP-Structure-ser.yml +++ b/paddlecv/configs/system/PP-Structure-ser.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Structure-table.yml b/paddlecv/configs/system/PP-Structure-table.yml index 059a010c121ce8b0a0c820f805f2dab1e70b0909..dc7384d5ba48a569aeb4abbc1688ef106cf5d38e 100644 --- a/paddlecv/configs/system/PP-Structure-table.yml +++ b/paddlecv/configs/system/PP-Structure-table.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Structure.yml b/paddlecv/configs/system/PP-Structure.yml index fd5af0f26aa37dbe4c1b5b68448871de8acbda29..dca1701576c76294ee24c79b357d4145dbeef53e 100644 --- a/paddlecv/configs/system/PP-Structure.yml +++ b/paddlecv/configs/system/PP-Structure.yml @@ -1,6 +1,5 @@ ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-TinyPose.yml b/paddlecv/configs/system/PP-TinyPose.yml index aca573e8ca780c3e50990d43e5cbdb8cf381feca..0b54d87c16b8554c3b0e47e1ac2b51ee45dc92e0 100644 --- a/paddlecv/configs/system/PP-TinyPose.yml +++ b/paddlecv/configs/system/PP-TinyPose.yml @@ -5,7 +5,6 @@ kpt_image_shape: &kpt_image_shape [*kpt_image_width, *kpt_image_height] ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/system/PP-Vehicle-Attr.yml b/paddlecv/configs/system/PP-Vehicle-Attr.yml new file mode 100644 index 0000000000000000000000000000000000000000..a83199be93b47b46ea530d8d8a0fbc0cd38ef20a --- /dev/null +++ b/paddlecv/configs/system/PP-Vehicle-Attr.yml @@ -0,0 +1,93 @@ +image_shape: &image_shape 640 + +ENV: + min_subgraph_size: 3 + trt_calib_mode: False + cpu_threads: 1 + trt_use_static: False + save_img: True + save_res: True + return_res: True + + +MODEL: + - DetectionOp: + name: det + param_path: paddlecv://models/mot_ppyoloe_l_36e_ppvehicle/model.pdiparams + model_path: paddlecv://models/mot_ppyoloe_l_36e_ppvehicle/model.pdmodel + batch_size: 1 + image_shape: [3, *image_shape, *image_shape] + PreProcess: + - Resize: + interp: 2 + keep_ratio: false + target_size: [*image_shape, *image_shape] + - Permute: + PostProcess: + - ParserDetResults: + label_list: + - vehicle + threshold: 0.1 + Inputs: + - input.image + + - TrackerOP: + name: tracker + type: OCSORTTracker + tracker_configs: + det_thresh: 0.4 + max_age: 30 + min_hits: 3 + iou_threshold: 0.3 + delta_t: 3 + inertia: 0.2 + vertical_ratio: 0 + min_box_area: 0 + use_byte: False + PostProcess: + - ParserTrackerResults: + label_list: + - vehicle + Inputs: + - det.dt_bboxes + - det.dt_scores + - det.dt_class_ids + - BboxCropOp: + name: bbox_crop + Inputs: + - input.image + - tracker.tk_bboxes + - ClassificationOp: + name: cls + param_path: paddlecv://models/vehicle_attribute/inference.pdiparams + model_path: paddlecv://models/vehicle_attribute/inference.pdmodel + batch_size: 8 + PreProcess: + - ResizeImage: + size: [256, 192] + - NormalizeImage: + scale: 0.00392157 + mean: [ 0.485, 0.456, 0.406 ] + std: [ 0.229, 0.224, 0.225 ] + order: '' + channel_num: 3 + - ToCHWImage: + - ExpandDim: + axis: 0 + PostProcess: + - VehicleAttribute: + Inputs: + - bbox_crop.crop_image + - TrackerOutput: + name: vis + Inputs: + - input.fn + - input.image + - tracker.tk_bboxes + - tracker.tk_scores + - tracker.tk_ids + - tracker.tk_cls_ids + - tracker.tk_cls_names + - cls.class_ids + - cls.scores + - cls.label_names diff --git a/paddlecv/configs/system/PP-Vehicle.yml b/paddlecv/configs/system/PP-Vehicle.yml index 76e3dc858351bdb377b325adab53f98935a352b4..74b85705dceb1e0e59e6f24bf8b6dd07099bc596 100644 --- a/paddlecv/configs/system/PP-Vehicle.yml +++ b/paddlecv/configs/system/PP-Vehicle.yml @@ -2,7 +2,6 @@ image_shape: &image_shape 640 ENV: min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_bbox_crop.yml b/paddlecv/configs/unittest/test_bbox_crop.yml index 7757474e2fe20c1008e0cb3884a99dd1f3fbfc19..705a6cf6eab81280aa8f7c49f7cac5671622fc03 100644 --- a/paddlecv/configs/unittest/test_bbox_crop.yml +++ b/paddlecv/configs/unittest/test_bbox_crop.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_classification.yml b/paddlecv/configs/unittest/test_classification.yml index a2e664014a6b59986cae24900b8b0f3e83afc42f..273a49b8a323acef1bbda9f20f8b35533e9855ee 100644 --- a/paddlecv/configs/unittest/test_classification.yml +++ b/paddlecv/configs/unittest/test_classification.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_cls_connector.yml b/paddlecv/configs/unittest/test_cls_connector.yml index 31c8fcd6f731e93be3b740c14b84f2fda2808522..6dec30926d2092c0207a6d0c33753f83caee6b71 100644 --- a/paddlecv/configs/unittest/test_cls_connector.yml +++ b/paddlecv/configs/unittest/test_cls_connector.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_custom_op.yml b/paddlecv/configs/unittest/test_custom_op.yml index d994be53c3537addd8e70d636224c4d4ce1a0529..1bdebd1439c3c0ac35ba273c12954eecf6643bcb 100644 --- a/paddlecv/configs/unittest/test_custom_op.yml +++ b/paddlecv/configs/unittest/test_custom_op.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_detection.yml b/paddlecv/configs/unittest/test_detection.yml index 62227f38b2df3fc1dfabdf8df59d1a345df779f0..a9297920cc939eb8cc43e5cc3c1a6dd1255e7e79 100644 --- a/paddlecv/configs/unittest/test_detection.yml +++ b/paddlecv/configs/unittest/test_detection.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_feature_extraction.yml b/paddlecv/configs/unittest/test_feature_extraction.yml index 8eabca4c57f652e0e46471a50523a0e33fb9d0bf..7de7b984274f60420590d24eaa7f6321deb59d31 100644 --- a/paddlecv/configs/unittest/test_feature_extraction.yml +++ b/paddlecv/configs/unittest/test_feature_extraction.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_fragment_composition.yml b/paddlecv/configs/unittest/test_fragment_composition.yml index 5d4b5aaa13d3af1732d49dde50bf22aacab1ef20..4f5da0cd3995faabee62bb743ce1afeca67631fc 100644 --- a/paddlecv/configs/unittest/test_fragment_composition.yml +++ b/paddlecv/configs/unittest/test_fragment_composition.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_key_frame_extraction.yml b/paddlecv/configs/unittest/test_key_frame_extraction.yml index 6a5e4931d6d97f105fbb2490fa7ea1d6a6585239..3704357de7184de561114613575376ebfea03e75 100644 --- a/paddlecv/configs/unittest/test_key_frame_extraction.yml +++ b/paddlecv/configs/unittest/test_key_frame_extraction.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_keypoint.yml b/paddlecv/configs/unittest/test_keypoint.yml index 96c9d598d384bc55344d155c61465ab8bc5e2b34..bcfef230deaca4159280ec7a43836746a0158b53 100644 --- a/paddlecv/configs/unittest/test_keypoint.yml +++ b/paddlecv/configs/unittest/test_keypoint.yml @@ -6,7 +6,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ocr_crnn_rec.yml b/paddlecv/configs/unittest/test_ocr_crnn_rec.yml index ee16e4cc666cef44e5f3ea31c3b1618748fd39ab..f10ef1c8be78f485bc76b87c43aea754df10f047 100644 --- a/paddlecv/configs/unittest/test_ocr_crnn_rec.yml +++ b/paddlecv/configs/unittest/test_ocr_crnn_rec.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ocr_db_det.yml b/paddlecv/configs/unittest/test_ocr_db_det.yml index b8939cc0ab2e82b0fd303f2fd79632cb4b0e9408..9f57fec940dc65b7d0bff0d629930b1a8395b116 100644 --- a/paddlecv/configs/unittest/test_ocr_db_det.yml +++ b/paddlecv/configs/unittest/test_ocr_db_det.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ocr_layout.yml b/paddlecv/configs/unittest/test_ocr_layout.yml index 12bfb05615cca1a89532ced821ed04797b89402a..89f10480a7eb06a60c9da8d09b9a28e1fceafe63 100644 --- a/paddlecv/configs/unittest/test_ocr_layout.yml +++ b/paddlecv/configs/unittest/test_ocr_layout.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ocr_table_structure.yml b/paddlecv/configs/unittest/test_ocr_table_structure.yml index a1f60ff40b7a341a4feb168f7fcf50e55377f915..972b7b3d2a5e8bdc18b3770d1029e511981d09e3 100644 --- a/paddlecv/configs/unittest/test_ocr_table_structure.yml +++ b/paddlecv/configs/unittest/test_ocr_table_structure.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_pipeline.yml b/paddlecv/configs/unittest/test_pipeline.yml index de77d737a87bc45c1052ecd49210347ad9fd01d1..0f0ee14e56e7316eab28b45fb1dcd5716ed5865c 100644 --- a/paddlecv/configs/unittest/test_pipeline.yml +++ b/paddlecv/configs/unittest/test_pipeline.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_poly_crop.yml b/paddlecv/configs/unittest/test_poly_crop.yml index 059b43e6dbeddd9ffb383c78964b8835d54e3610..b37b1127fc5f89bce06cff46d9379fe47e3a0d77 100644 --- a/paddlecv/configs/unittest/test_poly_crop.yml +++ b/paddlecv/configs/unittest/test_poly_crop.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ppstructure_filter.yml b/paddlecv/configs/unittest/test_ppstructure_filter.yml index e7b1a222ae3a36f9f14d45ed71adfd0a4ff884f2..1aa62f100eed9fe25bbf83ecb61a4a09b8e695d1 100644 --- a/paddlecv/configs/unittest/test_ppstructure_filter.yml +++ b/paddlecv/configs/unittest/test_ppstructure_filter.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_ppstructure_result_concat.yml b/paddlecv/configs/unittest/test_ppstructure_result_concat.yml index e767be6ebdc5459ddfef22f2c158c0f3a1f44001..a0cac46bd97f651744e5b88464a67f00b45164aa 100644 --- a/paddlecv/configs/unittest/test_ppstructure_result_concat.yml +++ b/paddlecv/configs/unittest/test_ppstructure_result_concat.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_seg_pphumansegv2.yml b/paddlecv/configs/unittest/test_seg_pphumansegv2.yml index b03af31c3c186ae8bad036995ac7e2396966b617..07b8b65324c87a8d29851dbc11c7b038119ef745 100644 --- a/paddlecv/configs/unittest/test_seg_pphumansegv2.yml +++ b/paddlecv/configs/unittest/test_seg_pphumansegv2.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_seg_ppmattingv1.yml b/paddlecv/configs/unittest/test_seg_ppmattingv1.yml index 8c869fd0ea8fac476c67a42e198f1be6ecf15ad8..fd0cd78cf3d187c58d55cd48a047d32056f208d7 100644 --- a/paddlecv/configs/unittest/test_seg_ppmattingv1.yml +++ b/paddlecv/configs/unittest/test_seg_ppmattingv1.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_segmentation.yml b/paddlecv/configs/unittest/test_segmentation.yml index 2617a39750c4704badc33b8124ab94777c0b05dc..9a7a4ea4345f8771f03eaee27e34d9d3b2b0fddb 100644 --- a/paddlecv/configs/unittest/test_segmentation.yml +++ b/paddlecv/configs/unittest/test_segmentation.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/configs/unittest/test_table_matcher.yml b/paddlecv/configs/unittest/test_table_matcher.yml index afe4a889235da1e51cce019a50e05c47d0656ef9..ac07f0eaddb6d5e295e6b90d51fff82b3d318be2 100644 --- a/paddlecv/configs/unittest/test_table_matcher.yml +++ b/paddlecv/configs/unittest/test_table_matcher.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/custom_op/test_custom_detection.yml b/paddlecv/custom_op/test_custom_detection.yml index cc689206d2a13992533083a9cddd0c623f72a427..e5159431c45a70e7772febf8297122535b417b4f 100644 --- a/paddlecv/custom_op/test_custom_detection.yml +++ b/paddlecv/custom_op/test_custom_detection.yml @@ -2,7 +2,6 @@ ENV: run_mode: paddle device: GPU min_subgraph_size: 3 - shape_info_filename: ./ trt_calib_mode: False cpu_threads: 1 trt_use_static: False diff --git a/paddlecv/docs/config_anno.md b/paddlecv/docs/config_anno.md index 6df948f679a6cc2af2e25213d955cb39c6d07093..5844ac1ce13092c7c7fead5b1ed1923cdec06ec2 100644 --- a/paddlecv/docs/config_anno.md +++ b/paddlecv/docs/config_anno.md @@ -7,7 +7,6 @@ ``` ENV: min_subgraph_size: 3 # TensorRT最小子图大小 - shape_info_filename: ./ # TensorRT shape收集文件路径 trt_calib_mode: False # 如果设置TensorRT离线量化校准,需要设置为True cpu_threads: 1 # CPU部署时线程数 trt_use_static: False # TensorRT部署是否加载预生成的engine文件 diff --git a/paddlecv/paddlecv.py b/paddlecv/paddlecv.py index 49ba871bcb785e723181da11ca6d85faa542a1ca..7c926b6fa23f3acb6e24eeb800a969730eff3969 100644 --- a/paddlecv/paddlecv.py +++ b/paddlecv/paddlecv.py @@ -44,7 +44,7 @@ class PaddleCV(object): def __init__(self, task_name=None, config_path=None, - output_dir=None, + output_dir='output', run_mode='paddle', device='CPU'): diff --git a/paddlecv/ppcv/model_zoo/MODEL_ZOO b/paddlecv/ppcv/model_zoo/MODEL_ZOO index 04a82d26ad483da825ad0b576885f8a6743c1faa..d7a0f8a5c9771d35850adfc9d2ad3993b76ebb3e 100644 --- a/paddlecv/ppcv/model_zoo/MODEL_ZOO +++ b/paddlecv/ppcv/model_zoo/MODEL_ZOO @@ -1,23 +1,29 @@ -single_op/PP-YOLOv2 -single_op/PP-PicoDet -single_op/PP-LiteSeg -single_op/PP-YOLOE+ -single_op/PP-MattingV1 -single_op/PP-YOLO -single_op/PP-LCNetV2 -single_op/PP-HGNet -single_op/PP-LCNet -single_op/PP-HumanSegV2 -single_op/PP-YOLOE -system/PP-Structure-layout-table -system/PP-Structure-re -system/PP-Structure -system/PP-OCRv2 +system/PP-Vehicle-Attr system/PP-Vehicle +system/PP-OCRv3-TTS system/PP-ShiTuV2 system/PP-Structure-table -system/PP-Human -system/PP-TinyPose -system/PP-ShiTu +system/PP-Structure-layout-table +system/PP-OCRv3-SA +system/PP-OCRv2 system/PP-OCRv3 +system/Face-Detection-Attr +system/PP-ShiTu +system/PP-Structure system/PP-Structure-ser +system/PP-TinyPose +system/PP-Structure-re +system/PP-Human +system/PP-OCRv3-IE +system/PP-Human-Attr +single_op/PP-HumanSegV2 +single_op/PP-LCNet +single_op/PP-YOLOv2 +single_op/PP-LCNetV2 +single_op/PP-YOLOE +single_op/PP-YOLO +single_op/PP-YOLOE+ +single_op/PP-PicoDet +single_op/PP-HGNet +single_op/PP-MattingV1 +single_op/PP-LiteSeg diff --git a/paddlecv/ppcv/model_zoo/model_zoo.py b/paddlecv/ppcv/model_zoo/model_zoo.py index 885014e184a6d28f56e7f9abc30b87ffe9792fcb..6a46e0822343411f0f9baf883e079af4eedb9506 100644 --- a/paddlecv/ppcv/model_zoo/model_zoo.py +++ b/paddlecv/ppcv/model_zoo/model_zoo.py @@ -45,12 +45,18 @@ TASK_DICT = { # system 'PP-OCRv2': 'paddlecv://configs/system/PP-OCRv2.yml', 'PP-OCRv3': 'paddlecv://configs/system/PP-OCRv3.yml', + 'PP-OCRv3-IE': 'paddlecv://configs/system/PP-OCRv3-IE.yml', + 'PP-OCRv3-SA': 'paddlecv://configs/system/PP-OCRv3-SA.yml', + 'PP-OCRv3-TTS': 'paddlecv://configs/system/PP-OCRv3-TTS.yml', 'PP-Structure': 'paddlecv://configs/system/PP-Structure.yml', 'PP-ShiTuV2': 'paddlecv://configs/system/PP-ShiTuV2.yml', 'PP-ShiTu': 'paddlecv://configs/system/PP-ShiTu.yml', 'PP-Human': 'paddlecv://configs/system/PP-Human.yml', + 'PP-Human-Attr': 'paddlecv://configs/system/PP-Human-Attr.yml', 'PP-Vehicle': 'paddlecv://configs/system/PP-Vehicle.yml', + 'PP-Vehicle-Attr': 'paddlecv://configs/system/PP-Vehicle-Attr.yml', 'PP-TinyPose': 'paddlecv://configs/system/PP-TinyPose.yml', + 'Face-Detection-Attr': 'paddlecv://configs/system/Face-Detection-Attr.yml', } diff --git a/paddlecv/ppcv/ops/models/__init__.py b/paddlecv/ppcv/ops/models/__init__.py index 9ae990b711991aab8e3ee445ffd235e1628100a2..6d07cc7a902586d09566e3b2328ea9c16c4917fc 100644 --- a/paddlecv/ppcv/ops/models/__init__.py +++ b/paddlecv/ppcv/ops/models/__init__.py @@ -17,6 +17,8 @@ from . import detection from . import keypoint from . import ocr from . import segmentation +from . import nlp +from . import speech from .classification import * from .feature_extraction import * @@ -24,7 +26,11 @@ from .detection import * from .keypoint import * from .segmentation import * from .ocr import * +from .nlp import * +from .speech import * __all__ = classification.__all__ + detection.__all__ + keypoint.__all__ __all__ += segmentation.__all__ __all__ += ocr.__all__ +__all__ += nlp.__all__ +__all__ += speech.__all__ diff --git a/paddlecv/ppcv/ops/models/base.py b/paddlecv/ppcv/ops/models/base.py index 779f03906ef62653187516bfbb1e78e605effe37..1b33c33ede1901791e554eb99e11ece9ebfc6542 100644 --- a/paddlecv/ppcv/ops/models/base.py +++ b/paddlecv/ppcv/ops/models/base.py @@ -41,7 +41,7 @@ class ModelBaseOp(BaseOp): self.name = model_cfg["name"] self.frame = -1 self.predictor = PaddlePredictor(param_path, model_path, env_cfg, - delete_pass) + delete_pass, self.name) self.input_names = self.predictor.get_input_names() keys = self.get_output_keys() diff --git a/paddlecv/ppcv/ops/models/classification/inference.py b/paddlecv/ppcv/ops/models/classification/inference.py index 863f293c9db6f6ae198022c580b6e3fe556e9592..452125be10d53bdb773f89af9dd8fd8b3f0cd7ec 100644 --- a/paddlecv/ppcv/ops/models/classification/inference.py +++ b/paddlecv/ppcv/ops/models/classification/inference.py @@ -100,10 +100,16 @@ class ClassificationOp(ModelBaseOp): sub_start_idx = curr_offsef_id sub_end_idx = curr_offsef_id + sub_index_list[idx] output = outputs[sub_start_idx:sub_end_idx] - output = {k: [o[k] for o in output] for k in output[0]} - if is_list is not True: - output = {k: output[k][0] for k in output} + if len(output) > 0: + output = {k: [o[k] for o in output] for k in output[0]} + if is_list is not True: + output = {k: output[k][0] for k in output} + else: + output = { + self.output_keys[0]: [], + self.output_keys[1]: [], + self.output_keys[2]: [] + } pipe_outputs.append(output) - curr_offsef_id = sub_end_idx return pipe_outputs diff --git a/paddlecv/ppcv/ops/models/classification/postprocess.py b/paddlecv/ppcv/ops/models/classification/postprocess.py index ecb9e225434759c18811532fc6dc9cb430c8c5ff..924d32784b5867600970180ce4cce0e064746c98 100644 --- a/paddlecv/ppcv/ops/models/classification/postprocess.py +++ b/paddlecv/ppcv/ops/models/classification/postprocess.py @@ -67,3 +67,224 @@ class Topk(object): result[output_keys[2]] = label_name_list y.append(result) return y + + +class VehicleAttribute(object): + def __init__(self, color_threshold=0.5, type_threshold=0.5): + self.color_threshold = color_threshold + self.type_threshold = type_threshold + self.color_list = [ + "yellow", "orange", "green", "gray", "red", "blue", "white", + "golden", "brown", "black" + ] + self.type_list = [ + "sedan", "suv", "van", "hatchback", "mpv", "pickup", "bus", + "truck", "estate" + ] + + def __call__(self, x, output_keys): + # postprocess output of predictor + batch_res = [] + for idx, res in enumerate(x): + res = res.tolist() + label_res = [] + color_idx = np.argmax(res[:10]) + type_idx = np.argmax(res[10:]) + print(color_idx, type_idx) + if res[color_idx] >= self.color_threshold: + color_info = f"Color: ({self.color_list[color_idx]}, prob: {res[color_idx]})" + else: + color_info = "Color unknown" + + if res[type_idx + 10] >= self.type_threshold: + type_info = f"Type: ({self.type_list[type_idx]}, prob: {res[type_idx + 10]})" + else: + type_info = "Type unknown" + + label_res = f"{color_info}, {type_info}" + + threshold_list = [self.color_threshold + ] * 10 + [self.type_threshold] * 9 + pred_res = (np.array(res) > np.array(threshold_list) + ).astype(np.int8).tolist() + scores = np.array(res)[( + np.array(res) > np.array(threshold_list))].tolist() + batch_res.append({ + output_keys[0]: pred_res, + output_keys[1]: scores, + output_keys[2]: label_res + }) + return batch_res + + +class PersonAttribute(object): + def __init__(self, + threshold=0.5, + glasses_threshold=0.3, + hold_threshold=0.6): + self.threshold = threshold + self.glasses_threshold = glasses_threshold + self.hold_threshold = hold_threshold + + def __call__(self, x, output_keys): + # postprocess output of predictor + age_list = ['AgeLess18', 'Age18-60', 'AgeOver60'] + direct_list = ['Front', 'Side', 'Back'] + bag_list = ['HandBag', 'ShoulderBag', 'Backpack'] + upper_list = ['UpperStride', 'UpperLogo', 'UpperPlaid', 'UpperSplice'] + lower_list = [ + 'LowerStripe', 'LowerPattern', 'LongCoat', 'Trousers', 'Shorts', + 'Skirt&Dress' + ] + batch_res = [] + for idx, res in enumerate(x): + res = res.tolist() + label_res = [] + # gender + gender = 'Female' if res[22] > self.threshold else 'Male' + label_res.append(gender) + # age + age = age_list[np.argmax(res[19:22])] + label_res.append(age) + # direction + direction = direct_list[np.argmax(res[23:])] + label_res.append(direction) + # glasses + glasses = 'Glasses: ' + if res[1] > self.glasses_threshold: + glasses += 'True' + else: + glasses += 'False' + label_res.append(glasses) + # hat + hat = 'Hat: ' + if res[0] > self.threshold: + hat += 'True' + else: + hat += 'False' + label_res.append(hat) + # hold obj + hold_obj = 'HoldObjectsInFront: ' + if res[18] > self.hold_threshold: + hold_obj += 'True' + else: + hold_obj += 'False' + label_res.append(hold_obj) + # bag + bag = bag_list[np.argmax(res[15:18])] + bag_score = res[15 + np.argmax(res[15:18])] + bag_label = bag if bag_score > self.threshold else 'No bag' + label_res.append(bag_label) + # upper + upper_res = res[4:8] + upper_label = 'Upper:' + sleeve = 'LongSleeve' if res[3] > res[2] else 'ShortSleeve' + upper_label += ' {}'.format(sleeve) + for i, r in enumerate(upper_res): + if r > self.threshold: + upper_label += ' {}'.format(upper_list[i]) + label_res.append(upper_label) + # lower + lower_res = res[8:14] + lower_label = 'Lower: ' + has_lower = False + for i, l in enumerate(lower_res): + if l > self.threshold: + lower_label += ' {}'.format(lower_list[i]) + has_lower = True + if not has_lower: + lower_label += ' {}'.format(lower_list[np.argmax(lower_res)]) + + label_res.append(lower_label) + # shoe + shoe = 'Boots' if res[14] > self.threshold else 'No boots' + label_res.append(shoe) + + threshold_list = [0.5] * len(res) + threshold_list[1] = self.glasses_threshold + threshold_list[18] = self.hold_threshold + pred_res = (np.array(res) > np.array(threshold_list) + ).astype(np.int8).tolist() + scores = np.array(res)[( + np.array(res) > np.array(threshold_list))].tolist() + batch_res.append({ + output_keys[0]: pred_res, + output_keys[1]: scores, + output_keys[2]: label_res, + }) + return batch_res + + +class VehicleAttribute(object): + def __init__(self, color_threshold=0.5, type_threshold=0.5): + self.color_threshold = color_threshold + self.type_threshold = type_threshold + self.color_list = [ + "yellow", "orange", "green", "gray", "red", "blue", "white", + "golden", "brown", "black" + ] + self.type_list = [ + "sedan", "suv", "van", "hatchback", "mpv", "pickup", "bus", + "truck", "estate" + ] + + def __call__(self, x, output_keys): + # postprocess output of predictor + batch_res = [] + for idx, res in enumerate(x): + res = res.tolist() + label_res = [] + color_idx = np.argmax(res[:10]) + type_idx = np.argmax(res[10:]) + print(color_idx, type_idx) + if res[color_idx] >= self.color_threshold: + color_info = f"Color: ({self.color_list[color_idx]}, prob: {res[color_idx]})" + else: + color_info = "Color unknown" + + if res[type_idx + 10] >= self.type_threshold: + type_info = f"Type: ({self.type_list[type_idx]}, prob: {res[type_idx + 10]})" + else: + type_info = "Type unknown" + + label_res = f"{color_info}, {type_info}" + + threshold_list = [self.color_threshold + ] * 10 + [self.type_threshold] * 9 + pred_res = (np.array(res) > np.array(threshold_list) + ).astype(np.int8).tolist() + scores = np.array(res)[( + np.array(res) > np.array(threshold_list))].tolist() + batch_res.append({ + output_keys[0]: pred_res, + output_keys[1]: scores, + output_keys[2]: label_res + }) + return batch_res + + +class FaceAttribute(object): + def __init__(self, threshold=0.5): + self.threshold = threshold + self.label_list = np.array([ + '短胡子', '弯眉毛', '有吸引力', '眼袋', '秃顶', '刘海', '厚嘴唇', '大鼻子', '黑色头发', + '金色头发', '模糊', '棕色头发', '浓眉毛', '胖的', '双下巴', '眼镜', '山羊胡子', '灰白头发', + '浓妆', '高颧骨', '男性', '嘴巴微张', '胡子,髭', '小眼睛', '没有胡子', '鸭蛋脸', '皮肤苍白', + '尖鼻子', '发际线后移', '连鬓胡子', '红润双颊', '微笑', '直发', '卷发', '戴耳环', '戴帽子', + '涂唇膏', '戴项链', '戴领带', '年轻' + ]) + + def __call__(self, x, output_keys): + # postprocess output of predictor + batch_res = [] + for idx, res in enumerate(x): + pred_idx = res > self.threshold + pred_score = res[pred_idx] + pred_res = self.label_list[pred_idx] + + batch_res.append({ + output_keys[0]: pred_idx.astype(np.int8).tolist(), + output_keys[1]: pred_score.tolist(), + output_keys[2]: pred_res.tolist() + }) + return batch_res diff --git a/paddlecv/ppcv/ops/models/detection/inference.py b/paddlecv/ppcv/ops/models/detection/inference.py index d2e987aec1410d7fca5cb5d7feb28fabbdb31fad..5d875ebc9aaeef360df5f15e9196dfb2801bc19a 100644 --- a/paddlecv/ppcv/ops/models/detection/inference.py +++ b/paddlecv/ppcv/ops/models/detection/inference.py @@ -44,7 +44,9 @@ class DetectionOp(ModelBaseOp): [1., 1.], dtype=np.float32), 'im_shape': np.array( image.shape[:2], dtype=np.float32), - 'input_shape': self.model_cfg["image_shape"], + 'input_shape': self.model_cfg["image_shape"] + if 'image_shape' in self.model_cfg else np.array( + image.shape[:2], dtype=np.float32), } for ops in self.preprocessor: image, im_info = ops(image, im_info) @@ -156,4 +158,4 @@ class DetectionOp(ModelBaseOp): out = {k: v[start_id:end_id] for k, v in output.items()} pipe_outputs.append(out) start_id = end_id - return pipe_outputs \ No newline at end of file + return pipe_outputs diff --git a/paddlecv/ppcv/ops/models/nlp/__init__.py b/paddlecv/ppcv/ops/models/nlp/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e4a61dd4e80d9557c5968cff96095d7cc3d0e5bb --- /dev/null +++ b/paddlecv/ppcv/ops/models/nlp/__init__.py @@ -0,0 +1,17 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .inference import InformationExtractionOp, SentimentAnalysisOp + +__all__ = ['InformationExtractionOp', 'SentimentAnalysisOp'] diff --git a/paddlecv/ppcv/ops/models/nlp/inference.py b/paddlecv/ppcv/ops/models/nlp/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..7ba1f132a9d613288f0c0389eace1a07821cebe9 --- /dev/null +++ b/paddlecv/ppcv/ops/models/nlp/inference.py @@ -0,0 +1,132 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import importlib +from functools import reduce +import os +import numpy as np +import math +import paddle +from paddlenlp import Taskflow +from ..base import ModelBaseOp + +from ppcv.ops.base import create_operators, BaseOp +from ppcv.core.workspace import register + +from .postprocess import * + + +@register +class SentimentAnalysisOp(BaseOp): + def __init__(self, model_cfg, env_cfg): + super(SentimentAnalysisOp, self).__init__(model_cfg, env_cfg) + mod = importlib.import_module(__name__) + env_cfg["batch_size"] = model_cfg.get("batch_size", 1) + self.batch_size = env_cfg["batch_size"] + self.name = model_cfg["name"] + self.frame = -1 + keys = self.get_output_keys() + self.output_keys = [self.name + '.' + key for key in keys] + + self.postprocessor = create_operators(model_cfg["PostProcess"], mod) + self._init_task(model_cfg) + + def _init_task(self, model_cfg): + task = model_cfg.get('task', 'sentiment_analysis') + self.nlp = Taskflow(task) + + @classmethod + def get_output_keys(cls): + return ["label"] + + def postprocess(self, inputs, result): + outputs = result + for idx, ops in enumerate(self.postprocessor): + if idx == len(self.postprocessor) - 1: + outputs = ops(outputs, self.output_keys) + else: + outputs = ops(outputs) + return outputs + + @classmethod + def type(self): + return 'MODEL' + + def infer(self, image_list): + inputs = [] + batch_loop_cnt = math.ceil(float(len(image_list)) / self.batch_size) + results = [] + for i in range(batch_loop_cnt): + start_index = i * self.batch_size + end_index = min((i + 1) * self.batch_size, len(image_list)) + batch_image_list = image_list[start_index:end_index] + # preprocess + # model inference + result = self.nlp(batch_image_list) + # postprocess + result = self.postprocess(inputs, result) + results.extend(result) + # results = self.merge_batch_result(results) + return results + + def __call__(self, inputs): + """ + step1: parser inputs + step2: run + step3: merge results + input: a list of dict + """ + key = self.input_keys[0] + is_list = False + if isinstance(inputs[0][key], (list, tuple)): + inputs = [input[key] for input in inputs] + is_list = True + else: + inputs = [[input[key]] for input in inputs] + sub_index_list = [len(input) for input in inputs] + inputs = reduce(lambda x, y: x.extend(y) or x, inputs) + + # step2: run + outputs = self.infer(inputs) + + # step3: merge + curr_offsef_id = 0 + pipe_outputs = [] + for idx in range(len(sub_index_list)): + sub_start_idx = curr_offsef_id + sub_end_idx = curr_offsef_id + sub_index_list[idx] + output = outputs[sub_start_idx:sub_end_idx] + output = {k: [o[k] for o in output] for k in output[0]} + if is_list is not True: + output = {k: output[k][0] for k in output} + pipe_outputs.append(output) + + curr_offsef_id = sub_end_idx + return pipe_outputs + + +@register +class InformationExtractionOp(SentimentAnalysisOp): + def __init__(self, model_cfg, env_cfg): + super(InformationExtractionOp, self).__init__(model_cfg, env_cfg) + self._init_task(model_cfg) + + def _init_task(self, model_cfg): + task = model_cfg.get('task', 'information_extraction') + schema = model_cfg.get('schema', ['时间', '地点', '人物']) + self.nlp = Taskflow(task, schema=schema) + + @classmethod + def get_output_keys(cls): + return ["text", "type"] diff --git a/paddlecv/ppcv/ops/models/nlp/postprocess.py b/paddlecv/ppcv/ops/models/nlp/postprocess.py new file mode 100644 index 0000000000000000000000000000000000000000..95d8e3543f9408a493a5133590a29be340693fd0 --- /dev/null +++ b/paddlecv/ppcv/ops/models/nlp/postprocess.py @@ -0,0 +1,43 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class InformationExtractionDecode(object): + def __init__(self): + pass + + def __call__(self, preds, output_keys): + results = [] + for batch_idx, pred in enumerate(preds): + type_list = [] + txt_list = [] + for k, v_list in pred.items(): + type_list.append(k) + txt_list.append([v['text'] for v in v_list]) + results.append({ + output_keys[0]: txt_list, + output_keys[1]: type_list + }) + return results + + +class SentimentAnalysisDecode(object): + def __init__(self): + pass + + def __call__(self, preds, output_keys): + results = [] + for batch_idx, pred in enumerate(preds): + results.append({output_keys[0]: pred['label']}) + return results diff --git a/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py b/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py index ee1a7395c2404b1f8e07ec221f00be74eb3818b0..a1a67a4cbd24fd26fbb9fdc6e78dace27ee042db 100644 --- a/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py +++ b/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py @@ -238,8 +238,32 @@ class DBPostProcess(object): "box_type can only be one of ['quad', 'poly']") boxes_batch.append({ - output_keys[0]: boxes, + output_keys[0]: sorted_boxes(boxes), output_keys[1]: scores, }) return boxes_batch[0] + + +def sorted_boxes(dt_boxes): + """ + Sort text boxes in order from top to bottom, left to right + args: + dt_boxes(array):detected text boxes with shape [4, 2] + return: + sorted boxes(array) with shape [4, 2] + """ + num_boxes = dt_boxes.shape[0] + sorted_boxes = sorted(dt_boxes, key=lambda x: (x[0][1], x[0][0])) + _boxes = list(sorted_boxes) + + for i in range(num_boxes - 1): + for j in range(i, 0, -1): + if abs(_boxes[j + 1][0][1] - _boxes[j][0][1]) < 10 and \ + (_boxes[j + 1][0][0] < _boxes[j][0][0]): + tmp = _boxes[j] + _boxes[j] = _boxes[j + 1] + _boxes[j + 1] = tmp + else: + break + return np.array(_boxes) diff --git a/paddlecv/ppcv/ops/models/speech/__init__.py b/paddlecv/ppcv/ops/models/speech/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d2cec57de2bcb64b9646096e1b7f344054f57b2b --- /dev/null +++ b/paddlecv/ppcv/ops/models/speech/__init__.py @@ -0,0 +1,17 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .inference import TTSOp + +__all__ = ['TTSOp'] diff --git a/paddlecv/ppcv/ops/models/speech/inference.py b/paddlecv/ppcv/ops/models/speech/inference.py new file mode 100644 index 0000000000000000000000000000000000000000..fc180822092db7df83b031a99d9a2b4bd318107e --- /dev/null +++ b/paddlecv/ppcv/ops/models/speech/inference.py @@ -0,0 +1,73 @@ +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import importlib +import pathlib +import os +from paddlespeech.cli.tts import TTSExecutor + +from ppcv.ops.base import create_operators, BaseOp +from ppcv.core.workspace import register + + +@register +class TTSOp(BaseOp): + def __init__(self, model_cfg, env_cfg): + super(TTSOp, self).__init__(model_cfg, env_cfg) + mod = importlib.import_module(__name__) + env_cfg["batch_size"] = model_cfg.get("batch_size", 1) + self.batch_size = env_cfg["batch_size"] + self.name = model_cfg["name"] + self.frame = -1 + keys = self.get_output_keys() + self.output_keys = [self.name + '.' + key for key in keys] + + self.tts = TTSExecutor() + self.output_dir = self.env_cfg.get('output_dir', 'output') + + @classmethod + def get_output_keys(cls): + return ["fn"] + + @classmethod + def type(self): + return 'MODEL' + + def infer(self, inputs): + results = [] + for data in inputs: + img_path = data[self.input_keys[0]] + txts = data[self.input_keys[1]] + save_path = os.path.join(self.output_dir, + pathlib.Path(img_path).stem + '.wav') + # model inference + self.tts(text=''.join(txts), + output=save_path, + am='fastspeech2_mix', + voc='hifigan_csmsc', + lang='mix', + spk_id=174) + results.append({self.output_keys[0]: save_path}) + return results + + def __call__(self, inputs): + """ + step1: parser inputs + step2: run + step3: merge results + input: a list of dict + """ + # step2: run + outputs = self.infer(inputs) + return outputs diff --git a/paddlecv/ppcv/ops/output/detection.py b/paddlecv/ppcv/ops/output/detection.py index 8baeefdc9f99c5ae9d5587ce7759b9e0fd1316fd..9b3bb3928df5f1aaca46239d85bb71504d1b892f 100644 --- a/paddlecv/ppcv/ops/output/detection.py +++ b/paddlecv/ppcv/ops/output/detection.py @@ -96,7 +96,8 @@ class DetOutput(OutputBaseOp): def __call__(self, inputs): total_res = [] for res in inputs: - fn, image, dt_bboxes, dt_scores, dt_cls_names = res.values() + fn, image, dt_bboxes, dt_scores, dt_cls_names = list(res.values( + ))[:5] image = draw_det(image, dt_bboxes, dt_scores, dt_cls_names) res.pop('input.image') if self.frame_id != -1: diff --git a/paddlecv/ppcv/ops/output/ocr.py b/paddlecv/ppcv/ops/output/ocr.py index 3f19bee9c4bb2972e82e34cebd8b908f51771365..a3b634a1df40f6fa8d37407b28208c0f8b71eb2c 100644 --- a/paddlecv/ppcv/ops/output/ocr.py +++ b/paddlecv/ppcv/ops/output/ocr.py @@ -83,27 +83,27 @@ class OCROutput(OutputBaseOp): def __init__(self, model_cfg, env_cfg): super(OCROutput, self).__init__(model_cfg, env_cfg) font_path = model_cfg.get('font_path', None) - self.font_path = get_font_path(font_path) + if font_path is not None: + self.font_path = get_font_path(font_path) + else: + self.font_path = None def __call__(self, inputs): total_res = [] for input in inputs: fn, image, dt_polys = list(input.values())[:3] - rec_text = input.get('rec.rec_text', None) - rec_score = input.get('rec.rec_score', None) - res = dict( - filename=fn, - dt_polys=dt_polys.tolist(), - rec_text=rec_text, - rec_score=rec_score) + input.pop('input.image') + input['det.dt_polys'] = input['det.dt_polys'].tolist() + res = input if self.frame_id != -1: res.update({'frame_id': frame_id}) logger.info(res) if self.save_img: image = image[:, :, ::-1] - if rec_text is not None: + if 'rec.rec_text' in input: image = self.draw_ocr_box_txt( - Image.fromarray(image), dt_polys, rec_text, rec_score) + Image.fromarray(image), input['det.dt_polys'], + input['rec.rec_text'], input['rec.rec_score']) else: image = draw_boxes(image, dt_polys.reshape([-1, 8])) file_name = os.path.split(fn)[-1] @@ -132,7 +132,7 @@ class OCROutput(OutputBaseOp): img_left = image.copy() img_right = np.ones((h, w, 3), dtype=np.uint8) * 255 random.seed(0) - + boxes = np.array(boxes) draw_left = ImageDraw.Draw(img_left) if txts is None or len(txts) != len(boxes): txts = [None] * len(boxes) diff --git a/paddlecv/ppcv/ops/output/tracker.py b/paddlecv/ppcv/ops/output/tracker.py index 20334eb56d9a23cf9f9364fd0ae9156eb2666f73..0df393bc437d7098472b6cb7eebcfd7a5c2d1fc1 100644 --- a/paddlecv/ppcv/ops/output/tracker.py +++ b/paddlecv/ppcv/ops/output/tracker.py @@ -72,8 +72,8 @@ class TrackerOutput(OutputBaseOp): total_res = [] vis_images = [] for res in inputs: - fn, image, tk_bboxes, tk_scores, tk_ids, tk_cls_ids, tk_cls_names = res.values( - ) + fn, image, tk_bboxes, tk_scores, tk_ids, tk_cls_ids, tk_cls_names = list( + res.values())[:7] tk_names = [ '{} {}'.format(tk_cls_name, tk_id) for tk_id, tk_cls_name in zip(tk_ids, tk_cls_names) diff --git a/paddlecv/ppcv/ops/predictor.py b/paddlecv/ppcv/ops/predictor.py index 5cb61a06445ecdb4e8456755a78cf7d67cbaabbd..5b9a7d747387a84af8fe38a9467e5bce923e7276 100644 --- a/paddlecv/ppcv/ops/predictor.py +++ b/paddlecv/ppcv/ops/predictor.py @@ -21,16 +21,26 @@ from paddle.inference import create_predictor class PaddlePredictor(object): - def __init__(self, param_path, model_path, config, delete_pass=[]): + def __init__(self, + param_path, + model_path, + config, + delete_pass=[], + name='model'): super().__init__() + run_mode = config.get("run_mode", "paddle") # used trt or mkldnn + shape_info_filename = os.path.join( + config.get("output_dir", "output"), + '{}_{}_shape_info.txt'.format(name, run_mode)) + self.predictor, self.inference_config, self.input_names, self.input_tensors, self.output_tensors = self.create_paddle_predictor( param_path, model_path, batch_size=config['batch_size'], - run_mode=config.get("run_mode", "paddle"), # used trt or mkldnn + run_mode=run_mode, device=config.get("device", "CPU"), min_subgraph_size=config["min_subgraph_size"], - shape_info_filename=config["shape_info_filename"], + shape_info_filename=shape_info_filename, trt_calib_mode=config["trt_calib_mode"], cpu_threads=config["cpu_threads"], trt_use_static=config["trt_use_static"], @@ -53,9 +63,12 @@ class PaddlePredictor(object): f"inference model: {model_path} or param: {param_path} does not exist, please check again..." ) assert run_mode in [ - "paddle", "trt_fp32", "trt_fp16", "trt_int8", "mkldnn", - "mkldnn_bf16" - ], "The run_mode must be 'paddle', 'trt_fp32', 'trt_fp16', 'trt_int8', 'mkldnn', 'mkldnn_bf16', but received run_mode: {}".format( + "paddle", + "trt_fp32", + "trt_fp16", + "trt_int8", + "mkldnn", + ], "The run_mode must be 'paddle', 'trt_fp32', 'trt_fp16', 'trt_int8', 'mkldnn', but received run_mode: {}".format( run_mode) config = Config(model_path, param_path) if device == 'GPU': @@ -66,8 +79,6 @@ class PaddlePredictor(object): try: config.enable_mkldnn() config.set_cpu_math_library_num_threads(cpu_threads) - if 'bf16' in run_mode: - config.enable_mkldnn_bfloat16() except Exception as e: print( "The current environment does not support `mkldnn`, so disable mkldnn." @@ -85,7 +96,7 @@ class PaddlePredictor(object): max_batch_size=batch_size, min_subgraph_size=min_subgraph_size, precision_mode=precision_map[run_mode], - trt_use_static=trt_use_static, + use_static=trt_use_static, use_calib_mode=trt_calib_mode) if shape_info_filename is not None: diff --git a/paddlecv/requirements.txt b/paddlecv/requirements.txt index a8c8fcd9379815a432c462acc151c633bb67e995..cbae902034efec4b9b29da837c2ae0973f91fc51 100644 --- a/paddlecv/requirements.txt +++ b/paddlecv/requirements.txt @@ -4,3 +4,5 @@ opencv-contrib-python PyYAML>=5.1 Pillow faiss-cpu==1.7.1.post2 +paddlenlp +paddlespeech