OpenVINO Development Tools
OpenVINO™ Development Tools (openvino-dev) is Intel's comprehensive toolkit for optimizing and deploying AI models for inference across various Intel hardware. It includes the OpenVINO™ Runtime, Model Optimizer, and Post-Training Optimization Tool. The current version is 2024.6.0. Intel typically releases major updates quarterly, providing a consistent cadence of new features and performance improvements.
Common errors
-
RuntimeError: Cannot find plugin to use for device <device_name>
cause OpenVINO cannot find the necessary plugin (driver) to run inference on the specified device. This often happens with 'GPU' if Intel graphics drivers or OpenCL/oneAPI runtimes are not installed, or with 'NPU' if the corresponding hardware and drivers are missing.fixVerify that the target device is physically present and its respective drivers/run-time components are correctly installed. Use `ov.Core().available_devices` to check which devices are recognized by OpenVINO. Fallback to 'CPU' if other devices are unavailable. -
AttributeError: 'openvino.runtime.Core' object has no attribute 'read_network'
cause This error indicates usage of the old API (`read_network` was part of `IECore`) with the new `openvino.runtime.Core` object. The `read_network` method was deprecated and removed.fixReplace `core.read_network(...)` with `core.read_model(...)`. The new API uses `read_model` to load an IR or other framework model. -
RuntimeError: Check 'device != ""' failed at src/inference_engine/ie_core.cpp:...
cause An empty string was passed as the device name to `core.compile_model()` or `core.get_versions()`, which is not a valid device identifier.fixAlways provide a valid device string like 'CPU', 'GPU', 'NPU', or 'AUTO'. Ensure any environment variables or configuration values used for the device string are not empty.
Warnings
- breaking Major API changes occurred in OpenVINO 2023.0+ concerning `IECore` to `Core`, `read_network` to `read_model`, and `load_network` to `compile_model`.
- breaking The Model Optimizer functionality, previously accessed via `openvino.tools.mo.convert_model`, is now directly exposed as `openvino.convert_model`.
- gotcha Device selection (e.g., 'CPU', 'GPU', 'NPU') requires the correct drivers and hardware. Using 'AUTO' or a non-existent device may lead to runtime errors or fallback to CPU.
Install
-
pip install openvino-dev
Imports
- Core
from openvino.inference_engine import IECore
from openvino.runtime import Core
- Model
from openvino.runtime import Model
- CompiledModel
from openvino.runtime import CompiledModel
- convert_model
from openvino.tools.mo import convert_model
from openvino import convert_model
- Type
from openvino.runtime import Type
- opset12
from openvino.runtime import opset12
Quickstart
import openvino as ov
import numpy as np
import os
# 1. Create a Core object
core = ov.Core()
# 2. Define a simple model programmatically (e.g., a single addition operation)
# This avoids external files and frameworks for a minimal example.
input_a = ov.opset12.parameter([1, 3, 224, 224], ov.Type.f32, name="input_a")
input_b = ov.opset12.parameter([1, 3, 224, 224], ov.Type.f32, name="input_b")
result_op = ov.opset12.add(input_a, input_b, name="add_result")
model = ov.Model([result_op], [input_a, input_b], "simple_add_model")
# 3. Compile the model for a specific device (e.g., 'CPU', 'GPU', 'NPU')
# Use 'AUTO' to let OpenVINO select the best available device.
device = os.environ.get("OPENVINO_DEVICE", "CPU") # Default to CPU
try:
compiled_model = core.compile_model(model, device)
print(f"Model compiled successfully for {device} device.")
except RuntimeError as e:
print(f"Warning: Could not compile model for device '{device}': {e}")
print("Falling back to CPU if available.")
device = "CPU"
compiled_model = core.compile_model(model, device)
# 4. Prepare input data
input_data_a = np.random.rand(1, 3, 224, 224).astype(np.float32)
input_data_b = np.random.rand(1, 3, 224, 224).astype(np.float32)
# 5. Perform inference
# Inputs can be passed as a list, dictionary, or single tensor depending on model
outputs = compiled_model([input_data_a, input_data_b])
# 6. Process results
print(f"Inference successful on {device} device.")
# The output is a list of numpy arrays, one for each output of the model
print(f"Output shape: {outputs[0].shape}, dtype: {outputs[0].dtype}")