dnn: fixup available backends/targets
authorAlexander Alekhin <alexander.alekhin@intel.com>
Wed, 5 Dec 2018 15:31:14 +0000 (18:31 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Wed, 5 Dec 2018 16:19:17 +0000 (19:19 +0300)
modules/dnn/src/dnn.cpp
modules/dnn/test/test_backends.cpp
modules/dnn/test/test_common.hpp

index d1fdbcc..b6eff6c 100644 (file)
@@ -74,6 +74,16 @@ static int PARAM_DNN_BACKEND_DEFAULT = (int)utils::getConfigurationParameterSize
 #endif
 );
 
+// Additional checks (slowdowns execution!)
+static bool DNN_CHECK_NAN_INF = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF", false);
+static bool DNN_CHECK_NAN_INF_DUMP = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF_DUMP", false);
+static bool DNN_CHECK_NAN_INF_RAISE_ERROR = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF_RAISE_ERROR", false);
+
+using std::vector;
+using std::map;
+using std::make_pair;
+using std::set;
+
 //==================================================================================================
 
 class BackendRegistry
@@ -160,6 +170,9 @@ std::vector< std::pair<Backend, Target> > getAvailableBackends()
 
 std::vector<Target> getAvailableTargets(Backend be)
 {
+    if (be == DNN_BACKEND_DEFAULT)
+        be = (Backend)PARAM_DNN_BACKEND_DEFAULT;
+
     std::vector<Target> result;
     const BackendRegistry::BackendsList all_backends = getAvailableBackends();
     for(BackendRegistry::BackendsList::const_iterator i = all_backends.begin(); i != all_backends.end(); ++i )
@@ -172,16 +185,6 @@ std::vector<Target> getAvailableTargets(Backend be)
 
 //==================================================================================================
 
-// Additional checks (slowdowns execution!)
-static bool DNN_CHECK_NAN_INF = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF", false);
-static bool DNN_CHECK_NAN_INF_DUMP = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF_DUMP", false);
-static bool DNN_CHECK_NAN_INF_RAISE_ERROR = utils::getConfigurationParameterBool("OPENCV_DNN_CHECK_NAN_INF_RAISE_ERROR", false);
-
-using std::vector;
-using std::map;
-using std::make_pair;
-using std::set;
-
 namespace
 {
     typedef std::vector<MatShape> ShapesVec;
index ab8f31d..a1216a5 100644 (file)
@@ -292,6 +292,6 @@ TEST_P(DNNTestNetwork, FastNeuralStyle_eccv16)
     processNet("dnn/fast_neural_style_eccv16_starry_night.t7", "", inp, "", "", l1, lInf);
 }
 
-INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets());
+INSTANTIATE_TEST_CASE_P(/*nothing*/, DNNTestNetwork, dnnBackendsAndTargets(true, true, false));
 
 }} // namespace
index 6e1140b..a499a71 100644 (file)
@@ -236,8 +236,14 @@ testing::internal::ParamGenerator< tuple<Backend, Target> > dnnBackendsAndTarget
     {
         available = getAvailableTargets(DNN_BACKEND_OPENCV);
         for (std::vector< Target >::const_iterator i = available.begin(); i != available.end(); ++i)
+        {
+            if (!withCpuOCV && *i == DNN_TARGET_CPU)
+                continue;
             targets.push_back(make_tuple(DNN_BACKEND_OPENCV, *i));
+        }
     }
+    if (targets.empty())  // validate at least CPU mode
+        targets.push_back(make_tuple(DNN_BACKEND_OPENCV, DNN_TARGET_CPU));
     return testing::ValuesIn(targets);
 }