-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infer num threads in openvino and paddle version.
- Loading branch information
Showing
4 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# @Contact: [email protected] | ||
import argparse | ||
import math | ||
import os | ||
import random | ||
from io import BytesIO | ||
from pathlib import Path | ||
|
@@ -20,11 +21,17 @@ | |
|
||
class OpenVINOInferSession: | ||
def __init__(self, config): | ||
ie = Core() | ||
core = Core() | ||
|
||
self._verify_model(config["model_path"]) | ||
model_onnx = ie.read_model(config["model_path"]) | ||
compile_model = ie.compile_model(model=model_onnx, device_name="CPU") | ||
model_onnx = core.read_model(config["model_path"]) | ||
|
||
cpu_nums = os.cpu_count() | ||
infer_num_threads = config.get("inference_num_threads", -1) | ||
if infer_num_threads != -1 and 1 <= infer_num_threads <= cpu_nums: | ||
core.set_property("CPU", {"INFERENCE_NUM_THREADS": str(infer_num_threads)}) | ||
|
||
compile_model = core.compile_model(model=model_onnx, device_name="CPU") | ||
self.session = compile_model.create_infer_request() | ||
|
||
def __call__(self, input_content: np.ndarray) -> np.ndarray: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters