diff --git a/ppocr/modeling/transforms/tps.py b/ppocr/modeling/transforms/tps.py index 78338edf67d69e32322912d75dec01ce1e63cb49..dcce6246ac64b4b84229cbd69a4dc53c658b4c7b 100644 --- a/ppocr/modeling/transforms/tps.py +++ b/ppocr/modeling/transforms/tps.py @@ -230,15 +230,8 @@ class GridGenerator(nn.Layer): def build_inv_delta_C_paddle(self, C): """ Return inv_delta_C which is needed to calculate T """ F = self.F - hat_C = paddle.zeros((F, F), dtype='float64') # F x F - for i in range(0, F): - for j in range(i, F): - if i == j: - hat_C[i, j] = 1 - else: - r = paddle.norm(C[i] - C[j]) - hat_C[i, j] = r - hat_C[j, i] = r + hat_eye = paddle.eye(F, dtype='float64') # F x F + hat_C = paddle.norm(C.reshape([1, F, 2]) - C.reshape([F, 1, 2]), axis=2) + hat_eye hat_C = (hat_C**2) * paddle.log(hat_C) delta_C = paddle.concat( # F+3 x F+3 [ diff --git a/tools/infer/predict_det.py b/tools/infer/predict_det.py index 1b52e717ca1edbbd9ede31260e47ec8973270d3f..b284654c23b04f9c959ca8b55d8b91ccf0236e05 100755 --- a/tools/infer/predict_det.py +++ b/tools/infer/predict_det.py @@ -237,3 +237,4 @@ if __name__ == "__main__": "det_res_{}".format(img_name_pure)) cv2.imwrite(img_path, src_im) logger.info("The visualized image saved in {}".format(img_path)) + diff --git a/tools/infer/utility.py b/tools/infer/utility.py index 5f4249eed67ea9c3e797193dd1ae6d5125f848e9..c17c5d2d59048f698b65da6994e2accc14716b12 100755 --- a/tools/infer/utility.py +++ b/tools/infer/utility.py @@ -37,6 +37,7 @@ def init_args(): parser.add_argument("--use_gpu", type=str2bool, default=True) parser.add_argument("--ir_optim", type=str2bool, default=True) parser.add_argument("--use_tensorrt", type=str2bool, default=False) + parser.add_argument("--min_subgraph_size", type=int, default=3) parser.add_argument("--precision", type=str, default="fp32") parser.add_argument("--gpu_mem", type=int, default=500) @@ -165,12 +166,14 @@ def create_predictor(args, mode, logger): config.enable_tensorrt_engine( precision_mode=inference.PrecisionType.Float32, max_batch_size=args.max_batch_size, - min_subgraph_size=3) # skip the minmum trt subgraph - if mode == "det" and "mobile" in model_file_path: + min_subgraph_size=args.min_subgraph_size) + # skip the minmum trt subgraph + if mode == "det": min_input_shape = { "x": [1, 3, 50, 50], "conv2d_92.tmp_0": [1, 96, 20, 20], "conv2d_91.tmp_0": [1, 96, 10, 10], + "conv2d_59.tmp_0": [1, 96, 20, 20], "nearest_interp_v2_1.tmp_0": [1, 96, 10, 10], "nearest_interp_v2_2.tmp_0": [1, 96, 20, 20], "nearest_interp_v2_3.tmp_0": [1, 24, 20, 20], @@ -183,6 +186,7 @@ def create_predictor(args, mode, logger): "x": [1, 3, 2000, 2000], "conv2d_92.tmp_0": [1, 96, 400, 400], "conv2d_91.tmp_0": [1, 96, 200, 200], + "conv2d_59.tmp_0": [1, 96, 400, 400], "nearest_interp_v2_1.tmp_0": [1, 96, 200, 200], "nearest_interp_v2_2.tmp_0": [1, 96, 400, 400], "nearest_interp_v2_3.tmp_0": [1, 24, 400, 400], @@ -195,6 +199,7 @@ def create_predictor(args, mode, logger): "x": [1, 3, 640, 640], "conv2d_92.tmp_0": [1, 96, 160, 160], "conv2d_91.tmp_0": [1, 96, 80, 80], + "conv2d_59.tmp_0": [1, 96, 160, 160], "nearest_interp_v2_1.tmp_0": [1, 96, 80, 80], "nearest_interp_v2_2.tmp_0": [1, 96, 160, 160], "nearest_interp_v2_3.tmp_0": [1, 24, 160, 160], @@ -203,31 +208,6 @@ def create_predictor(args, mode, logger): "elementwise_add_7": [1, 56, 40, 40], "nearest_interp_v2_0.tmp_0": [1, 96, 40, 40] } - if mode == "det" and "server" in model_file_path: - min_input_shape = { - "x": [1, 3, 50, 50], - "conv2d_59.tmp_0": [1, 96, 20, 20], - "nearest_interp_v2_2.tmp_0": [1, 96, 20, 20], - "nearest_interp_v2_3.tmp_0": [1, 24, 20, 20], - "nearest_interp_v2_4.tmp_0": [1, 24, 20, 20], - "nearest_interp_v2_5.tmp_0": [1, 24, 20, 20] - } - max_input_shape = { - "x": [1, 3, 2000, 2000], - "conv2d_59.tmp_0": [1, 96, 400, 400], - "nearest_interp_v2_2.tmp_0": [1, 96, 400, 400], - "nearest_interp_v2_3.tmp_0": [1, 24, 400, 400], - "nearest_interp_v2_4.tmp_0": [1, 24, 400, 400], - "nearest_interp_v2_5.tmp_0": [1, 24, 400, 400] - } - opt_input_shape = { - "x": [1, 3, 640, 640], - "conv2d_59.tmp_0": [1, 96, 160, 160], - "nearest_interp_v2_2.tmp_0": [1, 96, 160, 160], - "nearest_interp_v2_3.tmp_0": [1, 24, 160, 160], - "nearest_interp_v2_4.tmp_0": [1, 24, 160, 160], - "nearest_interp_v2_5.tmp_0": [1, 24, 160, 160] - } elif mode == "rec": min_input_shape = {"x": [args.rec_batch_num, 3, 32, 10]} max_input_shape = {"x": [args.rec_batch_num, 3, 32, 2000]}