From: Anton Potapov Date: Thu, 6 Aug 2020 03:26:49 +0000 (+0300) Subject: [PP GAPI] - U16toF32 conversion kernel (#1298) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea34f04028afd45745e34a03771b12f2bc0eef46;p=platform%2Fupstream%2Fdldt.git [PP GAPI] - U16toF32 conversion kernel (#1298) - the kernel itself is not yet used in the Preprocessing graph - tests --- diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp index f36c76f..f1b8e75 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.cpp @@ -2208,6 +2208,27 @@ GAPI_FLUID_KERNEL(FI420toRGB, I420toRGB, false) { calculate_i420_to_rgb_fallback(y_rows, u_row, v_row, out_rows, buf_width); } }; + +GAPI_FLUID_KERNEL(FU16toF32, U16toF32, false) { + static const int Window = 1; + + static void run(const cv::gapi::fluid::View& src, cv::gapi::fluid::Buffer& dst) { + GAPI_Assert(src.meta().depth == CV_16U); + GAPI_Assert(dst.meta().depth == CV_32F); + GAPI_Assert(src.meta().chan == 1); + GAPI_Assert(dst.meta().chan == 1); + GAPI_Assert(src.length() == dst.length()); + + const auto *in = src.InLine(0); + auto *out = dst.OutLine(); + + auto const width = dst.length(); + for (int i = 0; i < width; i++) { + out[i] = in[i]; + } + } +}; + } // namespace kernels //---------------------------------------------------------------------- @@ -2234,6 +2255,7 @@ cv::gapi::GKernelPackage preprocKernels() { , FSplit4 , FNV12toRGB , FI420toRGB + , FU16toF32 >(); } diff --git a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp index 6164e31..8caacd2 100644 --- a/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp +++ b/inference-engine/src/preprocessing/ie_preprocess_gapi_kernels.hpp @@ -143,6 +143,16 @@ namespace gapi { } }; + G_TYPED_KERNEL(U16toF32, , "com.intel.ie.u16tof32") { + static cv::GMatDesc outMeta(const cv::GMatDesc& in) { + GAPI_Assert(in.depth == CV_16U); + + return in.withDepth(CV_32F); + } + }; + + + cv::gapi::GKernelPackage preprocKernels(); } // namespace gapi diff --git a/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.cpp b/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.cpp index 071faa6..479c3e5 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.cpp +++ b/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.cpp @@ -624,6 +624,34 @@ TEST_P(I420toRGBTestGAPI, AccuracyTest) EXPECT_EQ(sz, out_mat_gapi.size()); } } + +TEST_P(U16toF32TestGAPI, AccuracyTest) +{ + const auto params = GetParam(); + cv::Size sz = std::get<0>(params); + double tolerance = std::get<1>(params); + + initMatrixRandU(CV_16UC1, sz, CV_32FC1); + + // G-API code ////////////////////////////////////////////////////////////// + FluidU16ToF32Computation cc(to_test(in_mat1), to_test(out_mat_gapi)); + cc.warmUp(); + +#if PERF_TEST + // iterate testing, and print performance + test_ms([&](){ cc.apply(); }, + 400, "U16ToF32 GAPI %s %dx%d", typeToString(CV_16UC1).c_str(), sz.width, sz.height); +#endif + + // OpenCV code ///////////////////////////////////////////////////////////// + { + in_mat1.convertTo(out_mat_ocv, CV_32FC1); + } + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_LE(cv::norm(out_mat_ocv, out_mat_gapi, cv::NORM_INF), tolerance); + } +} //---------------------------------------------------------------------- TEST_P(ResizeTestIE, AccuracyTest) diff --git a/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.hpp b/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.hpp index c76f67f..fb4535a 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.hpp +++ b/inference-engine/tests_deprecated/fluid_preproc/common/fluid_tests.hpp @@ -19,7 +19,7 @@ struct NV12toRGBTestGAPI: public TestParams> {}; struct I420toRGBTestGAPI: public TestParams> {}; struct ResizeRoiTestGAPI: public testing::TestWithParam, cv::Rect, double>> {}; struct ResizeRGB8URoiTestGAPI: public testing::TestWithParam, cv::Rect, double>> {}; - +struct U16toF32TestGAPI: public TestParams> {}; //------------------------------------------------------------------------------ struct ResizeTestIE: public testing::TestWithParam, double>> {}; diff --git a/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp b/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp index 6684cd3..1a41fcc 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp +++ b/inference-engine/tests_deprecated/fluid_preproc/cpu/fluid_tests_cpu.cpp @@ -170,6 +170,16 @@ INSTANTIATE_TEST_CASE_P(I420toRGBTestFluid, I420toRGBTestGAPI, cv::Size( 320, 200)), Values(0))); +INSTANTIATE_TEST_CASE_P(U16toF32TestGAPIFluid, U16toF32TestGAPI, + Combine(Values(cv::Size(3840, 2160), + cv::Size(1920, 1080), + cv::Size(1280, 720), + cv::Size(1280, 960), + cv::Size( 960, 720), + cv::Size( 640, 480), + cv::Size( 300, 300), + cv::Size( 320, 200)), + Values(0))); INSTANTIATE_TEST_CASE_P(ResizeRoiTestFluid, ResizeRoiTestGAPI, Combine(Values(CV_8UC1, CV_8UC3), diff --git a/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.cpp b/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.cpp index 8ec8bd9..f4afb49 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.cpp +++ b/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.cpp @@ -213,3 +213,15 @@ FluidI420toRGBComputation::FluidI420toRGBComputation(test::Mat inMat_y, test::Ma ,{to_own(outMat)} }) {} + +FluidU16ToF32Computation::FluidU16ToF32Computation(test::Mat inMatU16, test::Mat outMatF32) + : FluidComputation(new Priv{ []()-> cv::GComputation { + cv::GMat in_U16; + cv::GMat outf32 = InferenceEngine::gapi::U16toF32::on(in_U16); + return cv::GComputation(cv::GIn(in_U16), cv::GOut(outf32)); + }() + , {to_own(inMatU16)} + , {to_own(outMatF32)} + }) +{} + diff --git a/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.hpp b/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.hpp index 26b9221..39d06a3 100644 --- a/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.hpp +++ b/inference-engine/tests_deprecated/fluid_preproc/fluid_test_computations/fluid_test_computations.hpp @@ -98,4 +98,10 @@ public: FluidI420toRGBComputation(test::Mat inMat_y, test::Mat inMat_u, test::Mat inMat_v, test::Mat outMat); }; +class FLUID_COMPUTATION_VISIBILITY FluidU16ToF32Computation : public FluidComputation +{ +public: + FluidU16ToF32Computation(test::Mat inMatU16, test::Mat outMatF32); +}; + #endif // FLUID_TEST_COMPUTATIONS_HPP