OpenVINO Development Tools

2024.6.0 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an OpenVINO Core object, define a simple model programmatically, compile it for a target device, and perform inference. It uses the `openvino.runtime` API introduced in OpenVINO 2023.0+ and avoids external model files or deep learning frameworks for simplicity.

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}")

view raw JSON →