From 6e5f1123cc6e6693788f60cf82a9a0094d10a781 Mon Sep 17 00:00:00 2001 From: Kuporosova Date: Mon, 21 Jun 2021 18:24:33 +0300 Subject: [PATCH] [Python API] removal of deprecated python api --- .../src/openvino/inference_engine/ie_api.pyx | 117 ++---------------- .../openvino/inference_engine/ie_api_impl.cpp | 36 ------ .../openvino/inference_engine/ie_api_impl.hpp | 7 -- .../inference_engine/ie_api_impl_defs.pxd | 6 +- .../python/tests/test_ExecutableNetwork.py | 18 --- .../ie_bridges/python/tests/test_IENetwork.py | 64 +--------- .../python/tests/test_InferRequest.py | 26 ---- 7 files changed, 9 insertions(+), 265 deletions(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx index 66269fba630679..0b9b13993c1be8 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx @@ -923,25 +923,6 @@ cdef class ExecutableNetwork: 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.warn("'inputs' property of ExecutableNetwork class is deprecated. " - "To access DataPtrs user need to use 'input_data' property " - "of InputInfoCPtr objects which can be accessed by 'input_info' property.", - DeprecationWarning) - cdef map[string, C.DataPtr] c_inputs = deref(self.impl).getInputs() - inputs = {} - cdef DataPtr data_ptr - for in_ in c_inputs: - data_ptr = DataPtr() - data_ptr._ptr = in_.second - data_ptr._ptr_plugin = deref(self.impl).getPluginLink() - inputs[in_.first.decode()] = data_ptr - return inputs ## A dictionary that maps output layer names to CDataPtr objects @property @@ -1268,26 +1249,6 @@ cdef class InferRequest: "cpu_time": info.cpu_time, "execution_index": info.execution_index} return profile - ## A dictionary that maps input layer names to `numpy.ndarray` - # objects of proper shape with input data for the layer - @property - def inputs(self): - warnings.warn("'inputs' property of InferRequest is deprecated. Please instead use 'input_blobs' property.", - DeprecationWarning) - inputs = {} - for input in self._inputs_list: - inputs[input] = self._get_blob_buffer(input.encode()).to_numpy() - return inputs - - ## A dictionary that maps output layer names to `numpy.ndarray` objects with output data of the layer - @property - def outputs(self): - warnings.warn("'outputs' property of InferRequest is deprecated. Please instead use 'output_blobs' property.", - DeprecationWarning) - outputs = {} - for output in self._outputs_list: - outputs[output] = self._get_blob_buffer(output.encode()).to_numpy() - return deepcopy(outputs) ## Current infer request inference time in milliseconds @property @@ -1333,68 +1294,23 @@ cdef class InferRequest: cdef class IENetwork: ## Class constructor # - # \note Reading networks using IENetwork constructor is deprecated. - # Please, use IECore.read_network() method instead. + # @param model: A PyCapsule containing smart pointer to nGraph function. # - # @param model: A `.xml` file of the IR or PyCapsule containing smart pointer to nGraph function. - # In case of passing a `.xml` file attribute value can be a string path or bytes with file content - # depending on `init_from_buffer` attribute value - # . - # @param weights: A `.bin` file of the IR. Depending on `init_from_buffer` value, can be a string path or - # bytes with file content. - # @param init_from_buffer: Defines the way of how `model` and `weights` attributes are interpreted. - # If `False`, attributes are interpreted as strings with paths to .xml and .bin files - # of IR. If `True`, they are interpreted as Python `bytes` object with .xml and .bin files content. - # Ignored in case of `IENetwork` object initialization from nGraph function. # @return Instance of IENetwork class # # Usage example:\n # Initializing `IENetwork` object from IR files: # ```python - # net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file) - # ``` - # - # Initializing `IENetwork` object bytes with content of IR files: - # ```python - # with open(path_to_bin_file, 'rb') as f: - # bin = f.read() - # with open(path_to_xml_file, 'rb') as f: - # xml = f.read() - # net = IENetwork(model=xml, weights=bin, init_from_buffer=True) + # func = Function([relu], [param], 'test') + # caps = Function.to_capsule(func) + # net = IENetwork(caps) # ``` - - def __cinit__(self, model: [str, bytes] = "", weights: [str, bytes] = "", init_from_buffer: bool = False): + def __cinit__(self, model = ""): # Try to create Inference Engine network from capsule - if model.__class__.__name__ == 'PyCapsule' and weights == '' and init_from_buffer is False: + if model.__class__.__name__ == 'PyCapsule': self.impl = C.IENetwork(model) - return - cdef char*xml_buffer = malloc(len(model)+1) - cdef uint8_t*bin_buffer = malloc(len(weights)) - cdef string model_ - cdef string weights_ - if init_from_buffer: - warnings.warn("Reading network using constructor is deprecated. " - "Please, use IECore.read_network() method instead", DeprecationWarning) - memcpy(xml_buffer, model, len(model)) - memcpy(bin_buffer, weights, len(weights)) - xml_buffer[len(model)] = b'\0' - self.impl = C.IENetwork() - self.impl.load_from_buffer(xml_buffer, len(model), bin_buffer, len(weights)) else: - if model and weights: - warnings.warn("Reading network using constructor is deprecated. " - "Please, use IECore.read_network() method instead", DeprecationWarning) - if not os.path.isfile(model): - raise Exception(f"Path to the model {model} doesn't exist or it's a directory") - if not os.path.isfile(weights): - raise Exception(f"Path to the weights {weights} doesn't exist or it's a directory") - model_ = model.encode() - weights_ = weights.encode() - self.impl = C.IENetwork(model_, weights_) - else: - self.impl = C.IENetwork() - free(bin_buffer) - free(xml_buffer) + self.impl = C.IENetwork() ## Name of the loaded network @property @@ -1415,25 +1331,6 @@ cdef class IENetwork: 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.warn("'inputs' property of IENetwork class is deprecated. " - "To access DataPtrs user need to use 'input_data' property " - "of InputInfoPtr objects which can be accessed by 'input_info' property.", - DeprecationWarning) - cdef map[string, C.DataPtr] c_inputs = self.impl.getInputs() - inputs = {} - cdef DataPtr data_ptr - for input in c_inputs: - data_ptr = DataPtr() - data_ptr._ptr_network = &self.impl - data_ptr._ptr = input.second - inputs[input.first.decode()] = data_ptr - return inputs ## A dictionary that maps output layer names to DataPtr objects @property diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp index e9d4f7660bae40..1a6ae4f57edcca 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.cpp @@ -200,14 +200,6 @@ InferenceEnginePython::IENetwork InferenceEnginePython::read_network(std::string return InferenceEnginePython::IENetwork(std::make_shared(net)); } -InferenceEnginePython::IENetwork::IENetwork(const std::string& model, const std::string& weights) { - InferenceEngine::Core reader; - auto net = reader.ReadNetwork(model, weights); - actual = std::make_shared(net); - name = actual->getName(); - batch_size = actual->getBatchSize(); -} - InferenceEnginePython::IENetwork::IENetwork(const std::shared_ptr& cnn_network): actual(cnn_network) { if (actual == nullptr) IE_THROW() << "IENetwork was not initialized."; @@ -228,16 +220,6 @@ InferenceEnginePython::IENetwork::IENetwork(PyObject* network) { batch_size = actual->getBatchSize(); } -void InferenceEnginePython::IENetwork::load_from_buffer(const char* xml, size_t xml_size, uint8_t* bin, size_t bin_size) { - InferenceEngine::Core reader; - InferenceEngine::TensorDesc tensorDesc(InferenceEngine::Precision::U8, {bin_size}, InferenceEngine::Layout::C); - auto weights_blob = InferenceEngine::make_shared_blob(tensorDesc, bin, bin_size); - auto net = reader.ReadNetwork(std::string(xml, xml + xml_size), weights_blob); - name = net.getName(); - actual = std::make_shared(net); - batch_size = actual->getBatchSize(); -} - void InferenceEnginePython::IENetwork::serialize(const std::string& path_to_xml, const std::string& path_to_bin) { actual->serialize(path_to_xml, path_to_bin); } @@ -275,15 +257,6 @@ const std::map InferenceEnginePyth return inputs; } -const std::map InferenceEnginePython::IENetwork::getInputs() { - std::map inputs; - const InferenceEngine::InputsDataMap& inputsInfo = actual->getInputsInfo(); - for (auto& in : inputsInfo) { - inputs[in.first] = in.second->getInputData(); - } - return inputs; -} - const std::map InferenceEnginePython::IENetwork::getOutputs() { std::map outputs; const InferenceEngine::OutputsDataMap& outputsInfo = actual->getOutputsInfo(); @@ -338,15 +311,6 @@ void InferenceEnginePython::IEExecNetwork::exportNetwork(const std::string& mode actual->Export(model_file); } -std::map InferenceEnginePython::IEExecNetwork::getInputs() { - InferenceEngine::ConstInputsDataMap inputsDataMap = actual->GetInputsInfo(); - std::map pyInputs; - for (const auto& item : inputsDataMap) { - pyInputs[item.first] = item.second->getInputData(); - } - return pyInputs; -} - std::map InferenceEnginePython::IEExecNetwork::getInputsInfo() { InferenceEngine::ConstInputsDataMap inputsDataMap = actual->GetInputsInfo(); std::map pyInputs; diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp index cd3fa07c49ad1b..23d27474aff51e 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl.hpp @@ -60,18 +60,12 @@ struct IENetwork { const std::map getInputsInfo(); - const std::map getInputs(); - const std::map getOutputs(); void reshape(const std::map>& input_shapes); void serialize(const std::string& path_to_xml, const std::string& path_to_bin); - void load_from_buffer(const char* xml, size_t xml_size, uint8_t* bin, size_t bin_size); - - IENetwork(const std::string& model, const std::string& weights); - IENetwork(const std::shared_ptr& cnn_network); IENetwork(PyObject* network); @@ -146,7 +140,6 @@ struct IEExecNetwork { void exportNetwork(const std::string& model_file); std::map getInputsInfo(); - std::map getInputs(); std::map getOutputs(); PyObject* getMetric(const std::string& metric_name); diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd index 6f7fd9180896a9..7ab11604a92064 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api_impl_defs.pxd @@ -14,7 +14,7 @@ cdef extern from "" namespace "InferenceEngine": ctypedef vector[size_t] SizeVector cdef cppclass CExecutableNetwork "InferenceEngine::ExecutableNetwork" - + cdef cppclass TBlob[T]: ctypedef shared_ptr[TBlob[T]] Ptr @@ -154,7 +154,6 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython": 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 + @@ -167,13 +166,11 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython": cdef cppclass IENetwork: IENetwork() except + IENetwork(object) except + - IENetwork(const string &, const string &) except + string name size_t batch_size string precision map[string, vector[size_t]] inputs 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 + @@ -182,7 +179,6 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython": void setLayerParams(map[string, map[string, string]] params_map) except + void serialize(const string& path_to_xml, const string& path_to_bin) except + void reshape(map[string, vector[size_t]] input_shapes) except + - void load_from_buffer(const char*xml, size_t xml_size, uint8_t*bin, size_t bin_size) except + object getFunction() except + void convertToOldRepresentation() except + string getOVNameForTensor(const string &) except + diff --git a/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py b/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py index 11e4b479dac7f5..65811503d986e4 100644 --- a/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py +++ b/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py @@ -82,24 +82,6 @@ def test_input_info(device): 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) - 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 accessed by 'input_info' property." in str(w[i].message) - del exec_net - del ie_core - - def test_outputs(device): ie_core = ie.IECore() net = ie_core.read_network(model=test_net_xml, weights=test_net_bin) diff --git a/inference-engine/ie_bridges/python/tests/test_IENetwork.py b/inference-engine/ie_bridges/python/tests/test_IENetwork.py index 1c3474e689134d..d808e1772340c1 100644 --- a/inference-engine/ie_bridges/python/tests/test_IENetwork.py +++ b/inference-engine/ie_bridges/python/tests/test_IENetwork.py @@ -12,60 +12,12 @@ 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) - assert isinstance(net, IENetwork) - assert len(w) == 1 - assert issubclass(w[-1].category, DeprecationWarning) - assert "Reading network using constructor is deprecated. " \ - "Please, use IECore.read_network() method instead" in str(w[0].message) - - -def test_incorrect_xml_deprecated(): - with warnings.catch_warnings(record=True) as w: - with pytest.raises(Exception) as e: - IENetwork(model="./model.xml", weights=test_net_bin) - assert "Path to the model ./model.xml doesn't exist or it's a directory" in str(e.value) - assert len(w) == 1 - assert issubclass(w[-1].category, DeprecationWarning) - assert "Reading network using constructor is deprecated. " \ - "Please, use IECore.read_network() method instead" in str(w[0].message) - - -def test_incorrect_bin_deprecated(): - with warnings.catch_warnings(record=True) as w: - with pytest.raises(Exception) as e: - IENetwork(model=test_net_xml, weights="./model.bin") - assert "Path to the weights ./model.bin doesn't exist or it's a directory" in str(e.value) - assert len(w) == 1 - assert issubclass(w[-1].category, DeprecationWarning) - assert "Reading network using constructor is deprecated. " \ - "Please, use IECore.read_network() method instead" in str(w[0].message) - - def test_name(): ie = IECore() net = ie.read_network(model=test_net_xml, weights=test_net_bin) assert net.name == "test_model" -def test_inputs_deprecated(): - ie = IECore() - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - 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 accessed 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) @@ -208,21 +160,7 @@ def test_reshape(): net.reshape({"data": (2, 3, 32, 32)}) -def test_read_net_from_buffer_deprecated(): - with warnings.catch_warnings(record=True) as w: - with open(test_net_bin, 'rb') as f: - bin = f.read() - with open(test_net_xml, 'rb') as f: - xml = f.read() - net = IENetwork(model=xml, weights=bin, init_from_buffer=True) - assert isinstance(net, IENetwork) - assert len(w) == 1 - assert issubclass(w[-1].category, DeprecationWarning) - assert "Reading network using constructor is deprecated. " \ - "Please, use IECore.read_network() method instead" in str(w[0].message) - - -def test_net_from_buffer_valid_deprecated(): +def test_net_from_buffer_valid(): ie = IECore() with open(test_net_bin, 'rb') as f: bin = f.read() diff --git a/inference-engine/ie_bridges/python/tests/test_InferRequest.py b/inference-engine/ie_bridges/python/tests/test_InferRequest.py index af79c0ff155bf8..c1e92e2d410c23 100644 --- a/inference-engine/ie_bridges/python/tests/test_InferRequest.py +++ b/inference-engine/ie_bridges/python/tests/test_InferRequest.py @@ -66,32 +66,6 @@ def test_output_blobs(device): assert executable_network.requests[0].output_blobs['fc_out'].tensor_desc == td -def test_inputs_deprecated(device): - 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) - 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) - del executable_network - del ie_core - del net - - -def test_outputs_deprecated(device): - 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) - with warnings.catch_warnings(record=True) as w: - outputs = executable_network.requests[0].outputs - assert "'outputs' property of InferRequest is deprecated. Please instead use 'output_blobs' property." in str( - w[-1].message) - del executable_network - del ie_core - del net - - def test_inputs_list(device): ie_core = ie.IECore() net = ie_core.read_network(test_net_xml, test_net_bin)