diff --git a/modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp b/modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp index dedfa9dbe1..a4e8ac0f99 100644 --- a/modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp +++ b/modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp @@ -13,7 +13,7 @@ namespace cv { namespace gapi { namespace imgproc { namespace fluid { -GAPI_EXPORTS GKernelPackage kernels(); +GAPI_EXPORTS_W GKernelPackage kernels(); }}}} diff --git a/modules/gapi/include/opencv2/gapi/gkernel.hpp b/modules/gapi/include/opencv2/gapi/gkernel.hpp index 59beb556b5..50d2efdd55 100644 --- a/modules/gapi/include/opencv2/gapi/gkernel.hpp +++ b/modules/gapi/include/opencv2/gapi/gkernel.hpp @@ -414,8 +414,8 @@ namespace cv { class GAPI_EXPORTS_W_SIMPLE GKernelPackage; namespace gapi { - GAPI_EXPORTS cv::GKernelPackage combine(const cv::GKernelPackage &lhs, - const cv::GKernelPackage &rhs); + GAPI_EXPORTS_W cv::GKernelPackage combine(const cv::GKernelPackage &lhs, + const cv::GKernelPackage &rhs); /// @private class GFunctor @@ -513,7 +513,7 @@ namespace gapi { * * @return a number of kernels in the package */ - std::size_t size() const; + GAPI_WRAP std::size_t size() const; /** * @brief Returns vector of transformations included in the package @@ -717,6 +717,8 @@ namespace gapi { { return combine(a, combine(b, rest...)); } + // NB(DM): Variadic-arg version in Python may require the same + // approach as used in GComputation::compile/apply. /** \addtogroup gapi_compile_args * @{ diff --git a/modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp b/modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp index d539f6007d..af9f3c6f6f 100644 --- a/modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp +++ b/modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp @@ -26,6 +26,13 @@ public: GAPI_WRAP PyParams(const std::string& tag, const std::string& model_path); + GAPI_WRAP + PyParams& cfgMeanStd(const std::string &layer_name, + const cv::Scalar &m, + const cv::Scalar &s); + GAPI_WRAP + PyParams& cfgNormalize(const std::string &layer_name, bool flag); + GBackend backend() const; std::string tag() const; cv::util::any params() const; diff --git a/modules/gapi/include/opencv2/gapi/infer/ie.hpp b/modules/gapi/include/opencv2/gapi/infer/ie.hpp index 0f7a59d8ae..470d50ac98 100644 --- a/modules/gapi/include/opencv2/gapi/infer/ie.hpp +++ b/modules/gapi/include/opencv2/gapi/infer/ie.hpp @@ -242,7 +242,7 @@ public: @param cfg Map of pairs: (config parameter name, config parameter value). @return reference to this parameter structure. */ - Params& pluginConfig(const IEConfig& cfg) { + Params& pluginConfig(const IEConfig& cfg) { desc.config = cfg; return *this; } diff --git a/modules/gapi/include/opencv2/gapi/infer/onnx.hpp b/modules/gapi/include/opencv2/gapi/infer/onnx.hpp index 90e04a2477..dc9a51e541 100644 --- a/modules/gapi/include/opencv2/gapi/infer/onnx.hpp +++ b/modules/gapi/include/opencv2/gapi/infer/onnx.hpp @@ -70,6 +70,14 @@ struct ParamDesc { std::vector names_to_remap; //!< Names of output layers that will be processed in PostProc function. bool is_generic; + + // TODO: Needs to modify the rest of ParamDesc accordingly to support + // both generic and non-generic options without duplication + // (as it was done for the OV IE backend) + // These values are pushed into the respective vector<> fields above + // when the generic infer parameters are unpacked (see GONNXBackendImpl::unpackKernel) + std::unordered_map > generic_mstd; + std::unordered_map generic_norm; }; } // namespace detail @@ -298,7 +306,17 @@ public: @param model_path path to model file (.onnx file). */ Params(const std::string& tag, const std::string& model_path) - : desc{model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true}, m_tag(tag) {} + : desc{model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true, {}, {} }, m_tag(tag) {} + + void cfgMeanStdDev(const std::string &layer, + const cv::Scalar &m, + const cv::Scalar &s) { + desc.generic_mstd[layer] = std::make_pair(m, s); + } + + void cfgNormalize(const std::string &layer, bool flag) { + desc.generic_norm[layer] = flag; + } // BEGIN(G-API's network parametrization API) GBackend backend() const { return cv::gapi::onnx::backend(); } diff --git a/modules/gapi/misc/python/pyopencv_gapi.hpp b/modules/gapi/misc/python/pyopencv_gapi.hpp index 07bacd3665..86273da321 100644 --- a/modules/gapi/misc/python/pyopencv_gapi.hpp +++ b/modules/gapi/misc/python/pyopencv_gapi.hpp @@ -785,15 +785,14 @@ static void unpackMetasToTuple(const cv::GMetaArgs& meta, } } -static cv::GArg setup_py(cv::detail::PyObjectHolder setup, - const cv::GMetaArgs& meta, - const cv::GArgs& gargs) +static cv::GArg run_py_setup(cv::detail::PyObjectHolder setup, + const cv::GMetaArgs &meta, + const cv::GArgs &gargs) { PyGILState_STATE gstate; gstate = PyGILState_Ensure(); - cv::GArg out; - + cv::GArg state; try { // NB: Doesn't increase reference counter (false), @@ -801,23 +800,20 @@ static cv::GArg setup_py(cv::detail::PyObjectHolder setup, // In case exception decrement reference counter. cv::detail::PyObjectHolder args(PyTuple_New(meta.size()), false); unpackMetasToTuple(meta, gargs, args); - // NB: Take an onwership because this state is "Python" type so it will be wrapped as-is - // into cv::GArg and stored in GPythonBackend. Object without ownership can't - // be dealocated outside this function. - cv::detail::PyObjectHolder result(PyObject_CallObject(setup.get(), args.get()), true); + PyObject *py_kernel_state = PyObject_CallObject(setup.get(), args.get()); if (PyErr_Occurred()) { PyErr_PrintEx(0); PyErr_Clear(); - throw std::logic_error("Python kernel failed with error!"); + throw std::logic_error("Python kernel setup failed with error!"); } // NB: In fact it's impossible situation, because errors were handled above. - GAPI_Assert(result.get() && "Python kernel returned NULL!"); + GAPI_Assert(py_kernel_state && "Python kernel setup returned NULL!"); - if (!pyopencv_to(result.get(), out, ArgInfo("arg", false))) + if (!pyopencv_to(py_kernel_state, state, ArgInfo("arg", false))) { - util::throw_error(std::logic_error("Unsupported output meta type")); + util::throw_error(std::logic_error("Failed to convert python state")); } } catch (...) @@ -826,7 +822,7 @@ static cv::GArg setup_py(cv::detail::PyObjectHolder setup, throw; } PyGILState_Release(gstate); - return out; + return state; } static GMetaArg get_meta_arg(PyObject* obj) @@ -947,7 +943,7 @@ static PyObject* pyopencv_cv_gapi_kernels(PyObject* , PyObject* py_args, PyObjec gapi::python::GPythonFunctor f( id.c_str(), std::bind(run_py_meta, cv::detail::PyObjectHolder{out_meta}, _1, _2), std::bind(run_py_kernel, cv::detail::PyObjectHolder{run}, _1), - std::bind(setup_py, cv::detail::PyObjectHolder{setup}, _1, _2)); + std::bind(run_py_setup, cv::detail::PyObjectHolder{setup}, _1, _2)); pkg.include(f); } else diff --git a/modules/gapi/misc/python/test/test_gapi_infer_onnx.py b/modules/gapi/misc/python/test/test_gapi_infer_onnx.py index 443c6d4396..f63e172475 100644 --- a/modules/gapi/misc/python/test/test_gapi_infer_onnx.py +++ b/modules/gapi/misc/python/test/test_gapi_infer_onnx.py @@ -14,21 +14,14 @@ try: if sys.version_info[:2] < (3, 0): raise unittest.SkipTest('Python 2.x is not supported') - CLASSIFICATION_MODEL_PATH = "onnx_models/vision/classification/squeezenet/model/squeezenet1.0-9.onnx" - - testdata_required = bool(os.environ.get('OPENCV_DNN_TEST_REQUIRE_TESTDATA', False)) + CLASSIFICATION_MODEL_PATH = "vision/classification/squeezenet/model/squeezenet1.0-9.onnx" class test_gapi_infer(NewOpenCVTests): - def find_dnn_file(self, filename, required=None): - if not required: - required = testdata_required - return self.find_file(filename, [os.environ.get('OPENCV_DNN_TEST_DATA_PATH', os.getcwd()), - os.environ['OPENCV_TEST_DATA_PATH']], - required=required) + def find_dnn_file(self, filename): + return self.find_file(filename, [os.environ.get('OPENCV_GAPI_ONNX_MODEL_PATH')], False) def test_onnx_classification(self): model_path = self.find_dnn_file(CLASSIFICATION_MODEL_PATH) - if model_path is None: raise unittest.SkipTest("Missing DNN test file") @@ -45,6 +38,7 @@ try: comp = cv.GComputation(cv.GIn(g_in), cv.GOut(g_out)) net = cv.gapi.onnx.params("squeeze-net", model_path) + net.cfgNormalize("data_0", False) try: out_gapi = comp.apply(cv.gin(in_mat), cv.gapi.compile_args(cv.gapi.networks(net))) except cv.error as err: diff --git a/modules/gapi/misc/python/test/test_gapi_kernels.py b/modules/gapi/misc/python/test/test_gapi_kernels.py new file mode 100644 index 0000000000..8573391984 --- /dev/null +++ b/modules/gapi/misc/python/test/test_gapi_kernels.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import numpy as np +import cv2 as cv +import os +import sys +import unittest + +from tests_common import NewOpenCVTests + + +try: + + if sys.version_info[:2] < (3, 0): + raise unittest.SkipTest('Python 2.x is not supported') + + class gapi_kernels_test(NewOpenCVTests): + + def test_fluid_core_package(self): + fluid_core = cv.gapi.core.fluid.kernels() + self.assertLess(0, fluid_core.size()) + + def test_fluid_imgproc_package(self): + fluid_imgproc = cv.gapi.imgproc.fluid.kernels() + self.assertLess(0, fluid_imgproc.size()) + + def test_combine(self): + fluid_core = cv.gapi.core.fluid.kernels() + fluid_imgproc = cv.gapi.imgproc.fluid.kernels() + fluid = cv.gapi.combine(fluid_core, fluid_imgproc) + self.assertEqual(fluid_core.size() + fluid_imgproc.size(), fluid.size()) + +except unittest.SkipTest as e: + + message = str(e) + + class TestSkip(unittest.TestCase): + def setUp(self): + self.skipTest('Skip tests: ' + message) + + def test_skip(): + pass + + pass + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() diff --git a/modules/gapi/misc/python/test/test_gapi_stateful_kernel.py b/modules/gapi/misc/python/test/test_gapi_stateful_kernel.py index 9b3b614523..f6de7b211b 100644 --- a/modules/gapi/misc/python/test/test_gapi_stateful_kernel.py +++ b/modules/gapi/misc/python/test/test_gapi_stateful_kernel.py @@ -24,7 +24,7 @@ try: in_types=[cv.GOpaque.Int], out_types=[cv.GOpaque.Int]) class GStatefulCounter: - """Accumulate state counter on every call""" + """Accumulates state counter on every call""" @staticmethod def outMeta(desc): @@ -45,6 +45,22 @@ try: return state.counter + class SumState: + def __init__(self): + self.sum = 0 + + + @cv.gapi.op('stateful_sum', + in_types=[cv.GOpaque.Int, cv.GOpaque.Int], + out_types=[cv.GOpaque.Int]) + class GStatefulSum: + """Accumulates sum on every call""" + + @staticmethod + def outMeta(lhs_desc, rhs_desc): + return cv.empty_gopaque_desc() + + class gapi_sample_pipelines(NewOpenCVTests): def test_stateful_kernel_single_instance(self): g_in = cv.GOpaque.Int() @@ -124,6 +140,64 @@ try: cc.stop() + def test_stateful_multiple_inputs(self): + @cv.gapi.kernel(GStatefulSum) + class GStatefulSumImpl: + """Implementation for GStatefulCounter operation.""" + + @staticmethod + def setup(lhs_desc, rhs_desc): + return SumState() + + @staticmethod + def run(lhs, rhs, state): + state.sum+= lhs + rhs + return state.sum + + + g_in1 = cv.GOpaque.Int() + g_in2 = cv.GOpaque.Int() + g_out = GStatefulSum.on(g_in1, g_in2) + comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out)) + pkg = cv.gapi.kernels(GStatefulSumImpl) + + lhs_list = [1, 10, 15] + rhs_list = [2, 14, 32] + + ref_out = 0 + for lhs, rhs in zip(lhs_list, rhs_list): + ref_out += lhs + rhs + gapi_out = comp.apply(cv.gin(lhs, rhs), cv.gapi.compile_args(pkg)) + self.assertEqual(ref_out, gapi_out) + + + def test_stateful_multiple_inputs_throw(self): + @cv.gapi.kernel(GStatefulSum) + class GStatefulSumImplIncorrect: + """Incorrect implementation for GStatefulCounter operation.""" + + # NB: setup methods is intentionally + # incorrect - accepts one meta arg instead of two + @staticmethod + def setup(desc): + return SumState() + + @staticmethod + def run(lhs, rhs, state): + state.sum+= lhs + rhs + return state.sum + + + g_in1 = cv.GOpaque.Int() + g_in2 = cv.GOpaque.Int() + g_out = GStatefulSum.on(g_in1, g_in2) + comp = cv.GComputation(cv.GIn(g_in1, g_in2), cv.GOut(g_out)) + pkg = cv.gapi.kernels(GStatefulSumImplIncorrect) + + with self.assertRaises(Exception): comp.apply(cv.gin(42, 42), + args=cv.gapi.compile_args(pkg)) + + except unittest.SkipTest as e: message = str(e) diff --git a/modules/gapi/misc/python/test/test_gapi_streaming.py b/modules/gapi/misc/python/test/test_gapi_streaming.py index e4c5926204..7f9de5f767 100644 --- a/modules/gapi/misc/python/test/test_gapi_streaming.py +++ b/modules/gapi/misc/python/test/test_gapi_streaming.py @@ -17,7 +17,7 @@ try: @cv.gapi.op('custom.delay', in_types=[cv.GMat], out_types=[cv.GMat]) class GDelay: - """Delay for 10 ms.""" + """Delay for 50 ms.""" @staticmethod def outMeta(desc): @@ -30,7 +30,7 @@ try: @staticmethod def run(img): - time.sleep(0.01) + time.sleep(0.05) return img @@ -289,8 +289,7 @@ try: ccomp.start() # Assert - max_num_frames = 10 - proc_num_frames = 0 + max_num_frames = 50 out_counter = 0 desync_out_counter = 0 @@ -307,12 +306,11 @@ try: else: none_counter += 1 - proc_num_frames += 1 - if proc_num_frames == max_num_frames: + if out_counter == max_num_frames: ccomp.stop() break - self.assertLess(0, proc_num_frames) + self.assertLess(0, out_counter) self.assertLess(desync_out_counter, out_counter) self.assertLess(0, none_counter) diff --git a/modules/gapi/src/backends/onnx/bindings_onnx.cpp b/modules/gapi/src/backends/onnx/bindings_onnx.cpp index c43b86e0c8..c9c5fc58fa 100644 --- a/modules/gapi/src/backends/onnx/bindings_onnx.cpp +++ b/modules/gapi/src/backends/onnx/bindings_onnx.cpp @@ -8,6 +8,19 @@ cv::gapi::onnx::PyParams::PyParams(const std::string& tag, const std::string& model_path) : m_priv(std::make_shared>(tag, model_path)) {} +cv::gapi::onnx::PyParams& cv::gapi::onnx::PyParams::cfgMeanStd(const std::string &layer_name, + const cv::Scalar &m, + const cv::Scalar &s) { + m_priv->cfgMeanStdDev(layer_name, m, s); + return *this; +} + +cv::gapi::onnx::PyParams& cv::gapi::onnx::PyParams::cfgNormalize(const std::string &layer_name, + bool flag) { + m_priv->cfgNormalize(layer_name, flag); + return *this; +} + cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const { return m_priv->backend(); } diff --git a/modules/gapi/src/backends/onnx/gonnxbackend.cpp b/modules/gapi/src/backends/onnx/gonnxbackend.cpp index 85e427792b..1194caeeb3 100644 --- a/modules/gapi/src/backends/onnx/gonnxbackend.cpp +++ b/modules/gapi/src/backends/onnx/gonnxbackend.cpp @@ -284,6 +284,7 @@ inline void preprocess(const cv::Mat& src, cv::resize(csc, rsz, cv::Size(new_w, new_h)); if (src.depth() == CV_8U && type == CV_32F) { rsz.convertTo(pp, type, ti.normalize ? 1.f / 255 : 1.f); + if (ti.mstd.has_value()) { pp -= ti.mstd->mean; pp /= ti.mstd->stdev; @@ -1143,24 +1144,31 @@ namespace { if (pp.is_generic) { auto& info = cv::util::any_cast(op.params); - for (const auto& a : info.in_names) + for (const auto& layer_name : info.in_names) { - pp.input_names.push_back(a); - } - // Adding const input is necessary because the definition of input_names - // includes const input. - for (const auto& a : pp.const_inputs) - { - pp.input_names.push_back(a.first); + pp.input_names.push_back(layer_name); + if (!pp.generic_mstd.empty()) { + const auto &ms = pp.generic_mstd.at(layer_name); + pp.mean.push_back(ms.first); + pp.stdev.push_back(ms.second); + } + if (!pp.generic_norm.empty()) { + pp.normalize.push_back(pp.generic_norm.at(layer_name)); + } } pp.num_in = info.in_names.size(); + // Incorporate extra parameters associated with input layer names + // FIXME(DM): The current form assumes ALL input layers require + // this information, this is obviously not correct + for (const auto& a : info.out_names) { pp.output_names.push_back(a); } pp.num_out = info.out_names.size(); - } + } // if(is_generic) -- note, the structure is already filled at the user + // end when a non-generic Params are used gm.metadata(nh).set(ONNXUnit{pp}); gm.metadata(nh).set(ONNXCallable{ki.run}); diff --git a/modules/gapi/test/infer/gapi_infer_onnx_test.cpp b/modules/gapi/test/infer/gapi_infer_onnx_test.cpp index c38aa9df1d..dff91c597e 100644 --- a/modules/gapi/test/infer/gapi_infer_onnx_test.cpp +++ b/modules/gapi/test/infer/gapi_infer_onnx_test.cpp @@ -423,13 +423,17 @@ public: cv::Rect(cv::Point{50, 100}, cv::Size{250, 360}) }; - void preprocess(const cv::Mat& src, cv::Mat& dst) { + // FIXME(dm): There's too much "preprocess" routines in this file + // Only one must stay but better design it wisely (and later) + void preprocess(const cv::Mat& src, cv::Mat& dst, bool norm = true) { const int new_h = 224; const int new_w = 224; cv::Mat tmp, cvt, rsz; cv::resize(src, rsz, cv::Size(new_w, new_h)); - rsz.convertTo(cvt, CV_32F, 1.f / 255); - tmp = (cvt - mean) / std; + rsz.convertTo(cvt, CV_32F, norm ? 1.f / 255 : 1.f); + tmp = norm + ? (cvt - mean) / std + : cvt; toCHW(tmp, dst); dst = dst.reshape(1, {1, 3, new_h, new_w}); } @@ -550,16 +554,16 @@ TEST_F(ONNXClassification, Infer) in_mat = cv::imread(findDataFile("cv/dpm/cat.png", false)); // ONNX_API code cv::Mat processed_mat; - preprocess(in_mat, processed_mat); + preprocess(in_mat, processed_mat, false); // NO normalization for 1.0-9, see #23597 infer(processed_mat, out_onnx); // G_API code G_API_NET(SqueezNet, , "squeeznet"); cv::GMat in; cv::GMat out = cv::gapi::infer(in); cv::GComputation comp(cv::GIn(in), cv::GOut(out)); - // NOTE: We have to normalize U8 tensor - // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(in_mat), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -573,7 +577,7 @@ TEST_F(ONNXClassification, InferTensor) in_mat = cv::imread(findDataFile("cv/dpm/cat.png", false)); // Create tensor cv::Mat tensor; - preprocess(in_mat, tensor); + preprocess(in_mat, tensor, false); // NO normalization for 1.0-9, see #23597 // ONNX_API code infer(tensor, out_onnx); // G_API code @@ -581,7 +585,9 @@ TEST_F(ONNXClassification, InferTensor) cv::GMat in; cv::GMat out = cv::gapi::infer(in); cv::GComputation comp(cv::GIn(in), cv::GOut(out)); - auto net = cv::gapi::onnx::Params { model_path }; + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(tensor), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -596,7 +602,7 @@ TEST_F(ONNXClassification, InferROI) const auto ROI = rois.at(0); // ONNX_API code cv::Mat roi_mat; - preprocess(in_mat(ROI), roi_mat); + preprocess(in_mat(ROI), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); // G_API code G_API_NET(SqueezNet, , "squeeznet"); @@ -604,9 +610,9 @@ TEST_F(ONNXClassification, InferROI) cv::GOpaque rect; cv::GMat out = cv::gapi::infer(rect, in); cv::GComputation comp(cv::GIn(in, rect), cv::GOut(out)); - // NOTE: We have to normalize U8 tensor - // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(in_mat, ROI), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -621,7 +627,7 @@ TEST_F(ONNXClassification, InferROIList) // ONNX_API code for (size_t i = 0; i < rois.size(); ++i) { cv::Mat roi_mat; - preprocess(in_mat(rois[i]), roi_mat); + preprocess(in_mat(rois[i]), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); } // G_API code @@ -632,7 +638,9 @@ TEST_F(ONNXClassification, InferROIList) cv::GComputation comp(cv::GIn(in, rr), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(in_mat, rois), cv::gout(out_gapi), cv::compile_args(cv::gapi::networks(net))); @@ -647,7 +655,7 @@ TEST_F(ONNXClassification, Infer2ROIList) // ONNX_API code for (size_t i = 0; i < rois.size(); ++i) { cv::Mat roi_mat; - preprocess(in_mat(rois[i]), roi_mat); + preprocess(in_mat(rois[i]), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); } // G_API code @@ -658,7 +666,9 @@ TEST_F(ONNXClassification, Infer2ROIList) cv::GComputation comp(cv::GIn(in, rr), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(in_mat, rois), cv::gout(out_gapi), cv::compile_args(cv::gapi::networks(net))); @@ -747,7 +757,7 @@ TEST_F(ONNXMediaFrame, InferBGR) in_mat = cv::imread(findDataFile("cv/dpm/cat.png", false)); // ONNX_API code cv::Mat processed_mat; - preprocess(in_mat, processed_mat); + preprocess(in_mat, processed_mat, false); // NO normalization for 1.0-9, see #23597 infer(processed_mat, out_onnx); // G_API code auto frame = MediaFrame::Create(in_mat); @@ -757,7 +767,9 @@ TEST_F(ONNXMediaFrame, InferBGR) cv::GComputation comp(cv::GIn(in), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -774,7 +786,7 @@ TEST_F(ONNXMediaFrame, InferYUV) cv::Mat pp; cvtColorTwoPlane(m_in_y, m_in_uv, pp, cv::COLOR_YUV2BGR_NV12); cv::Mat processed_mat; - preprocess(pp, processed_mat); + preprocess(pp, processed_mat, false); // NO normalization for 1.0-9, see #23597 infer(processed_mat, out_onnx); // G_API code G_API_NET(SqueezNet, , "squeeznet"); @@ -783,7 +795,9 @@ TEST_F(ONNXMediaFrame, InferYUV) cv::GComputation comp(cv::GIn(in), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -798,7 +812,7 @@ TEST_F(ONNXMediaFrame, InferROIBGR) auto frame = MediaFrame::Create(in_mat); // ONNX_API code cv::Mat roi_mat; - preprocess(in_mat(rois.front()), roi_mat); + preprocess(in_mat(rois.front()), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); // G_API code G_API_NET(SqueezNet, , "squeeznet"); @@ -808,7 +822,9 @@ TEST_F(ONNXMediaFrame, InferROIBGR) cv::GComputation comp(cv::GIn(in, rect), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame, rois.front()), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -825,7 +841,7 @@ TEST_F(ONNXMediaFrame, InferROIYUV) cv::Mat pp; cvtColorTwoPlane(m_in_y, m_in_uv, pp, cv::COLOR_YUV2BGR_NV12); cv::Mat roi_mat; - preprocess(pp(rois.front()), roi_mat); + preprocess(pp(rois.front()), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); // G_API code G_API_NET(SqueezNet, , "squeeznet"); @@ -835,7 +851,9 @@ TEST_F(ONNXMediaFrame, InferROIYUV) cv::GComputation comp(cv::GIn(in, rect), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame, rois.front()), cv::gout(out_gapi.front()), cv::compile_args(cv::gapi::networks(net))); @@ -851,7 +869,7 @@ TEST_F(ONNXMediaFrame, InferListBGR) // ONNX_API code for (size_t i = 0; i < rois.size(); ++i) { cv::Mat roi_mat; - preprocess(in_mat(rois[i]), roi_mat); + preprocess(in_mat(rois[i]), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); } // G_API code @@ -862,7 +880,9 @@ TEST_F(ONNXMediaFrame, InferListBGR) cv::GComputation comp(cv::GIn(in, rr), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame, rois), cv::gout(out_gapi), cv::compile_args(cv::gapi::networks(net))); @@ -880,7 +900,7 @@ TEST_F(ONNXMediaFrame, InferListYUV) cvtColorTwoPlane(m_in_y, m_in_uv, pp, cv::COLOR_YUV2BGR_NV12); for (size_t i = 0; i < rois.size(); ++i) { cv::Mat roi_mat; - preprocess(pp(rois[i]), roi_mat); + preprocess(pp(rois[i]), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); } // G_API code @@ -891,7 +911,9 @@ TEST_F(ONNXMediaFrame, InferListYUV) cv::GComputation comp(cv::GIn(in, rr), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame, rois), cv::gout(out_gapi), cv::compile_args(cv::gapi::networks(net))); @@ -933,7 +955,7 @@ TEST_F(ONNXMediaFrame, InferList2BGR) // ONNX_API code for (size_t i = 0; i < rois.size(); ++i) { cv::Mat roi_mat; - preprocess(in_mat(rois[i]), roi_mat); + preprocess(in_mat(rois[i]), roi_mat, false); // NO normalization for 1.0-9, see #23597 infer(roi_mat, out_onnx); } // G_API code @@ -944,7 +966,9 @@ TEST_F(ONNXMediaFrame, InferList2BGR) cv::GComputation comp(cv::GIn(in, rr), cv::GOut(out)); // NOTE: We have to normalize U8 tensor // so cfgMeanStd() is here - auto net = cv::gapi::onnx::Params { model_path }.cfgMeanStd({ mean }, { std }); + auto net = cv::gapi::onnx::Params { + model_path + }.cfgNormalize({false}); comp.apply(cv::gin(frame, rois), cv::gout(out_gapi), cv::compile_args(cv::gapi::networks(net)));