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 b777218000e..b259a57c278 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 @@ -1011,6 +1011,22 @@ cdef class ExecutableNetwork: def get_config(self, config_name: str): 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. # @param model_file Full path to the target exported file location # @return None 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 d77671f9497..9ec099ff59f 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 @@ -358,6 +358,14 @@ PyObject* InferenceEnginePython::IEExecNetwork::getConfig(const std::string& nam return parse_parameter(actual->GetConfig(name)); } +void InferenceEnginePython::IEExecNetwork::setConfig(const std::map& config) { + std::map 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) { actual->Export(model_file); } 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 48fc2fd9c9a..588c316a849 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 @@ -146,6 +146,7 @@ struct IEExecNetwork { PyObject* getMetric(const std::string& metric_name); PyObject* getConfig(const std::string& name); + void setConfig(const std::map& config); int wait(int num_requests, int64_t timeout); int getIdleRequestId(); 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 502d7b3909e..3a09a7dfaa2 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 @@ -161,6 +161,7 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython": void exportNetwork(const string & model_file) except + object getMetric(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 getIdleRequestId() shared_ptr[CExecutableNetwork] getPluginLink() except + diff --git a/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py b/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py index 3b03b0339f1..b48fb2d9c82 100644 --- a/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py +++ b/inference-engine/ie_bridges/python/tests/test_ExecutableNetwork.py @@ -309,6 +309,19 @@ def test_get_config(device): 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 # checks that objects can deallocate in this order, if not - segfault happends def test_input_info_deallocation(device):