Support config as part of Infer node in yml
This commit is contained in:
parent
46d988e2cb
commit
eb8883160d
@ -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,10 @@ 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;
|
||||
RETHROW_WITH_MSG_IF_FAILED(
|
||||
utils::intersectMapWith(infer_params.config, gconfig),
|
||||
"Failed to combine global and local configs for Infer node: "
|
||||
+ call_params.name);
|
||||
builder.addInfer(call_params, infer_params);
|
||||
} else {
|
||||
throw std::logic_error("Unsupported node type: " + node_type);
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#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,26 @@ typename duration_t::rep timestamp() {
|
||||
return duration_cast<duration_t>(now.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
#define RETHROW_WITH_MSG_IF_FAILED(expr, msg) \
|
||||
try { \
|
||||
expr; \
|
||||
} catch (const std::exception& e) { \
|
||||
std::stringstream ss; \
|
||||
ss << msg << "\n caused by: " << e.what(); \
|
||||
throw std::logic_error(ss.str()); \
|
||||
} \
|
||||
|
||||
template <typename K, typename V>
|
||||
void intersectMapWith(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("Met already existing key: " + item.first);
|
||||
}
|
||||
target.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif // OPENCV_GAPI_PIPELINE_MODELING_TOOL_UTILS_HPP
|
||||
|
||||
Loading…
Reference in New Issue
Block a user