[IE Python API] Add set_config for executable_network (#7796)
* [IE Python API] Add set_config for executable_network * fix test * fix test comment
This commit is contained in:
parent
6c00da6e48
commit
58d845f351
@ -1011,6 +1011,22 @@ cdef class ExecutableNetwork:
|
|||||||
def get_config(self, config_name: str):
|
def get_config(self, config_name: str):
|
||||||
return deref(self.impl).getConfig(config_name.encode())
|
return deref(self.impl).getConfig(config_name.encode())
|
||||||
|
|
||||||
|
## Sets configuration for current executable network.
|
||||||
|
#
|
||||||
|
# @param config: a dictionary of configuration parameters as keys and their values
|
||||||
|
# @return None
|
||||||
|
#
|
||||||
|
# Usage example:\n
|
||||||
|
# ```python
|
||||||
|
# ie = IECore()
|
||||||
|
# net = ie.read_network(model=path_to_xml_file, weights=path_to_bin_file)
|
||||||
|
# exec_net = ie.load_network(net, "GNA")
|
||||||
|
# config = exec_net.set_config({"DEVICE_MODE" : "GNA_SW_EXACT"})
|
||||||
|
# ```
|
||||||
|
def set_config(self, config: dict):
|
||||||
|
cdef map[string, string] c_config = dict_to_c_map(config)
|
||||||
|
deref(self.impl).setConfig(c_config)
|
||||||
|
|
||||||
## Exports the current executable network.
|
## Exports the current executable network.
|
||||||
# @param model_file Full path to the target exported file location
|
# @param model_file Full path to the target exported file location
|
||||||
# @return None
|
# @return None
|
||||||
|
@ -358,6 +358,14 @@ PyObject* InferenceEnginePython::IEExecNetwork::getConfig(const std::string& nam
|
|||||||
return parse_parameter(actual->GetConfig(name));
|
return parse_parameter(actual->GetConfig(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InferenceEnginePython::IEExecNetwork::setConfig(const std::map<std::string, std::string>& config) {
|
||||||
|
std::map<std::string, InferenceEngine::Parameter> newConfig;
|
||||||
|
for (const auto& item : config) {
|
||||||
|
newConfig[item.first] = InferenceEngine::Parameter(item.second);
|
||||||
|
}
|
||||||
|
actual->SetConfig(newConfig);
|
||||||
|
}
|
||||||
|
|
||||||
void InferenceEnginePython::IEExecNetwork::exportNetwork(const std::string& model_file) {
|
void InferenceEnginePython::IEExecNetwork::exportNetwork(const std::string& model_file) {
|
||||||
actual->Export(model_file);
|
actual->Export(model_file);
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@ struct IEExecNetwork {
|
|||||||
|
|
||||||
PyObject* getMetric(const std::string& metric_name);
|
PyObject* getMetric(const std::string& metric_name);
|
||||||
PyObject* getConfig(const std::string& name);
|
PyObject* getConfig(const std::string& name);
|
||||||
|
void setConfig(const std::map<std::string, std::string>& config);
|
||||||
|
|
||||||
int wait(int num_requests, int64_t timeout);
|
int wait(int num_requests, int64_t timeout);
|
||||||
int getIdleRequestId();
|
int getIdleRequestId();
|
||||||
|
@ -161,6 +161,7 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
|
|||||||
void exportNetwork(const string & model_file) except +
|
void exportNetwork(const string & model_file) except +
|
||||||
object getMetric(const string & metric_name) except +
|
object getMetric(const string & metric_name) except +
|
||||||
object getConfig(const string & metric_name) except +
|
object getConfig(const string & metric_name) except +
|
||||||
|
void setConfig(const map[string, string]& config) except +
|
||||||
int wait(int num_requests, int64_t timeout) nogil
|
int wait(int num_requests, int64_t timeout) nogil
|
||||||
int getIdleRequestId()
|
int getIdleRequestId()
|
||||||
shared_ptr[CExecutableNetwork] getPluginLink() except +
|
shared_ptr[CExecutableNetwork] getPluginLink() except +
|
||||||
|
@ -309,6 +309,19 @@ def test_get_config(device):
|
|||||||
assert config == "NO"
|
assert config == "NO"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "GNA", reason="Device dependent test")
|
||||||
|
def test_set_config(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)
|
||||||
|
exec_net.set_config({"DEVICE_MODE" : "GNA_HW"})
|
||||||
|
parameter = exec_net.get_config("DEVICE_MODE")
|
||||||
|
assert parameter == "GNA_HW"
|
||||||
|
exec_net.set_config({"DEVICE_MODE" : "GNA_SW_EXACT"})
|
||||||
|
parameter = exec_net.get_config("DEVICE_MODE")
|
||||||
|
assert parameter == "GNA_SW_EXACT"
|
||||||
|
|
||||||
|
|
||||||
# issue 28996
|
# issue 28996
|
||||||
# checks that objects can deallocate in this order, if not - segfault happends
|
# checks that objects can deallocate in this order, if not - segfault happends
|
||||||
def test_input_info_deallocation(device):
|
def test_input_info_deallocation(device):
|
||||||
|
Loading…
Reference in New Issue
Block a user