Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6403 Discussions

Problems using OpenVino network inside python class

Nikolaev__Viktor
Beginner
512 Views

I write simple code for objects detection . But my application crashes when I try to run this code 

from  openvino.inference_engine import IENetwork, IEPlugin
import numpy as np
import os

class OpenVinoDetector():
    def __init__(self, model_path):
        # read the model
        self.plugin = IEPlugin(device="CPU", plugin_dirs=None)
        self.plugin.add_cpu_extension('cpu_extension.dll')
        net = IENetwork.from_ir(model=model_path, \
                                weights=os.path.splitext(model_path)[0] + ".bin")
        self.network = self.plugin.load(network=net, num_requests=2)
        # input and output
        self.input_blob = next(iter(net.inputs))
        self.out_blob = next(iter(net.outputs))

    def detect(self, frame):
        cur_request_id = 0
        self.network.start_async(request_id=cur_request_id, inputs={self.input_blob: frame})
        if self.network.requests[cur_request_id].wait(-1) == 0:
            res = self.network.requests[cur_request_id].outputs[self.out_blob]
        conf = res[0,0,:,2]
        rects = res[0, 0, :, 3:7]
        return conf, rects
    
detector = OpenVinoDetector(r'C:\Intel\computer_vision_sdk_2018.4.420\deployment_tools\model_optimizer\frozen_inference_graph.xml')
for i in range(0,10):
    frame = np.zeros((1, 3, 240, 320))
    conf,rects = detector.detect(frame)

I think problem in inference_engine library

void InferenceEnginePython::InferRequestWrap::infer_async() {
    InferenceEngine::ResponseDesc response;
    IE_CHECK_CALL(request_ptr->StartAsync(&response));
}

Because request_ptr is wrong.

 

If I move plugin initialization from class then application works.

0 Kudos
3 Replies
Nikolaev__Viktor
Beginner
512 Views

Solved, It was problem with removing variables

del self.network
del self.plugin

0 Kudos
谢__海蓉
Beginner
512 Views

Hello, Viktor

I want to know how I can import openvino in a python API, such as vsCode.

I can import openvino in command prompt, but it's not in Visual Studio Code.

thank you!

0 Kudos
Shubha_R_Intel
Employee
512 Views

Dear Victor and 谢, 海蓉:

You should find the below document quite useful, 

https://docs.openvinotoolkit.org/latest/_inference_engine_ie_bridges_python_docs_api_overview.html

Thanks for using OpenVino !

Shubha

0 Kudos
Reply