From a6277370cab46e4394b35cc93cf9aada69cb2a70 Mon Sep 17 00:00:00 2001 From: yuki takehara Date: Sun, 28 Nov 2021 03:34:52 +0900 Subject: [PATCH 01/13] Merge pull request #21107 from take1014:remove_assert_21038 resolves #21038 * remove C assert * revert C header * fix several points in review * fix test_ds.cpp --- modules/calib3d/src/calibration.cpp | 8 +-- modules/calib3d/src/compat_ptsetreg.cpp | 6 +- .../calib3d/test/test_cameracalibration.cpp | 22 +++---- modules/calib3d/test/test_fundam.cpp | 8 +-- modules/calib3d/test/test_stereomatching.cpp | 34 +++++------ modules/core/include/opencv2/core/wimage.hpp | 8 +-- modules/core/src/array.cpp | 20 +++---- modules/core/src/datastructs.cpp | 60 +++++++++---------- modules/core/src/dxt.cpp | 26 ++++---- modules/core/src/lapack.cpp | 4 +- modules/core/src/matmul.simd.hpp | 4 +- modules/core/src/matrix_sparse.cpp | 2 +- .../src/opencl/runtime/opencl_clamdblas.cpp | 2 +- .../src/opencl/runtime/opencl_clamdfft.cpp | 2 +- .../core/src/opencl/runtime/opencl_core.cpp | 2 +- modules/core/src/persistence.cpp | 4 +- modules/core/src/persistence_json.cpp | 2 +- modules/core/src/persistence_types.cpp | 18 +++--- modules/core/src/persistence_xml.cpp | 6 +- modules/core/src/persistence_yml.cpp | 2 +- modules/core/test/test_ds.cpp | 46 +++++++------- modules/core/test/test_dxt.cpp | 2 +- modules/core/test/test_mat.cpp | 6 +- modules/core/test/test_math.cpp | 14 ++--- .../src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp | 1 - .../test/test_descriptors_regression.cpp | 4 +- .../test/test_detectors_regression.cpp | 4 +- .../features2d/test/test_nearestneighbors.cpp | 2 +- .../flann/include/opencv2/flann/nn_index.h | 4 +- modules/highgui/src/precomp.hpp | 1 - modules/highgui/src/window_carbon.cpp | 2 +- modules/highgui/src/window_gtk.cpp | 2 +- modules/highgui/src/window_w32.cpp | 7 +-- modules/highgui/src/window_winrt.cpp | 1 - modules/imgproc/src/approx.cpp | 20 +++---- modules/imgproc/src/bilateral_filter.simd.hpp | 2 +- modules/imgproc/src/contours.cpp | 4 +- modules/imgproc/src/convhull.cpp | 2 +- modules/imgproc/src/drawing.cpp | 12 ++-- modules/imgproc/src/emd.cpp | 6 +- modules/imgproc/src/hough.cpp | 8 +-- modules/imgproc/src/median_blur.simd.hpp | 2 +- modules/imgproc/src/moments.cpp | 2 +- modules/imgproc/src/precomp.hpp | 1 - modules/imgproc/src/resize.cpp | 8 +-- modules/imgproc/src/samplers.cpp | 2 +- modules/imgproc/src/segmentation.cpp | 6 +- modules/imgproc/src/subdivision2d.cpp | 2 +- modules/imgproc/test/test_approxpoly.cpp | 4 +- .../imgproc/test/test_bilateral_filter.cpp | 2 +- modules/imgproc/test/test_canny.cpp | 2 +- modules/imgproc/test/test_color.cpp | 12 ++-- modules/imgproc/test/test_contours.cpp | 2 +- modules/imgproc/test/test_convhull.cpp | 16 ++--- .../imgproc/test/test_distancetransform.cpp | 2 +- modules/imgproc/test/test_filter.cpp | 8 +-- modules/imgproc/test/test_imgwarp.cpp | 4 +- modules/imgproc/test/test_imgwarp_strict.cpp | 2 +- modules/imgproc/test/test_templmatch.cpp | 2 +- modules/imgproc/test/test_thresh.cpp | 4 +- modules/ml/src/precomp.hpp | 1 - modules/ml/src/tree.cpp | 2 +- modules/objdetect/src/cascadedetect.cpp | 8 +-- .../objdetect/src/detection_based_tracker.cpp | 1 - modules/objdetect/src/haar.cpp | 4 +- modules/objdetect/src/hog.cpp | 4 +- modules/objdetect/test/test_cascadeandhog.cpp | 12 ++-- modules/ts/src/ocl_perf.cpp | 2 +- modules/ts/src/ts.cpp | 2 +- modules/ts/src/ts_arrtest.cpp | 6 +- modules/ts/src/ts_func.cpp | 8 +-- modules/ts/src/ts_perf.cpp | 8 +-- modules/videoio/src/cap_cmu.cpp | 4 +- modules/videoio/src/cap_dc1394.cpp | 2 +- modules/videoio/src/cap_dc1394_v2.cpp | 1 - modules/videoio/src/cap_ffmpeg_impl.hpp | 9 ++- modules/videoio/src/cap_giganetix.cpp | 2 +- modules/videoio/src/cap_libv4l.cpp | 3 +- modules/videoio/src/cap_qt.cpp | 5 +- modules/videoio/src/cap_v4l.cpp | 5 +- modules/videoio/src/precomp.hpp | 1 - 81 files changed, 277 insertions(+), 286 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 650735f035..ee1a751530 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -2125,7 +2125,7 @@ static double cvStereoCalibrateImpl( const CvMat* _objectPoints, const CvMat* _i if( solver.state == CvLevMarq::CALC_J ) { int iofs = (nimages+1)*6 + k*NINTRINSIC, eofs = (i+1)*6; - assert( JtJ && JtErr ); + CV_Assert( JtJ && JtErr ); Mat _JtJ(cvarrToMat(JtJ)), _JtErr(cvarrToMat(JtErr)); @@ -2929,7 +2929,7 @@ cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, CvMat Qx = cvMat(3, 3, CV_64F, _Qx); cvMatMul(&M, &Qx, &R); - assert(fabs(matR[2][1]) < FLT_EPSILON); + CV_DbgAssert(fabs(matR[2][1]) < FLT_EPSILON); matR[2][1] = 0; /* Find Givens rotation for y axis. */ @@ -2948,7 +2948,7 @@ cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, CvMat Qy = cvMat(3, 3, CV_64F, _Qy); cvMatMul(&R, &Qy, &M); - assert(fabs(matM[2][0]) < FLT_EPSILON); + CV_DbgAssert(fabs(matM[2][0]) < FLT_EPSILON); matM[2][0] = 0; /* Find Givens rotation for z axis. */ @@ -2968,7 +2968,7 @@ cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ, CvMat Qz = cvMat(3, 3, CV_64F, _Qz); cvMatMul(&M, &Qz, &R); - assert(fabs(matR[1][0]) < FLT_EPSILON); + CV_DbgAssert(fabs(matR[1][0]) < FLT_EPSILON); matR[1][0] = 0; // Solve the decomposition ambiguity. diff --git a/modules/calib3d/src/compat_ptsetreg.cpp b/modules/calib3d/src/compat_ptsetreg.cpp index 6e67000b3b..6199f26bb2 100644 --- a/modules/calib3d/src/compat_ptsetreg.cpp +++ b/modules/calib3d/src/compat_ptsetreg.cpp @@ -121,7 +121,7 @@ bool CvLevMarq::update( const CvMat*& _param, CvMat*& matJ, CvMat*& _err ) { matJ = _err = 0; - assert( !err.empty() ); + CV_Assert( !err.empty() ); if( state == DONE ) { _param = param; @@ -154,7 +154,7 @@ bool CvLevMarq::update( const CvMat*& _param, CvMat*& matJ, CvMat*& _err ) return true; } - assert( state == CHECK_ERR ); + CV_Assert( state == CHECK_ERR ); errNorm = cvNorm( err, 0, CV_L2 ); if( errNorm > prevErrNorm ) { @@ -222,7 +222,7 @@ bool CvLevMarq::updateAlt( const CvMat*& _param, CvMat*& _JtJ, CvMat*& _JtErr, d return true; } - assert( state == CHECK_ERR ); + CV_Assert( state == CHECK_ERR ); if( errNorm > prevErrNorm ) { if( ++lambdaLg10 <= 16 ) diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 366eee341a..a63c131a0f 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -831,30 +831,30 @@ void CV_CameraCalibrationTest_CPP::calibrate(int imageCount, int* pointCounts, perViewErrorsMat, flags ); - assert( stdDevsMatInt.type() == CV_64F ); - assert( stdDevsMatInt.total() == static_cast(CV_CALIB_NINTRINSIC) ); + CV_Assert( stdDevsMatInt.type() == CV_64F ); + CV_Assert( stdDevsMatInt.total() == static_cast(CV_CALIB_NINTRINSIC) ); memcpy( stdDevs, stdDevsMatInt.ptr(), CV_CALIB_NINTRINSIC*sizeof(double) ); - assert( stdDevsMatExt.type() == CV_64F ); - assert( stdDevsMatExt.total() == static_cast(6*imageCount) ); + CV_Assert( stdDevsMatExt.type() == CV_64F ); + CV_Assert( stdDevsMatExt.total() == static_cast(6*imageCount) ); memcpy( stdDevs + CV_CALIB_NINTRINSIC, stdDevsMatExt.ptr(), 6*imageCount*sizeof(double) ); - assert( perViewErrorsMat.type() == CV_64F); - assert( perViewErrorsMat.total() == static_cast(imageCount) ); + CV_Assert( perViewErrorsMat.type() == CV_64F); + CV_Assert( perViewErrorsMat.total() == static_cast(imageCount) ); memcpy( perViewErrors, perViewErrorsMat.ptr(), imageCount*sizeof(double) ); - assert( cameraMatrix.type() == CV_64FC1 ); + CV_Assert( cameraMatrix.type() == CV_64FC1 ); memcpy( _cameraMatrix, cameraMatrix.ptr(), 9*sizeof(double) ); - assert( cameraMatrix.type() == CV_64FC1 ); + CV_Assert( cameraMatrix.type() == CV_64FC1 ); memcpy( _distortionCoeffs, distCoeffs.ptr(), 4*sizeof(double) ); vector::iterator rvecsIt = rvecs.begin(); vector::iterator tvecsIt = tvecs.begin(); double *rm = rotationMatrices, *tm = translationVectors; - assert( rvecsIt->type() == CV_64FC1 ); - assert( tvecsIt->type() == CV_64FC1 ); + CV_Assert( rvecsIt->type() == CV_64FC1 ); + CV_Assert( tvecsIt->type() == CV_64FC1 ); for( int i = 0; i < imageCount; ++rvecsIt, ++tvecsIt, i++, rm+=9, tm+=3 ) { Mat r9( 3, 3, CV_64FC1 ); @@ -1141,7 +1141,7 @@ void CV_ProjectPointsTest::run(int) imgPoints, dpdrot, dpdt, dpdf, dpdc, dpddist, 0 ); // calculate and check image points - assert( (int)imgPoints.size() == pointCount ); + CV_Assert( (int)imgPoints.size() == pointCount ); vector::const_iterator it = imgPoints.begin(); for( int i = 0; i < pointCount; i++, ++it ) { diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 236db6ec4d..853695ef15 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -56,7 +56,7 @@ static int cvTsRodrigues( const CvMat* src, CvMat* dst, CvMat* jacobian ) if( jacobian ) { - assert( (jacobian->rows == 9 && jacobian->cols == 3) || + CV_Assert( (jacobian->rows == 9 && jacobian->cols == 3) || (jacobian->rows == 3 && jacobian->cols == 9) ); } @@ -65,7 +65,7 @@ static int cvTsRodrigues( const CvMat* src, CvMat* dst, CvMat* jacobian ) double r[3], theta; CvMat _r = cvMat( src->rows, src->cols, CV_MAKETYPE(CV_64F,CV_MAT_CN(src->type)), r); - assert( dst->rows == 3 && dst->cols == 3 ); + CV_Assert( dst->rows == 3 && dst->cols == 3 ); cvConvert( src, &_r ); @@ -320,7 +320,7 @@ static int cvTsRodrigues( const CvMat* src, CvMat* dst, CvMat* jacobian ) } else { - assert(0); + CV_Assert(0); return 0; } @@ -404,7 +404,7 @@ static void test_convertHomogeneous( const Mat& _src, Mat& _dst ) } else { - assert( count == dst.cols ); + CV_Assert( count == dst.cols ); ddims = dst.channels()*dst.rows; if( dst.rows == 1 ) { diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index e92c170c00..4ea23ebff3 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -406,7 +406,7 @@ void CV_StereoMatchingTest::run(int) { string dataPath = ts->get_data_path() + "cv/"; string algorithmName = name; - assert( !algorithmName.empty() ); + CV_Assert( !algorithmName.empty() ); if( dataPath.empty() ) { ts->printf( cvtest::TS::LOG, "dataPath is empty" ); @@ -553,22 +553,22 @@ int CV_StereoMatchingTest::processStereoMatchingResults( FileStorage& fs, int ca { // rightDisp is not used in current test virsion int code = cvtest::TS::OK; - assert( fs.isOpened() ); - assert( trueLeftDisp.type() == CV_32FC1 ); - assert( trueRightDisp.empty() || trueRightDisp.type() == CV_32FC1 ); - assert( leftDisp.type() == CV_32FC1 && (rightDisp.empty() || rightDisp.type() == CV_32FC1) ); + CV_Assert( fs.isOpened() ); + CV_Assert( trueLeftDisp.type() == CV_32FC1 ); + CV_Assert( trueRightDisp.empty() || trueRightDisp.type() == CV_32FC1 ); + CV_Assert( leftDisp.type() == CV_32FC1 && (rightDisp.empty() || rightDisp.type() == CV_32FC1) ); // get masks for unknown ground truth disparity values Mat leftUnknMask, rightUnknMask; DatasetParams params = datasetsParams[caseDatasets[caseIdx]]; absdiff( trueLeftDisp, Scalar(params.dispUnknVal), leftUnknMask ); leftUnknMask = leftUnknMask < std::numeric_limits::epsilon(); - assert(leftUnknMask.type() == CV_8UC1); + CV_Assert(leftUnknMask.type() == CV_8UC1); if( !trueRightDisp.empty() ) { absdiff( trueRightDisp, Scalar(params.dispUnknVal), rightUnknMask ); rightUnknMask = rightUnknMask < std::numeric_limits::epsilon(); - assert(rightUnknMask.type() == CV_8UC1); + CV_Assert(rightUnknMask.type() == CV_8UC1); } // calculate errors @@ -623,7 +623,7 @@ int CV_StereoMatchingTest::readDatasetsParams( FileStorage& fs ) } datasetsParams.clear(); FileNode fn = fs.getFirstTopLevelNode(); - assert(fn.isSeq()); + CV_Assert(fn.isSeq()); for( int i = 0; i < (int)fn.size(); i+=3 ) { String _name = fn[i]; @@ -649,7 +649,7 @@ int CV_StereoMatchingTest::readRunParams( FileStorage& fs ) void CV_StereoMatchingTest::writeErrors( const string& errName, const vector& errors, FileStorage* fs ) { - assert( (int)errors.size() == ERROR_KINDS_COUNT ); + CV_Assert( (int)errors.size() == ERROR_KINDS_COUNT ); vector::const_iterator it = errors.begin(); if( fs ) for( int i = 0; i < ERROR_KINDS_COUNT; i++, ++it ) @@ -696,9 +696,9 @@ void CV_StereoMatchingTest::readROI( FileNode& fn, Rect& validROI ) int CV_StereoMatchingTest::compareErrors( const vector& calcErrors, const vector& validErrors, const vector& eps, const string& errName ) { - assert( (int)calcErrors.size() == ERROR_KINDS_COUNT ); - assert( (int)validErrors.size() == ERROR_KINDS_COUNT ); - assert( (int)eps.size() == ERROR_KINDS_COUNT ); + CV_Assert( (int)calcErrors.size() == ERROR_KINDS_COUNT ); + CV_Assert( (int)validErrors.size() == ERROR_KINDS_COUNT ); + CV_Assert( (int)eps.size() == ERROR_KINDS_COUNT ); vector::const_iterator calcIt = calcErrors.begin(), validIt = validErrors.begin(), epsIt = eps.begin(); @@ -757,7 +757,7 @@ protected: { int code = CV_StereoMatchingTest::readRunParams( fs ); FileNode fn = fs.getFirstTopLevelNode(); - assert(fn.isSeq()); + CV_Assert(fn.isSeq()); for( int i = 0; i < (int)fn.size(); i+=5 ) { String caseName = fn[i], datasetName = fn[i+1]; @@ -776,8 +776,8 @@ protected: Rect& calcROI, Mat& leftDisp, Mat& /*rightDisp*/, int caseIdx ) { RunParams params = caseRunParams[caseIdx]; - assert( params.ndisp%16 == 0 ); - assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 ); + CV_Assert( params.ndisp%16 == 0 ); + CV_Assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 ); Mat leftImg; cvtColor( _leftImg, leftImg, COLOR_BGR2GRAY ); Mat rightImg; cvtColor( _rightImg, rightImg, COLOR_BGR2GRAY ); @@ -883,7 +883,7 @@ protected: { int code = CV_StereoMatchingTest::readRunParams(fs); FileNode fn = fs.getFirstTopLevelNode(); - assert(fn.isSeq()); + CV_Assert(fn.isSeq()); for( int i = 0; i < (int)fn.size(); i+=5 ) { String caseName = fn[i], datasetName = fn[i+1]; @@ -902,7 +902,7 @@ protected: Rect& calcROI, Mat& leftDisp, Mat& /*rightDisp*/, int caseIdx ) { RunParams params = caseRunParams[caseIdx]; - assert( params.ndisp%16 == 0 ); + CV_Assert( params.ndisp%16 == 0 ); Ptr sgbm = StereoSGBM::create( 0, params.ndisp, params.winSize, 10*params.winSize*params.winSize, 40*params.winSize*params.winSize, diff --git a/modules/core/include/opencv2/core/wimage.hpp b/modules/core/include/opencv2/core/wimage.hpp index c7b6efa06a..da3a7ba0b3 100644 --- a/modules/core/include/opencv2/core/wimage.hpp +++ b/modules/core/include/opencv2/core/wimage.hpp @@ -236,11 +236,11 @@ protected: void operator=(const WImage&); explicit WImage(IplImage* img) : image_(img) { - assert(!img || img->depth == Depth()); + CV_Assert(!img || img->depth == Depth()); } void SetIpl(IplImage* image) { - assert(!image || image->depth == Depth()); + CV_Assert(!image || image->depth == Depth()); image_ = image; } @@ -260,7 +260,7 @@ public: enum { kChannels = C }; explicit WImageC(IplImage* img) : WImage(img) { - assert(!img || img->nChannels == Channels()); + CV_Assert(!img || img->nChannels == Channels()); } // Construct a view into a region of this image @@ -283,7 +283,7 @@ protected: void operator=(const WImageC&); void SetIpl(IplImage* image) { - assert(!image || image->depth == WImage::Depth()); + CV_Assert(!image || image->depth == WImage::Depth()); WImage::SetIpl(image); } }; diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index 1a5ea0100f..2d87a8d9f2 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -497,7 +497,7 @@ cvInitNArrayIterator( int count, CvArr** arrs, // returns zero value if iteration is finished, non-zero otherwise CV_IMPL int cvNextNArraySlice( CvNArrayIterator* iterator ) { - assert( iterator != 0 ); + CV_Assert( iterator != 0 ); int i, dims; for( dims = iterator->dims; dims > 0; dims-- ) @@ -648,7 +648,7 @@ icvGetNodePtr( CvSparseMat* mat, const int* idx, int* _type, int i, tabidx; unsigned hashval = 0; CvSparseNode *node; - assert( CV_IS_SPARSE_MAT( mat )); + CV_Assert( CV_IS_SPARSE_MAT( mat )); if( !precalc_hashval ) { @@ -697,7 +697,7 @@ icvGetNodePtr( CvSparseMat* mat, const int* idx, int* _type, int newrawsize = newsize*sizeof(newtable[0]); CvSparseMatIterator iterator; - assert( (newsize & (newsize - 1)) == 0 ); + CV_Assert( (newsize & (newsize - 1)) == 0 ); // resize hash table newtable = (void**)cvAlloc( newrawsize ); @@ -742,7 +742,7 @@ icvDeleteNode( CvSparseMat* mat, const int* idx, unsigned* precalc_hashval ) int i, tabidx; unsigned hashval = 0; CvSparseNode *node, *prev = 0; - assert( CV_IS_SPARSE_MAT( mat )); + CV_Assert( CV_IS_SPARSE_MAT( mat )); if( !precalc_hashval ) { @@ -1462,7 +1462,7 @@ cvScalarToRawData( const CvScalar* scalar, void* data, int type, int extend_to_1 int cn = CV_MAT_CN( type ); int depth = type & CV_MAT_DEPTH_MASK; - assert( scalar && data ); + CV_Assert( scalar && data ); if( (unsigned)(cn - 1) >= 4 ) CV_Error( CV_StsOutOfRange, "The number of channels must be 1, 2, 3 or 4" ); @@ -1509,7 +1509,7 @@ cvScalarToRawData( const CvScalar* scalar, void* data, int type, int extend_to_1 ((double*)data)[cn] = (double)(scalar->val[cn]); break; default: - assert(0); + CV_Assert(0); CV_Error( CV_BadDepth, "" ); } @@ -1534,7 +1534,7 @@ cvRawDataToScalar( const void* data, int flags, CvScalar* scalar ) { int cn = CV_MAT_CN( flags ); - assert( scalar && data ); + CV_Assert( scalar && data ); if( (unsigned)(cn - 1) >= 4 ) CV_Error( CV_StsOutOfRange, "The number of channels must be 1, 2, 3 or 4" ); @@ -1572,7 +1572,7 @@ cvRawDataToScalar( const void* data, int flags, CvScalar* scalar ) scalar->val[cn] = ((double*)data)[cn]; break; default: - assert(0); + CV_Assert(0); CV_Error( CV_BadDepth, "" ); } } @@ -2623,7 +2623,7 @@ cvReshapeMatND( const CvArr* arr, { CvMatND* mat = (CvMatND*)arr; - assert( new_cn > 0 ); + CV_Assert( new_cn > 0 ); int last_dim_size = mat->dim[mat->dims-1].size*CV_MAT_CN(mat->type); int new_size = last_dim_size/new_cn; @@ -2901,7 +2901,7 @@ CV_IMPL IplImage * cvCreateImage( CvSize size, int depth, int channels ) { IplImage *img = cvCreateImageHeader( size, depth, channels ); - assert( img ); + CV_Assert( img ); cvCreateData( img ); return img; diff --git a/modules/core/src/datastructs.cpp b/modules/core/src/datastructs.cpp index cd9196a130..898fce4cc2 100644 --- a/modules/core/src/datastructs.cpp +++ b/modules/core/src/datastructs.cpp @@ -97,7 +97,7 @@ icvInitMemStorage( CvMemStorage* storage, int block_size ) block_size = CV_STORAGE_BLOCK_SIZE; block_size = cvAlign( block_size, CV_STRUCT_ALIGN ); - assert( sizeof(CvMemBlock) % CV_STRUCT_ALIGN == 0 ); + CV_Assert( sizeof(CvMemBlock) % CV_STRUCT_ALIGN == 0 ); memset( storage, 0, sizeof( *storage )); storage->signature = CV_STORAGE_MAGIC_VAL; @@ -240,7 +240,7 @@ icvGoNextMemBlock( CvMemStorage * storage ) if( block == parent->top ) /* the single allocated block */ { - assert( parent->bottom == block ); + CV_Assert( parent->bottom == block ); parent->top = parent->bottom = 0; parent->free_space = 0; } @@ -266,7 +266,7 @@ icvGoNextMemBlock( CvMemStorage * storage ) if( storage->top->next ) storage->top = storage->top->next; storage->free_space = storage->block_size - sizeof(CvMemBlock); - assert( storage->free_space % CV_STRUCT_ALIGN == 0 ); + CV_Assert( storage->free_space % CV_STRUCT_ALIGN == 0 ); } @@ -331,7 +331,7 @@ cvMemStorageAlloc( CvMemStorage* storage, size_t size ) if( size > INT_MAX ) CV_Error( CV_StsOutOfRange, "Too large memory block is requested" ); - assert( storage->free_space % CV_STRUCT_ALIGN == 0 ); + CV_Assert( storage->free_space % CV_STRUCT_ALIGN == 0 ); if( (size_t)storage->free_space < size ) { @@ -343,7 +343,7 @@ cvMemStorageAlloc( CvMemStorage* storage, size_t size ) } ptr = ICV_FREE_PTR(storage); - assert( (size_t)ptr % CV_STRUCT_ALIGN == 0 ); + CV_Assert( (size_t)ptr % CV_STRUCT_ALIGN == 0 ); storage->free_space = cvAlignLeft(storage->free_space - (int)size, CV_STRUCT_ALIGN ); return ptr; @@ -683,7 +683,7 @@ icvGrowSeq( CvSeq *seq, int in_front_of ) else { icvGoNextMemBlock( storage ); - assert( storage->free_space >= delta ); + CV_Assert( storage->free_space >= delta ); } } @@ -716,7 +716,7 @@ icvGrowSeq( CvSeq *seq, int in_front_of ) * For used blocks it means current number * of sequence elements in the block: */ - assert( block->count % seq->elem_size == 0 && block->count > 0 ); + CV_Assert( block->count % seq->elem_size == 0 && block->count > 0 ); if( !in_front_of ) { @@ -732,7 +732,7 @@ icvGrowSeq( CvSeq *seq, int in_front_of ) if( block != block->prev ) { - assert( seq->first->start_index == 0 ); + CV_Assert( seq->first->start_index == 0 ); seq->first = block; } else @@ -760,7 +760,7 @@ icvFreeSeqBlock( CvSeq *seq, int in_front_of ) { CvSeqBlock *block = seq->first; - assert( (in_front_of ? block : block->prev)->count == 0 ); + CV_Assert( (in_front_of ? block : block->prev)->count == 0 ); if( block == block->prev ) /* single block case */ { @@ -775,7 +775,7 @@ icvFreeSeqBlock( CvSeq *seq, int in_front_of ) if( !in_front_of ) { block = block->prev; - assert( seq->ptr == block->data ); + CV_Assert( seq->ptr == block->data ); block->count = (int)(seq->block_max - seq->ptr); seq->block_max = seq->ptr = block->prev->data + @@ -804,7 +804,7 @@ icvFreeSeqBlock( CvSeq *seq, int in_front_of ) block->next->prev = block->prev; } - assert( block->count > 0 && block->count % seq->elem_size == 0 ); + CV_Assert( block->count > 0 && block->count % seq->elem_size == 0 ); block->next = seq->free_blocks; seq->free_blocks = block; } @@ -861,7 +861,7 @@ cvFlushSeqWriter( CvSeqWriter * writer ) CvSeqBlock *block = first_block; writer->block->count = (int)((writer->ptr - writer->block->data) / seq->elem_size); - assert( writer->block->count > 0 ); + CV_Assert( writer->block->count > 0 ); do { @@ -891,7 +891,7 @@ cvEndWriteSeq( CvSeqWriter * writer ) CvMemStorage *storage = seq->storage; schar *storage_block_max = (schar *) storage->top + storage->block_size; - assert( writer->block->count > 0 ); + CV_Assert( writer->block->count > 0 ); if( (unsigned)((storage_block_max - storage->free_space) - seq->block_max) < CV_STRUCT_ALIGN ) @@ -1147,7 +1147,7 @@ cvSeqPush( CvSeq *seq, const void *element ) icvGrowSeq( seq, 0 ); ptr = seq->ptr; - assert( ptr + elem_size <= seq->block_max /*&& ptr == seq->block_min */ ); + CV_Assert( ptr + elem_size <= seq->block_max /*&& ptr == seq->block_min */ ); } if( element ) @@ -1183,7 +1183,7 @@ cvSeqPop( CvSeq *seq, void *element ) if( --(seq->first->prev->count) == 0 ) { icvFreeSeqBlock( seq, 0 ); - assert( seq->ptr == seq->block_max ); + CV_Assert( seq->ptr == seq->block_max ); } } @@ -1207,7 +1207,7 @@ cvSeqPushFront( CvSeq *seq, const void *element ) icvGrowSeq( seq, 1 ); block = seq->first; - assert( block->start_index > 0 ); + CV_Assert( block->start_index > 0 ); } ptr = block->data -= elem_size; @@ -1289,7 +1289,7 @@ cvSeqInsert( CvSeq *seq, int before_index, const void *element ) icvGrowSeq( seq, 0 ); ptr = seq->ptr + elem_size; - assert( ptr <= seq->block_max ); + CV_Assert( ptr <= seq->block_max ); } delta_index = seq->first->start_index; @@ -1307,7 +1307,7 @@ cvSeqInsert( CvSeq *seq, int before_index, const void *element ) block = prev_block; /* Check that we don't fall into an infinite loop: */ - assert( block != seq->first->prev ); + CV_Assert( block != seq->first->prev ); } before_index = (before_index - block->start_index + delta_index) * elem_size; @@ -1346,7 +1346,7 @@ cvSeqInsert( CvSeq *seq, int before_index, const void *element ) block = next_block; /* Check that we don't fall into an infinite loop: */ - assert( block != seq->first ); + CV_Assert( block != seq->first ); } before_index = (before_index - block->start_index + delta_index) * elem_size; @@ -1502,7 +1502,7 @@ cvSeqPushMulti( CvSeq *seq, const void *_elements, int count, int front ) icvGrowSeq( seq, 1 ); block = seq->first; - assert( block->start_index > 0 ); + CV_Assert( block->start_index > 0 ); } delta = MIN( block->start_index, count ); @@ -1543,7 +1543,7 @@ cvSeqPopMulti( CvSeq *seq, void *_elements, int count, int front ) int delta = seq->first->prev->count; delta = MIN( delta, count ); - assert( delta > 0 ); + CV_Assert( delta > 0 ); seq->first->prev->count -= delta; seq->total -= delta; @@ -1568,7 +1568,7 @@ cvSeqPopMulti( CvSeq *seq, void *_elements, int count, int front ) int delta = seq->first->count; delta = MIN( delta, count ); - assert( delta > 0 ); + CV_Assert( delta > 0 ); seq->first->count -= delta; seq->total -= delta; @@ -2418,7 +2418,7 @@ cvSeqPartition( const CvSeq* seq, CvMemStorage* storage, CvSeq** labels, root2->rank += root->rank == root2->rank; root = root2; } - assert( root->parent == 0 ); + CV_Assert( root->parent == 0 ); // Compress path from node2 to the root: while( node2->parent ) @@ -2521,7 +2521,7 @@ cvSetAdd( CvSet* set, CvSetElem* element, CvSetElem** inserted_element ) ((CvSetElem*)ptr)->flags = count | CV_SET_ELEM_FREE_FLAG; ((CvSetElem*)ptr)->next_free = (CvSetElem*)(ptr + elem_size); } - assert( count <= CV_SET_ELEM_IDX_MASK+1 ); + CV_Assert( count <= CV_SET_ELEM_IDX_MASK+1 ); ((CvSetElem*)(ptr - elem_size))->next_free = 0; set->first->prev->count += count - set->total; set->total = count; @@ -2720,7 +2720,7 @@ cvFindGraphEdgeByPtr( const CvGraph* graph, for( ; edge; edge = edge->next[ofs] ) { ofs = start_vtx == edge->vtx[1]; - assert( ofs == 1 || start_vtx == edge->vtx[0] ); + CV_Assert( ofs == 1 || start_vtx == edge->vtx[0] ); if( edge->vtx[1] == end_vtx ) break; } @@ -2784,7 +2784,7 @@ cvGraphAddEdgeByPtr( CvGraph* graph, "vertex pointers coincide (or set to NULL)" ); edge = (CvGraphEdge*)cvSetNew( (CvSet*)(graph->edges) ); - assert( edge->flags >= 0 ); + CV_Assert( edge->flags >= 0 ); edge->vtx[0] = start_vtx; edge->vtx[1] = end_vtx; @@ -2861,7 +2861,7 @@ cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, CvGraphVtx* end_v prev_ofs = ofs, prev_edge = edge, edge = edge->next[ofs] ) { ofs = start_vtx == edge->vtx[1]; - assert( ofs == 1 || start_vtx == edge->vtx[0] ); + CV_Assert( ofs == 1 || start_vtx == edge->vtx[0] ); if( edge->vtx[1] == end_vtx ) break; } @@ -2879,7 +2879,7 @@ cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, CvGraphVtx* end_v prev_ofs = ofs, prev_edge = edge, edge = edge->next[ofs] ) { ofs = end_vtx == edge->vtx[1]; - assert( ofs == 1 || end_vtx == edge->vtx[0] ); + CV_Assert( ofs == 1 || end_vtx == edge->vtx[0] ); if( edge->vtx[0] == start_vtx ) break; } @@ -3396,7 +3396,7 @@ cvInsertNodeIntoTree( void* _node, void* _parent, void* _frame ) node->v_prev = _parent != _frame ? parent : 0; node->h_next = parent->v_next; - assert( parent->v_next != node ); + CV_Assert( parent->v_next != node ); if( parent->v_next ) parent->v_next->h_prev = node; @@ -3430,7 +3430,7 @@ cvRemoveNodeFromTree( void* _node, void* _frame ) if( parent ) { - assert( parent->v_next == node ); + CV_Assert( parent->v_next == node ); parent->v_next = node->h_next; } } diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index e378f31e66..a15f21b47f 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -238,7 +238,7 @@ DFTInit( int n0, int nf, const int* factors, int* itab, int elem_size, void* _wa else { // radix[] is initialized from index 'nf' down to zero - assert (nf < 34); + CV_Assert (nf < 34); radix[nf] = 1; digits[nf] = 0; for( i = 0; i < nf; i++ ) @@ -374,7 +374,7 @@ DFTInit( int n0, int nf, const int* factors, int* itab, int elem_size, void* _wa else { Complex* wave = (Complex*)_wave; - assert( elem_size == sizeof(Complex) ); + CV_Assert( elem_size == sizeof(Complex) ); wave[0].re = 1.f; wave[0].im = 0.f; @@ -874,13 +874,13 @@ DFT(const OcvDftOptions & c, const Complex* src, Complex* dst) // 0. shuffle data if( dst != src ) { - assert( !c.noPermute ); + CV_Assert( !c.noPermute ); if( !inv ) { for( i = 0; i <= n - 2; i += 2, itab += 2*tab_step ) { int k0 = itab[0], k1 = itab[tab_step]; - assert( (unsigned)k0 < (unsigned)n && (unsigned)k1 < (unsigned)n ); + CV_Assert( (unsigned)k0 < (unsigned)n && (unsigned)k1 < (unsigned)n ); dst[i] = src[k0]; dst[i+1] = src[k1]; } @@ -892,7 +892,7 @@ DFT(const OcvDftOptions & c, const Complex* src, Complex* dst) for( i = 0; i <= n - 2; i += 2, itab += 2*tab_step ) { int k0 = itab[0], k1 = itab[tab_step]; - assert( (unsigned)k0 < (unsigned)n && (unsigned)k1 < (unsigned)n ); + CV_Assert( (unsigned)k0 < (unsigned)n && (unsigned)k1 < (unsigned)n ); t.re = src[k0].re; t.im = -src[k0].im; dst[i] = t; t.re = src[k1].re; t.im = -src[k1].im; @@ -921,7 +921,7 @@ DFT(const OcvDftOptions & c, const Complex* src, Complex* dst) for( i = 0; i < n2; i += 2, itab += tab_step*2 ) { j = itab[0]; - assert( (unsigned)j < (unsigned)n2 ); + CV_Assert( (unsigned)j < (unsigned)n2 ); CV_SWAP(dst[i+1], dsth[j], t); if( j > i ) @@ -938,7 +938,7 @@ DFT(const OcvDftOptions & c, const Complex* src, Complex* dst) for( i = 0; i < n; i++, itab += tab_step ) { j = itab[0]; - assert( (unsigned)j < (unsigned)n ); + CV_Assert( (unsigned)j < (unsigned)n ); if( j > i ) CV_SWAP(dst[i], dst[j], t); } @@ -1218,7 +1218,7 @@ RealDFT(const OcvDftOptions & c, const T* src, T* dst) setIppErrorStatus(); #endif } - assert( c.tab_size == n ); + CV_Assert( c.tab_size == n ); if( n == 1 ) { @@ -1338,11 +1338,11 @@ CCSIDFT(const OcvDftOptions & c, const T* src, T* dst) T save_s1 = 0.; T t0, t1, t2, t3, t; - assert( c.tab_size == n ); + CV_Assert( c.tab_size == n ); if( complex_input ) { - assert( src != dst ); + CV_Assert( src != dst ); save_s1 = src[1]; ((T*)src)[1] = src[0]; src++; @@ -3175,7 +3175,7 @@ protected: } else { - assert( !inv ); + CV_Assert( !inv ); CopyColumn( dbuf0, complex_elem_size, dptr0, dst_step, len, complex_elem_size ); if( even ) @@ -3872,7 +3872,7 @@ DCTInit( int n, int elem_size, void* _wave, int inv ) if( n == 1 ) return; - assert( (n&1) == 0 ); + CV_Assert( (n&1) == 0 ); if( (n & (n - 1)) == 0 ) { @@ -3910,7 +3910,7 @@ DCTInit( int n, int elem_size, void* _wave, int inv ) else { Complex* wave = (Complex*)_wave; - assert( elem_size == sizeof(Complex) ); + CV_Assert( elem_size == sizeof(Complex) ); w.re = (float)scale; w.im = 0.f; diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 9bca6a8211..a644fe15a7 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -1020,7 +1020,7 @@ double invert( InputArray _src, OutputArray _dst, int method ) } else { - assert( n == 1 ); + CV_Assert( n == 1 ); if( type == CV_32FC1 ) { @@ -1208,7 +1208,7 @@ bool solve( InputArray _src, InputArray _src2arg, OutputArray _dst, int method ) } else { - assert( src.rows == 1 ); + CV_Assert( src.rows == 1 ); if( type == CV_32FC1 ) { diff --git a/modules/core/src/matmul.simd.hpp b/modules/core/src/matmul.simd.hpp index c828e2906d..5a7f36d12b 100644 --- a/modules/core/src/matmul.simd.hpp +++ b/modules/core/src/matmul.simd.hpp @@ -169,7 +169,7 @@ GEMM_TransposeBlock( const uchar* src, size_t src_step, } break; default: - assert(0); + CV_Assert(0); return; } } @@ -2062,7 +2062,7 @@ MulTransposedR(const Mat& srcmat, const Mat& dstmat, const Mat& deltamat, double if( delta && delta_cols < size.width ) { - assert( delta_cols == 1 ); + CV_Assert( delta_cols == 1 ); buf_size *= 5; } buf.allocate(buf_size); diff --git a/modules/core/src/matrix_sparse.cpp b/modules/core/src/matrix_sparse.cpp index 21e7e91151..173f9ea8f6 100644 --- a/modules/core/src/matrix_sparse.cpp +++ b/modules/core/src/matrix_sparse.cpp @@ -638,7 +638,7 @@ void SparseMat::resizeHashTab(size_t newsize) uchar* SparseMat::newNode(const int* idx, size_t hashval) { const int HASH_MAX_FILL_FACTOR=3; - assert(hdr); + CV_Assert(hdr); size_t hsize = hdr->hashtab.size(); if( ++hdr->nodeCount > hsize*HASH_MAX_FILL_FACTOR ) { diff --git a/modules/core/src/opencl/runtime/opencl_clamdblas.cpp b/modules/core/src/opencl/runtime/opencl_clamdblas.cpp index 379929993f..9b7aaa4c61 100644 --- a/modules/core/src/opencl/runtime/opencl_clamdblas.cpp +++ b/modules/core/src/opencl/runtime/opencl_clamdblas.cpp @@ -113,7 +113,7 @@ static void* openclamdblas_check_fn(int ID); static void* openclamdblas_check_fn(int ID) { - assert(ID >= 0 && ID < (int)(sizeof(openclamdblas_fn)/sizeof(openclamdblas_fn[0]))); + CV_Assert(ID >= 0 && ID < (int)(sizeof(openclamdblas_fn)/sizeof(openclamdblas_fn[0]))); const struct DynamicFnEntry* e = openclamdblas_fn[ID]; void* func = CV_CL_GET_PROC_ADDRESS(e->fnName); if (!func) diff --git a/modules/core/src/opencl/runtime/opencl_clamdfft.cpp b/modules/core/src/opencl/runtime/opencl_clamdfft.cpp index 255bcd826a..eb5d6f0169 100644 --- a/modules/core/src/opencl/runtime/opencl_clamdfft.cpp +++ b/modules/core/src/opencl/runtime/opencl_clamdfft.cpp @@ -113,7 +113,7 @@ static void* openclamdfft_check_fn(int ID); static void* openclamdfft_check_fn(int ID) { - assert(ID >= 0 && ID < (int)(sizeof(openclamdfft_fn)/sizeof(openclamdfft_fn[0]))); + CV_Assert(ID >= 0 && ID < (int)(sizeof(openclamdfft_fn)/sizeof(openclamdfft_fn[0]))); const struct DynamicFnEntry* e = openclamdfft_fn[ID]; void* func = CV_CL_GET_PROC_ADDRESS(e->fnName); if (!func) diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index db2385a258..464777f864 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -360,7 +360,7 @@ static void* opencl_gl_check_fn(int ID); static void* opencl_gl_check_fn(int ID) { const struct DynamicFnEntry* e = NULL; - assert(ID >= 0 && ID < (int)(sizeof(opencl_gl_fn_list)/sizeof(opencl_gl_fn_list[0]))); + CV_Assert(ID >= 0 && ID < (int)(sizeof(opencl_gl_fn_list)/sizeof(opencl_gl_fn_list[0]))); e = opencl_gl_fn_list[ID]; void* func = CV_CL_GET_PROC_ADDRESS(e->fnName); if (!func) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 7e9d107c35..ff24b105a6 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -160,7 +160,7 @@ void icvFSCreateCollection( CvFileStorage* fs, int tag, CvFileNode* collection ) { if( collection->tag != CV_NODE_NONE ) { - assert( fs->fmt == CV_STORAGE_FORMAT_XML ); + CV_Assert( fs->fmt == CV_STORAGE_FORMAT_XML ); CV_PARSE_ERROR( "Sequence element should not have name (use <_>)" ); } @@ -551,7 +551,7 @@ int icvDecodeFormat( const char* dt, int* fmt_pairs, int max_len ) if( !dt || !len ) return 0; - assert( fmt_pairs != 0 && max_len > 0 ); + CV_Assert( fmt_pairs != 0 && max_len > 0 ); fmt_pairs[0] = 0; max_len *= 2; diff --git a/modules/core/src/persistence_json.cpp b/modules/core/src/persistence_json.cpp index 1ed6321b78..763a3fbe76 100644 --- a/modules/core/src/persistence_json.cpp +++ b/modules/core/src/persistence_json.cpp @@ -756,7 +756,7 @@ void icvJSONEndWriteStruct( CvFileStorage* fs ) cvSeqPop( fs->write_stack, &parent_flags ); fs->struct_indent -= 4; fs->struct_flags = parent_flags & ~CV_NODE_EMPTY; - assert( fs->struct_indent >= 0 ); + CV_Assert( fs->struct_indent >= 0 ); if ( CV_NODE_IS_COLLECTION(struct_flags) ) { diff --git a/modules/core/src/persistence_types.cpp b/modules/core/src/persistence_types.cpp index a446645734..ed1e1bd82d 100644 --- a/modules/core/src/persistence_types.cpp +++ b/modules/core/src/persistence_types.cpp @@ -34,7 +34,7 @@ static void icvWriteMat( CvFileStorage* fs, const char* name, const void* struct cv::Size size; int y; - assert( CV_IS_MAT_HDR_Z(mat) ); + CV_Assert( CV_IS_MAT_HDR_Z(mat) ); cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_MAT ); cvWriteInt( fs, "rows", mat->rows ); @@ -121,7 +121,7 @@ static void icvWriteMatND( CvFileStorage* fs, const char* name, const void* stru int dims, sizes[CV_MAX_DIM]; char dt[16]; - assert( CV_IS_MATND_HDR(mat) ); + CV_Assert( CV_IS_MATND_HDR(mat) ); cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_MATND ); dims = cvGetDims( mat, sizes ); @@ -237,7 +237,7 @@ static void icvWriteSparseMat( CvFileStorage* fs, const char* name, const void* int *prev_idx = 0; char dt[16]; - assert( CV_IS_SPARSE_MAT(mat) ); + CV_Assert( CV_IS_SPARSE_MAT(mat) ); memstorage = cvCreateMemStorage(); @@ -273,7 +273,7 @@ static void icvWriteSparseMat( CvFileStorage* fs, const char* name, const void* if( i > 0 ) { for( ; idx[k] == prev_idx[k]; k++ ) - assert( k < dims ); + CV_Assert( k < dims ); if( k < dims - 1 ) fs->write_int( fs, 0, k - dims + 1 ); } @@ -383,7 +383,7 @@ static void icvWriteImage( CvFileStorage* fs, const char* name, const void* stru cv::Size size; int y, depth; - assert( CV_IS_IMAGE(image) ); + CV_Assert( CV_IS_IMAGE(image) ); if( image->dataOrder == IPL_DATA_ORDER_PLANE ) CV_Error( CV_StsUnsupportedFormat, @@ -623,7 +623,7 @@ static void icvWriteSeq( CvFileStorage* fs, const char* name, const void* struct char buf[128]; char dt_buf[128], *dt; - assert( CV_IS_SEQ( seq )); + CV_Assert( CV_IS_SEQ( seq )); cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_SEQ ); if( level >= 0 ) @@ -671,7 +671,7 @@ static void icvWriteSeqTree( CvFileStorage* fs, const char* name, const void* st strcmp(recursive_value,"False") != 0 && strcmp(recursive_value,"FALSE") != 0; - assert( CV_IS_SEQ( seq )); + CV_Assert( CV_IS_SEQ( seq )); if( !is_recursive ) { @@ -873,7 +873,7 @@ static void* icvReadSeqTree( CvFileStorage* fs, CvFileNode* node ) root = seq; if( level > prev_level ) { - assert( level == prev_level + 1 ); + CV_Assert( level == prev_level + 1 ); parent = prev_seq; prev_seq = 0; if( parent ) @@ -933,7 +933,7 @@ static void icvWriteGraph( CvFileStorage* fs, const char* name, const void* stru char edge_dt_buf[128], *edge_dt; int write_buf_size; - assert( CV_IS_GRAPH(graph) ); + CV_Assert( CV_IS_GRAPH(graph) ); vtx_count = cvGraphGetVtxCount( graph ); edge_count = cvGraphGetEdgeCount( graph ); flag_buf = (int*)cvAlloc( vtx_count*sizeof(flag_buf[0])); diff --git a/modules/core/src/persistence_xml.cpp b/modules/core/src/persistence_xml.cpp index aaaa613bc2..a22faaa358 100644 --- a/modules/core/src/persistence_xml.cpp +++ b/modules/core/src/persistence_xml.cpp @@ -37,7 +37,7 @@ icvXMLSkipSpaces( CvFileStorage* fs, char* ptr, int mode ) if( c == '-' ) { - assert( ptr[1] == '-' && ptr[2] == '>' ); + CV_Assert( ptr[1] == '-' && ptr[2] == '>' ); mode = 0; ptr += 3; } @@ -484,7 +484,7 @@ icvXMLParseTag( CvFileStorage* fs, char* ptr, CvStringHashNode** _tag, else if( *ptr == '!' ) { tag_type = CV_XML_DIRECTIVE_TAG; - assert( ptr[1] != '-' || ptr[2] != '-' ); + CV_Assert( ptr[1] != '-' || ptr[2] != '-' ); ptr++; } else @@ -549,7 +549,7 @@ icvXMLParseTag( CvFileStorage* fs, char* ptr, CvStringHashNode** _tag, } ptr = icvXMLParseValue( fs, ptr, &stub, CV_NODE_STRING ); - assert( stub.tag == CV_NODE_STRING ); + CV_Assert( stub.tag == CV_NODE_STRING ); last->attr[count*2+1] = stub.data.str.ptr; count++; } diff --git a/modules/core/src/persistence_yml.cpp b/modules/core/src/persistence_yml.cpp index 713da33c50..885139fe76 100644 --- a/modules/core/src/persistence_yml.cpp +++ b/modules/core/src/persistence_yml.cpp @@ -797,7 +797,7 @@ void icvYMLEndWriteStruct( CvFileStorage* fs ) if( !CV_NODE_IS_FLOW(parent_flags) ) fs->struct_indent -= CV_YML_INDENT + CV_NODE_IS_FLOW(struct_flags); - assert( fs->struct_indent >= 0 ); + CV_Assert( fs->struct_indent >= 0 ); fs->struct_flags = parent_flags; } diff --git a/modules/core/test/test_ds.cpp b/modules/core/test/test_ds.cpp index 64d54c5966..a215b58d77 100644 --- a/modules/core/test/test_ds.cpp +++ b/modules/core/test/test_ds.cpp @@ -33,7 +33,7 @@ static void cvTsReleaseSimpleSeq( CvTsSimpleSeq** seq ) static schar* cvTsSimpleSeqElem( CvTsSimpleSeq* seq, int index ) { - assert( 0 <= index && index < seq->count ); + CV_Assert( 0 <= index && index < seq->count ); return seq->array + index * seq->elem_size; } @@ -50,7 +50,11 @@ static void cvTsSimpleSeqShiftAndCopy( CvTsSimpleSeq* seq, int from_idx, int to_ if( from_idx == to_idx ) return; - assert( (from_idx > to_idx && !elem) || (from_idx < to_idx && elem) ); + + if (elem) + CV_Assert(from_idx < to_idx); + else + CV_Assert(from_idx > to_idx); if( from_idx < seq->count ) { @@ -128,7 +132,7 @@ static void cvTsReleaseSimpleSet( CvTsSimpleSet** set_header ) static schar* cvTsSimpleSetFind( CvTsSimpleSet* set_header, int index ) { int idx = index * set_header->elem_size; - assert( 0 <= index && index < set_header->max_count ); + CV_Assert( 0 <= index && index < set_header->max_count ); return set_header->array[idx] ? set_header->array + idx + 1 : 0; } @@ -136,11 +140,11 @@ static schar* cvTsSimpleSetFind( CvTsSimpleSet* set_header, int index ) static int cvTsSimpleSetAdd( CvTsSimpleSet* set_header, void* elem ) { int idx, idx2; - assert( set_header->free_count > 0 ); + CV_Assert( set_header->free_count > 0 ); idx = set_header->free_stack[--set_header->free_count]; idx2 = idx * set_header->elem_size; - assert( set_header->array[idx2] == 0 ); + CV_Assert( set_header->array[idx2] == 0 ); set_header->array[idx2] = 1; if( set_header->elem_size > 1 ) memcpy( set_header->array + idx2 + 1, elem, set_header->elem_size - 1 ); @@ -152,9 +156,9 @@ static int cvTsSimpleSetAdd( CvTsSimpleSet* set_header, void* elem ) static void cvTsSimpleSetRemove( CvTsSimpleSet* set_header, int index ) { - assert( set_header->free_count < set_header->max_count && - 0 <= index && index < set_header->max_count ); - assert( set_header->array[index * set_header->elem_size] == 1 ); + CV_Assert( set_header->free_count < set_header->max_count && + 0 <= index && index < set_header->max_count ); + CV_Assert( set_header->array[index * set_header->elem_size] == 1 ); set_header->free_stack[set_header->free_count++] = index; set_header->array[index * set_header->elem_size] = 0; @@ -187,7 +191,7 @@ static CvTsSimpleGraph* cvTsCreateSimpleGraph( int max_vtx_count, int vtx_size, { CvTsSimpleGraph* graph; - assert( max_vtx_count > 1 && vtx_size >= 0 && edge_size >= 0 ); + CV_Assert( max_vtx_count > 1 && vtx_size >= 0 && edge_size >= 0 ); graph = (CvTsSimpleGraph*)cvAlloc( sizeof(*graph) + max_vtx_count * max_vtx_count * (edge_size + 1)); graph->vtx = cvTsCreateSimpleSet( max_vtx_count, vtx_size ); @@ -235,13 +239,13 @@ static void cvTsSimpleGraphAddEdge( CvTsSimpleGraph* graph, int idx1, int idx2, { int i, t, n = graph->oriented ? 1 : 2; - assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && - cvTsSimpleSetFind( graph->vtx, idx2 )); + CV_Assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && + cvTsSimpleSetFind( graph->vtx, idx2 )); for( i = 0; i < n; i++ ) { int ofs = (idx1*graph->vtx->max_count + idx2)*graph->edge_size; - assert( graph->matrix[ofs] == 0 ); + CV_Assert( graph->matrix[ofs] == 0 ); graph->matrix[ofs] = 1; if( graph->edge_size > 1 ) memcpy( graph->matrix + ofs + 1, edge, graph->edge_size - 1 ); @@ -255,13 +259,13 @@ static void cvTsSimpleGraphRemoveEdge( CvTsSimpleGraph* graph, int idx1, int id { int i, t, n = graph->oriented ? 1 : 2; - assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && + CV_Assert( cvTsSimpleSetFind( graph->vtx, idx1 ) && cvTsSimpleSetFind( graph->vtx, idx2 )); for( i = 0; i < n; i++ ) { int ofs = (idx1*graph->vtx->max_count + idx2)*graph->edge_size; - assert( graph->matrix[ofs] == 1 ); + CV_Assert( graph->matrix[ofs] == 1 ); graph->matrix[ofs] = 0; CV_SWAP( idx1, idx2, t ); } @@ -291,7 +295,7 @@ static int cvTsSimpleGraphVertexDegree( CvTsSimpleGraph* graph, int index ) int i, count = 0; int edge_size = graph->edge_size; int max_vtx_count = graph->vtx->max_count; - assert( cvTsSimpleGraphFindVertex( graph, index ) != 0 ); + CV_Assert( cvTsSimpleGraphFindVertex( graph, index ) != 0 ); for( i = 0; i < max_vtx_count; i++ ) { @@ -301,7 +305,7 @@ static int cvTsSimpleGraphVertexDegree( CvTsSimpleGraph* graph, int index ) if( !graph->oriented ) { - assert( count % 2 == 0 ); + CV_Assert( count % 2 == 0 ); count /= 2; } return count; @@ -609,7 +613,7 @@ int Core_SeqBaseTest::test_get_seq_elem( int _struct_idx, int iters ) CvTsSimpleSeq* sseq = (CvTsSimpleSeq*)simple_struct[_struct_idx]; struct_idx = _struct_idx; - assert( seq->total == sseq->count ); + CV_Assert( seq->total == sseq->count ); if( sseq->count == 0 ) return 0; @@ -656,7 +660,7 @@ int Core_SeqBaseTest::test_get_seq_reading( int _struct_idx, int iters ) vector _elem(sseq->elem_size); schar* elem = &_elem[0]; - assert( total == sseq->count ); + CV_Assert( total == sseq->count ); this->struct_idx = _struct_idx; int pos = cvtest::randInt(rng) % 2; @@ -964,7 +968,7 @@ int Core_SeqBaseTest::test_seq_ops( int iters ) "The sequence doesn't become empty after clear" ); break; default: - assert(0); + CV_Assert(0); return -1; } @@ -1903,7 +1907,7 @@ int Core_GraphScanTest::create_random_graph( int _struct_idx ) for( i = 0; i < vtx_count; i++ ) cvGraphAddVtx( graph ); - assert( graph->active_count == vtx_count ); + CV_Assert( graph->active_count == vtx_count ); for( i = 0; i < edge_count; i++ ) { @@ -1914,7 +1918,7 @@ int Core_GraphScanTest::create_random_graph( int _struct_idx ) cvGraphAddEdge( graph, j, k ); } - assert( graph->active_count == vtx_count && graph->edges->active_count <= edge_count ); + CV_Assert( graph->active_count == vtx_count && graph->edges->active_count <= edge_count ); return 0; } diff --git a/modules/core/test/test_dxt.cpp b/modules/core/test/test_dxt.cpp index dbb378aa08..05d1f3062c 100644 --- a/modules/core/test/test_dxt.cpp +++ b/modules/core/test/test_dxt.cpp @@ -204,7 +204,7 @@ static void DCT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat( } } else - assert(0); + CV_Assert(0); } diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 4f7cbb6725..041e7d979f 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -28,7 +28,7 @@ protected: template void testReduce( const Mat& src, Mat& sum, Mat& avg, Mat& max, Mat& min, int dim ) { - assert( src.channels() == 1 ); + CV_Assert( src.channels() == 1 ); if( dim == 0 ) // row { sum.create( 1, src.cols, CV_64FC1 ); @@ -138,7 +138,7 @@ int Core_ReduceTest::checkOp( const Mat& src, int dstType, int opType, const Mat eps = 0.6; } - assert( opRes.type() == CV_64FC1 ); + CV_Assert( opRes.type() == CV_64FC1 ); Mat _dst, dst, diff; cv::reduce( src, _dst, dim, opType, dstType ); _dst.convertTo( dst, CV_64FC1 ); @@ -192,7 +192,7 @@ int Core_ReduceTest::checkCase( int srcType, int dstType, int dim, Size sz ) else if( srcType == CV_64FC1 ) testReduce( src, sum, avg, max, min, dim ); else - assert( 0 ); + CV_Assert( 0 ); // 1. sum tempCode = checkOp( src, dstType, CV_REDUCE_SUM, sum, dim ); diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 066475b19e..cbd0b7ceb3 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -1039,7 +1039,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa } else { - assert( mat_depth == CV_64F ); + CV_Assert( mat_depth == CV_64F ); for( i = 0; i < transmat->rows; i++ ) for( j = 0; j < cols; j++ ) mat[i*cols + j] = ((double*)(transmat->data.ptr + transmat->step*i))[j]; @@ -1065,7 +1065,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa buf[j] = ((double*)src)[j]; break; default: - assert(0); + CV_Assert(0); } switch( cn ) @@ -1095,7 +1095,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa } break; default: - assert(0); + CV_Assert(0); } switch( depth ) @@ -1109,7 +1109,7 @@ static void cvTsPerspectiveTransform( const CvArr* _src, CvArr* _dst, const CvMa ((double*)dst)[j] = buf[j]; break; default: - assert(0); + CV_Assert(0); } } } @@ -1458,8 +1458,8 @@ static double cvTsLU( CvMat* a, CvMat* b=NULL, CvMat* x=NULL, int* rank=0 ) double *a0 = a->data.db, *b0 = b ? b->data.db : 0; double *x0 = x ? x->data.db : 0; double t, det = 1.; - assert( CV_MAT_TYPE(a->type) == CV_64FC1 && - (!b || CV_ARE_TYPES_EQ(a,b)) && (!x || CV_ARE_TYPES_EQ(a,x))); + CV_Assert( CV_MAT_TYPE(a->type) == CV_64FC1 && + (!b || CV_ARE_TYPES_EQ(a,b)) && (!x || CV_ARE_TYPES_EQ(a,x))); for( i = 0; i < Nm; i++ ) { @@ -1514,7 +1514,7 @@ static double cvTsLU( CvMat* a, CvMat* b=NULL, CvMat* x=NULL, int* rank=0 ) if( x ) { - assert( b ); + CV_Assert( b ); for( i = N-1; i >= 0; i-- ) { diff --git a/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp b/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp index dc1a7b89ef..a6f0b796bf 100644 --- a/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp +++ b/modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp @@ -48,7 +48,6 @@ #include #include #include -#include #include "../include/common.hpp" #include "../include/ocl4dnn.hpp" #include "opencl_kernels_dnn.hpp" diff --git a/modules/features2d/test/test_descriptors_regression.cpp b/modules/features2d/test/test_descriptors_regression.cpp index f8760d6478..0de2b2bd55 100644 --- a/modules/features2d/test/test_descriptors_regression.cpp +++ b/modules/features2d/test/test_descriptors_regression.cpp @@ -159,7 +159,7 @@ protected: void emptyDataTest() { - assert( dextractor ); + CV_Assert( dextractor ); // One image. Mat image; @@ -205,7 +205,7 @@ protected: void regressionTest() { - assert( dextractor ); + CV_Assert( dextractor ); // Read the test image. string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; diff --git a/modules/features2d/test/test_detectors_regression.cpp b/modules/features2d/test/test_detectors_regression.cpp index 5bdede7508..c082b43800 100644 --- a/modules/features2d/test/test_detectors_regression.cpp +++ b/modules/features2d/test/test_detectors_regression.cpp @@ -154,7 +154,7 @@ void CV_FeatureDetectorTest::compareKeypointSets( const vector& validK } } - assert( minDist >= 0 ); + CV_Assert( minDist >= 0 ); if( !isSimilarKeypoints( validKeypoints[v], calcKeypoints[nearestIdx] ) ) badPointCount++; } @@ -171,7 +171,7 @@ void CV_FeatureDetectorTest::compareKeypointSets( const vector& validK void CV_FeatureDetectorTest::regressionTest() { - assert( !fdetector.empty() ); + CV_Assert( !fdetector.empty() ); string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME; string resFilename = string(ts->get_data_path()) + DETECTOR_DIR + "/" + string(name) + ".xml.gz"; diff --git a/modules/features2d/test/test_nearestneighbors.cpp b/modules/features2d/test/test_nearestneighbors.cpp index f63ebb8d92..4f9d883866 100644 --- a/modules/features2d/test/test_nearestneighbors.cpp +++ b/modules/features2d/test/test_nearestneighbors.cpp @@ -312,7 +312,7 @@ void CV_FlannSavedIndexTest::createModel(const cv::Mat &data) case 1: createIndex( data, KDTreeIndexParams() ); break; //case 2: createIndex( data, CompositeIndexParams() ); break; // nothing to save for linear search //case 2: createIndex( data, AutotunedIndexParams() ); break; // possible linear index ! - default: assert(0); + default: CV_Assert(0); } string filename = tempfile(); index->save( filename ); diff --git a/modules/flann/include/opencv2/flann/nn_index.h b/modules/flann/include/opencv2/flann/nn_index.h index f6e17d19fc..23a1de7453 100644 --- a/modules/flann/include/opencv2/flann/nn_index.h +++ b/modules/flann/include/opencv2/flann/nn_index.h @@ -106,8 +106,8 @@ public: fprintf(stderr, "I can only search one feature at a time for range search\n"); return -1; } - assert(query.cols == veclen()); - assert(indices.cols == dists.cols); + CV_Assert(query.cols == veclen()); + CV_Assert(indices.cols == dists.cols); int n = 0; int* indices_ptr = NULL; diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 12e823ba2c..6ce3a28aba 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -58,7 +58,6 @@ #include #include #include -#include #if defined _WIN32 || defined WINCE #include diff --git a/modules/highgui/src/window_carbon.cpp b/modules/highgui/src/window_carbon.cpp index 19bc9f1162..6fada90faa 100644 --- a/modules/highgui/src/window_carbon.cpp +++ b/modules/highgui/src/window_carbon.cpp @@ -119,7 +119,7 @@ static CvWindow* hg_windows = 0; if( !(exp) ) \ { \ printf("Assertion: %s %s: %d\n", #exp, __FILE__, __LINE__);\ - assert(exp); \ + CV_Assert(exp); \ } static int wasInitialized = 0; diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 78e78e12a2..5ce88fb7d9 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -356,7 +356,7 @@ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_he } - assert( image_widget->scaled_image ); + CV_Assert( image_widget->scaled_image ); } static void diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 50c3dc652f..13ad679b4b 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -60,7 +60,6 @@ using namespace cv; #include #include #include -#include #ifdef HAVE_OPENGL #include @@ -105,7 +104,7 @@ static const char* trackbar_text = static void FillBitmapInfo( BITMAPINFO* bmi, int width, int height, int bpp, int origin ) { - assert( bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32)); + CV_Assert( bmi && width >= 0 && height >= 0 && (bpp == 8 || bpp == 24 || bpp == 32)); BITMAPINFOHEADER* bmih = &(bmi->bmiHeader); @@ -1107,7 +1106,7 @@ static RECT icvCalcWindowRect( CvWindow* window ) { RECT crect = { 0 }, trect = { 0 }, rect = { 0 }; - assert(window); + CV_Assert(window); GetClientRect(window->frame, &crect); if (window->toolbar.toolbar) @@ -1157,7 +1156,7 @@ static bool icvGetBitmapData( CvWindow* window, SIZE* size, int* channels, void* static void icvUpdateWindowPos( CvWindow* window ) { RECT rect = { 0 }; - assert(window); + CV_Assert(window); if( (window->flags & CV_WINDOW_AUTOSIZE) && window->image ) { diff --git a/modules/highgui/src/window_winrt.cpp b/modules/highgui/src/window_winrt.cpp index 1572929b90..af771bd00b 100644 --- a/modules/highgui/src/window_winrt.cpp +++ b/modules/highgui/src/window_winrt.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include "window_winrt_bridge.hpp" diff --git a/modules/imgproc/src/approx.cpp b/modules/imgproc/src/approx.cpp index e581fb09e7..b7e51a4c62 100644 --- a/modules/imgproc/src/approx.cpp +++ b/modules/imgproc/src/approx.cpp @@ -129,7 +129,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, len = i; current = temp.next; - assert( current ); + CV_Assert( current ); /* Pass 1. Determines support region for all the remained points */ @@ -148,7 +148,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, int dx, dy; Cv32suf d; - assert( k <= len ); + CV_Assert( k <= len ); /* calc indices */ i1 = i - k; @@ -205,7 +205,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, ((double)dx2 * dx2 + (double)dy2 * dy2) )); sk.f = (float) (temp_num + 1.1); - assert( 0 <= sk.f && sk.f <= 2.2 ); + CV_Assert( 0 <= sk.f && sk.f <= 2.2 ); if( j < k && sk.i <= s ) break; @@ -258,7 +258,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, /* Pass 3. Removes non-dominant points with 1-length support region */ current = temp.next; - assert( current ); + CV_Assert( current ); prev_current = &temp; do @@ -293,7 +293,7 @@ CvSeq* icvApproximateChainTC89( CvChain* chain, int header_size, /* Pass 4. Cleans remained couples of points */ - assert( temp.next ); + CV_Assert( temp.next ); if( array[0].s != 0 && array[len - 1].s != 0 ) /* specific case */ { @@ -362,7 +362,7 @@ copy_vect: // gather points current = temp.next; - assert( current ); + CV_Assert( current ); do { @@ -439,7 +439,7 @@ cvApproxChains( CvSeq* src_seq, if( src_seq->v_next && len >= minimal_perimeter ) { - assert( prev_contour != 0 ); + CV_Assert( prev_contour != 0 ); parent = prev_contour; prev_contour = 0; src_seq = src_seq->v_next; @@ -590,7 +590,7 @@ approxPolyDP_( const Point_* src_contour, int count0, Point_* dst_contour, dx = end_pt.x - start_pt.x; dy = end_pt.y - start_pt.y; - assert( dx != 0 || dy != 0 ); + CV_Assert( dx != 0 || dy != 0 ); while( pos != slice.end ) { @@ -815,7 +815,7 @@ cvApproxPoly( const void* array, int header_size, CV_Error( CV_StsBadArg, "Invalid approximation method" ); } - assert( contour ); + CV_Assert( contour ); if( header_size >= (int)sizeof(CvContour)) cvBoundingRect( contour, 1 ); @@ -836,7 +836,7 @@ cvApproxPoly( const void* array, int header_size, if( src_seq->v_next ) { - assert( prev_contour != 0 ); + CV_Assert( prev_contour != 0 ); parent = prev_contour; prev_contour = 0; src_seq = src_seq->v_next; diff --git a/modules/imgproc/src/bilateral_filter.simd.hpp b/modules/imgproc/src/bilateral_filter.simd.hpp index 65abcd4e40..0d2c394368 100644 --- a/modules/imgproc/src/bilateral_filter.simd.hpp +++ b/modules/imgproc/src/bilateral_filter.simd.hpp @@ -205,7 +205,7 @@ public: } else { - assert( cn == 3 ); + CV_Assert( cn == 3 ); AutoBuffer buf(alignSize(size.width, CV_SIMD_WIDTH)*3 + size.width + CV_SIMD_WIDTH - 1); memset(buf.data(), 0, buf.size() * sizeof(float)); float *sum_b = alignPtr(buf.data(), CV_SIMD_WIDTH); diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index 241f1443f5..2afa96b293 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -97,7 +97,7 @@ cvReadChainPoint( CvChainPtReader * reader ) reader->ptr = ptr; reader->code = (schar)code; - assert( (code & ~7) == 0 ); + CV_Assert( (code & ~7) == 0 ); reader->pt.x = pt.x + icvCodeDeltas[code].x; reader->pt.y = pt.y + icvCodeDeltas[code].y; } @@ -1187,7 +1187,7 @@ cvFindNextContour( CvContourScanner scanner ) } /* hole flag of the parent must differ from the flag of the contour */ - assert( par_info->is_hole != is_hole ); + CV_Assert( par_info->is_hole != is_hole ); if( par_info->contour == 0 ) /* removed contour */ goto resume_scan; } diff --git a/modules/imgproc/src/convhull.cpp b/modules/imgproc/src/convhull.cpp index b964ca3f62..d6e02cc0fb 100644 --- a/modules/imgproc/src/convhull.cpp +++ b/modules/imgproc/src/convhull.cpp @@ -716,7 +716,7 @@ CV_IMPL CvSeq* cvConvexityDefects( const CvArr* array, dx0 = (double)hull_next->x - (double)hull_cur->x; dy0 = (double)hull_next->y - (double)hull_cur->y; - assert( dx0 != 0 || dy0 != 0 ); + CV_Assert( dx0 != 0 || dy0 != 0 ); scale = 1./std::sqrt(dx0*dx0 + dy0*dy0); defect.start = hull_cur; diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index aa889d1dc8..8bbe4fa0e3 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -138,7 +138,7 @@ bool clipLine( Size2l img_size, Point2l& pt1, Point2l& pt2 ) } } - assert( (c1 & c2) != 0 || (x1 | y1 | x2 | y2) >= 0 ); + CV_Assert( (c1 & c2) != 0 || (x1 | y1 | x2 | y2) >= 0 ); } return (c1 | c2) == 0; @@ -222,7 +222,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2, if( connectivity == 8 ) { - assert( dx >= 0 && dy >= 0 ); + CV_Assert( dx >= 0 && dy >= 0 ); err = dx - (dy + dy); plusDelta = dx + dx; @@ -233,7 +233,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2, } else /* connectivity == 4 */ { - assert( dx >= 0 && dy >= 0 ); + CV_Assert( dx >= 0 && dy >= 0 ); err = 0; plusDelta = (dx + dx) + (dy + dy); @@ -1102,7 +1102,7 @@ FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int lin p0.x <<= XY_SHIFT - shift; p0.y <<= XY_SHIFT - shift; - assert( 0 <= shift && shift <= XY_SHIFT ); + CV_Assert( 0 <= shift && shift <= XY_SHIFT ); xmin = xmax = v[0].x; ymin = ymax = v[0].y; @@ -1322,7 +1322,7 @@ FillEdgeCollection( Mat& img, std::vector& edges, const void* color ) for( i = 0; i < total; i++ ) { PolyEdge& e1 = edges[i]; - assert( e1.y0 < e1.y1 ); + CV_Assert( e1.y0 < e1.y1 ); // Determine x-coordinate of the end of the edge. // (This is not necessary x-coordinate of any vertex in the array.) int64 x1 = e1.x + (e1.y1 - e1.y0) * e1.dx; @@ -2596,7 +2596,7 @@ cvDrawContours( void* _img, CvSeq* contour, char code; CV_READ_SEQ_ELEM( code, reader ); - assert( (code & ~7) == 0 ); + CV_Assert( (code & ~7) == 0 ); if( code != prev_code ) { diff --git a/modules/imgproc/src/emd.cpp b/modules/imgproc/src/emd.cpp index 20ab6feafb..3e065b0404 100644 --- a/modules/imgproc/src/emd.cpp +++ b/modules/imgproc/src/emd.cpp @@ -336,7 +336,7 @@ static int icvInitEMD( const float* signature1, int size1, char *buffer, *buffer_end; memset( state, 0, sizeof( *state )); - assert( cost_step % sizeof(float) == 0 ); + CV_Assert( cost_step % sizeof(float) == 0 ); cost_step /= sizeof(float); /* calculate buffer size */ @@ -510,7 +510,7 @@ static int icvInitEMD( const float* signature1, int size1, } else { - assert( cost ); + CV_Assert( cost ); val = cost[cost_step*ci + cj]; } state->cost[i][j] = val; @@ -552,7 +552,7 @@ static int icvInitEMD( const float* signature1, int size1, buffer += dsize; } - assert( buffer <= buffer_end ); + CV_Assert( buffer <= buffer_end ); icvRussel( state ); diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index 9ed6cc5c57..5fa24f4789 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -340,8 +340,8 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type, rv = r0 * std::cos( phi ); i = (int)rv * tn; i += cvFloor( phi1 ); - assert( i >= 0 ); - assert( i < rn * tn ); + CV_Assert( i >= 0 ); + CV_Assert( i < rn * tn ); caccum[i] = (uchar) (caccum[i] + ((i ^ iprev) != 0)); iprev = i; if( cmax < caccum[i] ) @@ -405,8 +405,8 @@ HoughLinesSDiv( InputArray image, OutputArray lines, int type, i = CV_IMAX( i, -1 ); i = CV_IMIN( i, sfn ); mcaccum[i]++; - assert( i >= -1 ); - assert( i <= sfn ); + CV_Assert( i >= -1 ); + CV_Assert( i <= sfn ); } } diff --git a/modules/imgproc/src/median_blur.simd.hpp b/modules/imgproc/src/median_blur.simd.hpp index c3203f2a07..068b7d638f 100644 --- a/modules/imgproc/src/median_blur.simd.hpp +++ b/modules/imgproc/src/median_blur.simd.hpp @@ -463,7 +463,7 @@ medianBlur_8u_Om( const Mat& _src, Mat& _dst, int m ) } else { - assert( cn == 4 ); + CV_Assert( cn == 4 ); for( k = 0; k < m*4; k += 4 ) { UPDATE_ACC01( src_top[k], 0, -- ); diff --git a/modules/imgproc/src/moments.cpp b/modules/imgproc/src/moments.cpp index 9e7e6d2dfd..204c8654af 100644 --- a/modules/imgproc/src/moments.cpp +++ b/modules/imgproc/src/moments.cpp @@ -52,7 +52,7 @@ static void completeMomentState( Moments* moments ) double cx = 0, cy = 0; double mu20, mu11, mu02; double inv_m00 = 0.0; - assert( moments != 0 ); + CV_Assert( moments != 0 ); if( fabs(moments->m00) > DBL_EPSILON ) { diff --git a/modules/imgproc/src/precomp.hpp b/modules/imgproc/src/precomp.hpp index 400b7cc2db..b300192e9c 100644 --- a/modules/imgproc/src/precomp.hpp +++ b/modules/imgproc/src/precomp.hpp @@ -54,7 +54,6 @@ #include "hal_replacement.hpp" #include -#include #include #include #include diff --git a/modules/imgproc/src/resize.cpp b/modules/imgproc/src/resize.cpp index 4f82bddfa0..4f1a4576ce 100644 --- a/modules/imgproc/src/resize.cpp +++ b/modules/imgproc/src/resize.cpp @@ -3191,7 +3191,7 @@ static int computeResizeAreaTab( int ssize, int dsize, int cn, double scale, Dec if( sx1 - fsx1 > 1e-3 ) { - assert( k < ssize*2 ); + CV_Assert( k < ssize*2 ); tab[k].di = dx * cn; tab[k].si = (sx1 - 1) * cn; tab[k++].alpha = (float)((sx1 - fsx1) / cellWidth); @@ -3199,7 +3199,7 @@ static int computeResizeAreaTab( int ssize, int dsize, int cn, double scale, Dec for(int sx = sx1; sx < sx2; sx++ ) { - assert( k < ssize*2 ); + CV_Assert( k < ssize*2 ); tab[k].di = dx * cn; tab[k].si = sx * cn; tab[k++].alpha = float(1.0 / cellWidth); @@ -3207,7 +3207,7 @@ static int computeResizeAreaTab( int ssize, int dsize, int cn, double scale, Dec if( fsx2 - sx2 > 1e-3 ) { - assert( k < ssize*2 ); + CV_Assert( k < ssize*2 ); tab[k].di = dx * cn; tab[k].si = sx2 * cn; tab[k++].alpha = (float)(std::min(std::min(fsx2 - sx2, 1.), cellWidth) / cellWidth); @@ -3899,7 +3899,7 @@ void resize(int src_type, { if( k == 0 || ytab[k].di != ytab[k-1].di ) { - assert( ytab[k].di == dy ); + CV_Assert( ytab[k].di == dy ); tabofs[dy++] = k; } } diff --git a/modules/imgproc/src/samplers.cpp b/modules/imgproc/src/samplers.cpp index a0b2aba223..287e78c6df 100644 --- a/modules/imgproc/src/samplers.cpp +++ b/modules/imgproc/src/samplers.cpp @@ -74,7 +74,7 @@ adjustRect( const uchar* src, size_t src_step, int pix_size, src += rect.width*pix_size; rect.width = 0; } - assert( rect.width <= win_size.width ); + CV_Assert( rect.width <= win_size.width ); } if( ip.y >= 0 ) diff --git a/modules/imgproc/src/segmentation.cpp b/modules/imgproc/src/segmentation.cpp index c78931221f..79cb641e80 100644 --- a/modules/imgproc/src/segmentation.cpp +++ b/modules/imgproc/src/segmentation.cpp @@ -155,7 +155,7 @@ void cv::watershed( InputArray _src, InputOutputArray _markers ) dr = std::abs((ptr1)[2] - (ptr2)[2]);\ diff = ws_max(db,dg); \ diff = ws_max(diff,dr); \ - assert( 0 <= diff && diff <= 255 ); \ + CV_Assert( 0 <= diff && diff <= 255 ); \ } CV_Assert( src.type() == CV_8UC3 && dst.type() == CV_32SC1 ); @@ -215,7 +215,7 @@ void cv::watershed( InputArray _src, InputOutputArray _markers ) } // Add to according queue - assert( 0 <= idx && idx <= 255 ); + CV_Assert( 0 <= idx && idx <= 255 ); ws_push( idx, i*mstep + j, i*istep + j*3 ); m[0] = IN_QUEUE; } @@ -286,7 +286,7 @@ void cv::watershed( InputArray _src, InputOutputArray _markers ) } // Set label to current pixel in marker image - assert( lab != 0 ); + CV_Assert( lab != 0 ); m[0] = lab; if( lab == WSHED ) diff --git a/modules/imgproc/src/subdivision2d.cpp b/modules/imgproc/src/subdivision2d.cpp index c254c5f9c6..980a03b7db 100644 --- a/modules/imgproc/src/subdivision2d.cpp +++ b/modules/imgproc/src/subdivision2d.cpp @@ -436,7 +436,7 @@ int Subdiv2D::insert(Point2f pt) else CV_Error_(CV_StsError, ("Subdiv2D::locate returned invalid location = %d", location) ); - assert( curr_edge != 0 ); + CV_Assert( curr_edge != 0 ); validGeometry = false; curr_point = newPoint(pt, false); diff --git a/modules/imgproc/test/test_approxpoly.cpp b/modules/imgproc/test/test_approxpoly.cpp index 81a9772bb1..80ab408f0a 100644 --- a/modules/imgproc/test/test_approxpoly.cpp +++ b/modules/imgproc/test/test_approxpoly.cpp @@ -182,7 +182,7 @@ int CV_ApproxPolyTest::check_slice( CvPoint StartPt, CvPoint EndPt, //////////////////////////////// if( SrcReader == NULL ) { - assert( false ); + CV_Assert( false ); return 0; } @@ -237,7 +237,7 @@ int CV_ApproxPolyTest::check( CvSeq* SrcSeq, CvSeq* DstSeq, float Eps ) int Count; int i,j; - assert( SrcSeq && DstSeq ); + CV_Assert( SrcSeq && DstSeq ); ////////// init //////////////////// Count = SrcSeq->total; diff --git a/modules/imgproc/test/test_bilateral_filter.cpp b/modules/imgproc/test/test_bilateral_filter.cpp index f5e8caab80..badd879a8a 100644 --- a/modules/imgproc/test/test_bilateral_filter.cpp +++ b/modules/imgproc/test/test_bilateral_filter.cpp @@ -203,7 +203,7 @@ namespace opencv_test { namespace { } else { - assert( cn == 3 ); + CV_Assert( cn == 3 ); for( j = 0; j < size.width*3; j += 3 ) { float sum_b = 0, sum_g = 0, sum_r = 0, wsum = 0; diff --git a/modules/imgproc/test/test_canny.cpp b/modules/imgproc/test/test_canny.cpp index 9d9b7c397e..e040da61ad 100644 --- a/modules/imgproc/test/test_canny.cpp +++ b/modules/imgproc/test/test_canny.cpp @@ -249,7 +249,7 @@ test_Canny( const Mat& src, Mat& dst, } else { - assert( fabs(tg) > tan_3pi_8 ); + CV_Assert( fabs(tg) > tan_3pi_8 ); x1 = x2 = x; y1 = y + 1; y2 = y - 1; } diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index 204203d053..3cd57c9d38 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -217,7 +217,7 @@ void CV_ColorCvtBaseTest::convert_forward( const Mat& src, Mat& dst ) float* dst_buf = &_dst_buf[0]; int i, j; - assert( (cn == 3 || cn == 4) && (dst_cn == 3 || dst_cn == 1) ); + CV_Assert( (cn == 3 || cn == 4) && (dst_cn == 3 || dst_cn == 1) ); for( i = 0; i < src.rows; i++ ) { @@ -281,7 +281,7 @@ void CV_ColorCvtBaseTest::convert_forward( const Mat& src, Mat& dst ) } break; default: - assert(0); + CV_Assert(0); } } } @@ -312,7 +312,7 @@ void CV_ColorCvtBaseTest::convert_backward( const Mat& src, const Mat& dst, Mat& float* dst_buf = &_dst_buf[0]; int i, j; - assert( cn == 3 || cn == 4 ); + CV_Assert( cn == 3 || cn == 4 ); for( i = 0; i < src.rows; i++ ) { @@ -385,7 +385,7 @@ void CV_ColorCvtBaseTest::convert_backward( const Mat& src, const Mat& dst, Mat& } break; default: - assert(0); + CV_Assert(0); } } } @@ -1571,7 +1571,7 @@ void CV_ColorRGBTest::convert_forward( const Mat& src, Mat& dst ) } break; default: - assert(0); + CV_Assert(0); } } } @@ -1677,7 +1677,7 @@ void CV_ColorRGBTest::convert_backward( const Mat& /*src*/, const Mat& src, Mat& } break; default: - assert(0); + CV_Assert(0); } } } diff --git a/modules/imgproc/test/test_contours.cpp b/modules/imgproc/test/test_contours.cpp index c07d19098b..224a2e1f1a 100644 --- a/modules/imgproc/test/test_contours.cpp +++ b/modules/imgproc/test/test_contours.cpp @@ -208,7 +208,7 @@ cvTsMarkContours( IplImage* img, int val ) int i, j; int step = img->widthStep; - assert( img->depth == IPL_DEPTH_8U && img->nChannels == 1 && (val&1) != 0); + CV_Assert( img->depth == IPL_DEPTH_8U && img->nChannels == 1 && (val&1) != 0); for( i = 1; i < img->height - 1; i++ ) for( j = 1; j < img->width - 1; j++ ) diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index bc5c940827..aa553e5efe 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -301,7 +301,7 @@ void CV_BaseShapeDescrTest::generate_point_set( void* pointsSet ) else { CvMat* ptm = (CvMat*)pointsSet; - assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); + CV_Assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); total = ptm->rows + ptm->cols - 1; point_type = CV_MAT_TYPE(ptm->type); data = ptm->data.ptr; @@ -310,7 +310,7 @@ void CV_BaseShapeDescrTest::generate_point_set( void* pointsSet ) n = CV_MAT_CN(point_type); point_type = CV_MAT_DEPTH(point_type); - assert( (point_type == CV_32S || point_type == CV_32F) && n <= 4 ); + CV_Assert( (point_type == CV_32S || point_type == CV_32F) && n <= 4 ); for( i = 0; i < total; i++ ) { @@ -1335,7 +1335,7 @@ void CV_FitEllipseTest::generate_point_set( void* pointsSet ) else { CvMat* ptm = (CvMat*)pointsSet; - assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); + CV_Assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); total = ptm->rows + ptm->cols - 1; point_type = CV_MAT_TYPE(ptm->type); data = ptm->data.ptr; @@ -1621,7 +1621,7 @@ void CV_FitLineTest::generate_point_set( void* pointsSet ) else { CvMat* ptm = (CvMat*)pointsSet; - assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); + CV_Assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); total = ptm->rows + ptm->cols - 1; point_type = CV_MAT_DEPTH(CV_MAT_TYPE(ptm->type)); data = ptm->data.ptr; @@ -1788,13 +1788,13 @@ cvTsGenerateTousledBlob( CvPoint2D32f center, CvSize2D32f axes, else { CvMat* ptm = (CvMat*)points; - assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); + CV_Assert( CV_IS_MAT(ptm) && CV_IS_MAT_CONT(ptm->type) ); total = ptm->rows + ptm->cols - 1; point_type = CV_MAT_TYPE(ptm->type); data = ptm->data.ptr; } - assert( point_type == CV_32SC2 || point_type == CV_32FC2 ); + CV_Assert( point_type == CV_32SC2 || point_type == CV_32FC2 ); for( i = 0; i < total; i++ ) { @@ -1874,8 +1874,8 @@ void CV_ContourMomentsTest::generate_point_set( void* pointsSet ) center.x = (float)(img_size.width*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.width - max_sz*2)*0.8); center.y = (float)(img_size.height*0.5 + (cvtest::randReal(rng)-0.5)*(img_size.height - max_sz*2)*0.8); - assert( 0 < center.x - max_sz && center.x + max_sz < img_size.width && - 0 < center.y - max_sz && center.y + max_sz < img_size.height ); + CV_Assert( 0 < center.x - max_sz && center.x + max_sz < img_size.width && + 0 < center.y - max_sz && center.y + max_sz < img_size.height ); max_r_scale = cvtest::randReal(rng)*max_max_r_scale*0.01; angle = cvtest::randReal(rng)*360; diff --git a/modules/imgproc/test/test_distancetransform.cpp b/modules/imgproc/test/test_distancetransform.cpp index 652b5bfd24..32fc7aa2c3 100644 --- a/modules/imgproc/test/test_distancetransform.cpp +++ b/modules/imgproc/test/test_distancetransform.cpp @@ -161,7 +161,7 @@ cvTsDistTransform( const CvMat* _src, CvMat* _dst, int dist_type, float delta[16]; int tstep, count; - assert( mask_size == 3 || mask_size == 5 ); + CV_Assert( mask_size == 3 || mask_size == 5 ); if( dist_type == CV_DIST_USER ) memcpy( mask, _mask, sizeof(mask) ); diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index 11d87a0abe..3e28a2caad 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -992,8 +992,8 @@ static void test_medianFilter( const Mat& src, Mat& dst, int m ) median_pair *buf0 = &_buf0[0], *buf1 = &_buf1[0]; int step = (int)(src.step/src.elemSize()); - assert( src.rows == dst.rows + m - 1 && src.cols == dst.cols + m - 1 && - src.type() == dst.type() && src.type() == CV_8UC1 ); + CV_Assert( src.rows == dst.rows + m - 1 && src.cols == dst.cols + m - 1 && + src.type() == dst.type() && src.type() == CV_8UC1 ); for( i = 0; i < dst.rows; i++ ) { @@ -1050,7 +1050,7 @@ static void test_medianFilter( const Mat& src, Mat& dst, int m ) *buf1++ = buf0[k++]; else { - assert( col_buf[l] < INT_MAX ); + CV_Assert( col_buf[l] < INT_MAX ); *buf1++ = median_pair(ins_col,col_buf[l++]); } } @@ -1061,7 +1061,7 @@ static void test_medianFilter( const Mat& src, Mat& dst, int m ) if( del_col < 0 ) n += m; buf1 -= n; - assert( n == m2 ); + CV_Assert( n == m2 ); dst1[j] = (uchar)buf1[n/2].val; median_pair* tbuf; CV_SWAP( buf0, buf1, tbuf ); diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index 7d0360dfb1..1257a472b7 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -169,7 +169,7 @@ int CV_ImgWarpBaseTest::prepare_test_case( int test_case_idx ) } break; default: - assert(0); + CV_Assert(0); } /*switch( depth ) @@ -482,7 +482,7 @@ static void test_remap( const Mat& src, Mat& dst, const Mat& mapx, const Mat& ma } break; default: - assert(0); + CV_Assert(0); } } } diff --git a/modules/imgproc/test/test_imgwarp_strict.cpp b/modules/imgproc/test/test_imgwarp_strict.cpp index cadc303cb3..5ca3d09ec4 100644 --- a/modules/imgproc/test/test_imgwarp_strict.cpp +++ b/modules/imgproc/test/test_imgwarp_strict.cpp @@ -935,7 +935,7 @@ void CV_Remap_Test::remap_generic(const Mat& _src, Mat& _dst) else if (interpolation == INTER_LANCZOS4) ksize = 8; else if (interpolation != INTER_LINEAR) - assert(0); + CV_Assert(0); int ofs = (ksize / 2) - 1; CV_Assert(_src.depth() == CV_32F && _dst.type() == _src.type()); diff --git a/modules/imgproc/test/test_templmatch.cpp b/modules/imgproc/test/test_templmatch.cpp index 035be685a9..858d7a35fe 100644 --- a/modules/imgproc/test/test_templmatch.cpp +++ b/modules/imgproc/test/test_templmatch.cpp @@ -185,7 +185,7 @@ static void cvTsMatchTemplate( const CvMat* img, const CvMat* templ, CvMat* resu b_denom = 1.; } - assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED ); + CV_Assert( CV_TM_SQDIFF <= method && method <= CV_TM_CCOEFF_NORMED ); for( i = 0; i < result->rows; i++ ) { diff --git a/modules/imgproc/test/test_thresh.cpp b/modules/imgproc/test/test_thresh.cpp index a61095d5cc..a8e961675d 100644 --- a/modules/imgproc/test/test_thresh.cpp +++ b/modules/imgproc/test/test_thresh.cpp @@ -157,7 +157,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, imaxval = cvRound(maxval); } - assert( depth == CV_8U || depth == CV_16S || depth == CV_16U || depth == CV_32F || depth == CV_64F ); + CV_Assert( depth == CV_8U || depth == CV_16S || depth == CV_16U || depth == CV_32F || depth == CV_64F ); switch( thresh_type ) { @@ -407,7 +407,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, } break; default: - assert(0); + CV_Assert(0); } } diff --git a/modules/ml/src/precomp.hpp b/modules/ml/src/precomp.hpp index 6d50357b7a..328cc4732a 100644 --- a/modules/ml/src/precomp.hpp +++ b/modules/ml/src/precomp.hpp @@ -48,7 +48,6 @@ #include "opencv2/core/private.hpp" -#include #include #include #include diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 5dae889013..b69ddaece2 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -869,7 +869,7 @@ DTreesImpl::WSplit DTreesImpl::findSplitCatClass( int vi, const vector& _si } else { - assert( m == 2 ); + CV_Assert( m == 2 ); dbl_ptr = (double**)(c_weights + _mi); for( j = 0; j < mi; j++ ) dbl_ptr[j] = cjk + j*2 + 1; diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index bd62cd21a1..c2d2221fda 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -960,10 +960,10 @@ int CascadeClassifierImpl::runAt( Ptr& evaluator, Point pt, in { CV_INSTRUMENT_REGION(); - assert( !oldCascade && - (data.featureType == FeatureEvaluator::HAAR || - data.featureType == FeatureEvaluator::LBP || - data.featureType == FeatureEvaluator::HOG) ); + CV_Assert( !oldCascade && + (data.featureType == FeatureEvaluator::HAAR || + data.featureType == FeatureEvaluator::LBP || + data.featureType == FeatureEvaluator::HOG) ); if( !evaluator->setWindow(pt, scaleIdx) ) return -1; diff --git a/modules/objdetect/src/detection_based_tracker.cpp b/modules/objdetect/src/detection_based_tracker.cpp index 5a6ccce328..14e0fe6617 100644 --- a/modules/objdetect/src/detection_based_tracker.cpp +++ b/modules/objdetect/src/detection_based_tracker.cpp @@ -42,7 +42,6 @@ //M*/ #include "precomp.hpp" -#include #ifdef CV_CXX11 #define USE_STD_THREADS diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 9e20111f43..ee485f914f 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -291,7 +291,7 @@ icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade ) } cascade->hid_cascade = out; - assert( (char*)haar_node_ptr - (char*)out <= datasize ); + CV_Assert( (char*)haar_node_ptr - (char*)out <= datasize ); return out; } @@ -622,7 +622,7 @@ cvRunHaarClassifierCascadeSum( const CvHaarClassifierCascade* _cascade, if( cascade->is_tree ) { CvHidHaarStageClassifier* ptr = cascade->stage_classifier; - assert( start_stage == 0 ); + CV_Assert( start_stage == 0 ); while( ptr ) { diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 8a2107734a..1ff2191dd0 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -852,7 +852,7 @@ void HOGCache::init(const HOGDescriptor* _descriptor, data->gradWeight = weights(i,j); } - assert( count1 + count2 + count4 == rawBlockSize ); + CV_Assert( count1 + count2 + count4 == rawBlockSize ); // defragment pixData for( j = 0; j < count2; j++ ) pixData[j + count1] = pixData[j + rawBlockSize]; @@ -874,7 +874,7 @@ void HOGCache::init(const HOGDescriptor* _descriptor, const float* HOGCache::getBlock(Point pt, float* buf) { float* blockHist = buf; - assert(descriptor != 0); + CV_Assert(descriptor != 0); // Size blockSize = descriptor->blockSize; pt += imgoffset; diff --git a/modules/objdetect/test/test_cascadeandhog.cpp b/modules/objdetect/test/test_cascadeandhog.cpp index 83100dd796..e6bf9a23ca 100644 --- a/modules/objdetect/test/test_cascadeandhog.cpp +++ b/modules/objdetect/test/test_cascadeandhog.cpp @@ -191,7 +191,7 @@ void CV_DetectorTest::run( int ) // write detectors validationFS << DETECTORS << "{"; - assert( detectorNames.size() == detectorFilenames.size() ); + CV_Assert( detectorNames.size() == detectorFilenames.size() ); nit = detectorNames.begin(); for( int di = 0; nit != detectorNames.end(); ++nit, di++ ) { @@ -291,7 +291,7 @@ static bool isZero( uchar i ) {return i == 0;} int CV_DetectorTest::validate( int detectorIdx, vector >& objects ) { - assert( imageFilenames.size() == objects.size() ); + CV_Assert( imageFilenames.size() == objects.size() ); int imageIdx = 0; int totalNoPair = 0, totalValRectCount = 0; @@ -504,7 +504,7 @@ int CV_HOGDetectorTest::detectMultiScale( int di, const Mat& img, if( detectorFilenames[di].empty() ) hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); else - assert(0); + CV_Assert(0); hog.detectMultiScale(img, objects); return cvtest::TS::OK; } @@ -787,7 +787,7 @@ void HOGCacheTester::init(const HOGDescriptorTester* _descriptor, data->gradWeight = weights(i,j); } - assert( count1 + count2 + count4 == rawBlockSize ); + CV_Assert( count1 + count2 + count4 == rawBlockSize ); // defragment pixData for( j = 0; j < count2; j++ ) pixData[j + count1] = pixData[j + rawBlockSize]; @@ -809,7 +809,7 @@ void HOGCacheTester::init(const HOGDescriptorTester* _descriptor, const float* HOGCacheTester::getBlock(Point pt, float* buf) { float* blockHist = buf; - assert(descriptor != 0); + CV_Assert(descriptor != 0); Size blockSize = descriptor->blockSize; pt += imgoffset; @@ -1285,7 +1285,7 @@ void HOGDescriptorTester::computeGradient(const Mat& img, Mat& grad, Mat& qangle hidx += _nbins; else if( hidx >= _nbins ) hidx -= _nbins; - assert( (unsigned)hidx < (unsigned)_nbins ); + CV_Assert( (unsigned)hidx < (unsigned)_nbins ); qanglePtr[x*2] = (uchar)hidx; hidx++; diff --git a/modules/ts/src/ocl_perf.cpp b/modules/ts/src/ocl_perf.cpp index 8dacf219f6..90c2ece66a 100644 --- a/modules/ts/src/ocl_perf.cpp +++ b/modules/ts/src/ocl_perf.cpp @@ -50,7 +50,7 @@ namespace perf { void checkDeviceMaxMemoryAllocSize(const Size& size, int type, int factor) { - assert(factor > 0); + CV_Assert(factor > 0); if (!cv::ocl::useOpenCL()) return; diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index dfd20fbc36..aed205fbf6 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -377,7 +377,7 @@ void BaseTest::run( int start_from ) void BaseTest::run_func(void) { - assert(0); + CV_Assert(0); } diff --git a/modules/ts/src/ts_arrtest.cpp b/modules/ts/src/ts_arrtest.cpp index 365cf1550e..1c74fb4a33 100644 --- a/modules/ts/src/ts_arrtest.cpp +++ b/modules/ts/src/ts_arrtest.cpp @@ -268,14 +268,14 @@ void ArrayTest::fill_array( int /*test_case_idx*/, int i, int j, Mat& arr ) double ArrayTest::get_success_error_level( int /*test_case_idx*/, int i, int j ) { int elem_depth = CV_MAT_DEPTH(cvGetElemType(test_array[i][j])); - assert( i == OUTPUT || i == INPUT_OUTPUT ); + CV_Assert( i == OUTPUT || i == INPUT_OUTPUT ); return elem_depth < CV_32F ? 0 : elem_depth == CV_32F ? FLT_EPSILON*100: DBL_EPSILON*5000; } void ArrayTest::prepare_to_validation( int /*test_case_idx*/ ) { - assert(0); + CV_Assert(0); } @@ -293,7 +293,7 @@ int ArrayTest::validate_test_results( int test_case_idx ) int i1 = i == 0 ? REF_OUTPUT : REF_INPUT_OUTPUT; size_t sizei = test_array[i0].size(); - assert( sizei == test_array[i1].size() ); + CV_Assert( sizei == test_array[i1].size() ); for( j = 0; j < sizei; j++ ) { double err_level; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 6f1c389307..4b7dcbd234 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -2094,7 +2094,7 @@ int cmpEps( const Mat& arr, const Mat& refarr, double* _realmaxdiff, } break; default: - assert(0); + CV_Assert(0); return CMP_EPS_BIG_DIFF; } if(_realmaxdiff) @@ -2705,7 +2705,7 @@ static void calcSobelKernel1D( int order, int _aperture_size, int size, vector= cv::getTickFrequency() * 10) { std::cout << '.' << std::endl; @@ -1638,7 +1638,7 @@ performance_metrics& TestBase::calcMetrics() } else { - assert(false); + CV_Assert(false); } int offset = static_cast(start - times.begin()); @@ -1714,7 +1714,7 @@ void TestBase::validateMetrics() } else { - assert(false); + CV_Assert(false); } } diff --git a/modules/videoio/src/cap_cmu.cpp b/modules/videoio/src/cap_cmu.cpp index a9a499b4cd..72712cec0a 100644 --- a/modules/videoio/src/cap_cmu.cpp +++ b/modules/videoio/src/cap_cmu.cpp @@ -212,7 +212,7 @@ int CvCaptureCAM_CMU::getDepth() // TODO if( format==7 ) { - assert(0); + CV_Assert(0); return 1; } // irrelvant to depth @@ -233,7 +233,7 @@ int CvCaptureCAM_CMU::getNChannels() int mode = cmucam->GetVideoMode(); if( format==7 ){ - assert(0); + CV_Assert(0); return 1; } diff --git a/modules/videoio/src/cap_dc1394.cpp b/modules/videoio/src/cap_dc1394.cpp index 368bf3aa38..7f6c694ce4 100644 --- a/modules/videoio/src/cap_dc1394.cpp +++ b/modules/videoio/src/cap_dc1394.cpp @@ -272,7 +272,7 @@ static CvCaptureCAM_DC1394 * icvCaptureFromCAM_DC1394 (int index) format_idx = preferred_modes[i] - FORMAT_MIN; continue; } - assert(format_idx != -1); + CV_Assert(format_idx != -1); if ( ! icvFormatSupportedCAM_DC1394(pcap->format, formats) ) continue; if ( icvModeSupportedCAM_DC1394(pcap->format, preferred_modes[i], modes[format_idx]) ){ diff --git a/modules/videoio/src/cap_dc1394_v2.cpp b/modules/videoio/src/cap_dc1394_v2.cpp index 938b31f4a9..3e771a0476 100644 --- a/modules/videoio/src/cap_dc1394_v2.cpp +++ b/modules/videoio/src/cap_dc1394_v2.cpp @@ -64,7 +64,6 @@ static uint32_t getControlRegister(dc1394camera_t *camera, uint64_t offset) uint32_t value = 0; dc1394error_t err = dc1394_get_control_register(camera, offset, &value); - assert(err == DC1394_SUCCESS); return err == DC1394_SUCCESS ? value : 0xffffffff; } diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 6877a963ef..d5be759f43 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -44,7 +44,6 @@ #if !(defined(_WIN32) || defined(WINCE)) # include #endif -#include #include #include @@ -405,7 +404,7 @@ static inline int _opencv_ffmpeg_interrupt_callback(void *ptr) { AVInterruptCallbackMetadata* metadata = (AVInterruptCallbackMetadata*)ptr; - assert(metadata); + CV_Assert(metadata); if (metadata->timeout_after_ms == 0) { @@ -2113,7 +2112,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int } } else { - assert(false); + CV_Assert(false); } if( (width & -2) != frame_width || (height & -2) != frame_height || !data ) @@ -2165,7 +2164,7 @@ bool CvVideoWriter_FFMPEG::writeFrame( const unsigned char* data, int step, int } if ( c->pix_fmt != input_pix_fmt ) { - assert( input_picture ); + CV_Assert( input_picture ); // let input_picture point to the raw data buffer of 'image' _opencv_ffmpeg_av_image_fill_arrays(input_picture, (uint8_t *) data, (AVPixelFormat)input_pix_fmt, width, height); @@ -2441,7 +2440,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, #else oc = av_alloc_format_context(); #endif - assert (oc); + CV_Assert (oc); /* set file name */ oc->oformat = fmt; diff --git a/modules/videoio/src/cap_giganetix.cpp b/modules/videoio/src/cap_giganetix.cpp index 98fba269b0..aa86c1cb3a 100644 --- a/modules/videoio/src/cap_giganetix.cpp +++ b/modules/videoio/src/cap_giganetix.cpp @@ -441,7 +441,7 @@ CvCaptureCAM_Giganetix::grabImage () { gige::IImageInfo imageInfo; m_device->GetImageInfo (&imageInfo); - assert(imageInfo.IsValid()); + CV_Assert(imageInfo.IsValid()); if (m_device->GetPendingImagesCount() == 1) { diff --git a/modules/videoio/src/cap_libv4l.cpp b/modules/videoio/src/cap_libv4l.cpp index ba2b7985a3..6fd0f757a8 100644 --- a/modules/videoio/src/cap_libv4l.cpp +++ b/modules/videoio/src/cap_libv4l.cpp @@ -249,7 +249,6 @@ make & enjoy! #include #include #include /* for videodev2.h */ -#include #include #include @@ -1125,7 +1124,7 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) { } } - assert(buf.index < capture->req.count); + CV_Assert(buf.index < capture->req.count); #ifdef USE_TEMP_BUFFER memcpy(capture->buffers[MAX_V4L_BUFFERS].start, diff --git a/modules/videoio/src/cap_qt.cpp b/modules/videoio/src/cap_qt.cpp index 8acc5d5ab6..e2cd145d4d 100644 --- a/modules/videoio/src/cap_qt.cpp +++ b/modules/videoio/src/cap_qt.cpp @@ -55,7 +55,6 @@ // standard includes #include -#include // Mac OS includes #include @@ -608,14 +607,14 @@ static CvCapture_QT_Cam * icvCaptureFromCam_QT (const int index) /// capture properties currently unimplemented for QuickTime camera interface static double icvGetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id) { - assert (0); + CV_Assert (0); return 0; } /// capture properties currently unimplemented for QuickTime camera interface static int icvSetProperty_QT_Cam (CvCapture_QT_Cam * capture, int property_id, double value) { - assert (0); + CV_Assert (0); return 0; } diff --git a/modules/videoio/src/cap_v4l.cpp b/modules/videoio/src/cap_v4l.cpp index 2740c62e29..a4694b4b48 100644 --- a/modules/videoio/src/cap_v4l.cpp +++ b/modules/videoio/src/cap_v4l.cpp @@ -220,7 +220,6 @@ make & enjoy! #include #include -#include #include #include #include @@ -929,8 +928,8 @@ bool CvCaptureCAM_V4L::read_frame_v4l2() return false; } - assert(buf.index < req.count); - assert(buffers[buf.index].length == buf.length); + CV_Assert(buf.index < req.count); + CV_Assert(buffers[buf.index].length == buf.length); //We shouldn't use this buffer in the queue while not retrieve frame from it. buffers[buf.index].buffer = buf; diff --git a/modules/videoio/src/precomp.hpp b/modules/videoio/src/precomp.hpp index 800d471362..77fb29e849 100644 --- a/modules/videoio/src/precomp.hpp +++ b/modules/videoio/src/precomp.hpp @@ -68,7 +68,6 @@ #include #include #include -#include // FIXIT remove this #if defined _WIN32 || defined WINCE #if !defined _WIN32_WINNT From 58dc39793095c82676d1a1ff0c6c1e6fb1146646 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 27 Nov 2021 02:51:57 +0000 Subject: [PATCH 02/13] dnn(test): add two_inputs test with FP32/U8 data types - remove similar test from IE scope under HAVE_INF_ENGINE --- modules/dnn/test/test_layers.cpp | 51 --------------------------- modules/dnn/test/test_misc.cpp | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 836b0aab9a..e61fd733f9 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -1380,57 +1380,6 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_DLDT_two_inputs_3dim, Combine( testing::ValuesIn(list_sizes) )); -typedef testing::TestWithParam > > Test_DLDT_two_inputs; -TEST_P(Test_DLDT_two_inputs, as_backend) -{ - static const float kScale = 0.5f; - static const float kScaleInv = 1.0f / kScale; - - Backend backendId = get<0>(get<2>(GetParam())); - Target targetId = get<1>(get<2>(GetParam())); - - Net net; - LayerParams lp; - lp.type = "Eltwise"; - lp.name = "testLayer"; - lp.set("operation", "sum"); - int eltwiseId = net.addLayerToPrev(lp.name, lp.type, lp); // connect to a first input - net.connect(0, 1, eltwiseId, 1); // connect to a second input - - int inpSize[] = {1, 2, 3, 4}; - Mat firstInp(4, &inpSize[0], get<0>(GetParam())); - Mat secondInp(4, &inpSize[0], get<1>(GetParam())); - randu(firstInp, 0, 255); - randu(secondInp, 0, 255); - - net.setInputsNames({"data", "second_input"}); - net.setInput(firstInp, "data", kScale); - net.setInput(secondInp, "second_input", kScaleInv); - net.setPreferableBackend(backendId); - net.setPreferableTarget(targetId); - Mat out = net.forward(); - - Mat ref; - addWeighted(firstInp, kScale, secondInp, kScaleInv, 0, ref, CV_32F); - // Output values are in range [0, 637.5]. - double l1 = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 0.06 : 1e-6; - double lInf = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 0.3 : 1e-5; - normAssert(out, ref, "", l1, lInf); - if (cvtest::debugLevel > 0 || HasFailure()) - { - std::cout << "input1 scale=" << kScale << " input2 scale=" << kScaleInv << std::endl; - std::cout << "input1: " << firstInp.size << " " << firstInp.reshape(1, 1) << std::endl; - std::cout << "input2: " << secondInp.size << " " << secondInp.reshape(1, 1) << std::endl; - std::cout << "ref: " << ref.reshape(1, 1) << std::endl; - std::cout << "out: " << out.reshape(1, 1) << std::endl; - } -} - -INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_DLDT_two_inputs, Combine( - Values(CV_8U, CV_32F), Values(CV_8U, CV_32F), - dnnBackendsAndTargets() -)); - class UnsupportedLayer : public Layer { public: diff --git a/modules/dnn/test/test_misc.cpp b/modules/dnn/test/test_misc.cpp index 11e0f0ec2d..9971450478 100644 --- a/modules/dnn/test/test_misc.cpp +++ b/modules/dnn/test/test_misc.cpp @@ -828,4 +828,64 @@ INSTANTIATE_TEST_CASE_P(/**/, Test_Model_Optimizer, #endif // HAVE_INF_ENGINE +typedef testing::TestWithParam > > Test_two_inputs; +TEST_P(Test_two_inputs, basic) +{ + static const float kScale = 0.5f; + static const float kScaleInv = 1.0f / kScale; + + Backend backendId = get<0>(get<2>(GetParam())); + Target targetId = get<1>(get<2>(GetParam())); + + Net net; + LayerParams lp; + lp.type = "Eltwise"; + lp.name = "testLayer"; + lp.set("operation", "sum"); + int eltwiseId = net.addLayerToPrev(lp.name, lp.type, lp); // connect to a first input + net.connect(0, 1, eltwiseId, 1); // connect to a second input + + int inpSize[] = {1, 2, 3, 4}; + Mat firstInp(4, &inpSize[0], get<0>(GetParam())); + Mat secondInp(4, &inpSize[0], get<1>(GetParam())); + randu(firstInp, 0, 100); + randu(secondInp, 0, 100); + +#ifndef CV_CXX11 + std::vector input_names; + input_names.push_back("data"); + input_names.push_back("second_input"); + net.setInputsNames(input_names); +#else + net.setInputsNames({"data", "second_input"}); +#endif + net.setInput(firstInp, "data", kScale); + net.setInput(secondInp, "second_input", kScaleInv); + net.setPreferableBackend(backendId); + net.setPreferableTarget(targetId); + Mat out = net.forward(); + + Mat ref; + addWeighted(firstInp, kScale, secondInp, kScaleInv, 0, ref, CV_32F); + + double l1 = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 0.06 : 1e-6; + double lInf = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD) ? 0.3 : 1e-5; + normAssert(out, ref, "", l1, lInf); + + if (cvtest::debugLevel > 0 || HasFailure()) + { + std::cout << "input1 scale=" << kScale << " input2 scale=" << kScaleInv << std::endl; + std::cout << "input1: " << firstInp.size << " " << firstInp.reshape(1, 1) << std::endl; + std::cout << "input2: " << secondInp.size << " " << secondInp.reshape(1, 1) << std::endl; + std::cout << "ref: " << ref.reshape(1, 1) << std::endl; + std::cout << "out: " << out.reshape(1, 1) << std::endl; + } +} + +INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_two_inputs, Combine( + Values(CV_32F, CV_8U), + Values(CV_32F, CV_8U), + dnnBackendsAndTargets() +)); + }} // namespace From 58b06222ffa637b8278c04f70ffd60ae762a7bb2 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 28 Nov 2021 04:29:54 +0000 Subject: [PATCH 03/13] dnn(DataLayer): fix CPU/OpenCL code paths for FP16 handling --- modules/dnn/src/dnn.cpp | 113 ++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 52 deletions(-) diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 8182394387..b35dda9ddf 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -597,29 +597,26 @@ struct DataLayer : public Layer CV_TRACE_FUNCTION(); CV_TRACE_ARG_VALUE(name, "name", name.c_str()); + // FIXIT: add wrapper without exception suppression CV_OCL_RUN(IS_DNN_OPENCL_TARGET(preferableTarget), forward_ocl(inputs_arr, outputs_arr, internals_arr)) - if (outputs_arr.depth() == CV_16S) - { - forward_fallback(inputs_arr, outputs_arr, internals_arr); - return; - } + bool isFP16 = outputs_arr.depth() == CV_16S; std::vector outputs, internals; outputs_arr.getMatVector(outputs); internals_arr.getMatVector(internals); - // Supported modes: - // | Input type | Output type | - // | fp32 | fp32 | - // | uint8 | fp32 | for (int i = 0; i < inputsData.size(); ++i) { double scale = scaleFactors[i]; Scalar& mean = means[i]; + CV_Assert(mean == Scalar() || inputsData[i].size[1] <= 4); - CV_CheckTypeEQ(outputs[i].type(), CV_32FC1, ""); + if (isFP16) + CV_CheckTypeEQ(outputs[i].type(), CV_16SC1, ""); + else + CV_CheckTypeEQ(outputs[i].type(), CV_32FC1, ""); bool singleMean = true; for (int j = 1; j < std::min(4, inputsData[i].size[1]) && singleMean; ++j) @@ -629,34 +626,49 @@ struct DataLayer : public Layer if (singleMean) { - inputsData[i].convertTo(outputs[i], CV_32F, scale, -mean[0] * scale); + if (isFP16) + { + Mat input_f32; + inputsData[i].convertTo(input_f32, CV_32F, scale, -mean[0] * scale); + convertFp16(input_f32, outputs[i]); + } + else + { + inputsData[i].convertTo(outputs[i], CV_32F, scale, -mean[0] * scale); + } } else { for (int n = 0; n < inputsData[i].size[0]; ++n) + { for (int c = 0; c < inputsData[i].size[1]; ++c) { Mat inp = getPlane(inputsData[i], n, c); Mat out = getPlane(outputs[i], n, c); - inp.convertTo(out, CV_32F, scale, -mean[c] * scale); + if (isFP16) + { + Mat input_f32; + inp.convertTo(input_f32, CV_32F, scale, -mean[c] * scale); + convertFp16(input_f32, out); + } + else + { + inp.convertTo(out, CV_32F, scale, -mean[c] * scale); + } } + } } } } #ifdef HAVE_OPENCL - std::vector tmp_expressions; bool forward_ocl(InputArrayOfArrays, OutputArrayOfArrays outputs_, OutputArrayOfArrays internals_) { - // Supported modes: - // | Input type | Output type | - // | fp32 | fp32 | - // | fp32 | fp16 | - // | uint8 | fp32 | + bool isFP16 = outputs_.depth() == CV_16S; + std::vector outputs; outputs_.getUMatVector(outputs); - tmp_expressions.clear(); for (int i = 0; i < inputsData.size(); ++i) { Mat inputData = inputsData[i]; @@ -664,58 +676,55 @@ struct DataLayer : public Layer double scale = scaleFactors[i]; Scalar& mean = means[i]; - CV_Assert(mean == Scalar() || inputsData[i].size[1] <= 4); + CV_Assert(mean == Scalar() || inputData.size[1] <= 4); + if (isFP16) + CV_CheckTypeEQ(outputs[i].type(), CV_16SC1, ""); + else + CV_CheckTypeEQ(outputs[i].type(), CV_32FC1, ""); + bool singleMean = true; - for (int j = 1; j < std::min(4, inputsData[i].size[1]) && singleMean; ++j) + for (int j = 1; j < std::min(4, inputData.size[1]) && singleMean; ++j) { singleMean = mean[j] == mean[j - 1]; } - if (outputs_.depth() == CV_16S) + if (singleMean) { - if (singleMean) + if (isFP16) { - tmp_expressions.push_back(Mat(scale * (inputsData[i] - mean[0]))); - convertFp16(tmp_expressions.back(), outputs[i]); + UMat input_i; + inputData.convertTo(input_i, CV_32F, scale, -mean[0] * scale); + convertFp16(input_i, outputs[i]); } else { - for (int n = 0; n < inputsData[i].size[0]; ++n) - for (int c = 0; c < inputsData[i].size[1]; ++c) - { - Mat inp = getPlane(inputsData[i], n, c); - - std::vector plane(4, Range::all()); - plane[0] = Range(n, n + 1); - plane[1] = Range(c, c + 1); - UMat out = outputs[i](plane).reshape(1, inp.dims, inp.size); - - tmp_expressions.push_back(scale * (inp - mean[c])); - convertFp16(tmp_expressions.back(), out); - } + inputData.convertTo(outputs[i], CV_32F, scale, -mean[0] * scale); } } else { - CV_Assert(outputs_.depth() == CV_32F); - if (singleMean) - { - inputsData[i].convertTo(outputs[i], CV_32F, scale, -mean[0] * scale); - } - else + for (int n = 0; n < inputData.size[0]; ++n) { - for (int n = 0; n < inputsData[i].size[0]; ++n) - for (int c = 0; c < inputsData[i].size[1]; ++c) - { - Mat inp = getPlane(inputsData[i], n, c); + for (int c = 0; c < inputData.size[1]; ++c) + { + Mat inp = getPlane(inputData, n, c); - std::vector plane(4, Range::all()); - plane[0] = Range(n, n + 1); - plane[1] = Range(c, c + 1); - UMat out = outputs[i](plane).reshape(1, inp.dims, inp.size); + std::vector plane(4, Range::all()); + plane[0] = Range(n, n + 1); + plane[1] = Range(c, c + 1); + UMat out = outputs[i](plane).reshape(1, inp.dims, inp.size); + if (isFP16) + { + UMat input_i; + inp.convertTo(input_i, CV_32F, scale, -mean[c] * scale); + convertFp16(input_i, out); + } + else + { inp.convertTo(out, CV_32F, scale, -mean[c] * scale); } + } } } } From 05db8784ae43557a7958a752738d989372ece211 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Mon, 29 Nov 2021 19:56:23 +0300 Subject: [PATCH 04/13] fix Clip, LeakyReLU, LRN, Split defaults --- modules/dnn/src/layers/lrn_layer.cpp | 2 +- modules/dnn/src/onnx/onnx_importer.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/dnn/src/layers/lrn_layer.cpp b/modules/dnn/src/layers/lrn_layer.cpp index 434ba5ccbe..65cd160dfe 100644 --- a/modules/dnn/src/layers/lrn_layer.cpp +++ b/modules/dnn/src/layers/lrn_layer.cpp @@ -80,7 +80,7 @@ public: if (size % 2 != 1 || size <= 0) CV_Error(Error::StsBadArg, "LRN layer supports only positive odd values for local_size"); - alpha = params.get("alpha", 1); + alpha = params.get("alpha", 0.0001); beta = params.get("beta", 0.75); bias = params.get("bias", 1); normBySize = params.get("norm_by_size", true); diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index d70a81b9ad..f382d4637e 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -920,6 +920,7 @@ void ONNXImporter::parseSplit(LayerParams& layerParams, const opencv_onnx::NodeP layerParams.set("num_split", node_proto.output_size()); } layerParams.type = "Slice"; + layerParams.set("axis", layerParams.get("axis", 0)); addLayer(layerParams, node_proto); } @@ -1184,15 +1185,15 @@ void ONNXImporter::parseImageScaler(LayerParams& layerParams, const opencv_onnx: void ONNXImporter::parseClip(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto) { layerParams.type = "ReLU6"; - replaceLayerParam(layerParams, "min", "min_value"); - replaceLayerParam(layerParams, "max", "max_value"); + layerParams.set("min_value", layerParams.get("min", -FLT_MAX)); + layerParams.set("max_value", layerParams.get("max", FLT_MAX)); addLayer(layerParams, node_proto); } void ONNXImporter::parseLeakyRelu(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto) { layerParams.type = "ReLU"; - replaceLayerParam(layerParams, "alpha", "negative_slope"); + layerParams.set("negative_slope", layerParams.get("alpha", 0.01)); addLayer(layerParams, node_proto); } From ea7d4be3f81c6b7a2523e04f4c1f124b97497740 Mon Sep 17 00:00:00 2001 From: Andrew Ryrie Date: Mon, 29 Nov 2021 21:43:00 +0000 Subject: [PATCH 05/13] Merge pull request #20658 from smbz:lstm_optimisation * dnn: LSTM optimisation This uses the AVX-optimised fastGEMM1T for matrix multiplications where available, instead of the standard cv::gemm. fastGEMM1T is already used by the fully-connected layer. This commit involves two minor modifications: - Use unaligned access. I don't believe this involves any performance hit in on modern CPUs (Nehalem and Bulldozer onwards) in the case where the address is actually aligned. - Allow for weight matrices where the number of columns is not a multiple of 8. I have not enabled AVX-512 as I don't have an AVX-512 CPU to test on. * Fix warning about initialisation order * Remove C++11 syntax * Fix build when AVX(2) is not available In this case the CV_TRY_X macros are defined to 0, rather than being undefined. * Minor changes as requested: - Don't check hardware support for AVX(2) when dispatch is disabled for these - Add braces * Fix out-of-bounds access in fully connected layer The old tail handling in fastGEMM1T implicitly rounded vecsize up to the next multiple of 8, and the fully connected layer implements padding up to the next multiple of 8 to cope with this. The new tail handling does not round the vecsize upwards like this but it does require that the vecsize is at least 8. To adapt to the new tail handling, the fully connected layer now rounds vecsize itself at the same time as adding the padding(which makes more sense anyway). This also means that the fully connected layer always passes a vecsize of at least 8 to fastGEMM1T, which fixes the out-of-bounds access problems. * Improve tail mask handling - Use static array for generating tail masks (as requested) - Apply tail mask to the weights as well as the input vectors to prevent spurious propagation of NaNs/Infs * Revert whitespace change * Improve readability of conditions for using AVX * dnn(lstm): minor coding style changes, replaced left aligned load --- modules/dnn/perf/perf_recurrent.cpp | 90 +++++++++++++++ .../dnn/src/layers/fully_connected_layer.cpp | 6 +- modules/dnn/src/layers/layers_common.simd.hpp | 67 +++++++++--- modules/dnn/src/layers/recurrent_layers.cpp | 103 +++++++++++++++++- 4 files changed, 246 insertions(+), 20 deletions(-) create mode 100644 modules/dnn/perf/perf_recurrent.cpp diff --git a/modules/dnn/perf/perf_recurrent.cpp b/modules/dnn/perf/perf_recurrent.cpp new file mode 100644 index 0000000000..fe2a51886c --- /dev/null +++ b/modules/dnn/perf/perf_recurrent.cpp @@ -0,0 +1,90 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "perf_precomp.hpp" + +namespace opencv_test { + +struct LstmParams { + // Batch size + int nrSamples; + + // Size of the input vector + int inputSize; + + // Size of the internal state vector + int hiddenSize; + + // Number of timesteps for the LSTM + int nrSteps; +}; + +static inline void PrintTo(const LstmParams& params, ::std::ostream* os) { + (*os) << "BATCH=" << params.nrSamples + << ", IN=" << params.inputSize + << ", HIDDEN=" << params.hiddenSize + << ", TS=" << params.nrSteps; +} + +static const LstmParams testLstmConfigs[] = { + {1, 192, 192, 100}, + {1, 1024, 192, 100}, + {1, 64, 192, 100}, + {1, 192, 512, 100}, + {64, 192, 192, 2}, + {64, 1024, 192, 2}, + {64, 64, 192, 2}, + {64, 192, 512, 2}, + {128, 192, 192, 2}, + {128, 1024, 192, 2}, + {128, 64, 192, 2}, + {128, 192, 512, 2} +}; + +class Layer_LSTM : public TestBaseWithParam {}; + +PERF_TEST_P_(Layer_LSTM, lstm) { + const LstmParams& params = GetParam(); + LayerParams lp; + lp.type = "LSTM"; + lp.name = "testLstm"; + lp.set("produce_cell_output", false); + lp.set("use_timestamp_dim", true); + + Mat weightH(params.hiddenSize * 4, params.hiddenSize, CV_32FC1, cv::Scalar(0)); + Mat weightX(params.hiddenSize * 4, params.inputSize, CV_32FC1, cv::Scalar(0)); + Mat bias(params.hiddenSize * 4, 1, CV_32FC1, cv::Scalar(0)); + Mat hInternal(params.nrSteps, params.hiddenSize, CV_32FC1, cv::Scalar(0)); + Mat cInternal(params.nrSteps, params.hiddenSize, CV_32FC1, cv::Scalar(0)); + lp.blobs.push_back(weightH); + lp.blobs.push_back(weightX); + lp.blobs.push_back(bias); + lp.blobs.push_back(hInternal); + lp.blobs.push_back(cInternal); + + std::vector inputDims; + inputDims.push_back(params.nrSamples); + inputDims.push_back(params.nrSteps); + inputDims.push_back(params.inputSize); + Mat input(inputDims.size(), inputDims.data(), CV_32FC1); + input = cv::Scalar(0); + + Net net; + net.addLayerToPrev(lp.name, lp.type, lp); + net.setInput(input); + + // Warm up + std::vector outputs(2); + net.forward(outputs, "testLstm"); + + TEST_CYCLE() + { + net.forward(outputs, "testLstm"); + } + SANITY_CHECK_NOTHING(); +} + +INSTANTIATE_TEST_CASE_P(/**/, Layer_LSTM, testing::ValuesIn(testLstmConfigs)); + +} // namespace diff --git a/modules/dnn/src/layers/fully_connected_layer.cpp b/modules/dnn/src/layers/fully_connected_layer.cpp index e25ca5a68f..5acce939f1 100644 --- a/modules/dnn/src/layers/fully_connected_layer.cpp +++ b/modules/dnn/src/layers/fully_connected_layer.cpp @@ -222,17 +222,17 @@ public: #if CV_TRY_AVX512_SKX if( useAVX512 ) - opt_AVX512_SKX::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize); + opt_AVX512_SKX::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize_aligned); else #endif #if CV_TRY_AVX2 if( useAVX2 ) - opt_AVX2::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize); + opt_AVX2::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize_aligned); else #endif #if CV_TRY_AVX if( useAVX ) - opt_AVX::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize); + opt_AVX::fastGEMM1T( sptr, wptr, wstep, biasptr, dptr, nw, vecsize_aligned); else #endif { diff --git a/modules/dnn/src/layers/layers_common.simd.hpp b/modules/dnn/src/layers/layers_common.simd.hpp index 706695a7b2..accc644676 100644 --- a/modules/dnn/src/layers/layers_common.simd.hpp +++ b/modules/dnn/src/layers/layers_common.simd.hpp @@ -550,13 +550,24 @@ void fastDepthwiseConv( const float* wptr, _mm256_zeroupper(); } +// Used to generate the mask used when calculating tails +static const uint32_t tailMaskArray[15] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL, 0xffffffffUL +}; + // dst = vec * weights^t + bias +// Requires that vecsize is at least 8 or equal to 0 to avoid memory access problems. Does not require alignment. void fastGEMM1T( const float* vec, const float* weights, size_t wstep, const float* bias, float* dst, int nvecs, int vecsize ) { int i = 0; + CV_Assert(vecsize >= 8 || vecsize == 0); + + __m256 tailMask = _mm256_loadu_ps(reinterpret_cast(tailMaskArray) + (vecsize % 8)); + for( ; i <= nvecs - 8; i += 8 ) { const float* wptr = weights + i*wstep; @@ -565,18 +576,36 @@ void fastGEMM1T( const float* vec, const float* weights, vs4 = _mm256_setzero_ps(), vs5 = _mm256_setzero_ps(), vs6 = _mm256_setzero_ps(), vs7 = _mm256_setzero_ps(); - for( int k = 0; k < vecsize; k += 8, wptr += 8 ) + int k = 0; + for( ; k <= vecsize-8; k += 8, wptr += 8 ) { - __m256 v = _mm256_load_ps(vec + k); - - vs0 = _mm256_fmadd_ps(_mm256_load_ps(wptr), v, vs0); - vs1 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep), v, vs1); - vs2 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*2), v, vs2); - vs3 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*3), v, vs3); - vs4 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*4), v, vs4); - vs5 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*5), v, vs5); - vs6 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*6), v, vs6); - vs7 = _mm256_fmadd_ps(_mm256_load_ps(wptr + wstep*7), v, vs7); + __m256 v = _mm256_loadu_ps(vec + k); + + vs0 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr), v, vs0); + vs1 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep), v, vs1); + vs2 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*2), v, vs2); + vs3 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*3), v, vs3); + vs4 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*4), v, vs4); + vs5 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*5), v, vs5); + vs6 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*6), v, vs6); + vs7 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr + wstep*7), v, vs7); + } + + if (k != vecsize) { + // Tail + k = vecsize - 8; + wptr = weights + i * wstep + k; + __m256 v = _mm256_loadu_ps(vec + k); + v = _mm256_and_ps(v, tailMask); + + vs0 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr), tailMask), v, vs0); + vs1 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep), tailMask), v, vs1); + vs2 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 2), tailMask), v, vs2); + vs3 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 3), tailMask), v, vs3); + vs4 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 4), tailMask), v, vs4); + vs5 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 5), tailMask), v, vs5); + vs6 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 6), tailMask), v, vs6); + vs7 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr + wstep * 7), tailMask), v, vs7); } __m256 s0 = _mm256_hadd_ps(_mm256_hadd_ps(vs0, vs1), _mm256_hadd_ps(vs2, vs3)); @@ -598,10 +627,20 @@ void fastGEMM1T( const float* vec, const float* weights, const float* wptr = weights + i*wstep; __m256 vs0 = _mm256_setzero_ps(); - for( int k = 0; k < vecsize; k += 8, wptr += 8 ) + int k = 0; + for( ; k <= vecsize-8; k += 8, wptr += 8 ) { - __m256 v = _mm256_load_ps(vec + k); - vs0 = _mm256_fmadd_ps(_mm256_load_ps(wptr), v, vs0); + __m256 v = _mm256_loadu_ps(vec + k); + vs0 = _mm256_fmadd_ps(_mm256_loadu_ps(wptr), v, vs0); + } + + if (k != vecsize) { + // Tail + k = vecsize - 8; + wptr = weights + i * wstep + k; + __m256 v = _mm256_loadu_ps(vec + k); + v = _mm256_and_ps(v, tailMask); + vs0 = _mm256_fmadd_ps(_mm256_and_ps(_mm256_loadu_ps(wptr), tailMask), v, vs0); } __m256 s0 = _mm256_hadd_ps(_mm256_hadd_ps(vs0, vs0), vs0); diff --git a/modules/dnn/src/layers/recurrent_layers.cpp b/modules/dnn/src/layers/recurrent_layers.cpp index 9088c13390..21dafa142d 100644 --- a/modules/dnn/src/layers/recurrent_layers.cpp +++ b/modules/dnn/src/layers/recurrent_layers.cpp @@ -46,6 +46,8 @@ #include #include +#include "layers_common.hpp" + namespace cv { namespace dnn @@ -118,10 +120,23 @@ class LSTMLayerImpl CV_FINAL : public LSTMLayer ActivationFunction g_activation; ActivationFunction h_activation; +#if CV_TRY_AVX + bool useAVX; +#endif +#if CV_TRY_AVX2 + bool useAVX2; +#endif + public: LSTMLayerImpl(const LayerParams& params) : numTimeStamps(0), numSamples(0) +#if CV_TRY_AVX + , useAVX(checkHardwareSupport(CPU_AVX)) +#endif +#if CV_TRY_AVX2 + , useAVX2(checkHardwareSupport(CPU_AVX2)) +#endif { setParamsFrom(params); @@ -343,6 +358,15 @@ public: hOutTs = hOutTs.colRange(i * hOutTs.cols / numDirs, (i + 1) * hOutTs.cols / numDirs); Mat cOutTs = produceCellOutput ? output[1].reshape(1, numSamplesTotal) : Mat(); +#if CV_TRY_AVX2 || CV_TRY_AVX + bool canUseAvx = gates.isContinuous() && bias.isContinuous() + && Wx.depth() == CV_32F && gates.depth() == CV_32F + && bias.depth() == CV_32F && Wx.cols >= 8; + bool canUseAvx_hInternal = hInternal.isContinuous() && gates.isContinuous() && bias.isContinuous() + && Wh.depth() == CV_32F && hInternal.depth() == CV_32F && gates.depth() == CV_32F + && Wh.cols >= 8; +#endif + int tsStart, tsEnd, tsInc; if (reverse || i == 1) { tsStart = numTimeStamps - 1; @@ -359,9 +383,82 @@ public: Range curRowRange(ts*numSamples, (ts + 1)*numSamples); Mat xCurr = xTs.rowRange(curRowRange); - gemm(xCurr, Wx, 1, gates, 0, gates, GEMM_2_T); // Wx * x_t - gemm(hInternal, Wh, 1, gates, 1, gates, GEMM_2_T); //+Wh * h_{t-1} - gemm(dummyOnes, bias, 1, gates, 1, gates); //+b +#if CV_TRY_AVX2 + if (useAVX2 && canUseAvx && xCurr.isContinuous()) + { + for (int n = 0; n < xCurr.rows; n++) { + opt_AVX2::fastGEMM1T( + xCurr.ptr(n), + Wx.ptr(), + Wx.step1(), + bias.ptr(), + gates.ptr(n), + Wx.rows, + Wx.cols + ); + } + } + else +#endif +#if CV_TRY_AVX + if (useAVX && canUseAvx && xCurr.isContinuous()) + { + for (int n = 0; n < xCurr.rows; n++) { + opt_AVX::fastGEMM1T( + xCurr.ptr(n), + Wx.ptr(), + Wx.step1(), + bias.ptr(), + gates.ptr(n), + Wx.rows, + Wx.cols + ); + } + } + else +#endif + { + gemm(xCurr, Wx, 1, gates, 0, gates, GEMM_2_T); // Wx * x_t + gemm(dummyOnes, bias, 1, gates, 1, gates); //+b + } + +#if CV_TRY_AVX2 + if (useAVX2 && canUseAvx_hInternal) + { + for (int n = 0; n < hInternal.rows; n++) { + opt_AVX2::fastGEMM1T( + hInternal.ptr(n), + Wh.ptr(), + Wh.step1(), + gates.ptr(n), + gates.ptr(n), + Wh.rows, + Wh.cols + ); + } + } + else +#endif +#if CV_TRY_AVX + if (useAVX && canUseAvx_hInternal) + { + for (int n = 0; n < hInternal.rows; n++) { + opt_AVX::fastGEMM1T( + hInternal.ptr(n), + Wh.ptr(), + Wh.step1(), + gates.ptr(n), + gates.ptr(n), + Wh.rows, + Wh.cols + ); + } + } + else +#endif + { + gemm(hInternal, Wh, 1, gates, 1, gates, GEMM_2_T); //+Wh * h_{t-1} + } Mat gateI = gates.colRange(0*numOut, 1*numOut); Mat gateF = gates.colRange(1*numOut, 2*numOut); From 0e2a3686c0e5ee289f9de45b80ff06e16d8d9228 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Tue, 30 Nov 2021 12:20:35 +0300 Subject: [PATCH 06/13] add alpha parameter to ELU layer --- modules/dnn/include/opencv2/dnn/all_layers.hpp | 2 ++ modules/dnn/src/layers/elementwise_layers.cpp | 18 ++++++++++++++---- modules/dnn/src/opencl/activations.cl | 5 +++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/modules/dnn/include/opencv2/dnn/all_layers.hpp b/modules/dnn/include/opencv2/dnn/all_layers.hpp index e92ce2f565..991abba03a 100644 --- a/modules/dnn/include/opencv2/dnn/all_layers.hpp +++ b/modules/dnn/include/opencv2/dnn/all_layers.hpp @@ -453,6 +453,8 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN class CV_EXPORTS ELULayer : public ActivationLayer { public: + float alpha; + static Ptr create(const LayerParams ¶ms); }; diff --git a/modules/dnn/src/layers/elementwise_layers.cpp b/modules/dnn/src/layers/elementwise_layers.cpp index d8f0b654d3..21838fbe49 100644 --- a/modules/dnn/src/layers/elementwise_layers.cpp +++ b/modules/dnn/src/layers/elementwise_layers.cpp @@ -740,6 +740,9 @@ const char* const SigmoidFunctor::BaseDefaultFunctor::ocl_kernel struct ELUFunctor : public BaseDefaultFunctor { typedef ELULayer Layer; + float alpha; + + explicit ELUFunctor(float alpha_ = 1.f) : alpha(alpha_) {} bool supportBackend(int backendId, int) { @@ -749,14 +752,19 @@ struct ELUFunctor : public BaseDefaultFunctor inline float calculate(float x) const { - return x >= 0.f ? x : exp(x) - 1.f; + return x >= 0.f ? x : alpha * (exp(x) - 1.f); + } + + inline void setKernelParams(ocl::Kernel& kernel) const + { + kernel.set(3, alpha); } #ifdef HAVE_HALIDE void attachHalide(const Halide::Expr& input, Halide::Func& top) { Halide::Var x("x"), y("y"), c("c"), n("n"); - top(x, y, c, n) = select(input >= 0.0f, input, exp(input) - 1); + top(x, y, c, n) = select(input >= 0.0f, input, alpha * (exp(input) - 1)); } #endif // HAVE_HALIDE @@ -770,7 +778,7 @@ struct ELUFunctor : public BaseDefaultFunctor #ifdef HAVE_DNN_NGRAPH std::shared_ptr initNgraphAPI(const std::shared_ptr& node) { - return std::make_shared(node, 1.0); + return std::make_shared(node, alpha); } #endif // HAVE_DNN_NGRAPH @@ -1263,8 +1271,10 @@ Ptr SigmoidLayer::create(const LayerParams& params) Ptr ELULayer::create(const LayerParams& params) { - Ptr l(new ElementWiseLayer(ELUFunctor())); + float alpha = params.get("alpha", 1.0f); + Ptr l(new ElementWiseLayer(ELUFunctor(alpha))); l->setParamsFrom(params); + l->alpha = alpha; return l; } diff --git a/modules/dnn/src/opencl/activations.cl b/modules/dnn/src/opencl/activations.cl index 68f0dd7268..a75370d1bd 100644 --- a/modules/dnn/src/opencl/activations.cl +++ b/modules/dnn/src/opencl/activations.cl @@ -131,13 +131,14 @@ __kernel void PowForward(const int n, __global const T* in, __global T* out, out[index] = pow(shift + scale * in[index], power); } -__kernel void ELUForward(const int n, __global const T* in, __global T* out) +__kernel void ELUForward(const int n, __global const T* in, __global T* out, + const KERNEL_ARG_DTYPE alpha) { int index = get_global_id(0); if (index < n) { T src = in[index]; - out[index] = (src >= 0.f) ? src : exp(src) - 1; + out[index] = (src >= 0.f) ? src : alpha * (exp(src) - 1); } } From 829410729c8fe548a1786e5b3320194648aaa1e8 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Tue, 30 Nov 2021 15:20:52 +0300 Subject: [PATCH 07/13] add new (Log)SoftMax simplification passes --- .../dnn/src/onnx/onnx_graph_simplifier.cpp | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/modules/dnn/src/onnx/onnx_graph_simplifier.cpp b/modules/dnn/src/onnx/onnx_graph_simplifier.cpp index 76937e08f3..e4cf73fd07 100644 --- a/modules/dnn/src/onnx/onnx_graph_simplifier.cpp +++ b/modules/dnn/src/onnx/onnx_graph_simplifier.cpp @@ -107,17 +107,10 @@ private: opencv_onnx::GraphProto& net; }; -class SoftMaxSubgraph : public Subgraph +class SoftMaxSubgraphBase : public Subgraph { public: - SoftMaxSubgraph() : axis(1) - { - int input = addNodeToMatch(""); - int inpExp = addNodeToMatch("Exp", input); - int sum = addNodeToMatch("ReduceSum", inpExp); - addNodeToMatch("Div", inpExp, sum); - setFusedNode("Softmax", input); - } + SoftMaxSubgraphBase() : axis(1), id(-1) {} virtual bool match(const Ptr& net, int nodeId, std::vector& matchedNodesIds, @@ -125,7 +118,8 @@ public: { if (Subgraph::match(net, nodeId, matchedNodesIds, targetNodesIds)) { - Ptr sum = net->getNode(matchedNodesIds[1]); + CV_Assert(id >= 0 && id < matchedNodesIds.size()); + Ptr sum = net->getNode(matchedNodesIds[id]); opencv_onnx::NodeProto* node = sum.dynamicCast()->node; for (int i = 0; i < node->attribute_size(); i++) @@ -153,8 +147,60 @@ public: attr->set_i(axis); } -private: +protected: int axis; + int id; +}; + +class SoftMaxSubgraph : public SoftMaxSubgraphBase +{ +public: + SoftMaxSubgraph() + { + int input = addNodeToMatch(""); + int inpExp = addNodeToMatch("Exp", input); + + int sum = addNodeToMatch("ReduceSum", inpExp); + id = 1; + + addNodeToMatch("Div", inpExp, sum); + setFusedNode("Softmax", input); + } +}; + +class SoftMaxSubgraph2 : public SoftMaxSubgraphBase { +public: + SoftMaxSubgraph2() { + int input = addNodeToMatch(""); + + int reducemax = addNodeToMatch("ReduceMax", input); + id = 0; + + int sub = addNodeToMatch("Sub", input, reducemax); + int exp = addNodeToMatch("Exp", sub); + int reducesum = addNodeToMatch("ReduceSum", exp, addNodeToMatch("")); + addNodeToMatch("Div", exp, reducesum); + setFusedNode("Softmax", input); + } +}; + +class LogSoftMaxSubgraph : public SoftMaxSubgraphBase +{ +public: + LogSoftMaxSubgraph() + { + int input = addNodeToMatch(""); + + int reducemax = addNodeToMatch("ReduceMax", input); + id = 0; + + int sub_1 = addNodeToMatch("Sub", input, reducemax); + int exp = addNodeToMatch("Exp", sub_1); + int reducesum = addNodeToMatch("ReduceSum", exp, addNodeToMatch("")); + int log = addNodeToMatch("Log", reducesum); + addNodeToMatch("Sub", sub_1, log); + setFusedNode("LogSoftmax", input); + } }; class NormalizeSubgraphBase : public Subgraph @@ -574,6 +620,8 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) subgraphs.push_back(makePtr()); subgraphs.push_back(makePtr()); subgraphs.push_back(makePtr()); + subgraphs.push_back(makePtr()); + subgraphs.push_back(makePtr()); subgraphs.push_back(makePtr()); subgraphs.push_back(makePtr()); subgraphs.push_back(makePtr()); From 11e6848bb97d6b6c2b1dad90f283bafed29a9316 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Tue, 30 Nov 2021 15:34:34 +0300 Subject: [PATCH 08/13] add default order to transpose --- modules/dnn/src/onnx/onnx_importer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index d70a81b9ad..540dac3a90 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1644,6 +1644,16 @@ void ONNXImporter::parseTranspose(LayerParams& layerParams, const opencv_onnx::N { layerParams.type = "Permute"; replaceLayerParam(layerParams, "perm", "order"); + if (!layerParams.has("order")) { + MatShape inpShape = outShapes[node_proto.input(0)]; + size_t dims = inpShape.size(); + std::vector perm(dims); + for (size_t d = 0; d < dims; ++d) + { + perm[d] = static_cast(dims - 1 - d); + } + layerParams.set("order", DictValue::arrayInt(perm.data(), perm.size())); + } CV_Assert(node_proto.input_size() == 1); if (constBlobs.find(node_proto.input(0)) != constBlobs.end()) From 33e97e994db8e7e6e275dec6daf538f07f0e8d28 Mon Sep 17 00:00:00 2001 From: Smirnov Egor Date: Tue, 30 Nov 2021 15:42:20 +0300 Subject: [PATCH 09/13] add sum of 1 input --- modules/dnn/src/onnx/onnx_importer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index d70a81b9ad..7af095e360 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -929,6 +929,14 @@ void ONNXImporter::parseBias(LayerParams& layerParams, const opencv_onnx::NodePr opencv_onnx::NodeProto node_proto = node_proto_; const std::string& layer_type = node_proto.op_type(); bool isSub = layer_type == "Sub"; + + if (layer_type == "Sum" && node_proto.input_size() == 1) + { + layerParams.type = "Identity"; + addLayer(layerParams, node_proto); + return; + } + CV_Assert((node_proto.input_size() == 2) || (layer_type == "Sum" && node_proto.input_size() > 2)); if (layer_type == "Sum" && node_proto.input_size() > 2) From 1a1a7bbbfd5b0a5cd0bd544eafae8729c9874203 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Wed, 1 Dec 2021 13:46:03 +0100 Subject: [PATCH 10/13] Merge pull request #21112 from vrabaud:3.4_luv_overflow * Fix integer overflow in cv::Luv2RGBinteger::process. For LL=49, uu=205, vv=23, we end up with x=7373056 and y=458 which overflows y*x. * imgproc(test): adjust test parameters to cover SIMD code --- modules/imgproc/src/color_lab.cpp | 8 ++------ modules/imgproc/test/test_color.cpp | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/imgproc/src/color_lab.cpp b/modules/imgproc/src/color_lab.cpp index a181880862..6b03be6195 100644 --- a/modules/imgproc/src/color_lab.cpp +++ b/modules/imgproc/src/color_lab.cpp @@ -3567,7 +3567,7 @@ struct Luv2RGBinteger long long int xv = ((int)up)*(long long)vp; int x = (int)(xv/BASE); - x = y*x/BASE; + x = ((long long int)y)*x/BASE; long long int vpl = LUVLUT.LvToVpl_b[LL*256+vv]; long long int zp = vpl - xv*(255/3); @@ -3689,6 +3689,7 @@ struct Luv2RGBinteger vzm[i] = zm; vx[i] = (int32_t)(xv >> base_shift); + vx[i] = (((int64_t)y_)*vx[i]) >> base_shift; } v_int32 zm[4]; for(int k = 0; k < 4; k++) @@ -3697,11 +3698,6 @@ struct Luv2RGBinteger zm[k] = vx_load_aligned(vzm + k*vsize/4); } - for(int k = 0; k < 4; k++) - { - x[k] = (y[k]*x[k]) >> base_shift; - } - // z = zm/256 + zm/65536; for (int k = 0; k < 4; k++) { diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index 3cd57c9d38..f828dac18a 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -1840,6 +1840,21 @@ TEST(Imgproc_ColorLuv, accuracy) { CV_ColorLuvTest test; test.safe_run(); } TEST(Imgproc_ColorRGB, accuracy) { CV_ColorRGBTest test; test.safe_run(); } TEST(Imgproc_ColorBayer, accuracy) { CV_ColorBayerTest test; test.safe_run(); } +TEST(Imgproc_ColorLuv, Overflow_21112) +{ + const Size sz(107, 16); // unaligned size to run both SIMD and generic code + Mat luv_init(sz, CV_8UC3, Scalar(49, 205, 23)); + Mat rgb; + cvtColor(luv_init, rgb, COLOR_Luv2RGB); + // Convert to normal Luv coordinates for floats. + Mat luv_initf(sz, CV_32FC3, Scalar(49.0f/255.f*100, 205.0f*354/255.f - 134, 23.0f*262/255.f - 140)); + Mat rgbf; + cvtColor(luv_initf, rgbf, COLOR_Luv2RGB); + Mat rgb_converted; + rgb.convertTo(rgb_converted, CV_32F); + EXPECT_LE(cvtest::norm(255.f*rgbf, rgb_converted, NORM_INF), 1e-5); +} + TEST(Imgproc_ColorBayer, regression) { cvtest::TS* ts = cvtest::TS::ptr(); @@ -2569,7 +2584,7 @@ int row8uLuv2RGB(const uchar* src_row, uchar *dst_row, int n, int cn, int blue_i long long int xv = ((int)up)*(long long)vp; int x = (int)(xv/BASE); - x = y*x/BASE; + x = ((long long int)y)*x/BASE; long long int vpl = LvToVpl_b[LL*256+vv]; long long int zp = vpl - xv*(255/3); @@ -2725,11 +2740,11 @@ TEST(Imgproc_ColorLuv_Full, bitExactness) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0xec311a14, 0x995efefc, 0xf71b590b, 0xc1edfce7, 0x67b2b2e2, 0xe6d7f90d, 0xbcbaff5c, 0xd86ae19c, - 0x3e8e4647, 0x53f1a5e3, 0x60dfb6ca, 0xcda851fe, 0xd91084b3, 0xe361bf6f, 0x90fe66ed, 0xb19c5b89, + 0x4bff0e00, 0x76bbff01, 0x80735725, 0xb5e0f137, 0x96abb417, 0xfb2cf5cf, 0x314cf55e, 0x77bde10e, + 0x2ab24209, 0x81caa6F0, 0x3019b8eb, 0x427c505f, 0x5bba7d77, 0xf29cb4d6, 0x760f65ca, 0xf6b4536c, - 0x190508ec, 0xc7764e22, 0x19b042a8, 0x2db4c5d8, 0x6e1cfd1d, 0x39bddd51, 0x942714ed, 0x19444d39, - 0xed16e206, 0xc4102784, 0x590075fe, 0xaaef2ec6, 0xbeb84149, 0x8da31e4f, 0x7cbe7d77, 0x1c90b30a, + 0xb5cd0704, 0x82144fd4, 0x4e6f4843, 0x106bc505, 0xf587fc97, 0x3665d9a3, 0x3ea014a8, 0xec664953, + 0x6ec9e59e, 0xf9201e08, 0xf3676fb8, 0xe4e42c10, 0x92d33f64, 0x13b923f7, 0x308f7f50, 0xca98b420, }; RNG rng(0); From bd396e1fd5eb2b31fb55daf3b022ecbcf6f9510f Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 30 Nov 2021 12:08:35 +0000 Subject: [PATCH 11/13] dnn(test): re-enable tests which works with OpenVINO 2021.4.x (3.4) --- modules/dnn/test/test_backends.cpp | 2 +- modules/dnn/test/test_caffe_importer.cpp | 30 +++- modules/dnn/test/test_darknet_importer.cpp | 70 ++++++-- modules/dnn/test/test_halide_layers.cpp | 26 ++- modules/dnn/test/test_layers.cpp | 12 ++ modules/dnn/test/test_misc.cpp | 3 +- modules/dnn/test/test_onnx_importer.cpp | 176 +++++++++++++++++---- modules/dnn/test/test_tf_importer.cpp | 97 ++++++++++-- modules/dnn/test/test_torch_importer.cpp | 11 +- 9 files changed, 356 insertions(+), 71 deletions(-) diff --git a/modules/dnn/test/test_backends.cpp b/modules/dnn/test/test_backends.cpp index 19e0729abb..d1df4c35aa 100644 --- a/modules/dnn/test/test_backends.cpp +++ b/modules/dnn/test/test_backends.cpp @@ -248,7 +248,7 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_v1_TensorFlow_Different_Width_Height) { if (backend == DNN_BACKEND_HALIDE) applyTestTag(CV_TEST_TAG_DNN_SKIP_HALIDE); -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X); diff --git a/modules/dnn/test/test_caffe_importer.cpp b/modules/dnn/test/test_caffe_importer.cpp index 18b8d5ad82..7249fb4e9f 100644 --- a/modules/dnn/test/test_caffe_importer.cpp +++ b/modules/dnn/test/test_caffe_importer.cpp @@ -112,10 +112,12 @@ TEST(Test_Caffe, read_googlenet) TEST_P(Test_Caffe_nets, Axpy) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif String proto = _tf("axpy.prototxt"); Net net = readNetFromCaffe(proto); @@ -150,8 +152,17 @@ TEST_P(Test_Caffe_nets, Axpy) } } } - float l1 = (target == DNN_TARGET_OPENCL_FP16) ? 2e-4 : 1e-5; - float lInf = (target == DNN_TARGET_OPENCL_FP16) ? 1e-3 : 1e-4; + float l1 = 1e-5, lInf = 1e-4; + if (target == DNN_TARGET_OPENCL_FP16) + { + l1 = 2e-4; + lInf = 1e-3; + } + if (target == DNN_TARGET_MYRIAD) + { + l1 = 0.001; + lInf = 0.001; + } normAssert(ref, out, "", l1, lInf); } @@ -657,7 +668,7 @@ TEST_P(Test_Caffe_nets, FasterRCNN_vgg16) CV_TEST_TAG_DEBUG_VERYLONG ); -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16); @@ -668,6 +679,19 @@ TEST_P(Test_Caffe_nets, FasterRCNN_vgg16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD); #endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + // IE exception: Ngraph operation Reshape with name rpn_cls_score_reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); + // Check 'backward_compatible_check || in_out_elements_equal' failed at core/src/op/reshape.cpp:390: + // While validating node 'v1::Reshape bbox_pred_reshape (bbox_pred[0]:f32{1,84}, Constant_241202[0]:i64{4}) -> (f32{?,?,?,?})' with friendly_name 'bbox_pred_reshape': + // Requested output shape {1,6300,4,1} is incompatible with input shape Shape{1, 84} + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif + static Mat ref = (Mat_(3, 7) << 0, 2, 0.949398, 99.2454, 210.141, 601.205, 462.849, 0, 7, 0.997022, 481.841, 92.3218, 722.685, 175.953, 0, 12, 0.993028, 133.221, 189.377, 350.994, 563.166); diff --git a/modules/dnn/test/test_darknet_importer.cpp b/modules/dnn/test/test_darknet_importer.cpp index 885bd6eb6b..f069ad190d 100644 --- a/modules/dnn/test/test_darknet_importer.cpp +++ b/modules/dnn/test/test_darknet_importer.cpp @@ -121,7 +121,7 @@ public: { SCOPED_TRACE("batch size 2"); -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (target == DNN_TARGET_MYRIAD && name == "shortcut") applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD); #endif @@ -429,21 +429,30 @@ TEST_P(Test_Darknet_nets_async, Accuracy) { Backend backendId = get<0>(get<1>(GetParam())); Target targetId = get<1>(get<1>(GetParam())); + std::string prefix = get<0>(GetParam()); + applyTestTag(CV_TEST_TAG_MEMORY_512MB); + +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (INF_ENGINE_VER_MAJOR_LT(2019020000) && backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); - applyTestTag(CV_TEST_TAG_MEMORY_512MB); if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif - std::string prefix = get<0>(GetParam()); + if (backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + throw SkipTestException("No support for async forward"); +#if defined(INF_ENGINE_RELEASE) +#if INF_ENGINE_VER_MAJOR_GE(2021040000) + if (targetId == DNN_TARGET_MYRIAD && prefix == "yolov3") // NC_OUT_OF_MEMORY + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#else if (targetId == DNN_TARGET_MYRIAD && prefix == "yolov4") // NC_OUT_OF_MEMORY applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_VERSION); - - if (backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) - throw SkipTestException("No support for async forward"); +#endif +#endif const int numInputs = 2; std::vector inputs(numInputs); @@ -472,6 +481,34 @@ TEST_P(Test_Darknet_nets_async, Accuracy) netAsync.setPreferableBackend(backendId); netAsync.setPreferableTarget(targetId); + double l1 = 0.0; + double lInf = 0.0; +#if defined(INF_ENGINE_RELEASE) + if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + if (targetId == DNN_TARGET_MYRIAD && prefix == "yolo-voc") + { + l1 = 0.02; + lInf = 0.15; + } + if (targetId == DNN_TARGET_OPENCL_FP16 && prefix == "yolo-voc") + { + l1 = 0.02; + lInf = 0.1; + } + if (targetId == DNN_TARGET_OPENCL_FP16 && prefix == "yolov3") + { + l1 = 0.001; + lInf = 0.007; + } + if (targetId == DNN_TARGET_OPENCL_FP16 && prefix == "yolov4") + { + l1 = 0.001; + lInf = 0.005; + } + } +#endif + // Run asynchronously. To make test more robust, process inputs in the reversed order. for (int i = numInputs - 1; i >= 0; --i) { @@ -481,7 +518,7 @@ TEST_P(Test_Darknet_nets_async, Accuracy) ASSERT_TRUE(out.valid()); Mat result; EXPECT_TRUE(out.get(result, async_timeout)); - normAssert(refs[i], result, format("Index: %d", i).c_str(), 0, 0); + normAssert(refs[i], result, format("Index: %d", i).c_str(), l1, lInf); } } @@ -836,10 +873,23 @@ TEST_P(Test_Darknet_layers, avgpool_softmax) TEST_P(Test_Darknet_layers, region) { -#if defined(INF_ENGINE_RELEASE) - if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && INF_ENGINE_VER_MAJOR_GE(2020020000)) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && INF_ENGINE_VER_MAJOR_GE(2020020000)) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif + +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + // accuracy on CPU, OpenCL + // Expected: (normInf) <= (lInf), actual: 0.763223 vs 0.0001 + // |ref| = 1.207319974899292 + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); #endif + testDarknetLayer("region"); } diff --git a/modules/dnn/test/test_halide_layers.cpp b/modules/dnn/test/test_halide_layers.cpp index b24968b8e8..405587eec7 100644 --- a/modules/dnn/test/test_halide_layers.cpp +++ b/modules/dnn/test/test_halide_layers.cpp @@ -240,9 +240,11 @@ TEST_P(LRN, Accuracy) Backend backendId = get<0>(get<5>(GetParam())); Target targetId = get<1>(get<5>(GetParam())); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if ((inSize.width == 5 || inSize.height == 5) && targetId == DNN_TARGET_MYRIAD && nrmType == "ACROSS_CHANNELS") applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD); +#endif LayerParams lp; lp.set("norm_region", nrmType); @@ -407,12 +409,14 @@ TEST_P(FullyConnected, Accuracy) bool hasBias = get<3>(GetParam()); Backend backendId = get<0>(get<4>(GetParam())); Target targetId = get<1>(get<4>(GetParam())); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if ((backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && (targetId == DNN_TARGET_OPENCL_FP16 || (targetId == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X))) { applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16); applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X); } +#endif Mat weights(outChannels, inChannels * inSize.height * inSize.width, CV_32F); randu(weights, -1.0f, 1.0f); @@ -430,7 +434,21 @@ TEST_P(FullyConnected, Accuracy) int sz[] = {1, inChannels, inSize.height, inSize.width}; Mat input(4, &sz[0], CV_32F); - test(lp, input, backendId, targetId); + + double l1 = 0.0; + double lInf = 0.0; +#if defined(INF_ENGINE_RELEASE) + if (targetId == DNN_TARGET_MYRIAD) + { + l1 = 0.015; + lInf = 0.025; + } + else if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && targetId == DNN_TARGET_OPENCL_FP16) + { + l1 = 0.01; + } +#endif + test(lp, input, backendId, targetId, false, l1, lInf); } INSTANTIATE_TEST_CASE_P(Layer_Test_Halide, FullyConnected, Combine( @@ -812,18 +830,18 @@ TEST_P(Eltwise, Accuracy) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION); #endif -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && numConv > 1) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION); #endif -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && targetId == DNN_TARGET_OPENCL && op == "sum" && numConv == 1 && !weighted) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); #endif -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && numConv > 1) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); #endif diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index e61fd733f9..2d4f78c88c 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -194,13 +194,23 @@ TEST_P(Test_Caffe_layers, DeConvolution) TEST_P(Test_Caffe_layers, InnerProduct) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + // IE exception: Ngraph operation Reshape with name Reshape_4219609 has dynamic output shape on 0 port, but CPU plug-in supports only static shape + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); +#endif if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); + testLayerUsingCaffeModels("layer_inner_product", true); } @@ -295,10 +305,12 @@ TEST_P(Test_Caffe_layers, Concat) CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION); #endif +#if INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16)) applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif #endif testLayerUsingCaffeModels("layer_concat"); diff --git a/modules/dnn/test/test_misc.cpp b/modules/dnn/test/test_misc.cpp index 9971450478..0de503ac7d 100644 --- a/modules/dnn/test/test_misc.cpp +++ b/modules/dnn/test/test_misc.cpp @@ -578,7 +578,8 @@ TEST_P(Async, create_layer_pipeline_set_and_forward_all) if (backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) throw SkipTestException("No support for async forward"); - if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + // Exception: Default implementation fallbacks in asynchronous mode + if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && dtype == CV_8U) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) diff --git a/modules/dnn/test/test_onnx_importer.cpp b/modules/dnn/test/test_onnx_importer.cpp index 0fd5d08258..a432f2251e 100644 --- a/modules/dnn/test/test_onnx_importer.cpp +++ b/modules/dnn/test/test_onnx_importer.cpp @@ -185,17 +185,11 @@ TEST_P(Test_ONNX_layers, Gather) TEST_P(Test_ONNX_layers, Convolution3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif testONNXModels("conv3d"); } TEST_P(Test_ONNX_layers, Convolution3D_bias) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif testONNXModels("conv3d_bias"); } @@ -222,14 +216,73 @@ TEST_P(Test_ONNX_layers, Deconvolution) TEST_P(Test_ONNX_layers, Deconvolution3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2": + // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively) + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } #endif - if (backend == DNN_BACKEND_OPENCV || target != DNN_TARGET_CPU) - throw SkipTestException("Only DLIE backend on CPU is supported"); + + if (backend == DNN_BACKEND_OPENCV) + throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags + testONNXModels("deconv3d"); +} + +TEST_P(Test_ONNX_layers, Deconvolution3D_bias) +{ +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2": + // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively) + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif + + if (backend == DNN_BACKEND_OPENCV) + throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags + testONNXModels("deconv3d_bias"); +} + +TEST_P(Test_ONNX_layers, Deconvolution3D_pad) +{ +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2": + // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively) + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif + + if (backend == DNN_BACKEND_OPENCV) + throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags + testONNXModels("deconv3d_pad"); +} + +TEST_P(Test_ONNX_layers, Deconvolution3D_adjpad) +{ +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // [ GENERAL_ERROR ] vpu/graph_transformer/src/frontend/frontend.cpp:439 Failed to compile layer "2": + // [ GENERAL_ERROR ] vpu/graph_transformer/src/model/model.cpp:198 duplicateData error: while duplicating 2@weights Const data got different desc and content byte sizes (162 and 486 respectively) + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif + + if (backend == DNN_BACKEND_OPENCV) + throw SkipTestException("OpenCV backend is not supported"); // FIXIT use tags + testONNXModels("deconv3d_adjpad"); } @@ -295,12 +348,15 @@ TEST_P(Test_ONNX_layers, Scale) TEST_P(Test_ONNX_layers, ReduceMean3D) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + testONNXModels("reduce_mean3d"); } @@ -340,13 +396,12 @@ TEST_P(Test_ONNX_layers, Concatenation) TEST_P(Test_ONNX_layers, Eltwise3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported +#endif testONNXModels("eltwise3d"); } @@ -357,43 +412,56 @@ TEST_P(Test_ONNX_layers, AveragePooling) TEST_P(Test_ONNX_layers, MaxPooling3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // accuracy + if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); + // IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired() + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } #endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + testONNXModels("max_pool3d", npy, 0, 0, false, false); } TEST_P(Test_ONNX_layers, AvePooling3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + testONNXModels("ave_pool3d"); } TEST_P(Test_ONNX_layers, PoolConv3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + testONNXModels("pool_conv_3d"); } @@ -875,6 +943,7 @@ TEST_P(Test_ONNX_layers, DynamicAxes) TEST_P(Test_ONNX_layers, MaxPool1d) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); @@ -883,11 +952,20 @@ TEST_P(Test_ONNX_layers, MaxPool1d) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); } +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) + { + // 2021.4: [ GENERAL_ERROR ] AssertionFailed: !expired() + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); + } +#endif testONNXModels("maxpooling_1d"); } TEST_P(Test_ONNX_layers, MaxPoolSigmoid1d) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); @@ -896,11 +974,13 @@ TEST_P(Test_ONNX_layers, MaxPoolSigmoid1d) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); } +#endif testONNXModels("maxpooling_sigmoid_1d"); } TEST_P(Test_ONNX_layers, MaxPool1d_Twise) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); @@ -909,11 +989,13 @@ TEST_P(Test_ONNX_layers, MaxPool1d_Twise) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); } +#endif testONNXModels("two_maxpooling_1d"); } TEST_P(Test_ONNX_layers, AvePool1d) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); @@ -922,11 +1004,13 @@ TEST_P(Test_ONNX_layers, AvePool1d) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); } +#endif testONNXModels("average_pooling_1d"); } TEST_P(Test_ONNX_layers, PoolConv1d) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); @@ -935,6 +1019,7 @@ TEST_P(Test_ONNX_layers, PoolConv1d) { if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); } +#endif testONNXModels("pool_conv_1d"); } @@ -1014,11 +1099,18 @@ TEST_P(Test_ONNX_nets, Squeezenet) TEST_P(Test_ONNX_nets, Googlenet) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + // accuracy + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif const String model = _tf("models/googlenet.onnx", false); @@ -1264,7 +1356,7 @@ TEST_P(Test_ONNX_nets, DenseNet121) TEST_P(Test_ONNX_nets, Inception_v1) { -#if defined(INF_ENGINE_RELEASE) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 || backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD); @@ -1274,26 +1366,35 @@ TEST_P(Test_ONNX_nets, Inception_v1) TEST_P(Test_ONNX_nets, Shufflenet) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) { if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (target == DNN_TARGET_OPENCL) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); } +#endif testONNXModels("shufflenet", pb); } TEST_P(Test_ONNX_nets, Resnet34_kinetics) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // IE exception: Function contains several inputs and outputs with one friendly name! + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags String onnxmodel = findDataFile("dnn/resnet-34_kinetics.onnx", false); Mat image0 = imread(findDataFile("dnn/dog416.png")); @@ -1334,6 +1435,11 @@ TEST_P(Test_ONNX_nets, Resnet34_kinetics) // output range [-5, 11] float l1 = 0.0013; float lInf = 0.009; + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_OPENCL_FP16) + { + l1 = 0.02; + lInf = 0.07; + } checkBackend(&input0, &ref0); net.setInput(input0); diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index d02b7136d6..073a2f3395 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -215,13 +215,12 @@ TEST_P(Test_TensorFlow_layers, conv_pool_nchw) TEST_P(Test_TensorFlow_layers, Convolution3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported +#endif runTensorFlowNet("conv3d"); } @@ -230,7 +229,7 @@ TEST_P(Test_TensorFlow_layers, padding) runTensorFlowNet("padding_valid"); runTensorFlowNet("spatial_padding"); runTensorFlowNet("mirror_pad"); -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019020000) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019020000) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (target == DNN_TARGET_MYRIAD) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) @@ -343,6 +342,7 @@ TEST_P(Test_TensorFlow_layers, concat_axis_1) TEST_P(Test_TensorFlow_layers, concat_3d) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) { if (target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16); @@ -352,6 +352,7 @@ TEST_P(Test_TensorFlow_layers, concat_3d) if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH || backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); +#endif runTensorFlowNet("concat_3d"); } @@ -429,13 +430,27 @@ TEST_P(Test_TensorFlow_layers, batch_norm3D) TEST_P(Test_TensorFlow_layers, slim_batch_norm) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif // Output values range: [-40.0597, 207.827] - double l1 = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.041 : default_l1; - double lInf = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 0.33 : default_lInf; + double l1 = default_l1; + double lInf = default_lInf; + if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) + { + l1 = 0.041; + lInf = 0.33; + } +#if defined(INF_ENGINE_RELEASE) + else if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_CPU) + { + lInf = 0.0002; + } +#endif + runTensorFlowNet("slim_batch_norm", false, l1, lInf); } @@ -562,7 +577,7 @@ TEST_P(Test_TensorFlow_layers, max_pool_grad) TEST_P(Test_TensorFlow_layers, ave_pool_same) { // Reference output values are in range [-0.519531, 0.112976] -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (target == DNN_TARGET_MYRIAD && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X) { if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) @@ -576,29 +591,42 @@ TEST_P(Test_TensorFlow_layers, ave_pool_same) TEST_P(Test_TensorFlow_layers, MaxPooling3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // accuracy + if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); + // IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired() + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } #endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + runTensorFlowNet("max_pool3d"); } TEST_P(Test_TensorFlow_layers, AvePooling3D) { -#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2019010000) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_VERSION); -#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); // Only CPU on DLIE backend is supported if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target != DNN_TARGET_CPU) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); // Only CPU on DLIE backend is supported - if (target != DNN_TARGET_CPU) - throw SkipTestException("Only CPU is supported"); +#endif + if (backend == DNN_BACKEND_OPENCV && target != DNN_TARGET_CPU) + throw SkipTestException("Only CPU is supported"); // FIXIT use tags + runTensorFlowNet("ave_pool3d"); } @@ -628,10 +656,12 @@ TEST_P(Test_TensorFlow_layers, matmul) TEST_P(Test_TensorFlow_layers, reshape) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif runTensorFlowNet("shift_reshape_no_reorder"); runTensorFlowNet("reshape_no_reorder"); runTensorFlowNet("reshape_reduce"); @@ -1188,18 +1218,35 @@ TEST_P(Test_TensorFlow_layers, quantized) TEST_P(Test_TensorFlow_layers, lstm) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // Exception: Ngraph operation Reshape with name Reshape has dynamic output shape on 0 port, but CPU plug-in supports only static shape + if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); + // Xlink + if (target == DNN_TARGET_MYRIAD) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif if (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16) applyTestTag(CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); + runTensorFlowNet("lstm", true); runTensorFlowNet("lstm", true, 0.0, 0.0, true); } TEST_P(Test_TensorFlow_layers, split) { + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) @@ -1229,8 +1276,10 @@ TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_align_corners) TEST_P(Test_TensorFlow_layers, resize_nearest_neighbor_half_pixel) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif runTensorFlowNet("resize_nearest_neighbor", false, 0.0, 0.0, false, "_half_pixel"); } @@ -1369,10 +1418,26 @@ TEST_P(Test_TensorFlow_layers, clip_by_value) TEST_P(Test_TensorFlow_layers, tf2_prelu) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000) + if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) + { + // IE exception: Input prelu:StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add hasn't been found in primitiveIDs map + if (target == DNN_TARGET_OPENCL || target == DNN_TARGET_OPENCL_FP16) + applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16, + CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION + ); + // IE exception: Eltwise node with name `StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add` has invalid input/output dims configuration + if (target == DNN_TARGET_CPU) + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_CPU, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); + } +#endif + runTensorFlowNet("tf2_prelu"); } diff --git a/modules/dnn/test/test_torch_importer.cpp b/modules/dnn/test/test_torch_importer.cpp index 96e8ac85a8..fdd5a4b923 100644 --- a/modules/dnn/test/test_torch_importer.cpp +++ b/modules/dnn/test/test_torch_importer.cpp @@ -211,23 +211,32 @@ TEST_P(Test_Torch_layers, net_lp_pooling_square) } TEST_P(Test_Torch_layers, net_lp_pooling_power) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) - applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); + applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH, CV_TEST_TAG_DNN_SKIP_IE_VERSION); +#endif runTorchNet("net_lp_pooling_power", "", false, true); } TEST_P(Test_Torch_layers, net_conv_gemm_lrn) { +#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000) if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER); if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && target == DNN_TARGET_MYRIAD) applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NGRAPH); +#endif double l1 = 0.0, lInf = 0.0; if (target == DNN_TARGET_OPENCL_FP16) { l1 = 0.046; lInf = 0.023; } + else if (target == DNN_TARGET_MYRIAD) + { + l1 = 0.02; + lInf = 0.05; + } // The OpenCL kernels use the native_ math functions which have // implementation defined accuracy, so we use relaxed thresholds. See // https://github.com/opencv/opencv/issues/9821 for more details. From 37b1876807430148aba9208fceaeb3a1cb2c356a Mon Sep 17 00:00:00 2001 From: APrigarina Date: Thu, 2 Dec 2021 15:04:04 +0300 Subject: [PATCH 12/13] qr encoder: fix memory and unused variables issues --- modules/objdetect/src/qrcode_encoder.cpp | 47 ++++++++++-------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/modules/objdetect/src/qrcode_encoder.cpp b/modules/objdetect/src/qrcode_encoder.cpp index 8329c1c890..ae15c64f42 100644 --- a/modules/objdetect/src/qrcode_encoder.cpp +++ b/modules/objdetect/src/qrcode_encoder.cpp @@ -308,18 +308,7 @@ int QRCodeEncoderImpl::versionAuto(const std::string& input_str) for(size_t i = 0; i < possible_version.size(); i++) { int version_range_index = possible_version[i]; - if (version_range_index == 1) - { - tmp_version = 1; - } - else if (version_range_index == 2) - { - tmp_version = 10; - } - else - { - tmp_version = 27; - } + encodeAuto(input_str, payload_tmp); tmp_version = findVersionCapacity((int)payload_tmp.size(), ecc_level, version_range[version_range_index], version_range[version_range_index + 1]); @@ -351,10 +340,11 @@ void QRCodeEncoderImpl::generateQR(const std::string &input) int segment_begin = i * segment_len; int segemnt_end = min((i + 1) * segment_len, (int) input.length()) - 1; std::string input_info = input.substr(segment_begin, segemnt_end - segment_begin + 1); - int v = versionAuto(input_info); + int detected_version = versionAuto(input_info); + CV_Assert(detected_version != -1); if (version_level == 0) - version_level = v; - else if (version_level < v) + version_level = detected_version; + else if (version_level < detected_version) CV_Error(Error::StsBadArg, "The given version is not suitable for the given input string length "); payload.clear(); @@ -752,12 +742,14 @@ void QRCodeEncoderImpl::eccGenerate(vector > &data_blocks, vecto void QRCodeEncoderImpl::rearrangeBlocks(const vector > &data_blocks, const vector > &ecc_blocks) { rearranged_data.clear(); - rearranged_data.reserve(MAX_PAYLOAD_LEN); int blocks = cur_ecc_params->num_blocks_in_G2 + cur_ecc_params->num_blocks_in_G1; int col_border = max(cur_ecc_params->data_codewords_in_G2, cur_ecc_params->data_codewords_in_G1); int total_codeword_num = version_info->total_codewords; int is_not_equal = cur_ecc_params->data_codewords_in_G2 - cur_ecc_params->data_codewords_in_G1; - for (int i = 0; i < total_codeword_num; i++) + int add_steps = cur_ecc_params->data_codewords_in_G2 > cur_ecc_params->data_codewords_in_G1 ? + (cur_ecc_params->data_codewords_in_G2 - cur_ecc_params->data_codewords_in_G1) * cur_ecc_params->num_blocks_in_G1 : 0; + rearranged_data.reserve(total_codeword_num + add_steps); + for (int i = 0; i < total_codeword_num + add_steps; i++) { int cur_col = i / blocks; int cur_row = i % blocks; @@ -783,16 +775,6 @@ void QRCodeEncoderImpl::rearrangeBlocks(const vector > &data_blo } rearranged_data.push_back(tmp); } - const int remainder_len []= {0, - 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, - 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, - 3, 3, 3, 3, 0, 0, 0, 0, 0, 0}; - int cur_remainder_len = remainder_len[version_level]; - if (cur_remainder_len != 0) - { - rearranged_data.push_back(0); - } } void QRCodeEncoderImpl::findAutoMaskType() @@ -1078,6 +1060,8 @@ void QRCodeEncoderImpl::writeData() int dir = -1; int count = 0; int codeword_value = rearranged_data[0]; + const int limit_bits = (int)rearranged_data.size() * 8; + bool limit_reached = false; while (x > 0) { if (x == 6) @@ -1093,11 +1077,20 @@ void QRCodeEncoderImpl::writeData() continue; } count++; + if (count == limit_bits) + { + limit_reached = true; + break; + } if (count % 8 == 0) { codeword_value = rearranged_data[count / 8]; } } + if (limit_reached) + { + break; + } y += dir; if (y < 0 || y >= version_size) { From 1613d30544742b646e015660df76325740fcb9c2 Mon Sep 17 00:00:00 2001 From: rogday Date: Thu, 2 Dec 2021 20:11:11 +0300 Subject: [PATCH 13/13] Merge pull request #21159 from rogday:ceil_mode fix ceil_mode for Average/MaxPooling * fix ceil_mode * add a comment --- modules/dnn/src/onnx/onnx_importer.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 9f7895c7dd..f776bdc5da 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -612,11 +612,24 @@ void ONNXImporter::handleNode(const opencv_onnx::NodeProto& node_proto) } } +void setCeilMode(LayerParams& layerParams) +{ + // auto_pad attribute is deprecated and uses ceil + if (layerParams.has("pad_mode")) + { + layerParams.set("ceil_mode", true); + } + else if (!layerParams.has("ceil_mode")) + { + layerParams.set("ceil_mode", false); + } +} + void ONNXImporter::parseMaxPool(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto) { layerParams.type = "Pooling"; layerParams.set("pool", "MAX"); - layerParams.set("ceil_mode", layerParams.has("pad_mode")); + setCeilMode(layerParams); addLayer(layerParams, node_proto); } @@ -624,7 +637,7 @@ void ONNXImporter::parseAveragePool(LayerParams& layerParams, const opencv_onnx: { layerParams.type = "Pooling"; layerParams.set("pool", "AVE"); - layerParams.set("ceil_mode", layerParams.has("pad_mode")); + setCeilMode(layerParams); layerParams.set("ave_pool_padded_area", framework_name == "pytorch"); addLayer(layerParams, node_proto); }