Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add map<str, str> conversion instead of <str, Any> #736

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/python/py_generate_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@ bool py_object_is_any_map(const py::object& py_obj) {
});
}

bool py_object_is_map_str_str(const py::object& py_obj) {
if (!py::isinstance<py::dict>(py_obj)) {
return false;
}
auto dict = py::cast<py::dict>(py_obj);
return std::all_of(dict.begin(), dict.end(), [&](const std::pair<py::object::handle, py::object::handle>& elem) {
return py::isinstance<py::str>(elem.first) && py::isinstance<py::str>(elem.second);
});
}

std::map<std::string, std::string> py_object_to_map_str_str(const py::object& py_obj) {
OPENVINO_ASSERT(py_object_is_map_str_str(py_obj), "Unsupported attribute type.");
std::map<std::string, std::string> return_value = {};
for (auto& item : py::cast<py::dict>(py_obj)) {
std::string key = py::cast<std::string>(item.first);
std::string value = py::cast<std::string>(item.second);
return_value[key] = value;
}
return return_value;
}

ov::AnyMap py_object_to_any_map(const py::object& py_obj) {
OPENVINO_ASSERT(py_object_is_any_map(py_obj), "Unsupported attribute type.");
ov::AnyMap return_value = {};
Expand Down Expand Up @@ -332,7 +353,9 @@ ov::Any py_object_to_any(const py::object& py_obj) {
default:
OPENVINO_ASSERT(false, "Unsupported attribute type.");
}

// W/A For NPU
} else if (py_object_is_map_str_str(py_obj)) {
return py_object_to_map_str_str(py_obj);
// OV types
} else if (py_object_is_any_map(py_obj)) {
return py_object_to_any_map(py_obj);
Expand Down
Loading