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

Getting the person-detection-retail-0001 model to work with a python driver program

Astha_S_Intel
Employee
373 Views
Hi,
 
I am currently trying to create a python program as the execution file for the person-detection-retail-0001 model. I need to add a custom detection layer and I have not been able to find a DataPtr (C++) equivalent offered by the Python API.
 
I am trying to convert the following C++ code to Python.  
 
        DataPtr bbox_pred_reshapeInPort = ((ICNNNetwork&)network).getData(FLAGS_bbox_name.c_str());
 
        SizeVector bbox_pred_reshapeOutDims = {
            bbox_pred_reshapeInPort->getTensorDesc().getDims()[0] *
            bbox_pred_reshapeInPort->getTensorDesc().getDims()[1], 1
        };
 
Would be great if you could provide guidance in converting the following commands - 
1. (ICNNNetwork&)network).getData(FLAGS_bbox_name.c_str()
2. getTensorDesc().getDims()
 
Regards,
Astha
0 Kudos
3 Replies
Mark_L_Intel1
Moderator
373 Views

Hi Astha,

I am trying to understand your question, are you adding a customer layer to the person-detection-retail-0001 model?

I am looking at the document about adding customer layer but I can't find the code you referred.

https://software.intel.com/en-us/articles/OpenVINO-ModelOptimizer#Custom-Layers

If you are asking to port the C++ code to python in general, I think there is a standard way.

Mark

0 Kudos
Astha_S_Intel
Employee
373 Views

Hi Mark,

I am referring to the object_detection_sample present at "<Path to OpenVINO>\deployment_tools\inference_engine\samples\object_detection_sample", the "Adding DetectionOutput" section in the main.cpp. I want to convert the C++ code for object_detection_sample to Python. When I explored the Python API documentation, I could not get equivalent functions in Python API for the code mentioned earlier. 

(ICNNNetwork&)network).getData(FLAGS_bbox_name.c_str() gets me the network information for the '<FLAGS_bbox_name>' layer in the person-detection-retail-0001.xml file. 

The input and output functions of the IENetwork class in the Python API give something similar to what I need but not quite - 

input_blob = next(iter(net.inputs)) for a net object of IENetwork class in the Python API would give all the input layer names along with the network dimensions for each input layer from the xml file. But how do I get the dimensions for a layer that is not an input or output layer from the xml file using the Python API for OpenVINO. 

I can always read the xml file using Python but I wanted to check if there is a provision for doing so using the Python API for OpenVINO just like in the C++ API.

Regards,

Astha

 

 

 

0 Kudos
Mikhail_T_Intel
Employee
373 Views

Hi Astha,

To get data and dimensions of intermediate layers you should add it to outputs by calling add_outputs() method of IENetwork. Similar things are done in C++ code. 

Then you can get the output data of each output layer referring to `outputs` attribute of infer request even before inference was started. The output data represented as numpy ndarray so you can get dimensions from `shape` attribute . Finally the code  looks like this (I've skipped network reading, plugin initialization and all other things nor related to the problem)

layer_name = "some_layer_name"
net.add_outputs(layer_name)
exec_net = plugin.load(net)
layer_data = exec_net.requests[0].outputs[layer name]
data_shape = layer_data.shape

 

0 Kudos
Reply