Skip to content

Commit 16d70fb

Browse files
committed
add cpu_math_library_num_threads params
1 parent 5d24736 commit 16d70fb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tools/infer/utility.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
from PIL import Image, ImageDraw, ImageFont
2222
import math
2323
from paddle import inference
24+
import time
25+
from ppocr.utils.logging import get_logger
26+
logger = get_logger()
2427

2528

2629
def parse_args():
@@ -98,6 +101,7 @@ def str2bool(v):
98101
parser.add_argument("--cls_thresh", type=float, default=0.9)
99102

100103
parser.add_argument("--enable_mkldnn", type=str2bool, default=False)
104+
parser.add_argument("--cpu_threads", type=int, default=10)
101105
parser.add_argument("--use_pdserving", type=str2bool, default=False)
102106

103107
parser.add_argument("--use_mp", type=str2bool, default=False)
@@ -140,14 +144,15 @@ def create_predictor(args, mode, logger):
140144
max_batch_size=args.max_batch_size)
141145
else:
142146
config.disable_gpu()
143-
config.set_cpu_math_library_num_threads(6)
147+
if hasattr(args, "cpu_threads"):
148+
config.set_cpu_math_library_num_threads(args.cpu_threads)
149+
else:
150+
config.set_cpu_math_library_num_threads(
151+
10) # default cpu threads as 10
144152
if args.enable_mkldnn:
145153
# cache 10 different shapes for mkldnn to avoid memory leak
146154
config.set_mkldnn_cache_capacity(10)
147155
config.enable_mkldnn()
148-
# TODO LDOUBLEV: fix mkldnn bug when bach_size > 1
149-
#config.set_mkldnn_op({'conv2d', 'depthwise_conv2d', 'pool2d', 'batch_norm'})
150-
args.rec_batch_num = 1
151156

152157
# enable memory optim
153158
config.enable_memory_optim()

0 commit comments

Comments
 (0)