Skip to content

Commit bc79c0d

Browse files
authored
[Enhancement] Load openvino model from memory (#2027)
* fix cpu docker (different openvino ver for python & sdk) * load openvino model from memory * fix lint
1 parent ca773a7 commit bc79c0d

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

csrc/mmdeploy/net/openvino/openvino_net.cpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,18 @@ Result<void> OpenVINONet::Init(const Value& args) {
7777
auto model = context["model"].get<Model>();
7878
OUTCOME_TRY(auto config, model.GetModelConfig(name));
7979

80-
// TODO: read network with stream
81-
// save xml and bin to temp file
82-
auto tmp_dir = fs::temp_directory_path();
83-
std::string tmp_xml = (tmp_dir / fs::path("tmp.xml")).string();
84-
std::string tmp_bin = (tmp_dir / fs::path("tmp.bin")).string();
8580
OUTCOME_TRY(auto raw_xml, model.ReadFile(config.net));
8681
OUTCOME_TRY(auto raw_bin, model.ReadFile(config.weights));
87-
88-
try {
89-
std::ofstream xml_out(tmp_xml, std::ios::binary);
90-
xml_out << raw_xml;
91-
xml_out.close();
92-
std::ofstream bin_out(tmp_bin, std::ios::binary);
93-
bin_out << raw_bin;
94-
bin_out.close();
95-
} catch (const std::exception& e) {
96-
MMDEPLOY_ERROR("unhandled exception when creating tmp xml/bin: {}", e.what());
97-
return Status(eFail);
98-
}
82+
auto ov_tensor = InferenceEngine::TensorDesc(InferenceEngine::Precision::U8, {raw_bin.size()},
83+
InferenceEngine::Layout::C);
84+
auto ov_blob = InferenceEngine::make_shared_blob<uint8_t>(ov_tensor);
85+
ov_blob->allocate();
86+
memcpy(ov_blob->buffer(), raw_bin.data(), ov_blob->byteSize());
9987

10088
try {
10189
// create cnnnetwork
10290
core_ = InferenceEngine::Core();
103-
network_ = core_.ReadNetwork(tmp_xml, tmp_bin);
91+
network_ = core_.ReadNetwork(raw_xml, std::move(ov_blob));
10492

10593
// set input tensor
10694
InferenceEngine::InputsDataMap input_info = network_.getInputsInfo();

docker/CPU/Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM openvino/ubuntu18_dev:2021.4.2
1+
FROM openvino/ubuntu20_dev:2022.3.0
22
ARG PYTHON_VERSION=3.8
33
ARG TORCH_VERSION=1.10.0
44
ARG TORCHVISION_VERSION=0.11.0
@@ -57,7 +57,7 @@ RUN if [ ${USE_SRC_INSIDE} == true ] ; \
5757
RUN /opt/conda/bin/pip install torch==${TORCH_VERSION}+cpu torchvision==${TORCHVISION_VERSION}+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html \
5858
&& /opt/conda/bin/pip install --no-cache-dir openmim
5959

60-
RUN /opt/conda/bin/mim install --no-cache-dir "mmcv"${MMCV_VERSION} onnxruntime==${ONNXRUNTIME_VERSION} openvino-dev mmengine${MMENGINE_VERSION}
60+
RUN /opt/conda/bin/mim install --no-cache-dir "mmcv"${MMCV_VERSION} onnxruntime==${ONNXRUNTIME_VERSION} openvino-dev==2022.3.0 mmengine${MMENGINE_VERSION}
6161

6262
ENV PATH /opt/conda/bin:$PATH
6363
WORKDIR /root/workspace
@@ -100,14 +100,14 @@ RUN git clone -b main https://github.com/open-mmlab/mmdeploy.git &&\
100100
/opt/conda/bin/mim install -e .
101101

102102
### build SDK
103-
ENV LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:/opt/intel/openvino/deployment_tools/ngraph/lib:/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64:${LD_LIBRARY_PATH}"
103+
ENV LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${LD_LIBRARY_PATH}"
104104
RUN cd mmdeploy && rm -rf build/CM* && mkdir -p build && cd build && cmake .. \
105105
-DMMDEPLOY_BUILD_SDK=ON \
106106
-DMMDEPLOY_BUILD_EXAMPLES=ON \
107-
-DCMAKE_CXX_COMPILER=g++-7 \
107+
-DCMAKE_CXX_COMPILER=g++-9 \
108108
-DONNXRUNTIME_DIR=${ONNXRUNTIME_DIR} \
109109
-Dncnn_DIR=/root/workspace/ncnn/build/install/lib/cmake/ncnn \
110-
-DInferenceEngine_DIR=/opt/intel/openvino/deployment_tools/inference_engine/share \
110+
-DInferenceEngine_DIR=/opt/intel/openvino/runtime/cmake \
111111
-DMMDEPLOY_TARGET_DEVICES=cpu \
112112
-DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
113113
-DMMDEPLOY_TARGET_BACKENDS="ort;ncnn;openvino" \

0 commit comments

Comments
 (0)