/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2013, OpenCV Foundation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/40#ifndef __OPENCV_TEST_PRECOMP_HPP__41#define __OPENCV_TEST_PRECOMP_HPP__4243#include "opencv2/ts.hpp"44#include "opencv2/ts/ts_perf.hpp"45#include "opencv2/core/utility.hpp"46#include "opencv2/core/ocl.hpp"4748#include "opencv2/dnn.hpp"49#include "test_common.hpp"5051namespace opencv_test {52using namespace cv::dnn;5354static testing::internal::ParamGenerator<Target> availableDnnTargets()55{56static std::vector<Target> targets;57if (targets.empty())58{59targets.push_back(DNN_TARGET_CPU);60#ifdef HAVE_OPENCL61if (cv::ocl::useOpenCL())62targets.push_back(DNN_TARGET_OPENCL);63#endif64}65return testing::ValuesIn(targets);66}6768class DNNTestLayer : public TestWithParam<tuple<Backend, Target> >69{70public:71dnn::Backend backend;72dnn::Target target;73double default_l1, default_lInf;7475DNNTestLayer()76{77backend = (dnn::Backend)(int)get<0>(GetParam());78target = (dnn::Target)(int)get<1>(GetParam());79getDefaultThresholds(backend, target, &default_l1, &default_lInf);80}8182static void getDefaultThresholds(int backend, int target, double* l1, double* lInf)83{84if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD)85{86*l1 = 4e-3;87*lInf = 2e-2;88}89else90{91*l1 = 1e-5;92*lInf = 1e-4;93}94}9596static void checkBackend(int backend, int target, Mat* inp = 0, Mat* ref = 0)97{98if (backend == DNN_BACKEND_OPENCV && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16))99{100#ifdef HAVE_OPENCL101if (!cv::ocl::useOpenCL())102#endif103{104throw SkipTestException("OpenCL is not available/disabled in OpenCV");105}106}107if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD)108{109if (!checkMyriadTarget())110{111throw SkipTestException("Myriad is not available/disabled in OpenCV");112}113#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE < 2018030000114if (inp && ref && inp->size[0] != 1)115{116// Myriad plugin supports only batch size 1. Slice a single sample.117if (inp->size[0] == ref->size[0])118{119std::vector<cv::Range> range(inp->dims, Range::all());120range[0] = Range(0, 1);121*inp = inp->operator()(range);122123range = std::vector<cv::Range>(ref->dims, Range::all());124range[0] = Range(0, 1);125*ref = ref->operator()(range);126}127else128throw SkipTestException("Myriad plugin supports only batch size 1");129}130#else131if (inp && ref && inp->dims == 4 && ref->dims == 4 &&132inp->size[0] != 1 && inp->size[0] != ref->size[0])133throw SkipTestException("Inconsistent batch size of input and output blobs for Myriad plugin");134135#endif136}137}138139protected:140void checkBackend(Mat* inp = 0, Mat* ref = 0)141{142checkBackend(backend, target, inp, ref);143}144};145146} // namespace147#endif148149150