未验证 提交 3a64607d 编写于 作者: A Alexander Smorkalov 提交者: GitHub

Merge pull request #22518 from TolyaTalamanov:at/expand-modeling-tool-to-support-config-in-yml

[G-API] Pipeline modeling tool - support local infer node config
......@@ -190,6 +190,15 @@ CallParams read<CallParams>(const cv::FileNode& fn) {
return CallParams{std::move(name), static_cast<size_t>(call_every_nth)};
}
template <typename V>
std::map<std::string, V> readMap(const cv::FileNode& fn) {
std::map<std::string, V> map;
for (auto item : fn) {
map.emplace(item.name(), read<V>(item));
}
return map;
}
template <>
InferParams read<InferParams>(const cv::FileNode& fn) {
auto name =
......@@ -200,7 +209,7 @@ InferParams read<InferParams>(const cv::FileNode& fn) {
params.device = check_and_read<std::string>(fn, "device", name);
params.input_layers = readList<std::string>(fn, "input_layers", name);
params.output_layers = readList<std::string>(fn, "output_layers", name);
params.config = readMap<std::string>(fn["config"]);
return params;
}
......@@ -309,13 +318,13 @@ int main(int argc, char* argv[]) {
cv::FileStorage::MEMORY);
}
std::map<std::string, std::string> config;
std::map<std::string, std::string> gconfig;
if (!load_config.empty()) {
loadConfig(load_config, config);
loadConfig(load_config, gconfig);
}
// NB: Takes priority over config from file
if (!cached_dir.empty()) {
config =
gconfig =
std::map<std::string, std::string>{{"CACHE_DIR", cached_dir}};
}
......@@ -371,7 +380,14 @@ int main(int argc, char* argv[]) {
builder.addDummy(call_params, read<DummyParams>(node_fn));
} else if (node_type == "Infer") {
auto infer_params = read<InferParams>(node_fn);
infer_params.config = config;
try {
utils::mergeMapWith(infer_params.config, gconfig);
} catch (std::exception& e) {
std::stringstream ss;
ss << "Failed to merge global and local config for Infer node: "
<< call_params.name << std::endl << e.what();
throw std::logic_error(ss.str());
}
builder.addInfer(call_params, infer_params);
} else {
throw std::logic_error("Unsupported node type: " + node_type);
......
#ifndef OPENCV_GAPI_PIPELINE_MODELING_TOOL_UTILS_HPP
#define OPENCV_GAPI_PIPELINE_MODELING_TOOL_UTILS_HPP
#include <map>
#include <opencv2/core.hpp>
#if defined(_WIN32)
......@@ -91,6 +93,17 @@ typename duration_t::rep timestamp() {
return duration_cast<duration_t>(now.time_since_epoch()).count();
}
template <typename K, typename V>
void mergeMapWith(std::map<K, V>& target, const std::map<K, V>& second) {
for (auto&& item : second) {
auto it = target.find(item.first);
if (it != target.end()) {
throw std::logic_error("Error: key: " + it->first + " is already in target map");
}
target.insert(item);
}
}
} // namespace utils
#endif // OPENCV_GAPI_PIPELINE_MODELING_TOOL_UTILS_HPP
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册