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) -> None

    Another Tensor’s special constructor.

    It takes an array or slice of it, and shape that will be selected, starting from the first element of the given array/slice. Please use it only in advanced cases if necessary!

    param array

    Underlaying methods will retrieve pointer on first element from it, which is simulating host_ptr from C++ API. 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 will be reflected on this Tensor’s memory! Data is required to be C_CONTIGUOUS.

    type array

    numpy.array

    param shape

    Shape of the new tensor.

    type shape

    openvino.runtime.Shape

    Example

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array([[1, 2, 3], [4, 5, 6]])
    
    t = ov.Tensor(arr[1][0:1], ov.Shape([3]))
    
    t.data[0] = 9
    
    print(arr)
    >>> [[1 2 3]
    >>>  [9 5 6]]
    
  3. __init__(self: openvino.pyopenvino.Tensor, type: openvino.pyopenvino.Type, shape: openvino.pyopenvino.Shape) -> None

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

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

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

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

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

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

  10. __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) -> None

    Another Tensor’s special constructor.

    It takes an array or slice of it, and shape that will be selected, starting from the first element of the given array/slice. Please use it only in advanced cases if necessary!

    param array

    Underlaying methods will retrieve pointer on first element from it, which is simulating host_ptr from C++ API. 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 will be reflected on this Tensor’s memory! Data is required to be C_CONTIGUOUS.

    type array

    numpy.array

    param shape

    Shape of the new tensor.

    type shape

    openvino.runtime.Shape

    Example

    import openvino.runtime as ov
    import numpy as np
    
    arr = np.array([[1, 2, 3], [4, 5, 6]])
    
    t = ov.Tensor(arr[1][0:1], ov.Shape([3]))
    
    t.data[0] = 9
    
    print(arr)
    >>> [[1 2 3]
    >>>  [9 5 6]]
    
  3. __init__(self: openvino.pyopenvino.Tensor, type: openvino.pyopenvino.Type, shape: openvino.pyopenvino.Shape) -> None

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

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

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

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

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

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

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

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