openvino.runtime.Core

class openvino.runtime.Core

Bases: openvino._pyopenvino.Core

Core class represents OpenVINO runtime Core entity.

User applications can create several Core class instances, but in this case, the underlying plugins are created multiple times and not shared between several Core instances. The recommended way is to have a single Core instance per application.

__init__(self: openvino._pyopenvino.Core, xml_config_file: str = '') None

Methods

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__(self[, xml_config_file])

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__(self)

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

add_extension(*args, **kwargs)

Overloaded function.

compile_model(model[, device_name, config])

Creates a compiled model.

get_available_devices(self)

Returns devices available for inference Core objects goes over all registered plugins.

get_property(*args, **kwargs)

Overloaded function.

get_versions(self, device_name)

Returns device plugins version information.

import_model(model_stream, device_name[, config])

Imports a compiled model from a previously exported one.

query_model(self, model, device_name[, ...])

Query device if it supports specified model with specified properties.

read_model(*args, **kwargs)

Overloaded function.

register_plugin(*args, **kwargs)

Overloaded function.

register_plugins(self, xml_config_file)

Registers a device plugin to OpenVINO Runtime Core instance using XML configuration file with plugins description.

set_property(*args, **kwargs)

Overloaded function.

unload_plugin(self, device_name)

Unloads the previously loaded plugin identified by device_name from OpenVINO Runtime.

Attributes

available_devices

Returns devices available for inference Core objects goes over all registered plugins.

__class__

alias of pybind11_builtins.pybind11_type

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(value, /)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__hash__()

Return hash(self).

__init__(self: openvino._pyopenvino.Core, xml_config_file: str = '') None
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(**kwargs)
__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__(self: openvino._pyopenvino.Core) str
__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

add_extension(*args, **kwargs)

Overloaded function.

  1. add_extension(self: openvino._pyopenvino.Core, library_path: str) -> None

    Registers an extension to a Core object.

    param library_path

    Path to library with ov::Extension

    type library_path

    str

  2. add_extension(self: openvino._pyopenvino.Core, extension: ov::Extension) -> None

    Registers an extension to a Core object.

    param extension

    Extension object.

    type extension

    openvino.runtime.Extension

  3. add_extension(self: openvino._pyopenvino.Core, extensions: List[ov::Extension]) -> None

    Registers extensions to a Core object.

    param extensions

    List of Extension objects.

    type extensions

    list[openvino.runtime.Extension]

property available_devices

Returns devices available for inference Core objects goes over all registered plugins.

GIL is released while running this function.

Returns

A list of devices. The devices are returned as: CPU, GPU.0, GPU.1, GNA… If there more than one device of specific type, they are enumerated with .# suffix. Such enumerated device can later be used as a device name in all Core methods like: compile_model, query_model, set_property and so on.

Return type

list

compile_model(model: Union[openvino.runtime.ie_api.Model, str, pathlib.Path], device_name: Optional[str] = None, config: Optional[dict] = None) openvino.runtime.ie_api.CompiledModel

Creates a compiled model.

Creates a compiled model from a source Model object or reads model and creates a compiled model from IR / ONNX / PDPD / TF and TFLite file. This can be more efficient than using read_model + compile_model(model_in_memory_object) flow, especially for cases when caching is enabled and cached model is available. If device_name is not specified, the default OpenVINO device will be selected by AUTO plugin. Users can create as many compiled models as they need, and use them simultaneously (up to the limitation of the hardware resources).

Parameters
  • model (Union[openvino.runtime.Model, str, pathlib.Path]) – Model acquired from read_model function or a path to a model in IR / ONNX / PDPD / TF and TFLite format.

  • device_name (str) – Optional. Name of the device to load the model to. If not specified, the default OpenVINO device will be selected by AUTO plugin.

  • config (dict, optional) – Optional dict of pairs: (property name, property value) relevant only for this load operation.

Returns

A compiled model.

Return type

openvino.runtime.CompiledModel

get_available_devices(self: openvino._pyopenvino.Core) List[str]

Returns devices available for inference Core objects goes over all registered plugins.

GIL is released while running this function.

Returns

