openvino.Tensor#

class openvino.Tensor#

Bases: pybind11_object

openvino.runtime.Tensor holding either copy of memory or shared host memory.

__init__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shared_memory: bool = False) -> None

    Tensor’s special constructor.

    param array:

    Array to create the tensor from.

    type array:

    numpy.array

    param shared_memory:

    If True, this Tensor memory is being shared with a host. Any action performed on the host memory is reflected on this Tensor’s memory! If False, data is being copied to this Tensor. Requires data to be C_CONTIGUOUS if True. If the passed array contains strings, the flag must be set to `False’.

    type shared_memory:

    bool

  2. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shape: openvino._pyopenvino.Shape, type: openvino._pyopenvino.Type = <Type: ‘undefined’>) -> None

    Another Tensor’s special constructor.

    Represents array in the memory with given shape and element type. It’s recommended to use this constructor only for wrapping array’s memory with the specific openvino element type parameter.

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor with given parameters (shape and element_type). Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

    param shape:

    Shape of the new tensor.

    type shape:

    openvino.runtime.Shape

    param type:

    Element type

    type type:

    openvino.runtime.Type

    Example:

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array(shape=(100), dtype=np.uint8)
    t = ov.Tensor(arr, ov.Shape([100, 8]), ov.Type.u1)
    
  3. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shape: list[int], type: openvino._pyopenvino.Type = <Type: ‘undefined’>) -> None

    Another Tensor’s special constructor.

    Represents array in the memory with given shape and element type. It’s recommended to use this constructor only for wrapping array’s memory with the specific openvino element type parameter.

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor with given parameters (shape and element_type). Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

    param shape:

    Shape of the new tensor.

    type shape:

    list or tuple

    param type:

    Element type.

    type type:

    openvino.runtime.Type

    Example:

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array(shape=(100), dtype=np.uint8)
    t = ov.Tensor(arr, [100, 8], ov.Type.u1)
    
  4. __init__(self: openvino._pyopenvino.Tensor, list: list) -> None

    Tensor’s special constructor.

    Creates a Tensor from a given Python list. Warning: It is always a copy of list’s data!

    param array:

    List to create the tensor from.

    type array:

    List[int, float, str]

  5. __init__(self: openvino._pyopenvino.Tensor, type: openvino._pyopenvino.Type, shape: openvino._pyopenvino.Shape) -> None

  6. __init__(self: openvino._pyopenvino.Tensor, type: openvino._pyopenvino.Type, shape: list[int]) -> None

  7. __init__(self: openvino._pyopenvino.Tensor, type: numpy.dtype, shape: list[int]) -> None

  8. __init__(self: openvino._pyopenvino.Tensor, type: object, shape: list[int]) -> None

  9. __init__(self: openvino._pyopenvino.Tensor, type: numpy.dtype, shape: openvino._pyopenvino.Shape) -> None

  10. __init__(self: openvino._pyopenvino.Tensor, type: object, shape: openvino._pyopenvino.Shape) -> None

  11. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.Output) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.Output

  12. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.Output, array: numpy.ndarray) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.Output

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor. Array’s memory is being shared wi a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

  13. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.ConstOutput) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.ConstOutput

  14. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.ConstOutput, array: numpy.ndarray) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.ConstOutput

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor. Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

  15. __init__(self: openvino._pyopenvino.Tensor, other: openvino._pyopenvino.Tensor, begin: openvino._pyopenvino.Coordinate, end: openvino._pyopenvino.Coordinate) -> None

  16. __init__(self: openvino._pyopenvino.Tensor, other: openvino._pyopenvino.Tensor, begin: list[int], end: list[int]) -> 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__(*args, **kwargs)

Overloaded function.

__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().

copy_from(*args, **kwargs)

Overloaded function.

copy_to(*args, **kwargs)

Overloaded function.

get_byte_size(self)

Gets Tensor's size in bytes.

get_element_type(self)

Gets Tensor's element type.

get_shape(self)

Gets Tensor's shape.

get_size(self)

Gets Tensor's size as total number of elements.

get_strides(self)

Gets Tensor's strides in bytes.

is_continuous(self)

Reports whether the tensor is continuous or not.

set_shape(*args, **kwargs)

Overloaded function.

Attributes

byte_size

Tensor's size in bytes.

bytes_data

Access to Tensor's data with string Type in np.bytes_ dtype.

data

Access to Tensor's data.

element_type

Tensor's element type.

shape

Tensor's shape get/set.

size

Tensor's size as total number of elements.

str_data

Access to Tensor's data with string Type in np.str_ dtype.

strides

Tensor's strides in bytes.

__class__#

alias of 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__(*args, **kwargs)#

Overloaded function.

  1. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shared_memory: bool = False) -> None

    Tensor’s special constructor.

    param array:

    Array to create the tensor from.

    type array:

    numpy.array

    param shared_memory:

    If True, this Tensor memory is being shared with a host. Any action performed on the host memory is reflected on this Tensor’s memory! If False, data is being copied to this Tensor. Requires data to be C_CONTIGUOUS if True. If the passed array contains strings, the flag must be set to `False’.

    type shared_memory:

    bool

  2. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shape: openvino._pyopenvino.Shape, type: openvino._pyopenvino.Type = <Type: ‘undefined’>) -> None

    Another Tensor’s special constructor.

    Represents array in the memory with given shape and element type. It’s recommended to use this constructor only for wrapping array’s memory with the specific openvino element type parameter.

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor with given parameters (shape and element_type). Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

    param shape:

    Shape of the new tensor.

    type shape:

    openvino.runtime.Shape

    param type:

    Element type

    type type:

    openvino.runtime.Type

    Example:

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array(shape=(100), dtype=np.uint8)
    t = ov.Tensor(arr, ov.Shape([100, 8]), ov.Type.u1)
    
  3. __init__(self: openvino._pyopenvino.Tensor, array: numpy.ndarray, shape: list[int], type: openvino._pyopenvino.Type = <Type: ‘undefined’>) -> None

    Another Tensor’s special constructor.

    Represents array in the memory with given shape and element type. It’s recommended to use this constructor only for wrapping array’s memory with the specific openvino element type parameter.

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor with given parameters (shape and element_type). Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

    param shape:

    Shape of the new tensor.

    type shape:

    list or tuple

    param type:

    Element type.

    type type:

    openvino.runtime.Type

    Example:

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array(shape=(100), dtype=np.uint8)
    t = ov.Tensor(arr, [100, 8], ov.Type.u1)
    
  4. __init__(self: openvino._pyopenvino.Tensor, list: list) -> None

    Tensor’s special constructor.

    Creates a Tensor from a given Python list. Warning: It is always a copy of list’s data!

    param array:

    List to create the tensor from.

    type array:

    List[int, float, str]

  5. __init__(self: openvino._pyopenvino.Tensor, type: openvino._pyopenvino.Type, shape: openvino._pyopenvino.Shape) -> None

  6. __init__(self: openvino._pyopenvino.Tensor, type: openvino._pyopenvino.Type, shape: list[int]) -> None

  7. __init__(self: openvino._pyopenvino.Tensor, type: numpy.dtype, shape: list[int]) -> None

  8. __init__(self: openvino._pyopenvino.Tensor, type: object, shape: list[int]) -> None

  9. __init__(self: openvino._pyopenvino.Tensor, type: numpy.dtype, shape: openvino._pyopenvino.Shape) -> None

  10. __init__(self: openvino._pyopenvino.Tensor, type: object, shape: openvino._pyopenvino.Shape) -> None

  11. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.Output) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.Output

  12. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.Output, array: numpy.ndarray) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.Output

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor. Array’s memory is being shared wi a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

  13. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.ConstOutput) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.ConstOutput

  14. __init__(self: openvino._pyopenvino.Tensor, port: openvino._pyopenvino.ConstOutput, array: numpy.ndarray) -> None

    Constructs Tensor using port from node. Type and shape will be taken from the port.

    param port:

    Output port from a node.

    type param:

    openvino.runtime.ConstOutput

    param array:

    C_CONTIGUOUS numpy array which will be wrapped in openvino.runtime.Tensor. Array’s memory is being shared with a host. Any action performed on the host memory will be reflected on this Tensor’s memory!

    type array:

    numpy.array

  15. __init__(self: openvino._pyopenvino.Tensor, other: openvino._pyopenvino.Tensor, begin: openvino._pyopenvino.Coordinate, end: openvino._pyopenvino.Coordinate) -> None

  16. __init__(self: openvino._pyopenvino.Tensor, other: openvino._pyopenvino.Tensor, begin: list[int], end: list[int]) -> 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.Tensor) 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).

