[Python API] removal of deprecated python api (#6282)
* [Python API] removal of deprecated python api * [Python API] removal of deprecated python api
This commit is contained in:
parent
4d8825e4f8
commit
dd742de105
@ -940,26 +940,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
|
||||
def outputs(self):
|
||||
@ -1303,27 +1283,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
|
||||
def latency(self):
|
||||
@ -1368,69 +1327,25 @@ 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)
|
||||
# func = Function([relu], [param], 'test')
|
||||
# caps = Function.to_capsule(func)
|
||||
# net = IENetwork(caps)
|
||||
# ```
|
||||
#
|
||||
# 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)
|
||||
# ```
|
||||
|
||||
def __cinit__(self, model: [str, bytes] = "", weights: [str, bytes] = "", init_from_buffer: bool = False):
|
||||
def __cinit__(self, model = None):
|
||||
# Try to create Inference Engine network from capsule
|
||||
if model.__class__.__name__ == 'PyCapsule' and weights == '' and init_from_buffer is False:
|
||||
self.impl = C.IENetwork(model)
|
||||
return
|
||||
cdef char*xml_buffer = <char*> malloc(len(model)+1)
|
||||
cdef uint8_t*bin_buffer = <uint8_t *> 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, <char*> model, len(model))
|
||||
memcpy(bin_buffer, <uint8_t *> 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))
|
||||
if model is not None:
|
||||
with nogil:
|
||||
self.impl = C.IENetwork(model)
|
||||
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:
|
||||
with nogil:
|
||||
self.impl = C.IENetwork()
|
||||
free(bin_buffer)
|
||||
free(xml_buffer)
|
||||
with nogil:
|
||||
self.impl = C.IENetwork()
|
||||
|
||||
## Name of the loaded network
|
||||
@property
|
||||
@ -1453,26 +1368,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
|
||||
def outputs(self):
|
||||
|
@ -200,14 +200,6 @@ InferenceEnginePython::IENetwork InferenceEnginePython::read_network(std::string
|
||||
return InferenceEnginePython::IENetwork(std::make_shared<InferenceEngine::CNNNetwork>(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<InferenceEngine::CNNNetwork>(net);
|
||||
name = actual->getName();
|
||||
batch_size = actual->getBatchSize();
|
||||
}
|
||||
|
||||
InferenceEnginePython::IENetwork::IENetwork(const std::shared_ptr<InferenceEngine::CNNNetwork>& 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<uint8_t>(tensorDesc, bin, bin_size);
|
||||
auto net = reader.ReadNetwork(std::string(xml, xml + xml_size), weights_blob);
|
||||
name = net.getName();
|
||||
actual = std::make_shared<InferenceEngine::CNNNetwork>(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<std::string, InferenceEngine::InputInfo::Ptr> InferenceEnginePyth
|
||||
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();
|
||||
for (auto& in : inputsInfo) {
|
||||
inputs[in.first] = in.second->getInputData();
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
|
||||
const std::map<std::string, InferenceEngine::DataPtr> InferenceEnginePython::IENetwork::getOutputs() {
|
||||
std::map<std::string, InferenceEngine::DataPtr> 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<std::string, InferenceEngine::DataPtr> InferenceEnginePython::IEExecNetwork::getInputs() {
|
||||
InferenceEngine::ConstInputsDataMap inputsDataMap = actual->GetInputsInfo();
|
||||
std::map<std::string, InferenceEngine::DataPtr> pyInputs;
|
||||
for (const auto& item : inputsDataMap) {
|
||||
pyInputs[item.first] = item.second->getInputData();
|
||||
}
|
||||
return pyInputs;
|
||||
}
|
||||
|
||||
std::map<std::string, InferenceEngine::InputInfo::CPtr> InferenceEnginePython::IEExecNetwork::getInputsInfo() {
|
||||
InferenceEngine::ConstInputsDataMap inputsDataMap = actual->GetInputsInfo();
|
||||
std::map<std::string, InferenceEngine::InputInfo::CPtr> pyInputs;
|
||||
|
@ -60,18 +60,12 @@ struct IENetwork {
|
||||
|
||||
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 reshape(const std::map<std::string, std::vector<size_t>>& 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<InferenceEngine::CNNNetwork>& cnn_network);
|
||||
|
||||
IENetwork(PyObject* network);
|
||||
@ -146,7 +140,6 @@ struct IEExecNetwork {
|
||||
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();
|
||||
|
||||
PyObject* getMetric(const std::string& metric_name);
|
||||
|
@ -14,7 +14,7 @@ cdef extern from "<inference_engine.hpp>" 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 +
|
||||
@ -166,14 +165,12 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
|
||||
|
||||
cdef cppclass IENetwork:
|
||||
IENetwork() nogil except +
|
||||
IENetwork(object) except +
|
||||
IENetwork(const string &, const string &) except +
|
||||
IENetwork(object) nogil except +
|
||||
string name
|
||||
size_t batch_size
|
||||
string precision
|
||||
map[string, vector[size_t]] inputs
|
||||
const map[string, InputInfo.Ptr] getInputsInfo() nogil except +
|
||||
const map[string, DataPtr] getInputs() except +
|
||||
map[string, DataPtr] getOutputs() nogil 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 +
|
||||
|
@ -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)
|
||||
|
@ -12,60 +12,12 @@ 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)
|
||||
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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user