A list of devices. The devices are returned as: CPU, GPU.0, GPU.1, GNA… If there more than one device of specific type, they are enumerated with .# suffix. Such enumerated device can later be used as a device name in all Core methods like: compile_model, query_model, set_property and so on.

Return type

list

get_property(*args, **kwargs)

Overloaded function.

  1. get_property(self: openvino._pyopenvino.Core, device_name: str, property: str) -> object

    Gets properties dedicated to device behaviour.

    param device_name

    A name of a device to get a properties value.

    type device_name

    str

    param property

    Property or name of Property.

    type property

    str

    return

    Extracted information from property.

    rtype

    object

  2. get_property(self: openvino._pyopenvino.Core, property: str) -> object

    Gets properties dedicated to Core behaviour.

    param property

    Property or name of Property.

    type property

    str

    return

    Extracted information from property.

    rtype

    object

get_versions(self: openvino._pyopenvino.Core, device_name: str) Dict[str, ov::Version]

Returns device plugins version information.

Parameters

device_name (str) – Device name to identify a plugin.

Returns

Plugin version information.

Return type

Dict[str, openvino.runtime.Version]

import_model(model_stream: bytes, device_name: str, config: Optional[dict] = None) openvino.runtime.ie_api.CompiledModel

Imports a compiled model from a previously exported one.

Parameters
  • model_stream (bytes) – Input stream, containing a model previously exported, using export_model method.

  • device_name (str) – Name of device to which compiled model is imported. Note: if device_name is not used to compile the original model, an exception is thrown.

  • config (dict, optional) – Optional dict of pairs: (property name, property value) relevant only for this load operation.

Returns

A compiled model.

Return type

openvino.runtime.CompiledModel

Example

user_stream = compiled.export_model()

with open('./my_model', 'wb') as f:
    f.write(user_stream)

# ...

new_compiled = core.import_model(user_stream, "CPU")
user_stream = io.BytesIO()
compiled.export_model(user_stream)

with open('./my_model', 'wb') as f:
    f.write(user_stream.getvalue()) # or read() if seek(0) was applied before

# ...

new_compiled = core.import_model(user_stream, "CPU")
query_model(self: openvino._pyopenvino.Core, model: openvino._pyopenvino.Model, device_name: str, properties: Dict[str, object] = {}) Dict[str, str]

Query device if it supports specified model with specified properties.

GIL is released while running this function.

Parameters
  • model (openvino.runtime.Model) – Model object to query.

  • device_name (str) – A name of a device to query.

  • properties (dict) – Optional dict of pairs: (property name, property value)

Returns

Pairs a operation name -> a device name supporting this operation.

Return type

dict

read_model(*args, **kwargs)

Overloaded function.

  1. read_model(self: openvino._pyopenvino.Core, model: bytes, weights: bytes = b’’) -> openvino._pyopenvino.Model

    Reads models from IR / ONNX / PDPD / TF and TFLite formats.

    GIL is released while running this function.

    param model

    Bytes with model in IR / ONNX / PDPD / TF and TFLite format.

    type model

    bytes

    param weights

    Bytes with tensor’s data.

    type weights

    bytes

    return

    A model.

    rtype

    openvino.runtime.Model

  2. read_model(self: openvino._pyopenvino.Core, model: str, weights: str = ‘’) -> openvino._pyopenvino.Model

    Reads models from IR / ONNX / PDPD / TF and TFLite formats.

    GIL is released while running this function.

    param model

    A path to a model in IR / ONNX / PDPD / TF and TFLite format.

    type model

    str

    param weights

    A path to a data file For IR format (.bin): if path is empty, it tries to read a bin file with the same name as xml and if the bin file with the same name was not found, loads IR without weights. For ONNX format (.onnx): weights parameter is not used. For PDPD format (.pdmodel) weights parameter is not used. For TF format (.pb) weights parameter is not used. For TFLite format (*.tflite) weights parameter is not used.

    type weights

    str

    return

    A model.

    rtype

    openvino.runtime.Model

  3. read_model(self: openvino._pyopenvino.Core, model: str, weights: ov::Tensor) -> openvino._pyopenvino.Model

    Reads models from IR / ONNX / PDPD / TF and TFLite formats.

    GIL is released while running this function.

    param model

    A string with model in IR / ONNX / PDPD / TF and TFLite format.

    type model

    str

    param weights

    Tensor with weights. Reading ONNX / PDPD / TF and TFLite models doesn’t support loading weights from weights tensors.

    type weights

    openvino.runtime.Tensor

    return

    A model.

    rtype

    openvino.runtime.Model

  4. read_model(self: openvino._pyopenvino.Core, model: object, weights: object = None) -> openvino._pyopenvino.Model

    Reads models from IR / ONNX / PDPD / TF and TFLite formats.

    GIL is released while running this function.

    param model

    A path to a model in IR / ONNX / PDPD / TF and TFLite format or a model itself wrapped in io.ByesIO format.

    type model

    Union[pathlib.Path, io.BytesIO]

    param weights

    A path to a data file For IR format (.bin): if path is empty, it tries to read a bin file with the same name as xml and if the bin file with the same name was not found, loads IR without weights. For ONNX format (.onnx): weights parameter is not used. For PDPD format (.pdmodel) weights parameter is not used. For TF format (.pb): weights parameter is not used. For TFLite format (*.tflite) weights parameter is not used.

    type weights

    pathlib.Path

    return

    A model.

    rtype

    openvino.runtime.Model

