This section provides a high-level description of the process of integrating the Inference Engine into your application. Refer to the Hello Infer Request Classification Sample sources for example of using the Inference Engine in applications.
libinference_engine.so library implements loading and parsing a model Intermediate Representation (IR), and triggers inference using a specified plugin. The core library has the following API:
C++ Inference Engine API wraps the capabilities of core library:
Integration process includes the following steps:
1) Load a plugin by creating an instance of
InferenceEngine::InferenceEnginePluginPtr. Wrap it by creating instance of
InferenceEngine::InferencePlugin from C++ Inference Egine API. Specify the plugin or let the Inference Engine to choose it using
2) Create an IR reader by creating an instance of
InferenceEngine::CNNNetReader and read a model IR created by Model Optimizer:
3) Configure input and output. Request input and output information using
Optionally, set the number format (precision) and memory layout for inputs and outputs. Refer to the Supported configurations chapter to choose the relevant configuration.
You can also allow input of any size. To do this, mark each input as resizable by setting a desired resize algorithm (e.g.
BILINEAR) inside of the appropriate input info.
If you skip this step, the default values are set:
|Number of dimensions||5||4||3||2||1|
4) Load the model to the plugin using
It creates an executable network from a network object. The executable network is associated with single hardware device. It is possible to create as many networks as needed and to use them simultaneously (up to the limitation of the hardware resources). Second parameter is a configuration for plugin. It is map of pairs: (parameter name, parameter value). Choose device from Supported devices page for more details about supported configuration parameters.
5) Create an infer request:
6) Prepare input. You can use one of the following options to prepare input:
InferenceEngine::InferRequest::GetBlob()and feed an image and the input data to the blobs. In this case, input data must be aligned (resized manually) with a given blob size.
InferenceEngine::InferRequest::GetBlob()and set it as input for the second request using
InferenceEngine::make_shared_blob()with passing of
InferenceEngine::InferRequest::SetBlob()to set these blobs for an infer request:
SetBlob()method compares precision and layout of an input blob with ones defined on step 3 and throws an exception if they do not match. It also compares a size of the input blob with input size of the read network. But if input was configured as resizable, you can set an input blob of any size (for example, any ROI blob). Input resize will be invoked automatically using resize algorithm configured on step 3.
GetBlob()logic is the same for resizable and not-resizable input. Even if it is called with input configured as resizable, a blob allocated by an infer request is returned. Its size is already consistent to input size of a read network. No resize will happen for this blob. If you call
SetBlob(), you will get the blob you set in
or by calling the
InferenceEngine::InferRequest::Infer method for synchronous request:
StartAsync returns immediately and starts inference without blocking main thread,
Infer blocks main thread and returns when inference is completed. Call
Wait for waiting result to become available for asynchronous request.
There are three ways to use it:
InferenceEngine::IInferRequest::WaitMode::RESULT_READY- waits until inference result becomes available
InferenceEngine::IInferRequest::WaitMode::STATUS_ONLY- immediately returns request status.It does not block or interrupts current thread.
Both requests are thread-safe: can be called from different threads without fearing corruption and failures.
Multiple requests for single
ExecutableNetwork are executed sequentially one by one in FIFO order.
While request is ongoing, all its methods except
InferenceEngine::InferRequest::Wait would throw an exception.
8) Go over the output blobs and process the results. Note that casting
std::dynamic_pointer_cast is not recommended way, better to access data via
as() methods as follows:
For details about building your application, refer to the CMake files for the sample applications. All samples reside in the samples directory in the Inference Engine installation directory.
Before running compiled binary files, make sure your application can find the Inference Engine libraries. On Linux* operating systems, including Ubuntu* and CentOS*, the
LD_LIBRARY_PATH environment variable is usually used to specify directories to be looked for libraries. You can update the
LD_LIBRARY_PATH with paths to the directories in the Inference Engine installation directory where the libraries reside.
Add a path the directory containing the core and plugin libraries:
Add paths the directories containing the required third-party libraries:
Alternatively, you can use the following scripts that reside in the Inference Engine directory of the OpenVINO™ toolkit and Intel® Deep Learning Deployment Toolkit installation folders respectively:
To run compiled applications on Microsoft* Windows* OS, make sure that Microsoft* Visual C++ 2015 Redistributable and Intel® C++ Compiler 2017 Redistributable packages are installed and
<INSTALL_DIR>/bin/intel64/Release/*.dll files are placed to the application folder or accessible via
PATH% environment variable.