@@ -898,24 +898,16 @@ static const TestCase testConformanceConfig[] = {
898898};
899899
900900
901- struct TestCaseInput
902- {
903- std::vector<std::string> input_paths;
904- std::vector<std::string> output_paths;
905- std::string model_path;
906- std::string name;
907- };
908-
909- std::ostream& operator <<(std::ostream& os, const TestCaseInput& test_case)
901+ std::ostream& operator <<(std::ostream& os, const TestCase& test_case)
910902{
911903 return os << test_case.name ;
912904}
913905
914- typedef tuple<TestCaseInput , tuple<Backend, Target> > ONNXConfParams;
906+ typedef tuple<TestCase , tuple<Backend, Target> > ONNXConfParams;
915907
916908std::string printOnnxConfParams (const testing::TestParamInfo<ONNXConfParams>& params)
917909{
918- TestCaseInput test_case = get<0 >(params.param );
910+ TestCase test_case = get<0 >(params.param );
919911 Backend backend = get<0 >(get<1 >(params.param ));
920912 Target target = get<1 >(get<1 >(params.param ));
921913
@@ -928,45 +920,11 @@ std::string printOnnxConfParams(const testing::TestParamInfo<ONNXConfParams>& pa
928920 return ss.str ();
929921}
930922
931- template <typename TString>
932- static std::string _tf (TString filename, bool required = true )
933- {
934- return findDataFile (std::string (" dnn/onnx/" ) + filename, required);
935- }
936-
937- std::vector<TestCaseInput> readTestCases ()
938- {
939- std::vector<TestCaseInput> ret;
940- for (size_t i = 0 ; i < sizeof (testConformanceConfig) / sizeof (testConformanceConfig[0 ]); ++i)
941- {
942- const TestCase& test_case = testConformanceConfig[i];
943-
944- TestCaseInput input;
945-
946- std::string prefix = cv::format (" conformance/node/%s" , test_case.name );
947- input.name = test_case.name ;
948- input.model_path = _tf (cv::format (" %s/model.onnx" , prefix.c_str ()));
949-
950- for (int i = 0 ; i < test_case.inputs ; ++i)
951- {
952- input.input_paths .push_back (_tf (cv::format (" %s/test_data_set_0/input_%d.pb" , prefix.c_str (), i)));
953- }
954-
955- for (int i = 0 ; i < test_case.outputs ; ++i)
956- {
957- input.output_paths .push_back (_tf (cv::format (" %s/test_data_set_0/output_%d.pb" , prefix.c_str (), i)));
958- }
959-
960- ret.push_back (input);
961- }
962-
963- return ret;
964- }
965-
966923class Test_ONNX_conformance : public TestWithParam <ONNXConfParams>
967924{
968925public:
969- TestCaseInput test_case;
926+
927+ TestCase test_case;
970928 Backend backend;
971929 Target target;
972930
@@ -978,6 +936,9 @@ class Test_ONNX_conformance : public TestWithParam<ONNXConfParams>
978936 static std::set<std::string> opencl_fp16_deny_list;
979937 static std::set<std::string> opencl_deny_list;
980938 static std::set<std::string> cpu_deny_list;
939+ #ifdef HAVE_HALIDE
940+ static std::set<std::string> halide_deny_list;
941+ #endif
981942
982943 Test_ONNX_conformance ()
983944 {
@@ -1059,102 +1020,121 @@ class Test_ONNX_conformance : public TestWithParam<ONNXConfParams>
10591020 " " // dummy element of non empty list
10601021 };
10611022 initDenyList (cpu_deny_list, cpu, sizeof (cpu)/sizeof (cpu[0 ]));
1062- }
10631023
1064- void checkFilterLists () const
1065- {
1066- const std::string& name = test_case.name ;
1067- if (parser_deny_list.find (name) != parser_deny_list.end ())
1068- {
1069- applyTestTag (CV_TEST_TAG_DNN_SKIP_PARSER, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1070- }
1071-
1072- if (backend == DNN_BACKEND_OPENCV)
1073- {
1074- if (global_deny_list.find (name) != global_deny_list.end ())
1075- {
1076- applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1077- }
1078- if ((target == DNN_TARGET_OPENCL_FP16) && (opencl_fp16_deny_list.find (name) != opencl_fp16_deny_list.end ()))
1079- {
1080- applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1081- }
1082- if ((target == DNN_TARGET_OPENCL) && (opencl_deny_list.find (name) != opencl_deny_list.end ()))
1083- {
1084- applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_OPENCL, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1085- }
1086- if ((target == DNN_TARGET_CPU) && (cpu_deny_list.find (name) != cpu_deny_list.end ()))
1087- {
1088- applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_CPU, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1089- }
1090- }
1091- #if 0 //def HAVE_HALIDE
1092- else if (backend == DNN_BACKEND_HALIDE)
1093- {
1094- #include "test_onnx_conformance_layer_filter__halide.inl.hpp"
1095- }
1096- #endif
1097- #if 0 //def HAVE_INF_ENGINE
1098- else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1099- {
1100- #include "test_onnx_conformance_layer_filter__ngraph.inl.hpp"
1101- }
1102- #endif
1103- #if 0 //def HAVE_VULKAN
1104- else if (backend == DNN_BACKEND_VKCOM)
1105- {
1106- #include "test_onnx_conformance_layer_filter__vulkan.inl.hpp"
1107- }
1108- #endif
1109- #if 0 //def HAVE_CUDA
1110- else if (backend == DNN_BACKEND_CUDA)
1111- {
1112- #include "test_onnx_conformance_layer_filter__cuda.inl.hpp"
1113- }
1024+ #ifdef HAVE_HALIDE
1025+ const char * const halide_deny_list_[] = {
1026+ #include " test_onnx_conformance_layer_filter__halide_denylist.inl.hpp"
1027+ " " // dummy element of non empty list
1028+ };
1029+ initDenyList (halide_deny_list, halide_deny_list_, sizeof (halide_deny_list_)/sizeof (halide_deny_list_[0 ]));
11141030#endif
1115- else
1116- {
1117- std::ostringstream ss;
1118- ss << " No test filter available for backend " ;
1119- PrintTo (backend, &ss);
1120- ss << " . Run test by default" ;
1121- std::cout << ss.str () << std::endl;
1122- }
11231031 }
1032+
11241033};
11251034
11261035std::set<std::string> Test_ONNX_conformance::parser_deny_list;
11271036std::set<std::string> Test_ONNX_conformance::global_deny_list;
11281037std::set<std::string> Test_ONNX_conformance::opencl_fp16_deny_list;
11291038std::set<std::string> Test_ONNX_conformance::opencl_deny_list;
11301039std::set<std::string> Test_ONNX_conformance::cpu_deny_list;
1040+ #ifdef HAVE_HALIDE
1041+ std::set<std::string> Test_ONNX_conformance::halide_deny_list;
1042+ #endif
11311043
11321044TEST_P (Test_ONNX_conformance, Layer_Test)
11331045{
1134- std::string name = test_case.name ;
1046+ const std::string& name = test_case.name ;
11351047 ASSERT_FALSE (name.empty ());
11361048
11371049 bool checkLayersFallbacks = true ;
11381050 bool checkAccuracy = true ;
11391051
1140- checkFilterLists ();
1052+ if (parser_deny_list.find (name) != parser_deny_list.end ())
1053+ {
1054+ applyTestTag (CV_TEST_TAG_DNN_SKIP_PARSER, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1055+ }
1056+
1057+ if (backend == DNN_BACKEND_OPENCV)
1058+ {
1059+ if (global_deny_list.find (name) != global_deny_list.end ())
1060+ {
1061+ applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1062+ }
1063+ if ((target == DNN_TARGET_OPENCL_FP16) && (opencl_fp16_deny_list.find (name) != opencl_fp16_deny_list.end ()))
1064+ {
1065+ applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1066+ }
1067+ if ((target == DNN_TARGET_OPENCL) && (opencl_deny_list.find (name) != opencl_deny_list.end ()))
1068+ {
1069+ applyTestTag (CV_TEST_TAG_DNN_SKIP_OPENCL, CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1070+ }
1071+ if ((target == DNN_TARGET_CPU) && (cpu_deny_list.find (name) != cpu_deny_list.end ()))
1072+ {
1073+ applyTestTag (CV_TEST_TAG_DNN_SKIP_CPU, CV_TEST_TAG_DNN_SKIP_OPENCV_BACKEND, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1074+ }
1075+ }
1076+ #ifdef HAVE_HALIDE
1077+ else if (backend == DNN_BACKEND_HALIDE)
1078+ {
1079+ if (halide_deny_list.find (name) != halide_deny_list.end ())
1080+ {
1081+ applyTestTag (CV_TEST_TAG_DNN_SKIP_HALIDE, CV_TEST_TAG_DNN_SKIP_ONNX_CONFORMANCE);
1082+ }
1083+ }
1084+ #endif
1085+ #ifdef HAVE_INF_ENGINE
1086+ else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
1087+ {
1088+ #include " test_onnx_conformance_layer_filter__openvino.inl.hpp"
1089+ }
1090+ #endif
1091+ #if 0 //def HAVE_VULKAN
1092+ else if (backend == DNN_BACKEND_VKCOM)
1093+ {
1094+ #include "test_onnx_conformance_layer_filter__vulkan.inl.hpp"
1095+ }
1096+ #endif
1097+ #if 0 //def HAVE_CUDA
1098+ else if (backend == DNN_BACKEND_CUDA)
1099+ {
1100+ #include "test_onnx_conformance_layer_filter__cuda.inl.hpp"
1101+ }
1102+ #endif
1103+ else
1104+ {
1105+ std::ostringstream ss;
1106+ ss << " No test filter available for backend " ;
1107+ PrintTo (backend, &ss);
1108+ ss << " . Run test by default" ;
1109+ std::cout << ss.str () << std::endl;
1110+ }
11411111
11421112 std::vector<Mat> inputs;
11431113 std::vector<Mat> ref_outputs;
11441114
1115+ std::string prefix = cv::format (" dnn/onnx/conformance/node/%s" , test_case.name );
1116+
11451117 Net net;
11461118 try
11471119 {
1120+ std::string model_path = findDataFile (prefix + " /model.onnx" );
1121+
11481122 // cout << "Read ONNX inputs..." << endl;
1149- std::transform (test_case.input_paths .begin (), test_case.input_paths .end (),
1150- std::back_inserter (inputs), readTensorFromONNX);
1123+ for (int i = 0 ; i < test_case.inputs ; ++i)
1124+ {
1125+ Mat input = readTensorFromONNX (findDataFile (prefix + cv::format (" /test_data_set_0/input_%d.pb" , i)));
1126+ inputs.push_back (input);
1127+ }
11511128
11521129 // cout << "Read ONNX reference outputs..." << endl;
1153- std::transform (test_case.output_paths .begin (), test_case.output_paths .end (),
1154- std::back_inserter (ref_outputs), readTensorFromONNX);
1130+ for (int i = 0 ; i < test_case.outputs ; ++i)
1131+ {
1132+ Mat output = readTensorFromONNX (findDataFile (prefix + cv::format (" /test_data_set_0/output_%d.pb" , i)));
1133+ ref_outputs.push_back (output);
1134+ }
11551135
11561136 // cout << "Parse model..." << endl;
1157- net = readNetFromONNX (test_case. model_path );
1137+ net = readNetFromONNX (model_path);
11581138 if (net.empty ())
11591139 {
11601140 applyTestTag (CV_TEST_TAG_DNN_ERROR_PARSER);
@@ -1244,7 +1224,11 @@ TEST_P(Test_ONNX_conformance, Layer_Test)
12441224}
12451225
12461226INSTANTIATE_TEST_CASE_P (/* */ , Test_ONNX_conformance,
1247- testing::Combine (testing::ValuesIn(readTestCases()), dnnBackendsAndTargets()),
1248- printOnnxConfParams);
1227+ testing::Combine (
1228+ testing::ValuesIn (testConformanceConfig),
1229+ dnnBackendsAndTargets(/* withInferenceEngine=*/ true , /* withHalide=*/ true )
1230+ ),
1231+ printOnnxConfParams
1232+ );
12491233
12501234};
0 commit comments