"or --cpu_extension command line argument")
sys.exit(1)
- assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
+ assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
log.info("Preparing input blobs")
- input_blob = next(iter(net.inputs))
+ input_blob = next(iter(net.input_info))
out_blob = next(iter(net.outputs))
net.batch_size = len(args.input)
# Read and pre-process input images
- n, c, h, w = net.inputs[input_blob].shape
+ n, c, h, w = net.input_info[input_blob].input_data.shape
images = np.ndarray(shape=(n, c, h, w))
for i in range(n):
image = cv2.imread(args.input[i])
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
"or --cpu_extension command line argument")
sys.exit(1)
- assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
+ assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
log.info("Preparing input blobs")
- input_blob = next(iter(net.inputs))
+ input_blob = next(iter(net.input_info))
out_blob = next(iter(net.outputs))
net.batch_size = len(args.input)
# Read and pre-process input images
- n, c, h, w = net.inputs[input_blob].shape
+ n, c, h, w = net.input_info[input_blob].input_data.shape
images = np.ndarray(shape=(n, c, h, w))
for i in range(n):
image = cv2.imread(args.input[i])
# create one inference request for asynchronous execution
request_id = 0
- infer_request = exec_net.requests[request_id];
+ infer_request = exec_net.requests[request_id]
num_iter = 10
request_wrap = InferReqWrap(infer_request, request_id, num_iter)
# --------------------------- 3. Read and preprocess input --------------------------------------------
- print("inputs number: " + str(len(net.inputs.keys())))
+ print("inputs number: " + str(len(net.input_info.keys())))
- for input_key in net.inputs:
- print("input shape: " + str(net.inputs[input_key].shape))
+ for input_key in net.input_info:
+ print("input shape: " + str(net.input_info[input_key].input_data.shape))
print("input key: " + input_key)
- if len(net.inputs[input_key].layout) == 4:
- n, c, h, w = net.inputs[input_key].shape
+ if len(net.input_info[input_key].input_data.layout) == 4:
+ n, c, h, w = net.input_info[input_key].input_data.shape
images = np.ndarray(shape=(n, c, h, w))
images_hw = []
# --------------------------- 4. Configure input & output ---------------------------------------------
# --------------------------- Prepare input blobs -----------------------------------------------------
log.info("Preparing input blobs")
- assert (len(net.inputs.keys()) == 1 or len(
- net.inputs.keys()) == 2), "Sample supports topologies only with 1 or 2 inputs"
+ assert (len(net.input_info.keys()) == 1 or len(
+ net.input_info.keys()) == 2), "Sample supports topologies only with 1 or 2 inputs"
out_blob = next(iter(net.outputs))
input_name, input_info_name = "", ""
- for input_key in net.inputs:
- if len(net.inputs[input_key].layout) == 4:
+ for input_key in net.input_info:
+ if len(net.input_info[input_key].layout) == 4:
input_name = input_key
log.info("Batch size is {}".format(net.batch_size))
- net.inputs[input_key].precision = 'U8'
- elif len(net.inputs[input_key].layout) == 2:
+ net.input_info[input_key].precision = 'U8'
+ elif len(net.input_info[input_key].layout) == 2:
input_info_name = input_key
- net.inputs[input_key].precision = 'FP32'
- if net.inputs[input_key].shape[1] != 3 and net.inputs[input_key].shape[1] != 6 or \
- net.inputs[input_key].shape[0] != 1:
+ net.input_info[input_key].precision = 'FP32'
+ if net.input_info[input_key].input_data.shape[1] != 3 and net.input_info[input_key].input_data.shape[1] != 6 or \
+ net.input_info[input_key].input_data.shape[0] != 1:
log.error('Invalid input info. Should be 3 or 6 values length.')
data = {}
"or --cpu_extension command line argument")
sys.exit(1)
- assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
+ assert len(net.input_info.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
log.info("Preparing input blobs")
- input_blob = next(iter(net.inputs))
+ input_blob = next(iter(net.input_info))
out_blob = next(iter(net.outputs))
net.batch_size = len(args.input)
# Read and pre-process input images
- n, c, h, w = net.inputs[input_blob].shape
+ n, c, h, w = net.input_info[input_blob].input_data.shape
images = np.ndarray(shape=(n, c, h, w))
for i in range(n):
image = cv2.imread(args.input[i])
from .ie_api import *
-__all__ = ['IENetwork', "IETensorDesc", "IECore", "IEBlob", "get_version"]
+__all__ = ['IENetwork', "TensorDesc", "IECore", "Blob", "get_version"]
__version__ = get_version()
from .cimport ie_api_impl_defs as C
import numpy as np
+from enum import Enum
supported_precisions = ["FP32", "FP16", "I64", "U64", "I32", "I16", "I8", "U16", "U8"]
}
+class MeanVariant(Enum):
+ MEAN_IMAGE = 0
+ MEAN_VALUE = 1
+ NONE = 2
+
+
+class ResizeAlgorithm(Enum):
+ NO_RESIZE = 0
+ RESIZE_BILINEAR = 1
+ RESIZE_AREA = 2
+
+
+class ColorFormat(Enum):
+ RAW = 0
+ RGB = 1
+ BGR = 2
+ RGBX = 3
+ BGRX = 4
+ NV12 = 5
+ I420 = 6
+
+
cpdef enum StatusCode:
OK = 0
GENERAL_ERROR = -1
INFER_NOT_STARTED = -11
NETWORK_NOT_READ = -12
+
cpdef enum WaitMode:
RESULT_READY = -1
STATUS_ONLY = 0
from .cimport ie_api_impl_defs as C
-from .ie_api_impl_defs cimport Blob, TensorDesc
+from .ie_api_impl_defs cimport CBlob, CTensorDesc, InputInfo, CPreProcessChannel, CPreProcessInfo
from pathlib import Path
from libcpp cimport bool
from libcpp.memory cimport unique_ptr, shared_ptr
-cdef class IEBlob:
- cdef Blob.Ptr _ptr
+cdef class Blob:
+ cdef CBlob.Ptr _ptr
cdef public object _array_data
cdef public object _initial_shape
cdef class BlobBuffer:
- cdef Blob.Ptr ptr
+ cdef CBlob.Ptr ptr
cdef char*format
cdef vector[Py_ssize_t] shape
cdef vector[Py_ssize_t] strides
- cdef reset(self, Blob.Ptr &, vector[size_t] representation_shape = ?)
- cdef char*_get_blob_format(self, const TensorDesc & desc)
+ cdef reset(self, CBlob.Ptr &, vector[size_t] representation_shape = ?)
+ cdef char*_get_blob_format(self, const CTensorDesc & desc)
cdef public:
total_stride, item_size
cdef class IENetLayer:
cdef C.CNNLayerPtr _ptr
-cdef class IETensorDesc:
- cdef C.TensorDesc impl
+cdef class TensorDesc:
+ cdef C.CTensorDesc impl
+
+cdef class InputInfoPtr:
+ cdef InputInfo.Ptr _ptr
+
+cdef class InputInfoCPtr:
+ cdef InputInfo.CPtr _ptr
+
+cdef class PreProcessInfo:
+ cdef CPreProcessInfo* _ptr
+
+cdef class PreProcessChannel:
+ cdef CPreProcessChannel.Ptr _ptr
from libcpp.memory cimport unique_ptr
from libc.stdlib cimport malloc, free
from libc.stdint cimport int64_t, uint8_t, int8_t, int32_t, uint16_t, int16_t
+from libc.stddef cimport size_t
from libc.string cimport memcpy
import os
from .cimport ie_api_impl_defs as C
from .ie_api_impl_defs cimport SizeVector, Precision
-from .constants import supported_precisions, known_plugins, layout_int_to_str_map, \
- format_map, layout_str_to_enum, StatusCode, WaitMode
+from .constants import WaitMode, StatusCode, MeanVariant, layout_str_to_enum, format_map, layout_int_to_str_map,\
+ known_plugins, supported_precisions, ResizeAlgorithm, ColorFormat
import numpy as np
return C.get_version().decode()
## This class defines Tensor description
-cdef class IETensorDesc:
- def __eq__(self, other : IETensorDesc):
+cdef class TensorDesc:
+ def __eq__(self, other : TensorDesc):
return self.layout == other.layout and self.precision == other.precision and self.dims == other.dims
- def __ne__(self, other : IETensorDesc):
+ def __ne__(self, other : TensorDesc):
return self.layout != other.layout or self.precision != other.precision or self.dims != other.dims
def __deepcopy__(self, memodict={}):
- return IETensorDesc(deepcopy(self.precision, memodict), deepcopy(self.dims, memodict), deepcopy(self.layout, memodict))
+ return TensorDesc(deepcopy(self.precision, memodict), deepcopy(self.dims, memodict), deepcopy(self.layout, memodict))
## Class constructor
# @param precision: target memory precision
# @param dims: target memory dimensions
if precision not in supported_precisions:
raise ValueError("Unsupported precision {}! List of supported precisions: {}".format(precision,
supported_precisions))
- self.impl = C.TensorDesc(C.Precision.FromStr(precision.encode()), dims, layout_str_to_enum[layout])
- ## Shape (dimensions) of the IETensorDesc object
+ self.impl = C.CTensorDesc(C.Precision.FromStr(precision.encode()), dims, layout_str_to_enum[layout])
+ ## Shape (dimensions) of the TensorDesc object
@property
def dims(self):
return self.impl.getDims()
@dims.setter
def dims(self, dims_array : [list, tuple]):
self.impl.setDims(dims_array)
- ## Precision of the IETensorDesc object
+ ## Precision of the TensorDesc object
@property
def precision(self):
return self.impl.getPrecision().name().decode()
raise ValueError("Unsupported precision {}! List of supported precisions: {}".format(precision,
supported_precisions))
self.impl.setPrecision(C.Precision.FromStr(precision.encode()))
- ## Layout of the IETensorDesc object
+ ## Layout of the TensorDesc object
@property
def layout(self):
return layout_int_to_str_map[self.impl.getLayout()]
self.impl.setLayout(layout_str_to_enum[layout])
## This class represents Blob
-cdef class IEBlob:
+cdef class Blob:
## Class constructor
- # @param tensor_desc: IETensorDesc object describing creating IEBlob object.
+ # @param tensor_desc: TensorDesc object describing creating Blob object.
# @param array: numpy.ndarray with data to fill blob memory, The array have to have same elements count
# as specified in tensor_desc.dims attribute and same elements precision corresponding to
# tensor_desc.precision. If array isn't provided empty numpy.ndarray will be created accorsing
# to parameters of tensor_desc
- # @return Instance of IEBlob class
- def __cinit__(self, IETensorDesc tensor_desc = None, array : np.ndarray = None):
- cdef TensorDesc c_tensor_desc
+ # @return Instance of Blob class
+ def __cinit__(self, TensorDesc tensor_desc = None, array : np.ndarray = None):
+ cdef CTensorDesc c_tensor_desc
cdef float[::1] fp32_array_memview
cdef int16_t[::1] I16_array_memview
cdef uint16_t[::1] U16_array_memview
raise AttributeError("Unsupported precision {} for blob".format(precision))
def __deepcopy__(self, memodict):
- res = IEBlob(deepcopy(self.tensor_desc, memodict), deepcopy(self._array_data, memodict))
+ res = Blob(deepcopy(self.tensor_desc, memodict), deepcopy(self._array_data, memodict))
res.buffer[:] = deepcopy(self.buffer[:], memodict)
return res
- ## IEBlob's memory as numpy.ndarray representation
+ ## Blob's memory as numpy.ndarray representation
@property
def buffer(self):
representation_shape = self._initial_shape if self._initial_shape is not None else []
buffer.reset(self._ptr, representation_shape)
return buffer.to_numpy()
- ## IETensorDesc of created IEBlob
+ ## TensorDesc of created Blob
@property
def tensor_desc(self):
- cdef TensorDesc c_tensor_desc = deref(self._ptr).getTensorDesc()
+ cdef CTensorDesc c_tensor_desc = deref(self._ptr).getTensorDesc()
precision = c_tensor_desc.getPrecision().name().decode()
layout = c_tensor_desc.getLayout()
dims = c_tensor_desc.getDims()
- tensor_desc = IETensorDesc(precision, dims, layout_int_to_str_map[layout])
+ tensor_desc = TensorDesc(precision, dims, layout_int_to_str_map[layout])
return tensor_desc
## This class represents an Inference Engine entity and allows you to manipulate with plugins using unified interfaces.
# ```python
# ie = IECore()
# net = ie.read_network(model=path_to_xml_file, weights=path_to_bin_file)
- # exec_net = ie.load_network(network=net, device_name="MYRIAD", num_requsts=2)
+ # exec_net = ie.load_network(network=net, device_name="MYRIAD", num_requests=2)
# # export executable network
# exec_net.export(path_to_file_to_save)
# # import previously exported executable network
cdef vector[string] c_devices = self.impl.getAvailableDevices()
return [d.decode() for d in c_devices]
+## This structure stores info about pre-processing of network inputs (scale, mean image, ...)
+cdef class PreProcessChannel:
+ property mean_value:
+ def __get__(self):
+ return deref(self._ptr).meanValue
+ def __set__(self, float mean_value):
+ deref(self._ptr).meanValue = mean_value
+ property std_scale:
+ def __get__(self):
+ return deref(self._ptr).stdScale
+ def __set__(self, float std_scale):
+ deref(self._ptr).stdScale = std_scale
+ property mean_data:
+ def __get__(self):
+ blob = Blob()
+ blob._ptr = deref(self._ptr).meanData
+ return blob
+ def __set__(self, Blob mean_data):
+ deref(self._ptr).meanData = mean_data._ptr
+
+## This class stores pre-process information for the input
+cdef class PreProcessInfo:
+ def __getitem__(self, size_t index):
+ cdef CPreProcessChannel.Ptr c_channel = deref(self._ptr)[index]
+ channel = PreProcessChannel()
+ channel._ptr = c_channel
+ return channel
+
+ ## Returns a number of channels to preprocess
+ def get_number_of_channels(self):
+ return deref(self._ptr).getNumberOfChannels()
+
+ ## Initializes with given number of channels
+ def init(self, const size_t number_of_channels):
+ deref(self._ptr).init(number_of_channels)
+
+ ## Sets mean image values if operation is applicable.
+ # Also sets the mean type to MEAN_IMAGE for all channels
+ def set_mean_image(self, Blob mean_image):
+ deref(self._ptr).setMeanImage(mean_image._ptr)
+
+ ## Sets mean image values if operation is applicable.
+ # Also sets the mean type to MEAN_IMAGE for a particular channel
+ def set_mean_image_for_channel(self, Blob mean_image, size_t channel):
+ deref(self._ptr).setMeanImageForChannel(mean_image._ptr, channel)
+
+ ## Mean Variant to be applied for input before inference if needed.
+ #
+ # Usage example:\n
+ # ```python
+ # net = ie_core.read_network(model=path_to_xml_file, weights=path_to_bin_file)
+ # net.input_info['data'].preprocess_info.mean_variant = MeanVariant.MEAN_IMAGE
+ # ```
+ @property
+ def mean_variant(self):
+ return MeanVariant(deref(self._ptr).getMeanVariant())
+
+ @mean_variant.setter
+ def mean_variant(self, variant : MeanVariant):
+ deref(self._ptr).setVariant(variant.value)
+
+ ## Resize Algorithm to be applied for input before inference if needed.
+ #
+ # Usage example:\n
+ # ```python
+ # net = ie_core.read_network(model=path_to_xml_file, weights=path_to_bin_file)
+ # net.input_info['data'].preprocess_info.resize_algorithm = ResizeAlgorithm.RESIZE_BILINEAR
+ # ```
+ @property
+ def resize_algorithm(self):
+ return ResizeAlgorithm(deref(self._ptr).getResizeAlgorithm())
+
+ @resize_algorithm.setter
+ def resize_algorithm(self, alg : ResizeAlgorithm):
+ deref(self._ptr).setResizeAlgorithm(alg.value)
+
+ ## Color format to be used in on-demand color conversions applied to input before inference
+ #
+ # Usage example:\n
+ # ```python
+ # net = ie_core.read_network(model=path_to_xml_file, weights=path_to_bin_file)
+ # net.input_info['data'].preprocess_info.color_format = ColorFormat.BGR
+ # ```
+ @property
+ def color_format(self):
+ return ColorFormat(deref(self._ptr).getColorFormat())
+
+ @color_format.setter
+ def color_format(self, fmt : ColorFormat):
+ deref(self._ptr).setColorFormat(fmt.value)
+
+
+## This class contains information about each input of the network
+cdef class InputInfoPtr:
+ ## Name of this input
+ @property
+ def name(self):
+ return deref(self._ptr).name().decode()
+
+ ## Precision of this input
+ @property
+ def precision(self):
+ return deref(self._ptr).getPrecision().name().decode()
+
+ @precision.setter
+ def precision(self, precision : str):
+ if precision not in supported_precisions:
+ raise ValueError("Unsupported precision {}! List of supported precisions: {}".format(precision,
+ supported_precisions))
+ deref(self._ptr).setPrecision(C.Precision.FromStr(precision.encode()))
+
+ ## Layout of this input
+ @property
+ def layout(self):
+ return layout_int_to_str_map[deref(self._ptr).getLayout()]
+
+ @layout.setter
+ def layout(self, layout : str):
+ if layout not in layout_str_to_enum.keys():
+ raise ValueError("Unsupported layout {}! "
+ "List of supported layouts: {}".format(layout, list(layout_str_to_enum.keys())))
+ deref(self._ptr).setLayout(layout_str_to_enum[layout])
+
+ ## Gets pre-process info for the input
+ #
+ # Usage example:\n
+ # ```python
+ # net = ie_core.read_network(model=path_to_xml_file, weights=path_to_bin_file)
+ # net.input_info['data'].preprocess_info.color_format = ColorFormat.BGR
+ # ```
+ @property
+ def preprocess_info(self):
+ cdef CPreProcessInfo* c_preprocess_info = &deref(self._ptr).getPreProcess()
+ preprocess_info = PreProcessInfo()
+ preprocess_info._ptr = c_preprocess_info
+ return preprocess_info
+
+ @property
+ def tensor_desc(self):
+ cdef CTensorDesc c_tensor_desc = deref(self._ptr).getTensorDesc()
+ precision = c_tensor_desc.getPrecision().name().decode()
+ layout = c_tensor_desc.getLayout()
+ dims = c_tensor_desc.getDims()
+ tensor_desc = TensorDesc(precision, dims, layout_int_to_str_map[layout])
+ tensor_desc.impl = c_tensor_desc
+ return tensor_desc
+
+ ## Get access to DataPtr object
+ @property
+ def input_data(self):
+ cdef C.DataPtr c_data_ptr = deref(self._ptr).getInputData()
+ data_ptr = DataPtr()
+ data_ptr._ptr = c_data_ptr
+ return data_ptr
+
+ @input_data.setter
+ def input_data(self, input_ptr : DataPtr):
+ deref(self._ptr).setInputData(input_ptr._ptr)
+
+
+## This class contains const information about each input of the network.
+# Provides same interface as InputInfoPtr object except properties setters
+cdef class InputInfoCPtr:
+ ## Name of this input
+ @property
+ def name(self):
+ return deref(self._ptr).name().decode()
+
+ ## Precision of this input
+ @property
+ def precision(self):
+ return deref(self._ptr).getPrecision().name().decode()
+
+ ## Get access to DataPtr object
+ @property
+ def input_data(self):
+ cdef C.DataPtr c_data_ptr = deref(self._ptr).getInputData()
+ data_ptr = DataPtr()
+ data_ptr._ptr = c_data_ptr
+ return data_ptr
+
+ ## tensor_desc of this input
+ @property
+ def tensor_desc(self):
+ cdef CTensorDesc c_tensor_desc = deref(self._ptr).getTensorDesc()
+ precision = c_tensor_desc.getPrecision().name().decode()
+ layout = c_tensor_desc.getLayout()
+ dims = c_tensor_desc.getDims()
+ tensor_desc = TensorDesc(precision, dims, layout_int_to_str_map[layout])
+ tensor_desc.impl = c_tensor_desc
+ return tensor_desc
+
+
## This class is the layer data representation.
cdef class DataPtr:
## Name of the data object
@property
def name(self):
return deref(self._ptr).getName().decode()
+
## Precision of the data object
@property
def precision(self):
return deref(self._ptr).getPrecision().name().decode()
+
@precision.setter
def precision(self, precision):
if precision not in supported_precisions:
raise ValueError("Unsupported precision {}! List of supported precisions: {}".format(precision,
supported_precisions))
deref(self._ptr).setPrecision(C.Precision.FromStr(precision.encode()))
+
## Shape (dimensions) of the data object
@property
def shape(self):
return deref(self._ptr).getDims()
+
## Layout of the data object
@property
def layout(self):
return layout_int_to_str_map[deref(self._ptr).getLayout()]
+
@layout.setter
def layout(self, layout):
if layout not in layout_str_to_enum.keys():
raise ValueError("Unsupported layout {}! "
"List of supported layouts: {}".format(layout, list(layout_str_to_enum.keys())))
deref(self._ptr).setLayout(layout_str_to_enum[layout])
+
## Checks if the current data object is resolved
@property
def initialized(self):
return deref(self._ptr).isInitialized()
+
@property
def creator_layer(self):
cdef C.CNNLayerWeakPtr _l_ptr = deref(self._ptr).getCreatorLayer()
else:
raise RuntimeError("Creator IENetLayer of DataPtr object with name {} already released!".format(self.name))
return creator_layer
+
@property
def input_to(self):
cdef map[string, C.CNNLayerPtr] _l_ptr_map = deref(self._ptr).getInputTo()
for i in range(deref(self.impl).infer_requests.size()):
infer_request = InferRequest()
infer_request.impl = &(deref(self.impl).infer_requests[i])
- infer_request._inputs_list = list(self.inputs.keys())
+ infer_request._inputs_list = list(self.input_info.keys())
infer_request._outputs_list = list(self.outputs.keys())
self._infer_requests.append(infer_request)
raise Exception("Mismatch of infer requests number!")
return self._infer_requests
+
+ ## A dictionary that maps input layer names to InputInfoCPtr objects
+ @property
+ def input_info(self):
+ cdef map[string, C.InputInfo.CPtr] c_inputs = deref(self.impl).getInputsInfo()
+ inputs = {}
+ cdef InputInfoCPtr input_info_ptr
+ for in_ in c_inputs:
+ input_info_ptr = InputInfoCPtr()
+ input_info_ptr._ptr = in_.second
+ inputs[in_.first.decode()] = input_info_ptr
+ return inputs
+
+ ## \note The property is deprecated. Please use the input_info property
+ # to get the map of inputs
+ #
## A dictionary that maps input layer names to DataPtr objects
@property
def inputs(self):
+ warnings.filterwarnings("always", category=DeprecationWarning)
+ warnings.warn("'inputs' property of ExecutableNetwork class is deprecated. "
+ "To access DataPtrs user need to use 'input_data' property "
+ "of InputInfoCPtr objects which can be acessed by 'input_info' property.",
+ DeprecationWarning)
cdef map[string, C.DataPtr] c_inputs = deref(self.impl).getInputs()
inputs = {}
cdef DataPtr data_ptr
# ```python
# ie = IECore()
# net = ie.read_network(model=path_to_xml_file, weights=path_to_bin_file)
- # exec_net = ie.load_network(network=net, device_name="MYRIAD", num_requsts=2)
+ # exec_net = ie.load_network(network=net, device_name="MYRIAD", num_requests=2)
# exec_net.export(path_to_file_to_save)
# ```
def export(self, model_file: str):
cpdef BlobBuffer _get_blob_buffer(self, const string & blob_name):
cdef BlobBuffer buffer = BlobBuffer()
- cdef Blob.Ptr blob_ptr
+ cdef CBlob.Ptr blob_ptr
deref(self.impl).getBlobPtr(blob_name, blob_ptr)
buffer.reset(blob_ptr)
return buffer
- ## Dictionary that maps input layer names to corresponding IEBlobs
+ ## Dictionary that maps input layer names to corresponding Blobs
@property
def input_blobs(self):
input_blobs = {}
if input in self._user_blobs:
input_blobs[input] = self._user_blobs[input]
else:
- blob = IEBlob()
+ blob = Blob()
deref(self.impl).getBlobPtr(input.encode(), blob._ptr)
input_blobs[input] = blob
return input_blobs
- ## Dictionary that maps output layer names to corresponding IEBlobs
+ ## Dictionary that maps output layer names to corresponding Blobs
@property
def output_blobs(self):
output_blobs = {}
for output in self._outputs_list:
- blob = IEBlob()
+ blob = Blob()
deref(self.impl).getBlobPtr(output.encode(), blob._ptr)
output_blobs[output] = deepcopy(blob)
return output_blobs
- ## Sets user defined IEBlob for the infer request
+ ## Sets user defined Blob for the infer request
# @param blob_name: A name of input blob
- # @param blob: IEBlob object to set for the infer request
+ # @param blob: Blob object to set for the infer request
# @return None
#
# Usage example:\n
# ie = IECore()
# net = IENetwork("./model.xml", "./model.bin")
# exec_net = ie.load_network(net, "CPU", num_requests=2)
- # td = IETensorDesc("FP32", (1, 3, 224, 224), "NCHW")
+ # td = TensorDesc("FP32", (1, 3, 224, 224), "NCHW")
# blob_data = np.ones(shape=(1, 3, 224, 224), dtype=np.float32)
- # blob = IEBlob(td, blob_data)
+ # blob = Blob(td, blob_data)
# exec_net.requests[0].set_blob(blob_name="input_blob_name", blob=blob),
# ```
- def set_blob(self, blob_name : str, blob : IEBlob):
+ def set_blob(self, blob_name : str, blob : Blob):
deref(self.impl).setBlob(blob_name.encode(), blob._ptr)
self._user_blobs[blob_name] = blob
## Starts synchronous inference of the infer request and fill outputs array
## Dictionary with layer arbitrary layer blobs including weights and biases as any.
@property
def blobs(self):
- cdef map[string, Blob.Ptr] c_blobs_map
+ cdef map[string, CBlob.Ptr] c_blobs_map
c_blobs_map = deref(self._ptr).blobs
blobs_map = {}
cdef BlobBuffer weights_buffer
weights_buffer.reset(blob.second)
blobs_map[blob.first.decode()] = weights_buffer.to_numpy()
return blobs_map
+
## \note This property is deprecated.
# Please use blobs property instead.
#
name = bytes(self.impl.name)
return name.decode()
- ## A dictionary that maps input layer names to DataPtr objects.
+ ## A dictionary that maps input layer names to InputInfoPtr objects.
+ @property
+ def input_info(self):
+ cdef map[string, C.InputInfo.Ptr] c_inputs = self.impl.getInputsInfo()
+ inputs = {}
+ cdef InputInfoPtr input_info_ptr
+ for input in c_inputs:
+ input_info_ptr = InputInfoPtr()
+ input_info_ptr._ptr = input.second
+ inputs[input.first.decode()] = input_info_ptr
+ return inputs
+
+ ## \note The property is deprecated. Please use the input_info property
+ # to get the map of inputs
+ #
+ ## A dictionary that maps input layer names to DataPtr objects
@property
def inputs(self):
+ warnings.filterwarnings("always", category=DeprecationWarning)
+ warnings.warn("'inputs' property of IENetwork class is deprecated. "
+ "To access DataPtrs user need to use 'input_data' property "
+ "of InputInfoPtr objects which can be acessed by 'input_info' property.",
+ DeprecationWarning)
cdef map[string, C.DataPtr] c_inputs = self.impl.getInputs()
inputs = {}
cdef DataPtr data_ptr
# print(net.batch_size)
# net.batch_size = 4
# print(net.batch_size)
- # print(net.inputs['data'].shape)
+ # print(net.input_info['data'].input_data.shape)
# ```
@property
def batch_size(self):
return self.impl.getBatch()
+
## \note This property is deprecated:
# network precision does not make sense, use precision on edges.
#
# ```python
# ie = IECore()
# net = ie.read_network(model=path_to_xml_file, weights=path_to_bin_file)
- # input_layer = next(iter(net.inputs))
- # n, c, h, w = net.inputs[input_layer]
+ # input_layer = next(iter(net.input_info))
+ # n, c, h, w = net.input_info[input_layer].input_data.shape
# net.reshape({input_layer: (n, c, h*2, w*2)})
# ```
def reshape(self, input_shapes: dict):
cdef map[string, vector[size_t]] c_input_shapes;
cdef vector[size_t] c_shape
- net_inputs = self.inputs
+ net_inputs = self.input_info
for input, shape in input_shapes.items():
c_shape = []
if input not in net_inputs:
## This class is the main plugin interface and serves to initialize and configure the plugin.
#
-#\note This class is deprecated: Use IECore instead
+# \note This class is deprecated: Use IECore instead
#
cdef class IEPlugin:
## Class constructor
# ```python
# net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
# ie = IECore()
- # exec_net = ie.load_network(network=net, device_name="CPU", num_requsts=2)
+ # exec_net = ie.load_network(network=net, device_name="CPU", num_requests=2)
# ```
cpdef ExecutableNetwork load(self, IENetwork network, int num_requests=1, config=None):
cdef ExecutableNetwork exec_net = ExecutableNetwork()
cdef class BlobBuffer:
"""Copy-less accessor for Inference Engine Blob"""
- cdef reset(self, Blob.Ptr & ptr, vector[size_t] representation_shape = []):
+ cdef reset(self, CBlob.Ptr & ptr, vector[size_t] representation_shape = []):
self.ptr = ptr
- cdef TensorDesc desc = deref(ptr).getTensorDesc()
+ cdef CTensorDesc desc = deref(ptr).getTensorDesc()
cdef SizeVector shape
if len(representation_shape) == 0:
shape = desc.getDims()
buffer.strides = self.strides.data()
buffer.suboffsets = NULL
- cdef char*_get_blob_format(self, const TensorDesc & desc):
+ cdef char*_get_blob_format(self, const CTensorDesc & desc):
cdef Precision precision = desc.getPrecision()
name = bytes(precision.name()).decode()
# todo: half floats
}
}
+const std::map <std::string, InferenceEngine::InputInfo::Ptr> InferenceEnginePython::IENetwork::getInputsInfo() {
+ std::map <std::string, InferenceEngine::InputInfo::Ptr> inputs;
+ const InferenceEngine::InputsDataMap &inputsInfo = actual->getInputsInfo();
+ for (auto &in : inputsInfo) {
+ inputs[in.first] = in.second;
+ }
+ return inputs;
+}
+
const std::map <std::string, InferenceEngine::DataPtr> InferenceEnginePython::IENetwork::getInputs() {
std::map <std::string, InferenceEngine::DataPtr> inputs;
const InferenceEngine::InputsDataMap &inputsInfo = actual->getInputsInfo();
return pyInputs;
}
+std::map <std::string, InferenceEngine::InputInfo::CPtr> InferenceEnginePython::IEExecNetwork::getInputsInfo() {
+ InferenceEngine::ConstInputsDataMap inputsDataMap;
+ InferenceEngine::ResponseDesc response;
+ IE_CHECK_CALL(actual->GetInputsInfo(inputsDataMap, &response));
+ std::map <std::string, InferenceEngine::InputInfo::CPtr> pyInputs;
+ for (const auto &item : inputsDataMap) {
+ pyInputs[item.first] = item.second;
+ }
+ return pyInputs;
+}
+
std::map <std::string, InferenceEngine::CDataPtr> InferenceEnginePython::IEExecNetwork::getOutputs() {
InferenceEngine::ConstOutputsDataMap outputsDataMap;
InferenceEngine::ResponseDesc response;
const std::vector <InferenceEngine::CNNLayerPtr> getLayers();
+ const std::map<std::string, InferenceEngine::InputInfo::Ptr> getInputsInfo();
+
const std::map<std::string, InferenceEngine::DataPtr> getInputs();
const std::map<std::string, InferenceEngine::DataPtr> getOutputs();
void infer();
void exportNetwork(const std::string & model_file);
+ std::map<std::string, InferenceEngine::InputInfo::CPtr> getInputsInfo();
std::map<std::string, InferenceEngine::DataPtr> getInputs();
std::map<std::string, InferenceEngine::CDataPtr> getOutputs();
cdef cppclass TBlob[T]:
ctypedef shared_ptr[TBlob[T]] Ptr
- cdef cppclass Blob:
- ctypedef shared_ptr[Blob] Ptr
- const TensorDesc& getTensorDesc() except +
+ cdef cppclass CBlob "InferenceEngine::Blob":
+ ctypedef shared_ptr[CBlob] Ptr
+ const CTensorDesc& getTensorDesc() except +
size_t element_size() except +
void allocate()
- cdef TBlob[Type].Ptr make_shared_blob[Type](const TensorDesc& tensorDesc)
+ cdef TBlob[Type].Ptr make_shared_blob[Type](const CTensorDesc& tensorDesc)
- cdef TBlob[Type].Ptr make_shared_blob[Type](const TensorDesc& tensorDesc, Type* ptr, size_t size)
+ cdef TBlob[Type].Ptr make_shared_blob[Type](const CTensorDesc& tensorDesc, Type* ptr, size_t size)
- cdef cppclass TensorDesc:
- TensorDesc() except +
- TensorDesc(const Precision& precision, SizeVector dims, Layout layout) except +
+ cdef cppclass CTensorDesc "InferenceEngine::TensorDesc":
+ CTensorDesc() except +
+ CTensorDesc(const Precision& precision, SizeVector dims, Layout layout) except +
SizeVector& getDims() except +
void setDims(const SizeVector& dims) except +
Layout getLayout() except +
ctypedef shared_ptr[const Data] CDataPtr
+ cdef cppclass InputInfo:
+ ctypedef shared_ptr[InputInfo] Ptr
+ ctypedef shared_ptr[const InputInfo] CPtr
+ Precision getPrecision() const
+ void setPrecision(Precision p)
+ Layout getLayout()
+ void setLayout(Layout l)
+ const string& name() const
+ DataPtr getInputData() const
+ CPreProcessInfo& getPreProcess()
+ const CTensorDesc& getTensorDesc() const
+ void setInputData(DataPtr inputPtr)
+
+
+ cdef cppclass CPreProcessChannel "InferenceEngine::PreProcessChannel":
+ ctypedef shared_ptr[CPreProcessChannel] Ptr
+ CBlob.Ptr meanData
+ float stdScale
+ float meanValue
+
+ cdef cppclass CPreProcessInfo "InferenceEngine::PreProcessInfo":
+ CPreProcessChannel.Ptr& operator[](size_t index)
+ size_t getNumberOfChannels() const
+ void init(const size_t numberOfChannels)
+ void setMeanImage(const CBlob.Ptr& meanImage)
+ void setMeanImageForChannel(const CBlob.Ptr& meanImage, const size_t channel)
+ vector[CPreProcessChannel.Ptr] _channelsInfo
+ ColorFormat getColorFormat() const
+ void setColorFormat(ColorFormat fmt)
+ ResizeAlgorithm getResizeAlgorithm() const
+ void setResizeAlgorithm(const ResizeAlgorithm& alg)
+ MeanVariant getMeanVariant() const
+ void setVariant(const MeanVariant& variant)
+
+ ctypedef map[string, InputInfo.CPtr] InputsDataMap
+
cdef cppclass Precision:
const char*name() const
@staticmethod
vector[DataWeakPtr] insData
string affinity
map[string, string] params
- map[string, Blob.Ptr] blobs
+ map[string, CBlob.Ptr] blobs
ctypedef weak_ptr[CNNLayer] CNNLayerWeakPtr
ctypedef shared_ptr[CNNLayer] CNNLayerPtr
const char *description
apiVersion apiVersion
+ cpdef enum MeanVariant:
+ pass
+
+ cpdef enum ResizeAlgorithm:
+ pass
+
+ cpdef enum ColorFormat:
+ pass
+
cdef enum Layout:
ANY
NCHW
unsigned int execution_index
cdef cppclass WeightsInfo:
- Blob.Ptr & weights;
- Blob.Ptr & biases;
- map[string, Blob.Ptr] custom_blobs;
+ CBlob.Ptr & weights;
+ CBlob.Ptr & biases;
+ map[string, CBlob.Ptr] custom_blobs;
cdef cppclass IEExecNetwork:
vector[InferRequestWrap] infer_requests
IENetwork GetExecGraphInfo() except +
map[string, DataPtr] getInputs() except +
map[string, CDataPtr] getOutputs() except +
+ map[string, InputInfo.CPtr] getInputsInfo()
void exportNetwork(const string & model_file) except +
object getMetric(const string & metric_name) except +
object getConfig(const string & metric_name) except +
string precision
map[string, vector[size_t]] inputs
const vector[CNNLayerPtr] getLayers() except +
- map[string, DataPtr] getInputs() except +
+ const map[string, InputInfo.Ptr] getInputsInfo() except +
+ const map[string, DataPtr] getInputs() except +
map[string, DataPtr] getOutputs() except +
void addOutput(string &, size_t) except +
void setAffinity(map[string, string] & types_affinity_map, map[string, string] & layers_affinity_map) except +
cdef cppclass InferRequestWrap:
double exec_time;
int index;
- void getBlobPtr(const string & blob_name, Blob.Ptr & blob_ptr) except +
- void setBlob(const string & blob_name, const Blob.Ptr & blob_ptr) except +
+ void getBlobPtr(const string & blob_name, CBlob.Ptr & blob_ptr) except +
+ void setBlob(const string & blob_name, const CBlob.Ptr & blob_ptr) except +
map[string, ProfileInfo] getPerformanceCounts() except +
void infer() except +
void infer_async() except +
object getMetric(const string & deviceName, const string & name) except +
object getConfig(const string & deviceName, const string & name) except +
- cdef T*get_buffer[T](Blob &)
+ cdef T*get_buffer[T](CBlob &)
cdef string get_version()
import numpy as np
-from openvino.inference_engine import IETensorDesc, IEBlob
+from openvino.inference_engine import TensorDesc, Blob
from conftest import image_path
path_to_image = image_path()
+
def test_init_with_tensor_desc():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NHWC")
- blob = IEBlob(tensor_desc)
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NHWC")
+ blob = Blob(tensor_desc)
assert isinstance(blob.buffer, np.ndarray)
assert blob.tensor_desc == tensor_desc
def test_init_with_numpy():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array = np.ones(shape=(1, 3, 127, 127), dtype=np.float32)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
assert isinstance(blob.buffer, np.ndarray)
assert blob.tensor_desc == tensor_desc
def test_get_tensor_desc():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
- blob = IEBlob(tensor_desc)
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ blob = Blob(tensor_desc)
assert blob.tensor_desc == tensor_desc
def test_get_buffer():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array = np.ones(shape=(1, 3, 127, 127), dtype=np.float32)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
assert np.array_equal(blob.buffer, array)
+
def test_write_to_buffer_fp32():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.float32)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.float32)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
@pytest.mark.skip(reason="Need to figure out how to implement right conversion")
def test_write_to_buffer_fp16():
- tensor_desc = IETensorDesc("FP16", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.float16)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.float16)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_int8():
- tensor_desc = IETensorDesc("I8", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("I8", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int8)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int8)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_uint8():
- tensor_desc = IETensorDesc("U8", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("U8", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.uint8)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.uint8)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_int32():
- tensor_desc = IETensorDesc("I32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("I32", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int32)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int32)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_int16():
- tensor_desc = IETensorDesc("I16", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("I16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int16)
- blob = IEBlob(tensor_desc, array)
- ones_arr = np.ones(shape=(1, 3, 127, 127), dtype= np.int16)
+ blob = Blob(tensor_desc, array)
+ ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int16)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_uint16():
- tensor_desc = IETensorDesc("U16", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("U16", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.uint16)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.uint16)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_write_to_buffer_int64():
- tensor_desc = IETensorDesc("I64", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("I64", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 3, 127, 127), dtype=np.int64)
- blob = IEBlob(tensor_desc, array)
+ blob = Blob(tensor_desc, array)
ones_arr = np.ones(shape=(1, 3, 127, 127), dtype=np.int64)
blob.buffer[:] = ones_arr
- assert np.array_equal(blob.buffer, ones_arr)
+ assert np.array_equal(blob.buffer, ones_arr)
+
def test_incompatible_array_and_td():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
array = np.zeros(shape=(1, 2, 3, 4), dtype=np.float32)
with pytest.raises(AttributeError) as e:
- IEBlob(tensor_desc, array)
+ Blob(tensor_desc, array)
assert "Number of elements in provided numpy array 24 and " \
"required by TensorDesc 48387 are not equal" in str(e.value)
+
def test_incompatible_input_precision():
import cv2
n, c, h, w = (1, 3, 32, 32)
image = cv2.resize(image, (h, w))
image = image.transpose((2, 0, 1))
image = image.reshape((n, c, h, w))
- tensor_desc = IETensorDesc("FP32", [1, 3, 32, 32], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 32, 32], "NCHW")
with pytest.raises(ValueError) as e:
- IEBlob(tensor_desc, image)
+ Blob(tensor_desc, image)
assert "Data type float64 of provided numpy array " \
"doesn't match to TensorDesc precision FP32" in str(e.value)
test_net_xml, test_net_bin = model_path()
+
def test_name(device):
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
test_net_xml, test_net_bin = model_path()
+
def layer_out_data():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
import numpy as np
import os
import pytest
+import warnings
from openvino.inference_engine import ie_api as ie
from conftest import model_path, image_path
img = read_image()
res = exec_net.infer({'data': img})
res2 = exec_net2.infer({'data': img})
+ del ie_core
del exec_net
del exec_net2
- del ie_core
assert np.allclose(res['fc_out'], res2['fc_out'], atol=1E-4, rtol=1E-4)
del ie_core
-def test_inputs(device):
+def test_input_info(device):
+ ie_core = ie.IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie_core.load_network(net, device, num_requests=5)
+ assert isinstance(exec_net.input_info['data'], ie.InputInfoCPtr)
+ assert exec_net.input_info['data'].name == "data"
+ assert exec_net.input_info['data'].precision == "FP32"
+ assert isinstance(exec_net.input_info['data'].input_data, ie.DataPtr)
+ del exec_net
+ del ie_core
+
+
+def test_inputs_deprecated(device):
ie_core = ie.IECore()
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
exec_net = ie_core.load_network(net, device, num_requests=5)
- assert len(exec_net.inputs) == 1
- assert "data" in exec_net.inputs
- assert isinstance(exec_net.inputs['data'], ie.DataPtr)
+ with warnings.catch_warnings(record=True) as w:
+ assert len(exec_net.inputs) == 1
+ assert "data" in exec_net.inputs
+ assert isinstance(exec_net.inputs['data'], ie.DataPtr)
+ assert len(w) == 3
+ for i in range (len(w)):
+ assert "'inputs' property of ExecutableNetwork class is deprecated. " \
+ "To access DataPtrs user need to use 'input_data' property " \
+ "of InputInfoCPtr objects which " \
+ "can be acessed by 'input_info' property." in str(w[i].message)
del exec_net
del ie_core
ie_core = ie.IECore()
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
exec_net = ie_core.load_network(net, device)
- del ie_core
img = read_image()
res = exec_net.infer({'data': img})
assert np.argmax(res['fc_out'][0]) == 2
del exec_net
+ del ie_core
def test_exec_graph(device):
del ie_core
pass
-# TODO: return when cvs-29487 will be fixed
-@pytest.mark.skip(reason="get_metric('NETWORK_NAME') returns wrong name, problem somewhere in ngraph")
+
def test_get_metric(device):
ie_core = ie.IECore()
net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
test_net_xml, test_net_bin = model_path()
+
def test_name():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert len(recwarn) == 1
assert recwarn.pop(DeprecationWarning)
+
def test_precision_setter(recwarn):
warnings.simplefilter("always")
ie = IECore()
assert len(recwarn) == 1
assert recwarn.pop(DeprecationWarning)
+
def test_affinuty_getter():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert net.layers['19/Fused_Add_'].blobs["biases"].size != 0
assert net.layers['19/Fused_Add_'].blobs["weights"].size != 0
+
def test_weights(recwarn):
warnings.simplefilter("always")
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
assert isinstance(net.layers['27'].out_data[0], DataPtr)
+
def test_in_data():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
import warnings
import numpy as np
-from openvino.inference_engine import IENetwork, IENetLayer, DataPtr, LayersStatsMap, LayerStats, IECore
+from openvino.inference_engine import IECore, IENetwork, IENetLayer, DataPtr, \
+ LayersStatsMap, LayerStats, InputInfoPtr, PreProcessInfo
from conftest import model_path
+
test_net_xml, test_net_bin = model_path()
+
def test_create_ie_network_deprecated():
with warnings.catch_warnings(record=True) as w:
net = IENetwork(model=test_net_xml, weights=test_net_bin)
"Please, use IECore.read_network() method instead" in str(w[0].message)
-@pytest.mark.skip(reason="name) returns wrong name, problem somewhere in ngraph")
def test_name():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.name == "model"
+ assert net.name == "test_model"
-def test_inputs():
+def test_inputs_deprecated():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert isinstance(net.inputs['data'], DataPtr)
- assert net.inputs['data'].layout == "NCHW"
- assert net.inputs['data'].precision == "FP32"
- assert net.inputs['data'].shape == [1, 3, 32, 32]
+ with warnings.catch_warnings(record=True) as w:
+ inp = net.inputs
+ assert isinstance(inp['data'], DataPtr)
+ assert inp['data'].layout == "NCHW"
+ assert inp['data'].precision == "FP32"
+ assert inp['data'].shape == [1, 3, 32, 32]
+ assert len(w) == 1
+ assert "'inputs' property of IENetwork class is deprecated. " \
+ "To access DataPtrs user need to use 'input_data' property " \
+ "of InputInfoPtr objects which " \
+ "can be acessed by 'input_info' property." in str(w[-1].message)
+
+
+def test_input_info():
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ assert isinstance(net.input_info['data'], InputInfoPtr)
+ assert net.input_info['data'].layout == "NCHW"
+ assert net.input_info['data'].precision == "FP32"
+ assert isinstance(net.input_info['data'].input_data, DataPtr)
+ assert isinstance(net.input_info['data'].preprocess_info, PreProcessInfo)
-def test_input_precision_setter():
+def test_input_info_precision_setter():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.inputs['data'].layout == "NCHW"
- net.inputs['data'].layout = "NHWC"
- assert net.inputs['data'].layout == "NHWC"
+ assert net.input_info['data'].layout == "NCHW"
+ net.input_info['data'].layout = "NHWC"
+ assert net.input_info['data'].layout == "NHWC"
-def test_input_layout_setter():
+def test_input_input_info_layout_setter():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- assert net.inputs['data'].precision == "FP32"
- net.inputs['data'].precision = "I8"
- assert net.inputs['data'].precision == "I8"
+ assert net.input_info['data'].precision == "FP32"
+ net.input_info['data'].precision = "I8"
+ assert net.input_info['data'].precision == "I8"
def test_input_unsupported_precision_setter():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
with pytest.raises(ValueError) as e:
- net.inputs['data'].precision = "BLA"
+ net.input_info['data'].precision = "BLA"
assert "Unsupported precision BLA! List of supported precisions: " in str(e.value)
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
with pytest.raises(ValueError) as e:
- net.inputs['data'].layout = "BLA"
+ net.input_info['data'].layout = "BLA"
assert "Unsupported layout BLA! List of supported layouts: " in str(e.value)
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
net.batch_size = 4
assert net.batch_size == 4
- assert net.inputs['data'].shape == [4, 3, 32, 32]
+ assert net.input_info['data'].input_data.shape == [4, 3, 32, 32]
+
def test_batch_size_after_reshape():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
- net.reshape({'data' : [4, 3, 32, 32]})
+ net.reshape({'data': [4, 3, 32, 32]})
assert net.batch_size == 4
- assert net.inputs['data'].shape == [4, 3, 32, 32]
- net.reshape({'data' : [8, 3, 32, 32]})
+ assert net.input_info['data'].input_data.shape == [4, 3, 32, 32]
+ net.reshape({'data': [8, 3, 32, 32]})
assert net.batch_size == 8
- assert net.inputs['data'].shape == [8, 3, 32, 32]
+ assert net.input_info['data'].input_data.shape == [8, 3, 32, 32]
+
def test_layers():
ie = IECore()
net = ie.read_network(model=test_net_xml, weights=test_net_bin)
layers_name = [key for key in net.layers]
- assert sorted(layers_name) == ['19/Fused_Add_', '21', '22', '23', '24/Fused_Add_', '26', '27', '29', 'data', 'fc_out']
+ assert sorted(layers_name) == ['19/Fused_Add_', '21', '22', '23', '24/Fused_Add_',
+ '26', '27', '29', 'data', 'fc_out']
assert isinstance(net.layers['19/Fused_Add_'], IENetLayer)
test_net_xml, test_net_bin = model_path()
+
def test_init_plugin(device):
with warnings.catch_warnings(record=True) as w:
plugin = IEPlugin(device, None)
test_net_xml, test_net_bin = model_path(is_myriad)
path_to_img = image_path()
+
def read_image():
import cv2
n, c, h, w = (1, 3, 32, 32)
ie_core = ie.IECore()
net = ie_core.read_network(test_net_xml, test_net_bin)
executable_network = ie_core.load_network(net, device, num_requests=2)
- td = ie.IETensorDesc("FP32", (1, 3, 32, 32), "NCHW")
+ td = ie.TensorDesc("FP32", (1, 3, 32, 32), "NCHW")
assert executable_network.requests[0].input_blobs['data'].tensor_desc == td
ie_core = ie.IECore()
net = ie_core.read_network(test_net_xml, test_net_bin)
executable_network = ie_core.load_network(net, device, num_requests=2)
- td = ie.IETensorDesc("FP32", (1, 10), "NC")
+ td = ie.TensorDesc("FP32", (1, 10), "NC")
assert executable_network.requests[0].output_blobs['fc_out'].tensor_desc == td
executable_network = ie_core.load_network(net, device, num_requests=2)
with warnings.catch_warnings(record=True) as w:
inputs = executable_network.requests[0].inputs
- assert "'inputs' property of InferRequest is deprecated. Please instead use 'input_blobs' property." in str(
- w[-1].message)
+ assert "'inputs' property of InferRequest is deprecated. " \
+ "Please instead use 'input_blobs' property." in str(w[-1].message)
del executable_network
del ie_core
del net
ie_core.set_config({"DYN_BATCH_ENABLED": "YES"}, device)
net = ie_core.read_network(test_net_xml, test_net_bin)
net.batch_size = 10
- data = np.zeros(shape=net.inputs['data'].shape)
+ data = np.zeros(shape=net.input_info['data'].input_data.shape)
exec_net = ie_core.load_network(net, device)
data[0] = read_image()[0]
request = exec_net.requests[0]
def test_set_negative_batch_size(device):
ie_core = ie.IECore()
net = ie_core.read_network(test_net_xml, test_net_bin)
- exec_net = ie_core.load_network(net, device, num_requests=1)
+ exec_net = ie_core.load_network(net, device, num_requests=1)
request = exec_net.requests[0]
with pytest.raises(ValueError) as e:
request.set_batch(-1)
net = ie_core.read_network(test_net_xml, test_net_bin)
exec_net_1 = ie_core.load_network(network=net, device_name=device, num_requests=1)
- net.inputs['data'].layout = "NHWC"
+ net.input_info['data'].layout = "NHWC"
exec_net_2 = ie_core.load_network(network=net, device_name=device, num_requests=1)
img = read_image()
res_1 = np.sort(exec_net_1.infer({"data": img})['fc_out'])
img = np.transpose(img, axes=(0, 2, 3, 1)).astype(np.float32)
- tensor_desc = ie.IETensorDesc("FP32", [1, 3, 32, 32], "NHWC")
- img_blob = ie.IEBlob(tensor_desc, img)
+ tensor_desc = ie.TensorDesc("FP32", [1, 3, 32, 32], "NHWC")
+ img_blob = ie.Blob(tensor_desc, img)
request = exec_net_2.requests[0]
request.set_blob('data', img_blob)
request.infer()
--- /dev/null
+import pytest
+
+from openvino.inference_engine import InputInfoCPtr, DataPtr, IECore, TensorDesc
+from conftest import model_path
+
+
+test_net_xml, test_net_bin = model_path()
+
+
+def test_name(device):
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie.load_network(net, device, num_requests=5)
+ assert isinstance(exec_net.input_info['data'], InputInfoCPtr)
+ assert exec_net.input_info['data'].name == "data", "Incorrect name"
+ del exec_net
+
+
+def test_precision(device):
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie.load_network(net, device, num_requests=5)
+ assert isinstance(exec_net.input_info['data'], InputInfoCPtr)
+ assert exec_net.input_info['data'].precision == "FP32", "Incorrect precision"
+ del exec_net
+
+
+def test_no_precision_setter(device):
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie.load_network(net, device, num_requests=5)
+ with pytest.raises(AttributeError) as e:
+ exec_net.input_info['data'].precision = "I8"
+ assert "attribute 'precision' of 'openvino.inference_engine.ie_api.InputInfoCPtr' " \
+ "objects is not writable" in str(e.value)
+ del exec_net
+
+
+def test_input_data(device):
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie.load_network(net, device, num_requests=5)
+ assert isinstance(exec_net.input_info['data'], InputInfoCPtr)
+ assert isinstance(exec_net.input_info['data'].input_data, DataPtr), "Incorrect precision for layer 'fc_out'"
+ del exec_net
+
+
+def test_tensor_desc(device):
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ exec_net = ie.load_network(net, device, num_requests=5)
+ tensor_desc = exec_net.input_info['data'].tensor_desc
+ assert isinstance(tensor_desc, TensorDesc)
+ assert tensor_desc.layout == "NCHW"
--- /dev/null
+import pytest
+
+from openvino.inference_engine import InputInfoPtr, PreProcessInfo, DataPtr, IECore, TensorDesc, ColorFormat
+from conftest import model_path
+
+
+test_net_xml, test_net_bin = model_path()
+
+
+def get_input_info():
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ return net.input_info["data"]
+
+
+def test_input_info():
+ assert isinstance(get_input_info(), InputInfoPtr)
+
+
+def test_input_data():
+ assert isinstance(get_input_info().input_data, DataPtr)
+
+
+def test_input_data_setter():
+ ie = IECore()
+ net = ie.read_network(model=test_net_xml, weights=test_net_bin)
+ input_info = net.input_info["data"]
+ other_input_data = net.outputs["fc_out"]
+ input_info.input_data = other_input_data
+ assert input_info.input_data.name == "fc_out"
+
+
+def test_incorrect_input_info_setter():
+ with pytest.raises(TypeError) as e:
+ get_input_info().input_data = "dfds"
+ assert "Argument 'input_ptr' has incorrect type" in str(e.value)
+
+
+def test_name():
+ assert get_input_info().name == "data"
+
+
+def test_precision():
+ assert get_input_info().precision == "FP32"
+
+
+def test_precision_setter():
+ input_info = get_input_info()
+ input_info.precision = "I8"
+ assert input_info.precision == "I8", "Incorrect precision"
+
+
+def test_incorrect_precision_setter():
+ with pytest.raises(ValueError) as e:
+ get_input_info().precision = "123"
+ assert "Unsupported precision 123! List of supported precisions:" in str(e.value)
+
+
+def test_layout():
+ assert get_input_info().layout == "NCHW"
+
+
+def test_layout_setter():
+ input_info = get_input_info()
+ input_info.layout = "NHWC"
+ assert input_info.layout == "NHWC", "Incorrect layout"
+
+
+def test_incorrect_layout_setter():
+ with pytest.raises(ValueError) as e:
+ get_input_info().layout = "123"
+ assert "Unsupported layout 123! List of supported layouts:" in str(e.value)
+
+
+def test_preprocess_info():
+ preprocess_info = get_input_info().preprocess_info
+ assert isinstance(preprocess_info, PreProcessInfo)
+ assert preprocess_info.color_format == ColorFormat.RAW
+
+
+def test_tensor_desc():
+ tensor_desc = get_input_info().tensor_desc
+ assert isinstance(tensor_desc, TensorDesc)
+ assert tensor_desc.layout == "NCHW"
--- /dev/null
+import pytest
+
+from openvino.inference_engine import PreProcessInfo, IECore, TensorDesc, Blob, PreProcessChannel,\
+ MeanVariant, ResizeAlgorithm, ColorFormat
+from conftest import model_path
+
+
+test_net_xml, test_net_bin = model_path()
+
+
+def get_preprocess_info():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ return net.input_info["data"].preprocess_info
+
+
+def test_preprocess_info():
+ assert isinstance(get_preprocess_info(), PreProcessInfo)
+
+
+def test_color_format():
+ preprocess_info = get_preprocess_info()
+ assert preprocess_info.color_format == ColorFormat.RAW
+
+
+def test_color_format_setter():
+ preprocess_info = get_preprocess_info()
+ preprocess_info.color_format = ColorFormat.BGR
+ assert preprocess_info.color_format == ColorFormat.BGR
+
+
+def test_resize_algorithm():
+ preprocess_info = get_preprocess_info()
+ assert preprocess_info.resize_algorithm == ResizeAlgorithm.NO_RESIZE
+
+
+def test_resize_algorithm_setter():
+ preprocess_info = get_preprocess_info()
+ preprocess_info.resize_algorithm = ResizeAlgorithm.RESIZE_BILINEAR
+ assert preprocess_info.resize_algorithm == ResizeAlgorithm.RESIZE_BILINEAR
+
+
+def test_mean_variant():
+ preprocess_info = get_preprocess_info()
+ assert preprocess_info.mean_variant == MeanVariant.NONE
+
+
+def test_mean_variant_setter():
+ preprocess_info = get_preprocess_info()
+ preprocess_info.mean_variant = MeanVariant.MEAN_IMAGE
+ assert preprocess_info.mean_variant == MeanVariant.MEAN_IMAGE
+
+
+def test_get_number_of_channels():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ assert net.input_info["data"].preprocess_info.get_number_of_channels() == 0
+
+
+def test_init():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ net.input_info['data'].preprocess_info.init(5)
+ assert net.input_info["data"].preprocess_info.get_number_of_channels() == 5
+
+
+def test_set_mean_image():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ tensor_desc = TensorDesc("FP32", [0, 127, 127], "CHW")
+ mean_image_blob = Blob(tensor_desc)
+ preprocess_info = net.input_info["data"].preprocess_info
+ preprocess_info.set_mean_image(mean_image_blob)
+ assert preprocess_info.mean_variant == MeanVariant.MEAN_IMAGE
+
+
+def test_get_pre_process_channel():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ preprocess_info = net.input_info["data"].preprocess_info
+ preprocess_info.init(1)
+ pre_process_channel = preprocess_info[0]
+ assert isinstance(pre_process_channel, PreProcessChannel)
+
+
+def test_set_mean_image_for_channel():
+ ie_core = IECore()
+ net = ie_core.read_network(model=test_net_xml, weights=test_net_bin)
+ tensor_desc = TensorDesc("FP32", [127, 127], "HW")
+ mean_image_blob = Blob(tensor_desc)
+ preprocess_info = net.input_info["data"].preprocess_info
+ preprocess_info.init(1)
+ preprocess_info.set_mean_image_for_channel(mean_image_blob, 0)
+ pre_process_channel = preprocess_info[0]
+ assert isinstance(pre_process_channel.mean_data, Blob)
+ assert pre_process_channel.mean_data.tensor_desc.dims == [127, 127]
+ assert preprocess_info.mean_variant == MeanVariant.MEAN_IMAGE
import pytest
-from openvino.inference_engine import IETensorDesc
+from openvino.inference_engine import TensorDesc
def test_init():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
- assert isinstance(tensor_desc, IETensorDesc)
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ assert isinstance(tensor_desc, TensorDesc)
def test_precision():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
assert tensor_desc.precision == "FP32"
def test_layout():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
assert tensor_desc.layout == "NHWC"
def test_dims():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
assert tensor_desc.dims == [1, 127, 127, 3]
def test_incorrect_precision_setter():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
with pytest.raises(ValueError) as e:
tensor_desc.precision = "123"
assert "Unsupported precision 123! List of supported precisions:" in str(e.value)
def test_incorrect_layout_setter():
- tensor_desc = IETensorDesc("FP32", [1, 127, 127, 3], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 127, 127, 3], "NHWC")
with pytest.raises(ValueError) as e:
tensor_desc.layout = "123"
assert "Unsupported layout 123! List of supported layouts: " in str(e.value)
def test_init_incorrect_precision():
with pytest.raises(ValueError) as e:
- IETensorDesc("123", [1, 127, 127, 3], "NHWC")
+ TensorDesc("123", [1, 127, 127, 3], "NHWC")
assert "Unsupported precision 123! List of supported precisions: " in str(e.value)
def test_eq_operator():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NHWC")
- tensor_desc_2 = IETensorDesc("FP32", [1, 3, 127, 127], "NHWC")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NHWC")
+ tensor_desc_2 = TensorDesc("FP32", [1, 3, 127, 127], "NHWC")
assert tensor_desc == tensor_desc_2
def test_ne_operator():
- tensor_desc = IETensorDesc("FP32", [1, 3, 127, 127], "NHWC")
- tensor_desc_2 = IETensorDesc("FP32", [1, 3, 127, 127], "NCHW")
+ tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NHWC")
+ tensor_desc_2 = TensorDesc("FP32", [1, 3, 127, 127], "NCHW")
assert tensor_desc != tensor_desc_2