property byte_size#

Tensor’s size in bytes.

Return type:

int

property bytes_data#

Access to Tensor’s data with string Type in np.bytes_ dtype.

Getter returns a numpy array with corresponding shape and dtype. Warning: Data of string type is always a copy of underlaying memory!

Setter fills underlaying Tensor’s memory by copying strings from other. other must have the same size (number of elements) as the Tensor. Tensor’s shape is not changed by performing this operation!

copy_from(*args, **kwargs)#

Overloaded function.

  1. copy_from(self: openvino._pyopenvino.Tensor, source_tensor: openvino._pyopenvino.Tensor) -> None

    Copy source tensor’s data to this tensor. Tensors should have the same element type and shape.

    param source_tensor:

    The source tensor from which the data will be copied.

    type source_tensor:

    openvino.Tensor

  2. copy_from(self: openvino._pyopenvino.Tensor, source_tensor: RemoteTensorWrapper) -> None

    Copy source remote tensor’s data to this tensor. Tensors should have the same element type. In case of RoiTensor, tensors should also have the same shape.

    param source_tensor:

    The source remote tensor from which the data will be copied.

    type source_tensor:

    openvino.RemoteTensor

  3. copy_from(self: openvino._pyopenvino.Tensor, source: numpy.ndarray) -> None

    Copy the source to this tensor. This tensor and the source should have the same element type. Shape will be adjusted if there is a mismatch.

  4. copy_from(self: openvino._pyopenvino.Tensor, source: list) -> None

    Copy the source to this tensor. This tensor and the source should have the same element type. Shape will be adjusted if there is a mismatch.

