Skip to content

Commit a76050e

Browse files
committed
add map<str, str> conversion instead of <str, Any>
1 parent a295fe1 commit a76050e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/python/py_generate_pipeline.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ bool py_object_is_any_map(const py::object& py_obj) {
257257
});
258258
}
259259

260+
bool py_object_is_map_str_str(const py::object& py_obj) {
261+
if (!py::isinstance<py::dict>(py_obj)) {
262+
return false;
263+
}
264+
auto dict = py::cast<py::dict>(py_obj);
265+
return std::all_of(dict.begin(), dict.end(), [&](const std::pair<py::object::handle, py::object::handle>& elem) {
266+
return py::isinstance<py::str>(elem.first) && py::isinstance<py::str>(elem.second);
267+
});
268+
}
269+
270+
std::map<std::string, std::string> py_object_to_map_str_str(const py::object& py_obj) {
271+
OPENVINO_ASSERT(py_object_is_map_str_str(py_obj), "Unsupported attribute type.");
272+
std::map<std::string, std::string> return_value = {};
273+
for (auto& item : py::cast<py::dict>(py_obj)) {
274+
std::string key = py::cast<std::string>(item.first);
275+
std::string value = py::cast<std::string>(item.second);
276+
return_value[key] = value;
277+
}
278+
return return_value;
279+
}
280+
260281
ov::AnyMap py_object_to_any_map(const py::object& py_obj) {
261282
OPENVINO_ASSERT(py_object_is_any_map(py_obj), "Unsupported attribute type.");
262283
ov::AnyMap return_value = {};
@@ -332,7 +353,9 @@ ov::Any py_object_to_any(const py::object& py_obj) {
332353
default:
333354
OPENVINO_ASSERT(false, "Unsupported attribute type.");
334355
}
335-
356+
// W/A For NPU
357+
} else if (py_object_is_map_str_str(py_obj)) {
358+
return py_object_to_map_str_str(py_obj);
336359
// OV types
337360
} else if (py_object_is_any_map(py_obj)) {
338361
return py_object_to_any_map(py_obj);

0 commit comments

Comments
 (0)