register_plugin(*args, **kwargs)

Overloaded function.

  1. register_plugin(self: openvino._pyopenvino.Core, plugin_name: str, device_name: str) -> None

    Register a new device and plugin which enable this device inside OpenVINO Runtime.

    param plugin_name

    A path (absolute or relative) or name of a plugin. Depending on platform, plugin_name is wrapped with shared library suffix and prefix to identify library full name E.g. on Linux platform plugin name specified as plugin_name will be wrapped as libplugin_name.so.

    type plugin_name

    str

    param device_name

    A device name to register plugin for.

    type device_name

    str

  2. register_plugin(self: openvino._pyopenvino.Core, plugin_name: str, device_name: str, config: Dict[str, object]) -> None

    Register a new device and plugin which enable this device inside OpenVINO Runtime.

    param plugin_name

    A path (absolute or relative) or name of a plugin. Depending on platform, plugin_name is wrapped with shared library suffix and prefix to identify library full name E.g. on Linux platform plugin name specified as plugin_name will be wrapped as libplugin_name.so.

    type plugin_name

    str

    param device_name

    A device name to register plugin for.

    type device_name

    str

    param config

    Plugin default configuration

    type config

    dict, optional

register_plugins(self: openvino._pyopenvino.Core, xml_config_file: str) None

Registers a device plugin to OpenVINO Runtime Core instance using XML configuration file with plugins description.

Parameters

xml_config_file (str) – A path to .xml file with plugins to register.

set_property(*args, **kwargs)

Overloaded function.

  1. set_property(self: openvino._pyopenvino.Core, properties: Dict[str, object]) -> None

    Sets properties.

    param properties

    Dict of pairs: (property name, property value).

    type properties

    dict

  2. set_property(self: openvino._pyopenvino.Core, property: Tuple[str, object]) -> None

    Sets properties for the device.

    param property

    Tuple of (property name, matching property value).

    type property

    tuple

  3. set_property(self: openvino._pyopenvino.Core, device_name: str, properties: Dict[str, object]) -> None

    Sets properties for the device.

    param device_name

    Name of the device.

    type device_name

    str

    param properties

    Dict of pairs: (property name, property value).

    type properties

    dict

  4. set_property(self: openvino._pyopenvino.Core, device_name: str, property: Tuple[str, object]) -> None

    Sets properties for the device.

    param device_name

    Name of the device.

    type device_name

    str

    param property

    Tuple of (property name, matching property value).

    type property

    tuple

unload_plugin(self: openvino._pyopenvino.Core, device_name: str) None

Unloads the previously loaded plugin identified by device_name from OpenVINO Runtime. The method is needed to remove loaded plugin instance and free its resources. If plugin for a specified device has not been created before, the method throws an exception.

Parameters

device_name (str) – A device name identifying plugin to remove from OpenVINO.