copy_to(*args, **kwargs)#

Overloaded function.

  1. copy_to(self: openvino._pyopenvino.Tensor, target_tensor: openvino._pyopenvino.Tensor) -> None

    Copy tensor’s data to a destination tensor. The destination tensor should have the same element type and shape.

    param target_tensor:

    The destination tensor to which the data will be copied.

    type target_tensor:

    openvino.Tensor

  2. copy_to(self: openvino._pyopenvino.Tensor, target_tensor: RemoteTensorWrapper) -> None

    Copy tensor’s data to a destination remote tensor. The destination remote tensor should have the same element type. In case of RoiRemoteTensor, the destination tensor should also have the same shape.

    param target_tensor:

    The destination remote tensor to which the data will be copied.

    type target_tensor:

    openvino.RemoteTensor

property data#

Access to Tensor’s data.

Returns numpy array with corresponding shape and dtype.

For tensors with OpenVINO specific element type, such as u1, u4 or i4 it returns linear array, with uint8 / int8 numpy dtype.

For tensors with string element type, returns a numpy array of bytes without any decoding. To change the underlaying data use str_data/bytes_data properties or the copy_from function. Warning: Data of string type is always a copy of underlaying memory!

Return type:

numpy.array

property element_type#

Tensor’s element type.

Return type:

openvino.runtime.Type

get_byte_size(self: openvino._pyopenvino.Tensor) int#

Gets Tensor’s size in bytes.

Return type:

int

get_element_type(self: openvino._pyopenvino.Tensor) openvino._pyopenvino.Type#

Gets Tensor’s element type.

Return type:

openvino.runtime.Type

get_shape(self: openvino._pyopenvino.Tensor) openvino._pyopenvino.Shape#

Gets Tensor’s shape.

Return type:

openvino.runtime.Shape

get_size(self: openvino._pyopenvino.Tensor) int#

Gets Tensor’s size as total number of elements.

Return type:

int

get_strides(self: openvino._pyopenvino.Tensor) openvino._pyopenvino.Strides#

Gets Tensor’s strides in bytes.

Return type:

openvino.runtime.Strides

is_continuous(self: openvino._pyopenvino.Tensor) bool#

Reports whether the tensor is continuous or not. :return: True if the tensor is continuous, otherwise False. :rtype: bool

set_shape(*args, **kwargs)#

Overloaded function.

  1. set_shape(self: openvino._pyopenvino.Tensor, arg0: openvino._pyopenvino.Shape) -> None

    Sets Tensor’s shape.

  2. set_shape(self: openvino._pyopenvino.Tensor, arg0: list[int]) -> None

    Sets Tensor’s shape.

property shape#

Tensor’s shape get/set.

property size#

Tensor’s size as total number of elements.

Return type:

int

property str_data#

Access to Tensor’s data with string Type in np.str_ dtype.

Getter returns a numpy array with corresponding shape and dtype. Warning: Data of string type is always a copy of underlaying memory!

Setter fills underlaying Tensor’s memory by copying strings from other. other must have the same size (number of elements) as the Tensor. Tensor’s shape is not changed by performing this operation!

property strides#

Tensor’s strides in bytes.

Return type:

openvino.runtime.Strides