openvino.runtime.Tensor

class openvino.runtime.Tensor

Bases: pybind11_builtins.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 tensor from.

    type array

    numpy.array

    param shared_memory

    If True, this Tensor memory is being shared with a host, that means the responsibility of keeping host memory is on the side of a user. 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.

    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, that means the responsibility of keeping host memory is on the side of a user. 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, that means the responsibility of keeping host memory is on the side of a user. 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, type: openvino._pyopenvino.Type, shape: openvino._pyopenvino.Shape) -> None

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

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

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

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

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

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

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

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.

set_shape(*args, **kwargs)

Overloaded function.

Attributes

byte_size

Tensor's size in bytes.

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.

strides

Tensor's strides in bytes.

__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__(*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 tensor from.

    type array

    numpy.array

    param shared_memory

    If True, this Tensor memory is being shared with a host, that means the responsibility of keeping host memory is on the side of a user. 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.

    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, that means the responsibility of keeping host memory is on the side of a user. 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, that means the responsibility of keeping host memory is on the side of a user. 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, type: openvino._pyopenvino.Type, shape: openvino._pyopenvino.Shape) -> None

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

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

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

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

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

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

  11. __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 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.

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

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 strides

Tensor’s strides in bytes.

Return type

openvino.runtime.Strides