From 126c1a222afbcba4ded86ebc0bb657e7bf28a8d3 Mon Sep 17 00:00:00 2001 From: HinGwenWoong Date: Thu, 2 Feb 2023 09:57:52 +0800 Subject: [PATCH] [Improve Serving] Add OCR det bbox in output buffer which is very important for application (#1214) * Add ocr det bbox output * Add ocr det bbox output * Add ocr det bbox output * Add ocr det bbox output * Add ocr det bbox * Add ocr det bbox * Add ocr det bbox * Add ocr det bbox output --- examples/vision/ocr/PP-OCRv3/serving/client.py | 4 +++- .../PP-OCRv3/serving/models/det_postprocess/1/model.py | 8 +++++++- .../PP-OCRv3/serving/models/det_postprocess/config.pbtxt | 5 +++++ .../ocr/PP-OCRv3/serving/models/pp_ocr/config.pbtxt | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/vision/ocr/PP-OCRv3/serving/client.py b/examples/vision/ocr/PP-OCRv3/serving/client.py index 1b150b7d0..6b758c5e3 100755 --- a/examples/vision/ocr/PP-OCRv3/serving/client.py +++ b/examples/vision/ocr/PP-OCRv3/serving/client.py @@ -99,9 +99,11 @@ if __name__ == "__main__": result = runner.Run([im, ]) batch_texts = result['rec_texts'] batch_scores = result['rec_scores'] + batch_bboxes = result['det_bboxes'] for i_batch in range(len(batch_texts)): texts = batch_texts[i_batch] scores = batch_scores[i_batch] + bboxes = batch_bboxes[i_batch] for i_box in range(len(texts)): print('text=', texts[i_box].decode('utf-8'), ' score=', - scores[i_box]) + scores[i_box], ' bbox=', bboxes[i_box]) diff --git a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py index 9cfe2583e..a2b581e95 100644 --- a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py +++ b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/1/model.py @@ -142,6 +142,7 @@ class TritonPythonModel: results = self.postprocessor.run([infer_outputs], im_infos) batch_rec_texts = [] batch_rec_scores = [] + batch_box_list = [] for i_batch in range(len(results)): cls_labels = [] @@ -158,6 +159,9 @@ class TritonPythonModel: crop_img = get_rotate_crop_image(ori_imgs[i_batch], box) image_list.append(crop_img) + + batch_box_list.append(box_list) + cls_pre_tensors = self.cls_preprocessor.run(image_list) cls_dlpack_tensor = cls_pre_tensors[0].to_dlpack() cls_input_tensor = pb_utils.Tensor.from_dlpack( @@ -220,8 +224,10 @@ class TritonPythonModel: batch_rec_texts, dtype=np.object_)) out_tensor_1 = pb_utils.Tensor(self.output_names[1], np.array(batch_rec_scores)) + out_tensor_2 = pb_utils.Tensor(self.output_names[2], + np.array(batch_box_list)) inference_response = pb_utils.InferenceResponse( - output_tensors=[out_tensor_0, out_tensor_1]) + output_tensors=[out_tensor_0, out_tensor_1, out_tensor_2]) responses.append(inference_response) return responses diff --git a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/config.pbtxt b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/config.pbtxt index 1195fbc22..378b7bab6 100644 --- a/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/config.pbtxt +++ b/examples/vision/ocr/PP-OCRv3/serving/models/det_postprocess/config.pbtxt @@ -29,6 +29,11 @@ output [ name: "POST_OUTPUT_1" data_type: TYPE_FP32 dims: [ -1, 1 ] + }, + { + name: "POST_OUTPUT_2" + data_type: TYPE_FP32 + dims: [ -1, -1, 1 ] } ] diff --git a/examples/vision/ocr/PP-OCRv3/serving/models/pp_ocr/config.pbtxt b/examples/vision/ocr/PP-OCRv3/serving/models/pp_ocr/config.pbtxt index 688445e4f..5ef951107 100644 --- a/examples/vision/ocr/PP-OCRv3/serving/models/pp_ocr/config.pbtxt +++ b/examples/vision/ocr/PP-OCRv3/serving/models/pp_ocr/config.pbtxt @@ -18,6 +18,11 @@ output [ name: "rec_scores" data_type: TYPE_FP32 dims: [ -1, 1 ] + }, + { + name: "det_bboxes" + data_type: TYPE_FP32 + dims: [ -1, -1, 1 ] } ] ensemble_scheduling { @@ -73,6 +78,10 @@ ensemble_scheduling { key: "POST_OUTPUT_1" value: "rec_scores" } + output_map { + key: "POST_OUTPUT_2" + value: "det_bboxes" + } } ] }