Merge pull request #18701 from TolyaTalamanov:at/introduce-config-for-ie-params
Expand ie::Params to support config * Add config to IE params * Add test * Remove comments from tests * Rename to pluginConfig * Add one more overloads for pluginConfig * Add more tests
This commit is contained in:
parent
6df92b3bca
commit
2a3cdba724
@ -11,6 +11,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple> // tuple, tuple_size
|
#include <tuple> // tuple, tuple_size
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <opencv2/gapi/opencv_includes.hpp>
|
#include <opencv2/gapi/opencv_includes.hpp>
|
||||||
#include <opencv2/gapi/util/any.hpp>
|
#include <opencv2/gapi/util/any.hpp>
|
||||||
@ -42,6 +43,8 @@ enum class TraitAs: int
|
|||||||
IMAGE //!< G-API traits an associated cv::Mat as an image so creates an "image" blob (NCHW/NHWC, etc)
|
IMAGE //!< G-API traits an associated cv::Mat as an image so creates an "image" blob (NCHW/NHWC, etc)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using IEConfig = std::map<std::string, std::string>;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct ParamDesc {
|
struct ParamDesc {
|
||||||
std::string model_path;
|
std::string model_path;
|
||||||
@ -63,6 +66,7 @@ namespace detail {
|
|||||||
enum class Kind { Load, Import };
|
enum class Kind { Load, Import };
|
||||||
Kind kind;
|
Kind kind;
|
||||||
bool is_generic;
|
bool is_generic;
|
||||||
|
IEConfig config;
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
@ -86,7 +90,8 @@ public:
|
|||||||
, std::tuple_size<typename Net::InArgs>::value // num_in
|
, std::tuple_size<typename Net::InArgs>::value // num_in
|
||||||
, std::tuple_size<typename Net::OutArgs>::value // num_out
|
, std::tuple_size<typename Net::OutArgs>::value // num_out
|
||||||
, detail::ParamDesc::Kind::Load
|
, detail::ParamDesc::Kind::Load
|
||||||
, false} {
|
, false
|
||||||
|
, {}} {
|
||||||
};
|
};
|
||||||
|
|
||||||
Params(const std::string &model,
|
Params(const std::string &model,
|
||||||
@ -95,7 +100,8 @@ public:
|
|||||||
, std::tuple_size<typename Net::InArgs>::value // num_in
|
, std::tuple_size<typename Net::InArgs>::value // num_in
|
||||||
, std::tuple_size<typename Net::OutArgs>::value // num_out
|
, std::tuple_size<typename Net::OutArgs>::value // num_out
|
||||||
, detail::ParamDesc::Kind::Import
|
, detail::ParamDesc::Kind::Import
|
||||||
, false} {
|
, false
|
||||||
|
, {}} {
|
||||||
};
|
};
|
||||||
|
|
||||||
Params<Net>& cfgInputLayers(const typename PortCfg<Net>::In &ll) {
|
Params<Net>& cfgInputLayers(const typename PortCfg<Net>::In &ll) {
|
||||||
@ -121,6 +127,16 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Params& pluginConfig(IEConfig&& cfg) {
|
||||||
|
desc.config = std::move(cfg);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Params& pluginConfig(const IEConfig& cfg) {
|
||||||
|
desc.config = cfg;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// BEGIN(G-API's network parametrization API)
|
// BEGIN(G-API's network parametrization API)
|
||||||
GBackend backend() const { return cv::gapi::ie::backend(); }
|
GBackend backend() const { return cv::gapi::ie::backend(); }
|
||||||
std::string tag() const { return Net::tag(); }
|
std::string tag() const { return Net::tag(); }
|
||||||
@ -138,15 +154,25 @@ public:
|
|||||||
const std::string &model,
|
const std::string &model,
|
||||||
const std::string &weights,
|
const std::string &weights,
|
||||||
const std::string &device)
|
const std::string &device)
|
||||||
: desc{ model, weights, device, {}, {}, {}, 0u, 0u, detail::ParamDesc::Kind::Load, true}, m_tag(tag) {
|
: desc{ model, weights, device, {}, {}, {}, 0u, 0u, detail::ParamDesc::Kind::Load, true, {}}, m_tag(tag) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Params(const std::string &tag,
|
Params(const std::string &tag,
|
||||||
const std::string &model,
|
const std::string &model,
|
||||||
const std::string &device)
|
const std::string &device)
|
||||||
: desc{ model, {}, device, {}, {}, {}, 0u, 0u, detail::ParamDesc::Kind::Import, true}, m_tag(tag) {
|
: desc{ model, {}, device, {}, {}, {}, 0u, 0u, detail::ParamDesc::Kind::Import, true, {}}, m_tag(tag) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Params& pluginConfig(IEConfig&& cfg) {
|
||||||
|
desc.config = std::move(cfg);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Params& pluginConfig(const IEConfig& cfg) {
|
||||||
|
desc.config = cfg;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// BEGIN(G-API's network parametrization API)
|
// BEGIN(G-API's network parametrization API)
|
||||||
GBackend backend() const { return cv::gapi::ie::backend(); }
|
GBackend backend() const { return cv::gapi::ie::backend(); }
|
||||||
std::string tag() const { return m_tag; }
|
std::string tag() const { return m_tag; }
|
||||||
|
|||||||
@ -185,7 +185,8 @@ struct IEUnit {
|
|||||||
inputs = net.getInputsInfo();
|
inputs = net.getInputsInfo();
|
||||||
outputs = net.getOutputsInfo();
|
outputs = net.getOutputsInfo();
|
||||||
} else if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import) {
|
} else if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import) {
|
||||||
this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
||||||
|
this_plugin.SetConfig(params.config);
|
||||||
this_network = cv::gimpl::ie::wrap::importNetwork(this_plugin, params);
|
this_network = cv::gimpl::ie::wrap::importNetwork(this_plugin, params);
|
||||||
// FIXME: ICNNetwork returns InputsDataMap/OutputsDataMap,
|
// FIXME: ICNNetwork returns InputsDataMap/OutputsDataMap,
|
||||||
// but ExecutableNetwork returns ConstInputsDataMap/ConstOutputsDataMap
|
// but ExecutableNetwork returns ConstInputsDataMap/ConstOutputsDataMap
|
||||||
@ -225,6 +226,7 @@ struct IEUnit {
|
|||||||
// FIXME: In case importNetwork for fill inputs/outputs need to obtain ExecutableNetwork, but
|
// FIXME: In case importNetwork for fill inputs/outputs need to obtain ExecutableNetwork, but
|
||||||
// for loadNetwork they can be obtained by using readNetwork
|
// for loadNetwork they can be obtained by using readNetwork
|
||||||
non_const_this->this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
non_const_this->this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
||||||
|
non_const_this->this_plugin.SetConfig(params.config);
|
||||||
non_const_this->this_network = cv::gimpl::ie::wrap::loadNetwork(non_const_this->this_plugin, net, params);
|
non_const_this->this_network = cv::gimpl::ie::wrap::loadNetwork(non_const_this->this_plugin, net, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -403,6 +403,108 @@ TEST(TestAgeGenderIE, GenericInfer)
|
|||||||
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
|
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), gapi_gender, "Test gender output");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TestAgeGenderIE, InvalidConfigGeneric)
|
||||||
|
{
|
||||||
|
initDLDTDataPath();
|
||||||
|
|
||||||
|
std::string model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
|
||||||
|
std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
|
||||||
|
std::string device_id = "CPU";
|
||||||
|
|
||||||
|
// Configure & run G-API
|
||||||
|
cv::GMat in;
|
||||||
|
GInferInputs inputs;
|
||||||
|
inputs["data"] = in;
|
||||||
|
|
||||||
|
auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", inputs);
|
||||||
|
auto age = outputs.at("age_conv3");
|
||||||
|
auto gender = outputs.at("prob");
|
||||||
|
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
|
||||||
|
|
||||||
|
auto pp = cv::gapi::ie::Params<cv::gapi::Generic>{"age-gender-generic",
|
||||||
|
model_path,
|
||||||
|
weights_path,
|
||||||
|
device_id}.pluginConfig({{"unsupported_config", "some_value"}});
|
||||||
|
|
||||||
|
EXPECT_ANY_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
|
||||||
|
cv::compile_args(cv::gapi::networks(pp))));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestAgeGenderIE, CPUConfigGeneric)
|
||||||
|
{
|
||||||
|
initDLDTDataPath();
|
||||||
|
|
||||||
|
std::string model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
|
||||||
|
std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
|
||||||
|
std::string device_id = "CPU";
|
||||||
|
|
||||||
|
// Configure & run G-API
|
||||||
|
cv::GMat in;
|
||||||
|
GInferInputs inputs;
|
||||||
|
inputs["data"] = in;
|
||||||
|
|
||||||
|
auto outputs = cv::gapi::infer<cv::gapi::Generic>("age-gender-generic", inputs);
|
||||||
|
auto age = outputs.at("age_conv3");
|
||||||
|
auto gender = outputs.at("prob");
|
||||||
|
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
|
||||||
|
|
||||||
|
auto pp = cv::gapi::ie::Params<cv::gapi::Generic>{"age-gender-generic",
|
||||||
|
model_path,
|
||||||
|
weights_path,
|
||||||
|
device_id}.pluginConfig({{"ENFORCE_BF16", "NO"}});
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
|
||||||
|
cv::compile_args(cv::gapi::networks(pp))));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestAgeGenderIE, InvalidConfig)
|
||||||
|
{
|
||||||
|
initDLDTDataPath();
|
||||||
|
|
||||||
|
std::string model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
|
||||||
|
std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
|
||||||
|
std::string device_id = "CPU";
|
||||||
|
|
||||||
|
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
|
||||||
|
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
|
||||||
|
|
||||||
|
cv::GMat in;
|
||||||
|
cv::GMat age, gender;
|
||||||
|
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
|
||||||
|
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
|
||||||
|
|
||||||
|
auto pp = cv::gapi::ie::Params<AgeGender> {
|
||||||
|
model_path, weights_path, device_id
|
||||||
|
}.cfgOutputLayers({ "age_conv3", "prob" }).pluginConfig({{"unsupported_config", "some_value"}});
|
||||||
|
|
||||||
|
EXPECT_ANY_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
|
||||||
|
cv::compile_args(cv::gapi::networks(pp))));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(TestAgeGenderIE, CPUConfig)
|
||||||
|
{
|
||||||
|
initDLDTDataPath();
|
||||||
|
|
||||||
|
std::string model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
|
||||||
|
std::string weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
|
||||||
|
std::string device_id = "CPU";
|
||||||
|
|
||||||
|
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
|
||||||
|
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
|
||||||
|
|
||||||
|
cv::GMat in;
|
||||||
|
cv::GMat age, gender;
|
||||||
|
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
|
||||||
|
cv::GComputation comp(cv::GIn(in), cv::GOut(age, gender));
|
||||||
|
|
||||||
|
auto pp = cv::gapi::ie::Params<AgeGender> {
|
||||||
|
model_path, weights_path, device_id
|
||||||
|
}.cfgOutputLayers({ "age_conv3", "prob" }).pluginConfig({{"ENFORCE_BF16", "NO"}});
|
||||||
|
|
||||||
|
EXPECT_NO_THROW(comp.compile(cv::GMatDesc{CV_8U,3,cv::Size{320, 240}},
|
||||||
|
cv::compile_args(cv::gapi::networks(pp))));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace opencv_test
|
} // namespace opencv_test
|
||||||
|
|
||||||
#endif // HAVE_INF_ENGINE
|
#endif // HAVE_INF_ENGINE
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user