2017-06-26 18:35:51 +08:00
// 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.
2019-03-29 21:42:58 +08:00
// Copyright (C) 2017-2019, Intel Corporation, all rights reserved.
2017-06-26 18:35:51 +08:00
// Third party copyrights are property of their respective owners.
/*
Test for Tensorflow models loading
*/
# include "test_precomp.hpp"
# include "npy_blob.hpp"
2018-04-24 19:59:59 +08:00
# include <opencv2/dnn/layer.details.hpp> // CV_DNN_REGISTER_LAYER_CLASS
2021-08-20 22:43:47 +08:00
# include <opencv2/dnn/utils/debug_utils.hpp>
2018-04-24 19:59:59 +08:00
2017-11-05 21:48:40 +08:00
namespace opencv_test
2017-06-26 18:35:51 +08:00
{
using namespace cv ;
using namespace cv : : dnn ;
template < typename TString >
static std : : string _tf ( TString filename )
{
return ( getOpenCVExtraDir ( ) + " /dnn/ " ) + filename ;
}
TEST ( Test_TensorFlow , read_inception )
{
Net net ;
{
const string model = findDataFile ( " dnn/tensorflow_inception_graph.pb " , false ) ;
2017-08-03 22:43:52 +08:00
net = readNetFromTensorflow ( model ) ;
ASSERT_FALSE ( net . empty ( ) ) ;
2017-06-26 18:35:51 +08:00
}
2018-06-01 15:54:12 +08:00
net . setPreferableBackend ( DNN_BACKEND_OPENCV ) ;
2017-06-26 18:35:51 +08:00
Mat sample = imread ( _tf ( " grace_hopper_227.png " ) ) ;
ASSERT_TRUE ( ! sample . empty ( ) ) ;
Mat input ;
resize ( sample , input , Size ( 224 , 224 ) ) ;
2019-01-17 22:23:09 +08:00
input - = Scalar : : all ( 117 ) ; // mean sub
2017-06-26 18:35:51 +08:00
Mat inputBlob = blobFromImage ( input ) ;
net . setInput ( inputBlob , " input " ) ;
Mat out = net . forward ( " softmax2 " ) ;
std : : cout < < out . dims < < std : : endl ;
}
TEST ( Test_TensorFlow , inception_accuracy )
{
Net net ;
{
const string model = findDataFile ( " dnn/tensorflow_inception_graph.pb " , false ) ;
2017-08-03 22:43:52 +08:00
net = readNetFromTensorflow ( model ) ;
ASSERT_FALSE ( net . empty ( ) ) ;
2017-06-26 18:35:51 +08:00
}
2018-06-01 15:54:12 +08:00
net . setPreferableBackend ( DNN_BACKEND_OPENCV ) ;
2017-06-26 18:35:51 +08:00
Mat sample = imread ( _tf ( " grace_hopper_227.png " ) ) ;
ASSERT_TRUE ( ! sample . empty ( ) ) ;
2018-08-31 22:27:10 +08:00
Mat inputBlob = blobFromImage ( sample , 1.0 , Size ( 224 , 224 ) , Scalar ( ) , /*swapRB*/ true ) ;
2017-06-26 18:35:51 +08:00
net . setInput ( inputBlob , " input " ) ;
Mat out = net . forward ( " softmax2 " ) ;
Mat ref = blobFromNPY ( _tf ( " tf_inception_prob.npy " ) ) ;
normAssert ( ref , out ) ;
}
2017-08-01 23:21:47 +08:00
static std : : string path ( const std : : string & file )
{
2019-06-20 21:43:28 +08:00
return findDataFile ( " dnn/tensorflow/ " + file ) ;
2017-08-01 23:21:47 +08:00
}
2018-06-27 21:34:36 +08:00
class Test_TensorFlow_layers : public DNNTestLayer
2017-08-01 23:21:47 +08:00
{
2018-06-27 21:34:36 +08:00
public :
void runTensorFlowNet ( const std : : string & prefix , bool hasText = false ,
2020-12-03 06:48:18 +08:00
double l1 = 0.0 , double lInf = 0.0 , bool memoryLoad = false , const std : : string & groupPrefix = " " )
2017-10-28 00:01:41 +08:00
{
2021-11-26 03:56:27 +08:00
if ( cvtest : : debugLevel > 0 )
{
std : : cout < < prefix < < groupPrefix < < std : : endl ;
}
2020-12-03 06:48:18 +08:00
std : : string netPath = path ( prefix + groupPrefix + " _net.pb " ) ;
std : : string netConfig = ( hasText ? path ( prefix + groupPrefix + " _net.pbtxt " ) : " " ) ;
2018-06-27 21:34:36 +08:00
std : : string inpPath = path ( prefix + " _in.npy " ) ;
2020-12-03 06:48:18 +08:00
std : : string outPath = path ( prefix + groupPrefix + " _out.npy " ) ;
2018-06-27 21:34:36 +08:00
cv : : Mat input = blobFromNPY ( inpPath ) ;
cv : : Mat ref = blobFromNPY ( outPath ) ;
checkBackend ( & input , & ref ) ;
Net net ;
if ( memoryLoad )
{
// Load files into a memory buffers
2019-05-29 20:29:31 +08:00
std : : vector < char > dataModel ;
readFileContent ( netPath , dataModel ) ;
2018-06-27 21:34:36 +08:00
2019-05-29 20:29:31 +08:00
std : : vector < char > dataConfig ;
2018-06-27 21:34:36 +08:00
if ( hasText )
2018-11-15 04:25:23 +08:00
{
2019-05-29 20:29:31 +08:00
readFileContent ( netConfig , dataConfig ) ;
2018-11-15 04:25:23 +08:00
}
2018-06-27 21:34:36 +08:00
2019-05-29 20:29:31 +08:00
net = readNetFromTensorflow ( dataModel . data ( ) , dataModel . size ( ) ,
dataConfig . data ( ) , dataConfig . size ( ) ) ;
2018-06-27 21:34:36 +08:00
}
else
net = readNetFromTensorflow ( netPath , netConfig ) ;
2017-10-28 00:01:41 +08:00
2018-06-27 21:34:36 +08:00
ASSERT_FALSE ( net . empty ( ) ) ;
2017-10-28 00:01:41 +08:00
2018-06-27 21:34:36 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
net . setInput ( input ) ;
cv : : Mat output = net . forward ( ) ;
normAssert ( ref , output , " " , l1 ? l1 : default_l1 , lInf ? lInf : default_lInf ) ;
2021-11-26 03:56:27 +08:00
if ( cvtest : : debugLevel > 0 | | HasFailure ( ) )
{
std : : cout < < " input: " < < input . size < < std : : endl ;
std : : cout < < input . reshape ( 1 , 1 ) < < std : : endl ;
std : : cout < < " ref " < < ref . size < < std : : endl ;
std : : cout < < ref . reshape ( 1 , 1 ) < < std : : endl ;
std : : cout < < " output: " < < output . size < < std : : endl ;
std : : cout < < output . reshape ( 1 , 1 ) < < std : : endl ;
}
2017-10-28 00:01:41 +08:00
}
2018-06-27 21:34:36 +08:00
} ;
2017-08-01 23:21:47 +08:00
2020-01-10 16:22:19 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_mean )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
runTensorFlowNet ( " global_pool_by_axis " ) ;
}
2021-08-09 18:28:33 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_max )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
2021-11-26 03:56:27 +08:00
runTensorFlowNet ( " max_pool_by_axis " , false , 0.0f , 0.0f ) ;
2021-08-09 18:28:33 +08:00
}
2020-08-12 22:32:16 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_sum )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
runTensorFlowNet ( " sum_pool_by_axis " ) ;
}
2021-08-09 18:28:33 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_max_channel )
{
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD ) // incorrect result
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
runTensorFlowNet ( " reduce_max_channel " , false , 0.0f , 0.0f ) ;
2021-08-09 18:28:33 +08:00
}
2021-03-28 21:53:44 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_sum_channel )
{
runTensorFlowNet ( " reduce_sum_channel " ) ;
}
2021-08-09 18:28:33 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_max_channel_keep_dims )
{
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020040000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD ) // incorrect result
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2021-08-09 18:28:33 +08:00
runTensorFlowNet ( " reduce_max_channel " , false , 0.0 , 0.0 , false , " _keep_dims " ) ;
}
2021-03-28 21:53:44 +08:00
TEST_P ( Test_TensorFlow_layers , reduce_sum_channel_keep_dims )
{
runTensorFlowNet ( " reduce_sum_channel " , false , 0.0 , 0.0 , false , " _keep_dims " ) ;
}
2021-12-17 01:06:02 +08:00
TEST_P ( Test_TensorFlow_layers , ArgLayer )
{
if ( backend ! = DNN_BACKEND_OPENCV | | target ! = DNN_TARGET_CPU )
throw SkipTestException ( " Only CPU is supported " ) ; // FIXIT use tags
runTensorFlowNet ( " argmax " ) ;
runTensorFlowNet ( " argmin " ) ;
}
2020-04-22 17:01:25 +08:00
TEST_P ( Test_TensorFlow_layers , conv_single_conv )
2017-08-01 23:21:47 +08:00
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " single_conv " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , conv_atrous_conv2d_valid )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " atrous_conv2d_valid " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , conv_atrous_conv2d_same )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " atrous_conv2d_same " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , conv_depthwise_conv2d )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " depthwise_conv2d " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , conv_keras_atrous_conv2d_same )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " keras_atrous_conv2d_same " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , conv_pool_nchw )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " conv_pool_nchw " ) ;
2017-08-01 23:21:47 +08:00
}
2019-04-30 22:08:17 +08:00
TEST_P ( Test_TensorFlow_layers , Convolution3D )
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
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
2021-11-30 20:08:35 +08:00
# endif
2019-04-30 22:08:17 +08:00
runTensorFlowNet ( " conv3d " ) ;
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_layers , padding )
2018-01-04 02:21:04 +08:00
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " padding_valid " ) ;
runTensorFlowNet ( " spatial_padding " ) ;
2019-06-24 17:27:42 +08:00
runTensorFlowNet ( " mirror_pad " ) ;
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019020000) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2020-02-26 22:51:18 +08:00
if ( target = = DNN_TARGET_MYRIAD )
2019-09-03 23:58:57 +08:00
{
2020-02-26 22:51:18 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2020-02-26 22:51:18 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-09-03 23:58:57 +08:00
}
# endif
runTensorFlowNet ( " keras_pad_concat " ) ;
2018-01-04 02:21:04 +08:00
}
2021-11-26 03:56:27 +08:00
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_1 )
2021-07-19 23:24:15 +08:00
{
runTensorFlowNet ( " conv2d_asymmetric_pads_nchw " ) ;
2021-11-26 03:56:27 +08:00
}
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_2 )
{
2021-07-19 23:24:15 +08:00
runTensorFlowNet ( " conv2d_asymmetric_pads_nhwc " ) ;
2021-11-26 03:56:27 +08:00
}
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_3 )
{
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_CPU ) // Exception: Unsupported pad value
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_CPU , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD ) // Exception: Unsupported pad value
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2021-07-19 23:24:15 +08:00
runTensorFlowNet ( " max_pool2d_asymmetric_pads_nchw " ) ;
2021-11-26 03:56:27 +08:00
}
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_4 )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Unsupported pad value
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
// accuracy
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
) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD ) // Exception: Unsupported pad value
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2021-11-26 03:56:27 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_CPU ) // Exception: Unsupported pad value
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_CPU , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD ) // Exception: Unsupported pad value
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2022-03-31 03:03:38 +08:00
# endif
2021-11-26 03:56:27 +08:00
# endif
2021-07-19 23:24:15 +08:00
runTensorFlowNet ( " max_pool2d_asymmetric_pads_nhwc " ) ;
2021-11-26 03:56:27 +08:00
}
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_5 )
{
2021-07-19 23:24:15 +08:00
runTensorFlowNet ( " conv2d_backprop_input_asymmetric_pads_nchw " ) ;
2021-11-26 03:56:27 +08:00
}
TEST_P ( Test_TensorFlow_layers , padding_asymmetric_6 )
{
2021-07-19 23:24:15 +08:00
runTensorFlowNet ( " conv2d_backprop_input_asymmetric_pads_nhwc " ) ;
}
2019-03-29 21:42:58 +08:00
TEST_P ( Test_TensorFlow_layers , padding_same )
{
// Reference output values are in range [0.0006, 2.798]
runTensorFlowNet ( " padding_same " ) ;
}
2018-12-07 18:38:05 +08:00
TEST_P ( Test_TensorFlow_layers , eltwise )
2017-08-01 23:21:47 +08:00
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " eltwise_add_mul " ) ;
2018-12-07 18:38:05 +08:00
runTensorFlowNet ( " eltwise_sub " ) ;
2018-06-27 21:34:36 +08:00
}
2021-03-24 06:16:09 +08:00
TEST_P ( Test_TensorFlow_layers , eltwise_add_vec )
{
runTensorFlowNet ( " eltwise_add_vec " ) ;
}
2021-03-23 03:37:49 +08:00
TEST_P ( Test_TensorFlow_layers , eltwise_mul_vec )
{
runTensorFlowNet ( " eltwise_mul_vec " ) ;
}
2020-03-09 01:15:18 +08:00
TEST_P ( Test_TensorFlow_layers , channel_broadcast )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
runTensorFlowNet ( " channel_broadcast " ) ;
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , pad_and_concat )
{
runTensorFlowNet ( " pad_and_concat " ) ;
2017-08-01 23:21:47 +08:00
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , concat_axis_1 )
2017-08-01 23:21:47 +08:00
{
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
// IE Exception: Ngraph operation Transpose with name Flatten_1/flatten/Reshape/nhwc 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
2021-03-24 17:28:05 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ; // exception
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ; // exception
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " concat_axis_1 " ) ;
2017-08-01 23:21:47 +08:00
}
2020-04-27 01:42:11 +08:00
TEST_P ( Test_TensorFlow_layers , concat_3d )
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2020-04-27 01:42:11 +08:00
if ( backend = = DNN_BACKEND_OPENCV & & target ! = DNN_TARGET_CPU )
{
if ( target = = DNN_TARGET_OPENCL_FP16 ) applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 ) ;
if ( target = = DNN_TARGET_OPENCL ) applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL ) ;
}
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 ) ;
2021-11-30 20:08:35 +08:00
# endif
2020-04-27 01:42:11 +08:00
2020-04-21 15:34:56 +08:00
runTensorFlowNet ( " concat_3d " ) ;
2017-08-01 23:21:47 +08:00
}
2020-02-07 21:40:50 +08:00
TEST_P ( Test_TensorFlow_layers , batch_norm_1 )
2018-01-04 23:14:28 +08:00
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " batch_norm " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_2 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " batch_norm " , false , 0.0 , 0.0 , true ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_3 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fused_batch_norm " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_4 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fused_batch_norm " , false , 0.0 , 0.0 , true ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_5 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " batch_norm_text " , true ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_6 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " batch_norm_text " , true , 0.0 , 0.0 , true ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_7 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " unfused_batch_norm " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_8 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fused_batch_norm_no_gamma " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_9 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " unfused_batch_norm_no_gamma " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_10 )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " mvn_batch_norm " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_11 )
{
2021-03-24 17:28:05 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
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 ) ; // nan
# endif
2020-02-07 21:40:50 +08:00
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 ) ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " mvn_batch_norm_1x1 " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_12 )
{
2019-05-29 00:47:02 +08:00
runTensorFlowNet ( " switch_identity " ) ;
2020-02-07 21:40:50 +08:00
}
TEST_P ( Test_TensorFlow_layers , batch_norm_13 )
{
2019-06-07 00:08:45 +08:00
runTensorFlowNet ( " keras_batch_norm_training " ) ;
2018-01-04 23:14:28 +08:00
}
2019-04-29 15:29:34 +08:00
TEST_P ( Test_TensorFlow_layers , batch_norm3D )
{
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target ! = DNN_TARGET_CPU )
2019-06-15 20:17:25 +08:00
{
2019-12-02 21:16:06 +08:00
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 ) ;
2019-05-14 17:35:41 +08:00
throw SkipTestException ( " " ) ;
2019-06-15 20:17:25 +08:00
}
2019-04-29 15:29:34 +08:00
runTensorFlowNet ( " batch_norm3d " ) ;
}
2019-04-03 18:42:06 +08:00
TEST_P ( Test_TensorFlow_layers , slim_batch_norm )
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
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 ) ;
2021-11-30 20:08:35 +08:00
# endif
2019-04-03 18:42:06 +08:00
// Output values range: [-40.0597, 207.827]
2021-11-30 20:08:35 +08:00
double l1 = default_l1 ;
double lInf = default_lInf ;
2019-12-20 21:36:32 +08:00
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
l1 = 0.041 ;
lInf = 0.33 ;
}
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE)
else if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_CPU )
{
lInf = 0.0002 ;
}
# endif
2019-12-20 21:36:32 +08:00
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
l1 = 0.005 ;
lInf = 0.33 ;
}
2021-11-30 20:08:35 +08:00
2019-04-03 18:42:06 +08:00
runTensorFlowNet ( " slim_batch_norm " , false , l1 , lInf ) ;
}
2020-04-22 17:01:25 +08:00
TEST_P ( Test_TensorFlow_layers , pooling_max_pool_even )
2017-08-01 23:21:47 +08:00
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " max_pool_even " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , pooling_max_pool_odd_valid )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " max_pool_odd_valid " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , pooling_max_pool_odd_same )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " max_pool_odd_same " ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_mean )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " reduce_mean " ) ; // an average pooling over all spatial dimensions.
}
2021-08-09 18:28:33 +08:00
TEST_P ( Test_TensorFlow_layers , pooling_reduce_max )
{
runTensorFlowNet ( " reduce_max " ) ; // a MAX pooling over all spatial dimensions.
}
2020-08-12 22:32:16 +08:00
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum )
{
runTensorFlowNet ( " reduce_sum " ) ; // a SUM pooling over all spatial dimensions.
}
2021-11-26 03:56:27 +08:00
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_0_false )
2021-11-10 00:24:04 +08:00
{
2021-11-26 03:56:27 +08:00
runTensorFlowNet ( " reduce_sum_0_False " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_1_false )
{
runTensorFlowNet ( " reduce_sum_1_False " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_2_false )
{
runTensorFlowNet ( " reduce_sum_2_False " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_3_false )
{
runTensorFlowNet ( " reduce_sum_3_False " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_1_2_false )
{
# if defined(INF_ENGINE_RELEASE)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD )
2021-11-10 00:24:04 +08:00
{
2021-11-26 03:56:27 +08:00
default_l1 = 0.01f ;
}
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
{
default_l1 = 0.01f ;
}
# endif
runTensorFlowNet ( " reduce_sum_1_2_False " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_0_true )
{
runTensorFlowNet ( " reduce_sum_0_True " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_1_true )
{
runTensorFlowNet ( " reduce_sum_1_True " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_2_true )
{
runTensorFlowNet ( " reduce_sum_2_True " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_3_true )
{
runTensorFlowNet ( " reduce_sum_3_True " ) ;
}
TEST_P ( Test_TensorFlow_layers , pooling_reduce_sum_1_2_true )
{
# if defined(INF_ENGINE_RELEASE)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_MYRIAD )
{
default_l1 = 0.01f ;
2021-11-10 00:24:04 +08:00
}
2021-11-26 03:56:27 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
{
default_l1 = 0.01f ;
2021-11-10 00:24:04 +08:00
}
2021-11-26 03:56:27 +08:00
# endif
runTensorFlowNet ( " reduce_sum_1_2_True " ) ;
2021-11-10 00:24:04 +08:00
}
2021-11-26 03:56:27 +08:00
2019-06-15 23:51:13 +08:00
TEST_P ( Test_TensorFlow_layers , max_pool_grad )
{
2019-12-02 21:16:06 +08:00
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 ) ;
2019-06-15 23:51:13 +08:00
runTensorFlowNet ( " max_pool_grad " ) ;
}
2018-06-27 21:34:36 +08:00
// TODO: fix tests and replace to pooling
TEST_P ( Test_TensorFlow_layers , ave_pool_same )
{
2019-03-29 21:42:58 +08:00
// Reference output values are in range [-0.519531, 0.112976]
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-24 18:34:33 +08:00
if ( target = = DNN_TARGET_MYRIAD & & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
else if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
}
2019-03-29 21:42:58 +08:00
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " ave_pool_same " ) ;
2017-08-01 23:21:47 +08:00
}
2019-04-30 22:08:17 +08:00
TEST_P ( Test_TensorFlow_layers , MaxPooling3D )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// IE exception: [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
// accuracy
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
) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
2021-11-30 20:08:35 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
2019-12-02 21:18:07 +08:00
{
2021-11-30 20:08:35 +08:00
// 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 ) ;
2019-12-02 21:18:07 +08:00
}
2022-03-31 03:03:38 +08:00
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
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
2019-12-02 21:18:07 +08:00
else if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target ! = DNN_TARGET_CPU )
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ; // Only CPU on DLIE backend is supported
2021-11-30 20:08:35 +08:00
# endif
if ( backend = = DNN_BACKEND_OPENCV & & target ! = DNN_TARGET_CPU )
throw SkipTestException ( " Only CPU is supported " ) ; // FIXIT use tags
2019-12-02 21:18:07 +08:00
2021-12-17 21:28:34 +08:00
if ( backend = = DNN_BACKEND_VKCOM )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_VULKAN ) ;
2019-04-30 22:08:17 +08:00
runTensorFlowNet ( " max_pool3d " ) ;
}
TEST_P ( Test_TensorFlow_layers , AvePooling3D )
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
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
2019-12-02 21:18:07 +08:00
else if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target ! = DNN_TARGET_CPU )
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ; // Only CPU on DLIE backend is supported
2021-11-30 20:08:35 +08:00
# endif
if ( backend = = DNN_BACKEND_OPENCV & & target ! = DNN_TARGET_CPU )
throw SkipTestException ( " Only CPU is supported " ) ; // FIXIT use tags
2019-12-02 21:18:07 +08:00
2021-12-17 21:28:34 +08:00
if ( backend = = DNN_BACKEND_VKCOM )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_VULKAN ) ;
2019-04-30 22:08:17 +08:00
runTensorFlowNet ( " ave_pool3d " ) ;
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_layers , deconvolution )
2017-08-11 21:23:41 +08:00
{
2019-12-20 21:36:32 +08:00
if ( backend = = DNN_BACKEND_CUDA )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA ) ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " deconvolution " ) ;
runTensorFlowNet ( " deconvolution_same " ) ;
runTensorFlowNet ( " deconvolution_stride_2_same " ) ;
runTensorFlowNet ( " deconvolution_adj_pad_valid " ) ;
runTensorFlowNet ( " deconvolution_adj_pad_same " ) ;
runTensorFlowNet ( " keras_deconv_valid " ) ;
runTensorFlowNet ( " keras_deconv_same " ) ;
2019-06-07 00:08:45 +08:00
runTensorFlowNet ( " keras_deconv_same_v2 " ) ;
2017-08-11 21:23:41 +08:00
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_layers , matmul )
2018-01-16 21:54:32 +08:00
{
2018-06-27 21:34:36 +08:00
if ( backend = = DNN_BACKEND_OPENCV & & target = = DNN_TARGET_OPENCL_FP16 )
2019-06-15 20:17:25 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " matmul " ) ;
runTensorFlowNet ( " nhwc_transpose_reshape_matmul " ) ;
2019-03-29 21:42:58 +08:00
// Reference output values are in range [-5.688, 4.484]
double l1 = target = = DNN_TARGET_MYRIAD ? 6.1e-3 : default_l1 ;
runTensorFlowNet ( " nhwc_reshape_matmul " , false , l1 ) ;
2019-08-15 00:44:05 +08:00
runTensorFlowNet ( " matmul_layout " ) ;
2021-12-10 19:44:27 +08:00
runTensorFlowNet ( " two_inputs_matmul " ) ;
}
TEST_P ( Test_TensorFlow_layers , batch_matmul )
{
if ( backend = = DNN_BACKEND_OPENCV & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
runTensorFlowNet ( " batch_matmul " ) ;
2018-01-16 21:54:32 +08:00
}
2021-12-13 21:43:13 +08:00
TEST_P ( Test_TensorFlow_layers , square )
{
if ( backend = = DNN_BACKEND_OPENCV & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
runTensorFlowNet ( " square " ) ;
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_layers , reshape )
2017-09-14 03:18:02 +08:00
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
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 ) ;
2021-11-30 20:08:35 +08:00
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " shift_reshape_no_reorder " ) ;
runTensorFlowNet ( " reshape_no_reorder " ) ;
runTensorFlowNet ( " reshape_reduce " ) ;
2018-08-02 16:12:22 +08:00
runTensorFlowNet ( " reshape_as_shape " ) ;
2018-06-27 21:34:36 +08:00
}
TEST_P ( Test_TensorFlow_layers , flatten )
{
2019-03-29 21:42:58 +08:00
# if defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD
2019-03-29 21:42:58 +08:00
& & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
)
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2 , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
2019-03-29 21:42:58 +08:00
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " flatten " , true ) ;
2018-09-04 22:33:34 +08:00
}
TEST_P ( Test_TensorFlow_layers , unfused_flatten )
{
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " unfused_flatten " ) ;
runTensorFlowNet ( " unfused_flatten_unknown_batch " ) ;
2017-09-14 03:18:02 +08:00
}
2021-03-01 00:55:43 +08:00
TEST_P ( Test_TensorFlow_layers , reshape_layer )
{
runTensorFlowNet ( " reshape_layer " ) ;
}
TEST_P ( Test_TensorFlow_layers , reshape_nchw )
{
runTensorFlowNet ( " reshape_nchw " ) ;
}
2021-03-24 03:28:26 +08:00
TEST_P ( Test_TensorFlow_layers , reshape_conv )
{
runTensorFlowNet ( " reshape_conv " ) ;
}
2018-07-20 09:03:17 +08:00
TEST_P ( Test_TensorFlow_layers , leaky_relu )
{
2019-03-29 21:42:58 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_OPENCL )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2018-12-20 18:14:47 +08:00
# endif
2021-02-04 16:50:08 +08:00
runTensorFlowNet ( " leaky_relu " ) ;
2018-07-20 09:03:17 +08:00
runTensorFlowNet ( " leaky_relu_order1 " ) ;
runTensorFlowNet ( " leaky_relu_order2 " ) ;
runTensorFlowNet ( " leaky_relu_order3 " ) ;
}
2018-04-05 01:32:00 +08:00
TEST_P ( Test_TensorFlow_layers , l2_normalize )
{
2019-04-01 20:00:25 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD
2019-03-29 21:42:58 +08:00
& & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
)
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-03-29 21:42:58 +08:00
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " l2_normalize " ) ;
2018-04-05 01:32:00 +08:00
}
2021-09-10 18:15:22 +08:00
TEST_P ( Test_TensorFlow_layers , BiasAdd )
{
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD
& & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
)
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
runTensorFlowNet ( " bias_add_1 " ) ;
}
2021-10-05 00:37:38 +08:00
TEST_P ( Test_TensorFlow_layers , ExpandDims )
{
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
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 ) ; // Layout::ANY is broken on CPU
# endif
2021-10-05 00:37:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2019010000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD
& & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X
)
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
runTensorFlowNet ( " expand_dims_1 " ) ;
runTensorFlowNet ( " expand_dims_2 " ) ;
}
2018-06-27 21:34:36 +08:00
// TODO: fix it and add to l2_normalize
TEST_P ( Test_TensorFlow_layers , l2_normalize_3d )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// Cannot get memory!
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & ( target = = DNN_TARGET_OPENCL | | target = = DNN_TARGET_OPENCL_FP16 ) )
2019-12-02 21:16:06 +08:00
applyTestTag ( target = = DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_IE_OPENCL : CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 ,
2022-03-31 03:03:38 +08:00
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION
) ;
// accuracy
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
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 ) ;
2019-12-24 18:34:33 +08:00
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 ) ;
2019-03-29 21:42:58 +08:00
# endif
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " l2_normalize_3d " ) ;
}
2017-09-20 18:30:25 +08:00
2021-07-13 17:20:35 +08:00
class Test_TensorFlow_diagnostics : public DNNTestLayer {
public :
Test_TensorFlow_diagnostics ( )
{
enableModelDiagnostics ( true ) ;
2021-08-20 22:43:47 +08:00
skipModelImport ( true ) ;
2021-07-13 17:20:35 +08:00
}
~ Test_TensorFlow_diagnostics ( )
{
enableModelDiagnostics ( false ) ;
2021-08-20 22:43:47 +08:00
skipModelImport ( false ) ;
2021-07-13 17:20:35 +08:00
}
void runFailingTensorFlowNet ( const std : : string & prefix , bool hasText = false )
{
std : : string netPath = path ( prefix + " _net.pb " ) ;
std : : string netConfig = ( hasText ? path ( prefix + " _net.pbtxt " ) : " " ) ;
Net net = readNetFromTensorflow ( netPath , netConfig ) ;
}
} ;
TEST_P ( Test_TensorFlow_diagnostics , not_implemented_layer )
{
runFailingTensorFlowNet ( " not_implemented_layer " ) ;
}
TEST_P ( Test_TensorFlow_diagnostics , broken_parameters )
{
runFailingTensorFlowNet ( " broken_layer " ) ;
}
INSTANTIATE_TEST_CASE_P ( /**/ , Test_TensorFlow_diagnostics , dnnBackendsAndTargets ( ) ) ;
2018-07-14 00:47:50 +08:00
class Test_TensorFlow_nets : public DNNTestLayer { } ;
2017-09-18 18:04:43 +08:00
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_nets , MobileNet_SSD )
2017-09-28 21:51:47 +08:00
{
2019-04-08 16:29:10 +08:00
# if defined(INF_ENGINE_RELEASE)
2019-12-24 18:34:33 +08:00
if ( target = = DNN_TARGET_MYRIAD )
2019-06-14 23:17:02 +08:00
{
2019-08-06 23:41:30 +08:00
# if INF_ENGINE_VER_MAJOR_GE(2019020000)
2019-06-14 23:17:02 +08:00
if ( getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X )
2019-12-24 18:34:33 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X ,
backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ?
CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER :
CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ,
CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-06-14 23:17:02 +08:00
# endif
2020-02-07 21:40:50 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-06-14 23:17:02 +08:00
}
2019-04-08 16:29:10 +08:00
# endif
2018-07-14 00:47:50 +08:00
2019-04-08 16:29:10 +08:00
checkBackend ( ) ;
2019-06-20 21:43:28 +08:00
std : : string imgPath = findDataFile ( " dnn/street.png " ) ;
std : : string netConfig = findDataFile ( " dnn/ssd_mobilenet_v1_coco.pbtxt " ) ;
2017-09-28 21:51:47 +08:00
std : : string netPath = findDataFile ( " dnn/ssd_mobilenet_v1_coco.pb " , false ) ;
Mat inp ;
resize ( imread ( imgPath ) , inp , Size ( 300 , 300 ) ) ;
inp = blobFromImage ( inp , 1.0f / 127.5 , Size ( ) , Scalar ( 127.5 , 127.5 , 127.5 ) , true ) ;
2019-06-20 21:43:28 +08:00
Mat ref = blobFromNPY ( findDataFile ( " dnn/tensorflow/ssd_mobilenet_v1_coco.detection_out.npy " ) ) ;
2017-09-28 21:51:47 +08:00
Net net = readNetFromTensorflow ( netPath , netConfig ) ;
2018-07-14 00:47:50 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2018-03-05 23:21:19 +08:00
2017-09-28 21:51:47 +08:00
net . setInput ( inp ) ;
2019-04-08 16:29:10 +08:00
Mat out = net . forward ( ) ;
2017-09-28 21:51:47 +08:00
2019-12-20 21:36:32 +08:00
double scoreDiff = default_l1 , iouDiff = default_lInf ;
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
2021-11-26 03:56:27 +08:00
scoreDiff = 0.01 ;
iouDiff = 0.1 ;
2019-12-20 21:36:32 +08:00
}
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
iouDiff = 0.04 ;
}
2021-11-26 03:56:27 +08:00
2019-04-08 16:29:10 +08:00
normAssertDetections ( ref , out , " " , 0.2 , scoreDiff , iouDiff ) ;
2019-06-14 23:17:02 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_RELEASE >= 2019010000
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2019-06-14 23:17:02 +08:00
# endif
2017-09-07 15:18:13 +08:00
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_nets , Inception_v2_SSD )
2018-01-26 21:45:25 +08:00
{
2018-10-09 06:38:06 +08:00
applyTestTag ( target = = DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB ) ;
2019-08-06 23:41:30 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2019010000)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD & &
2019-08-06 23:41:30 +08:00
getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X )
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-03-29 21:42:58 +08:00
# endif
2018-07-14 00:47:50 +08:00
checkBackend ( ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " dnn/street.png " ) ) ;
std : : string proto = findDataFile ( " dnn/ssd_inception_v2_coco_2017_11_17.pbtxt " ) ;
2018-01-26 21:45:25 +08:00
std : : string model = findDataFile ( " dnn/ssd_inception_v2_coco_2017_11_17.pb " , false ) ;
Net net = readNetFromTensorflow ( model , proto ) ;
2018-08-31 20:41:56 +08:00
Mat blob = blobFromImage ( img , 1.0f , Size ( 300 , 300 ) , Scalar ( ) , true , false ) ;
2018-01-26 21:45:25 +08:00
2018-07-14 00:47:50 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2018-03-05 23:21:19 +08:00
2018-01-26 21:45:25 +08:00
net . setInput ( blob ) ;
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat out = net . forward ( ) ;
2018-04-18 22:26:54 +08:00
Mat ref = ( Mat_ < float > ( 5 , 7 ) < < 0 , 1 , 0.90176028 , 0.19872092 , 0.36311883 , 0.26461923 , 0.63498729 ,
0 , 3 , 0.93569964 , 0.64865261 , 0.45906419 , 0.80675775 , 0.65708131 ,
0 , 3 , 0.75838411 , 0.44668293 , 0.45907149 , 0.49459291 , 0.52197015 ,
0 , 10 , 0.95932811 , 0.38349164 , 0.32528657 , 0.40387636 , 0.39165527 ,
0 , 10 , 0.93973452 , 0.66561931 , 0.37841269 , 0.68074018 , 0.42907384 ) ;
2019-03-29 21:42:58 +08:00
2019-12-20 21:36:32 +08:00
double scoreDiff = default_l1 , iouDiff = default_lInf ;
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
scoreDiff = 0.0097 ;
iouDiff = 0.09 ;
}
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
scoreDiff = 6e-3 ;
iouDiff = 0.05 ;
}
2018-07-14 00:47:50 +08:00
normAssertDetections ( ref , out , " " , 0.5 , scoreDiff , iouDiff ) ;
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2018-01-26 21:45:25 +08:00
}
2018-09-03 22:08:40 +08:00
TEST_P ( Test_TensorFlow_nets , MobileNet_v1_SSD )
{
checkBackend ( ) ;
2019-06-20 21:43:28 +08:00
std : : string proto = findDataFile ( " dnn/ssd_mobilenet_v1_coco_2017_11_17.pbtxt " ) ;
2018-09-03 22:08:40 +08:00
std : : string model = findDataFile ( " dnn/ssd_mobilenet_v1_coco_2017_11_17.pb " , false ) ;
Net net = readNetFromTensorflow ( model , proto ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " dnn/dog416.png " ) ) ;
2018-09-03 22:08:40 +08:00
Mat blob = blobFromImage ( img , 1.0f , Size ( 300 , 300 ) , Scalar ( ) , true , false ) ;
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
net . setInput ( blob ) ;
Mat out = net . forward ( ) ;
Mat ref = blobFromNPY ( findDataFile ( " dnn/tensorflow/ssd_mobilenet_v1_coco_2017_11_17.detection_out.npy " ) ) ;
2019-12-20 21:36:32 +08:00
float scoreDiff = 1.5e-5 , iouDiff = 1e-3 ;
2019-06-25 02:55:32 +08:00
float detectionConfThresh = ( target = = DNN_TARGET_MYRIAD ) ? 0.35 : 0.3 ;
2019-12-20 21:36:32 +08:00
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
scoreDiff = 0.011 ;
iouDiff = 0.012 ;
}
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
scoreDiff = 0.006 ;
iouDiff = 0.01 ;
}
2019-06-25 02:55:32 +08:00
# if defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD & &
2019-08-06 23:41:30 +08:00
getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X )
{
2019-06-25 02:55:32 +08:00
scoreDiff = 0.061 ;
iouDiff = 0.12 ;
detectionConfThresh = 0.36 ;
2019-08-06 23:41:30 +08:00
}
2019-06-25 02:55:32 +08:00
# endif
normAssertDetections ( ref , out , " " , detectionConfThresh , scoreDiff , iouDiff ) ;
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2018-09-03 22:08:40 +08:00
}
2021-11-26 03:56:27 +08:00
TEST_P ( Test_TensorFlow_nets , Faster_RCNN_inception_v2_coco_2018_01_28 )
2018-04-03 23:28:05 +08:00
{
2019-05-27 20:14:18 +08:00
applyTestTag (
( target = = DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB ) ,
CV_TEST_TAG_LONG ,
CV_TEST_TAG_DEBUG_VERYLONG
) ;
2018-08-31 20:41:56 +08:00
2019-09-10 00:24:54 +08:00
# ifdef INF_ENGINE_RELEASE
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & &
2019-09-10 00:24:54 +08:00
( INF_ENGINE_VER_MAJOR_LT ( 2019020000 ) | | target ! = DNN_TARGET_CPU ) )
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-12-24 18:34:33 +08:00
if ( INF_ENGINE_VER_MAJOR_GT ( 2019030000 ) & &
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 ) ;
2019-09-10 00:24:54 +08:00
# endif
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2019-12-02 21:16:06 +08:00
// segfault: inference-engine/thirdparty/clDNN/src/gpu/detection_output_cpu.cpp:111:
// Assertion `prior_height > 0' failed.
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
2021-11-26 03:56:27 +08:00
# endif
2019-12-02 21:16:06 +08:00
2021-11-27 21:17:44 +08:00
if ( backend = = DNN_BACKEND_CUDA & & target = = DNN_TARGET_CUDA_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA_FP16 ) ;
2021-11-26 03:56:27 +08:00
checkBackend ( ) ;
double scoresDiff = 1e-5 ;
double iouDiff = 1e-4 ;
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 | | backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
{
scoresDiff = 0.02 ;
iouDiff = 0.1 ;
}
std : : string name = " faster_rcnn_inception_v2_coco_2018_01_28 " ;
{
std : : string proto = findDataFile ( " dnn/ " + name + " .pbtxt " ) ;
std : : string model = findDataFile ( " dnn/ " + name + " .pb " , false ) ;
Net net = readNetFromTensorflow ( model , proto ) ;
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
Mat img = imread ( findDataFile ( " dnn/dog416.png " ) ) ;
Mat blob = blobFromImage ( img , 1.0f , Size ( 800 , 600 ) , Scalar ( ) , true , false ) ;
net . setInput ( blob ) ;
Mat out = net . forward ( ) ;
Mat ref = blobFromNPY ( findDataFile ( " dnn/tensorflow/ " + name + " .detection_out.npy " ) ) ;
// accuracy (both OpenCV & IE)
if ( target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
normAssertDetections ( ref , out , name . c_str ( ) , 0.3 , scoresDiff , iouDiff ) ;
}
}
TEST_P ( Test_TensorFlow_nets , Faster_RCNN_resnet50_coco_2018_01_28 )
{
applyTestTag (
( target = = DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_1GB : CV_TEST_TAG_MEMORY_2GB ) ,
CV_TEST_TAG_LONG ,
CV_TEST_TAG_DEBUG_VERYLONG
) ;
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep < subgraphs.size()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
// [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep < subgraphs.size()
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
) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
// [ GENERAL_ERROR ] AssertionFailed: subgraphTopoSortsStep++ < subgraphs.size()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2021-11-26 03:56:27 +08:00
// IE exception: Ngraph operation Transpose with name FirstStageBoxPredictor/ClassPredictor/reshape_1/nhwc 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
) ;
2022-03-31 03:03:38 +08:00
# elif defined(INF_ENGINE_RELEASE)
2021-11-26 03:56:27 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & &
( INF_ENGINE_VER_MAJOR_LT ( 2019020000 ) | | target ! = DNN_TARGET_CPU ) )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
if ( INF_ENGINE_VER_MAJOR_GT ( 2019030000 ) & &
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 ) ;
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
// segfault: inference-engine/thirdparty/clDNN/src/gpu/detection_output_cpu.cpp:111:
// Assertion `prior_height > 0' failed.
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
2022-03-31 03:03:38 +08:00
# endif
2021-11-26 03:56:27 +08:00
# endif
2018-07-14 00:47:50 +08:00
2019-12-20 21:36:32 +08:00
if ( backend = = DNN_BACKEND_CUDA & & target = = DNN_TARGET_CUDA_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA_FP16 ) ;
2019-12-02 21:16:06 +08:00
checkBackend ( ) ;
double scoresDiff = backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ? 2.9e-5 : 1e-5 ;
2020-07-02 02:17:57 +08:00
double iouDiff = 1e-4 ;
if ( target = = DNN_TARGET_CUDA )
{
scoresDiff = 0.06 ;
iouDiff = 0.08 ;
}
2021-11-26 03:56:27 +08:00
std : : string name = " faster_rcnn_resnet50_coco_2018_01_28 " ;
2018-08-31 20:41:56 +08:00
{
2021-11-26 03:56:27 +08:00
std : : string proto = findDataFile ( " dnn/ " + name + " .pbtxt " ) ;
std : : string model = findDataFile ( " dnn/ " + name + " .pb " , false ) ;
2018-04-03 23:28:05 +08:00
2018-08-31 20:41:56 +08:00
Net net = readNetFromTensorflow ( model , proto ) ;
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " dnn/dog416.png " ) ) ;
2018-08-31 20:41:56 +08:00
Mat blob = blobFromImage ( img , 1.0f , Size ( 800 , 600 ) , Scalar ( ) , true , false ) ;
2018-04-03 23:28:05 +08:00
2018-08-31 20:41:56 +08:00
net . setInput ( blob ) ;
Mat out = net . forward ( ) ;
2018-04-03 23:28:05 +08:00
2021-11-26 03:56:27 +08:00
Mat ref = blobFromNPY ( findDataFile ( " dnn/tensorflow/ " + name + " .detection_out.npy " ) ) ;
// accuracy
if ( target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
normAssertDetections ( ref , out , name . c_str ( ) , 0.3 , scoresDiff , iouDiff ) ;
2018-08-31 20:41:56 +08:00
}
2018-04-03 23:28:05 +08:00
}
2018-08-01 16:34:04 +08:00
TEST_P ( Test_TensorFlow_nets , MobileNet_v1_SSD_PPN )
{
2019-03-29 21:42:58 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & ( 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_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2018-12-20 18:14:47 +08:00
# endif
2018-08-01 16:34:04 +08:00
checkBackend ( ) ;
2019-06-20 21:43:28 +08:00
std : : string proto = findDataFile ( " dnn/ssd_mobilenet_v1_ppn_coco.pbtxt " ) ;
2018-08-01 16:34:04 +08:00
std : : string model = findDataFile ( " dnn/ssd_mobilenet_v1_ppn_coco.pb " , false ) ;
Net net = readNetFromTensorflow ( model , proto ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " dnn/dog416.png " ) ) ;
Mat ref = blobFromNPY ( findDataFile ( " dnn/tensorflow/ssd_mobilenet_v1_ppn_coco.detection_out.npy " ) ) ;
2018-08-31 20:41:56 +08:00
Mat blob = blobFromImage ( img , 1.0f , Size ( 300 , 300 ) , Scalar ( ) , true , false ) ;
2018-08-01 16:34:04 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
net . setInput ( blob ) ;
Mat out = net . forward ( ) ;
2018-09-03 22:08:40 +08:00
2019-12-20 21:36:32 +08:00
double scoreDiff = 1.1e-5 , iouDiff = default_lInf ;
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
scoreDiff = 0.048 ;
iouDiff = 0.058 ;
}
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
scoreDiff = 0.006 ;
iouDiff = 0.05 ;
}
2019-03-29 21:42:58 +08:00
normAssertDetections ( ref , out , " " , 0.45 , scoreDiff , iouDiff ) ;
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2018-08-01 16:34:04 +08:00
}
2018-03-05 23:21:19 +08:00
TEST_P ( Test_TensorFlow_nets , opencv_face_detector_uint8 )
2018-02-19 20:56:40 +08:00
{
2018-07-14 00:47:50 +08:00
checkBackend ( ) ;
2019-06-20 21:43:28 +08:00
std : : string proto = findDataFile ( " dnn/opencv_face_detector.pbtxt " ) ;
2018-03-05 23:21:19 +08:00
std : : string model = findDataFile ( " dnn/opencv_face_detector_uint8.pb " , false ) ;
2018-02-19 20:56:40 +08:00
Net net = readNetFromTensorflow ( model , proto ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " gpu/lbpcascade/er.png " ) ) ;
2018-03-05 23:21:19 +08:00
Mat blob = blobFromImage ( img , 1.0 , Size ( ) , Scalar ( 104.0 , 177.0 , 123.0 ) , false , false ) ;
2018-02-19 20:56:40 +08:00
2018-07-14 00:47:50 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2018-02-19 20:56:40 +08:00
net . setInput ( blob ) ;
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat out = net . forward ( ) ;
2018-03-05 23:21:19 +08:00
// References are from test for Caffe model.
2018-04-18 22:26:54 +08:00
Mat ref = ( Mat_ < float > ( 6 , 7 ) < < 0 , 1 , 0.99520785 , 0.80997437 , 0.16379407 , 0.87996572 , 0.26685631 ,
0 , 1 , 0.9934696 , 0.2831718 , 0.50738752 , 0.345781 , 0.5985168 ,
0 , 1 , 0.99096733 , 0.13629119 , 0.24892329 , 0.19756334 , 0.3310290 ,
0 , 1 , 0.98977017 , 0.23901358 , 0.09084064 , 0.29902688 , 0.1769477 ,
0 , 1 , 0.97203469 , 0.67965847 , 0.06876482 , 0.73999709 , 0.1513494 ,
0 , 1 , 0.95097077 , 0.51901293 , 0.45863652 , 0.5777427 , 0.5347801 ) ;
2019-12-20 21:36:32 +08:00
double scoreDiff = 3.4e-3 , iouDiff = 1e-2 ;
if ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD )
{
scoreDiff = 4e-3 ;
iouDiff = 0.024 ;
}
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
scoreDiff = 4e-3 ;
iouDiff = 0.02 ;
}
2018-07-14 00:47:50 +08:00
normAssertDetections ( ref , out , " " , 0.9 , scoreDiff , iouDiff ) ;
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2018-03-05 23:21:19 +08:00
}
2018-02-19 20:56:40 +08:00
2018-06-07 21:29:04 +08:00
// inp = cv.imread('opencv_extra/testdata/cv/ximgproc/sources/08.png')
// inp = inp[:,:,[2, 1, 0]].astype(np.float32).reshape(1, 512, 512, 3)
// outs = sess.run([sess.graph.get_tensor_by_name('feature_fusion/Conv_7/Sigmoid:0'),
// sess.graph.get_tensor_by_name('feature_fusion/concat_3:0')],
// feed_dict={'input_images:0': inp})
// scores = np.ascontiguousarray(outs[0].transpose(0, 3, 1, 2))
// geometry = np.ascontiguousarray(outs[1].transpose(0, 3, 1, 2))
// np.save('east_text_detection.scores.npy', scores)
// np.save('east_text_detection.geometry.npy', geometry)
TEST_P ( Test_TensorFlow_nets , EAST_text_detection )
{
2019-05-27 20:14:18 +08:00
applyTestTag (
( target = = DNN_TARGET_CPU ? CV_TEST_TAG_MEMORY_512MB : CV_TEST_TAG_MEMORY_1GB ) ,
CV_TEST_TAG_DEBUG_LONG
) ;
2018-10-09 06:38:06 +08:00
2019-03-29 21:42:58 +08:00
# if defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
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 ) ;
2020-02-07 21:40:50 +08:00
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 ) ;
2019-09-03 23:58:57 +08:00
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_OPENCL_FP16 & &
2020-02-07 21:40:50 +08:00
( INF_ENGINE_VER_MAJOR_EQ ( 2019020000 ) | | INF_ENGINE_VER_MAJOR_GE ( 2020010000 ) )
)
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2020-02-07 21:40:50 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_OPENCL_FP16 , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
2019-03-29 21:42:58 +08:00
# endif
2018-07-14 00:47:50 +08:00
checkBackend ( ) ;
2019-03-29 21:42:58 +08:00
2018-06-07 21:29:04 +08:00
std : : string netPath = findDataFile ( " dnn/frozen_east_text_detection.pb " , false ) ;
2019-06-20 21:43:28 +08:00
std : : string imgPath = findDataFile ( " cv/ximgproc/sources/08.png " ) ;
std : : string refScoresPath = findDataFile ( " dnn/east_text_detection.scores.npy " ) ;
std : : string refGeometryPath = findDataFile ( " dnn/east_text_detection.geometry.npy " ) ;
2018-06-07 21:29:04 +08:00
2019-06-20 21:43:28 +08:00
Net net = readNet ( netPath ) ;
2018-06-07 21:29:04 +08:00
2018-07-14 00:47:50 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2018-06-07 21:29:04 +08:00
Mat img = imread ( imgPath ) ;
Mat inp = blobFromImage ( img , 1.0 , Size ( ) , Scalar ( 123.68 , 116.78 , 103.94 ) , true , false ) ;
net . setInput ( inp ) ;
std : : vector < Mat > outs ;
std : : vector < String > outNames ( 2 ) ;
outNames [ 0 ] = " feature_fusion/Conv_7/Sigmoid " ;
outNames [ 1 ] = " feature_fusion/concat_3 " ;
net . forward ( outs , outNames ) ;
Mat scores = outs [ 0 ] ;
Mat geometry = outs [ 1 ] ;
2018-08-27 20:45:44 +08:00
// Scores are in range [0, 1]. Geometry values are in range [-0.23, 290]
double l1_scores = default_l1 , lInf_scores = default_lInf ;
double l1_geometry = default_l1 , lInf_geometry = default_lInf ;
if ( target = = DNN_TARGET_OPENCL_FP16 )
{
2019-12-02 21:16:06 +08:00
lInf_scores = backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 ? 0.16 : 0.11 ;
2018-08-27 20:45:44 +08:00
l1_geometry = 0.28 ; lInf_geometry = 5.94 ;
}
else if ( target = = DNN_TARGET_MYRIAD )
{
2019-03-29 21:42:58 +08:00
lInf_scores = 0.41 ;
l1_geometry = 0.28 ; lInf_geometry = 5.94 ;
2018-08-27 20:45:44 +08:00
}
2019-12-20 21:36:32 +08:00
else if ( target = = DNN_TARGET_CUDA_FP16 )
{
lInf_scores = 0.1 ;
l1_geometry = 0.3 ; lInf_geometry = 7 ;
}
2018-08-27 20:45:44 +08:00
else
{
2022-07-01 18:03:15 +08:00
l1_geometry = 1e-4 , lInf_geometry = 4.3e-3 ;
2018-08-27 20:45:44 +08:00
}
normAssert ( scores , blobFromNPY ( refScoresPath ) , " scores " , l1_scores , lInf_scores ) ;
normAssert ( geometry , blobFromNPY ( refGeometryPath ) , " geometry " , l1_geometry , lInf_geometry ) ;
2019-04-19 19:54:08 +08:00
expectNoFallbacksFromIE ( net ) ;
2018-06-07 21:29:04 +08:00
}
2018-07-14 00:47:50 +08:00
INSTANTIATE_TEST_CASE_P ( /**/ , Test_TensorFlow_nets , dnnBackendsAndTargets ( ) ) ;
2018-03-05 23:21:19 +08:00
2020-04-22 17:01:25 +08:00
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_single_conv )
2018-03-05 23:21:19 +08:00
{
2020-04-22 17:01:25 +08:00
float l1 = 0.00078 , lInf = 0.012 ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fp16_single_conv " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_max_pool_odd_same )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
float l1 = 0.00078 , lInf = 0.012 ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fp16_max_pool_odd_same " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_eltwise_add_mul )
{
float l1 = 0.00078 , lInf = 0.012 ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fp16_eltwise_add_mul " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_pad_and_concat )
{
float l1 = 0.00078 , lInf = 0.012 ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " fp16_pad_and_concat " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_padding_valid )
{
float l1 = 0.00078 , lInf = 0.012 ;
2019-03-29 21:42:58 +08:00
runTensorFlowNet ( " fp16_padding_valid " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_max_pool_even )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
float l1 = 0.00078 , lInf = 0.012 ;
2019-03-29 21:42:58 +08:00
// Reference output values are in range [0.0889, 1.651]
runTensorFlowNet ( " fp16_max_pool_even " , false , ( target = = DNN_TARGET_MYRIAD ) ? 0.003 : l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_deconvolution )
{
float l1 = 0.00078 , lInf = 0.012 ;
2019-03-29 21:42:58 +08:00
if ( target = = DNN_TARGET_MYRIAD ) {
l1 = 0.0041 ;
lInf = 0.024 ;
}
// Reference output values are in range [0, 10.75]
runTensorFlowNet ( " fp16_deconvolution " , false , l1 , lInf ) ;
2020-04-22 17:01:25 +08:00
}
TEST_P ( Test_TensorFlow_layers , fp16_weights_fp16_max_pool_odd_valid )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// [ GENERAL_ERROR ] AssertionFailed: !expired()
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2020020000)
2020-04-22 17:01:25 +08:00
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
float l1 = 0.00078 , lInf = 0.012 ;
if ( target = = DNN_TARGET_MYRIAD ) {
l1 = 0.0041 ;
lInf = 0.024 ;
}
2019-03-29 21:42:58 +08:00
// Reference output values are in range [0.418, 2.297]
runTensorFlowNet ( " fp16_max_pool_odd_valid " , false , l1 , lInf ) ;
}
TEST_P ( Test_TensorFlow_layers , fp16_padding_same )
{
// Reference output values are in range [-3.504, -0.002]
2019-06-25 02:55:32 +08:00
runTensorFlowNet ( " fp16_padding_same " , false , 7e-4 , 4e-3 ) ;
2018-06-27 21:34:36 +08:00
}
2018-04-28 23:50:37 +08:00
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , defun )
2018-03-05 23:21:19 +08:00
{
2018-04-28 23:50:37 +08:00
runTensorFlowNet ( " defun_dropout " ) ;
2018-03-05 23:21:19 +08:00
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , quantized )
2018-03-05 23:21:19 +08:00
{
runTensorFlowNet ( " uint8_single_conv " ) ;
2018-02-19 20:56:40 +08:00
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , lstm )
2017-08-25 19:45:03 +08:00
{
Merge pull request #14827 from YashasSamaga:cuda4dnn-csl-low
CUDA backend for the DNN module
* stub cuda4dnn design
* minor fixes for tests and doxygen
* add csl public api directory to module headers
* add low-level CSL components
* add high-level CSL components
* integrate csl::Tensor into backbone code
* switch to CPU iff unsupported; otherwise, fail on error
* add fully connected layer
* add softmax layer
* add activation layers
* support arbitary rank TensorDescriptor
* pass input wrappers to `initCUDA()`
* add 1d/2d/3d-convolution
* add pooling layer
* reorganize and refactor code
* fixes for gcc, clang and doxygen; remove cxx14/17 code
* add blank_layer
* add LRN layer
* add rounding modes for pooling layer
* split tensor.hpp into tensor.hpp and tensor_ops.hpp
* add concat layer
* add scale layer
* add batch normalization layer
* split math.cu into activations.cu and math.hpp
* add eltwise layer
* add flatten layer
* add tensor transform api
* add asymmetric padding support for convolution layer
* add reshape layer
* fix rebase issues
* add permute layer
* add padding support for concat layer
* refactor and reorganize code
* add normalize layer
* optimize bias addition in scale layer
* add prior box layer
* fix and optimize normalize layer
* add asymmetric padding support for pooling layer
* add event API
* improve pooling performance for some padding scenarios
* avoid over-allocation of compute resources to kernels
* improve prior box performance
* enable layer fusion
* add const layer
* add resize layer
* add slice layer
* add padding layer
* add deconvolution layer
* fix channelwise ReLU initialization
* add vector traits
* add vectorized versions of relu, clipped_relu, power
* add vectorized concat kernels
* improve concat_with_offsets performance
* vectorize scale and bias kernels
* add support for multi-billion element tensors
* vectorize prior box kernels
* fix address alignment check
* improve bias addition performance of conv/deconv/fc layers
* restructure code for supporting multiple targets
* add DNN_TARGET_CUDA_FP64
* add DNN_TARGET_FP16
* improve vectorization
* add region layer
* improve tensor API, add dynamic ranks
1. use ManagedPtr instead of a Tensor in backend wrapper
2. add new methods to tensor classes
- size_range: computes the combined size of for a given axis range
- tensor span/view can be constructed from a raw pointer and shape
3. the tensor classes can change their rank at runtime (previously rank was fixed at compile-time)
4. remove device code from tensor classes (as they are unused)
5. enforce strict conditions on tensor class APIs to improve debugging ability
* fix parametric relu activation
* add squeeze/unsqueeze tensor API
* add reorg layer
* optimize permute and enable 2d permute
* enable 1d and 2d slice
* add split layer
* add shuffle channel layer
* allow tensors of different ranks in reshape primitive
* patch SliceOp to allow Crop Layer
* allow extra shape inputs in reshape layer
* use `std::move_backward` instead of `std::move` for insert in resizable_static_array
* improve workspace management
* add spatial LRN
* add nms (cpu) to region layer
* add max pooling with argmax ( and a fix to limits.hpp)
* add max unpooling layer
* rename DNN_TARGET_CUDA_FP32 to DNN_TARGET_CUDA
* update supportBackend to be more rigorous
* remove stray include from preventing non-cuda build
* include op_cuda.hpp outside condition #if
* refactoring, fixes and many optimizations
* drop DNN_TARGET_CUDA_FP64
* fix gcc errors
* increase max. tensor rank limit to six
* add Interp layer
* drop custom layers; use BackendNode
* vectorize activation kernels
* fixes for gcc
* remove wrong assertion
* fix broken assertion in unpooling primitive
* fix build errors in non-CUDA build
* completely remove workspace from public API
* fix permute layer
* enable accuracy and perf. tests for DNN_TARGET_CUDA
* add asynchronous forward
* vectorize eltwise ops
* vectorize fill kernel
* fixes for gcc
* remove CSL headers from public API
* remove csl header source group from cmake
* update min. cudnn version in cmake
* add numerically stable FP32 log1pexp
* refactor code
* add FP16 specialization to cudnn based tensor addition
* vectorize scale1 and bias1 + minor refactoring
* fix doxygen build
* fix invalid alignment assertion
* clear backend wrappers before allocateLayers
* ignore memory lock failures
* do not allocate internal blobs
* integrate NVTX
* add numerically stable half precision log1pexp
* fix indentation, following coding style, improve docs
* remove accidental modification of IE code
* Revert "add asynchronous forward"
This reverts commit 1154b9da9da07e9b52f8a81bdcea48cf31c56f70.
* [cmake] throw error for unsupported CC versions
* fix rebase issues
* add more docs, refactor code, fix bugs
* minor refactoring and fixes
* resolve warnings/errors from clang
* remove haveCUDA() checks from supportBackend()
* remove NVTX integration
* changes based on review comments
* avoid exception when no CUDA device is present
* add color code for CUDA in Net::dump
2019-10-21 19:28:00 +08:00
if ( backend = = DNN_BACKEND_CUDA )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA ) ; /* not supported */
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Xlink, Failed to allocate graph: NC_ERROR
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
2021-11-30 20:08:35 +08:00
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 ) ;
}
2022-03-31 03:03:38 +08:00
# elif 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 ) ;
2021-11-30 20:08:35 +08:00
# endif
2019-06-15 20:17:25 +08:00
if ( backend = = DNN_BACKEND_OPENCV & & target = = DNN_TARGET_OPENCL_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
2021-11-30 20:08:35 +08:00
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " lstm " , true ) ;
runTensorFlowNet ( " lstm " , true , 0.0 , 0.0 , true ) ;
2017-08-25 19:45:03 +08:00
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , split )
2017-10-03 03:44:42 +08:00
{
2021-11-30 20:08:35 +08:00
2019-11-28 00:37:56 +08:00
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 ) ;
2020-02-26 22:51:18 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
2019-07-20 00:18:34 +08:00
runTensorFlowNet ( " split " ) ;
2019-12-02 21:16:06 +08:00
}
TEST_P ( Test_TensorFlow_layers , split_equals )
{
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 ) ;
2017-10-03 03:44:42 +08:00
runTensorFlowNet ( " split_equals " ) ;
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , resize_nearest_neighbor )
2017-10-06 19:24:01 +08:00
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// Cannot get memory!
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
2017-10-06 19:24:01 +08:00
runTensorFlowNet ( " resize_nearest_neighbor " ) ;
2022-03-31 03:03:38 +08:00
}
TEST_P ( Test_TensorFlow_layers , resize_nearest_neighbor_keras_upsampling2d )
{
2018-07-04 16:53:24 +08:00
runTensorFlowNet ( " keras_upsampling2d " ) ;
2017-10-06 19:24:01 +08:00
}
2020-12-10 19:27:23 +08:00
TEST_P ( Test_TensorFlow_layers , resize_nearest_neighbor_align_corners )
{
runTensorFlowNet ( " resize_nearest_neighbor " , false , 0.0 , 0.0 , false , " _align_corners " ) ;
}
TEST_P ( Test_TensorFlow_layers , resize_nearest_neighbor_half_pixel )
{
2021-11-30 20:08:35 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LT(2021040000)
2020-12-10 19:27:23 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
2021-11-30 20:08:35 +08:00
# endif
2020-12-10 19:27:23 +08:00
runTensorFlowNet ( " resize_nearest_neighbor " , false , 0.0 , 0.0 , false , " _half_pixel " ) ;
}
2020-04-04 21:02:17 +08:00
TEST_P ( Test_TensorFlow_layers , fused_resize_conv )
{
runTensorFlowNet ( " fused_resize_conv " ) ;
}
2022-03-31 03:03:38 +08:00
TEST_P ( Test_TensorFlow_layers , slice_crop2d )
2018-02-01 00:12:37 +08:00
{
2020-02-01 03:10:03 +08:00
double l1 = target = = DNN_TARGET_MYRIAD ? 4.9e-3 : default_l1 ;
runTensorFlowNet ( " crop2d " , false , l1 ) ;
2022-03-31 03:03:38 +08:00
}
TEST_P ( Test_TensorFlow_layers , slice_4d )
{
2018-02-01 00:12:37 +08:00
runTensorFlowNet ( " slice_4d " ) ;
2022-03-31 03:03:38 +08:00
}
TEST_P ( Test_TensorFlow_layers , slice_strided )
{
2019-04-30 20:33:32 +08:00
runTensorFlowNet ( " strided_slice " ) ;
2018-02-01 00:12:37 +08:00
}
2022-03-31 03:03:38 +08:00
TEST_P ( Test_TensorFlow_layers , softmax_keras )
2018-03-02 00:47:50 +08:00
{
runTensorFlowNet ( " keras_softmax " ) ;
2022-03-31 03:03:38 +08:00
}
TEST_P ( Test_TensorFlow_layers , softmax_slim )
{
2019-03-27 20:10:57 +08:00
runTensorFlowNet ( " slim_softmax " ) ;
2018-03-02 00:47:50 +08:00
}
2022-03-31 03:03:38 +08:00
TEST_P ( Test_TensorFlow_layers , softmax_slim_v2 )
2019-04-12 23:40:27 +08:00
{
# if defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD & &
2019-04-12 23:40:27 +08:00
getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
)
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2 , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
2019-04-12 23:40:27 +08:00
# endif
runTensorFlowNet ( " slim_softmax_v2 " ) ;
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , relu6 )
2018-03-02 00:47:50 +08:00
{
runTensorFlowNet ( " keras_relu6 " ) ;
2018-06-27 21:34:36 +08:00
runTensorFlowNet ( " keras_relu6 " , /*hasText*/ true ) ;
2018-03-02 00:47:50 +08:00
}
2019-04-29 23:55:09 +08:00
TEST_P ( Test_TensorFlow_layers , subpixel )
{
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Cannot get memory!
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 ) ;
// Cannot get memory!
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 , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# elif defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
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 ) ;
2022-03-31 03:03:38 +08:00
# endif
2019-04-29 23:55:09 +08:00
runTensorFlowNet ( " subpixel " ) ;
}
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , keras_mobilenet_head )
2018-03-02 00:47:50 +08:00
{
runTensorFlowNet ( " keras_mobilenet_head " ) ;
2019-08-25 04:14:26 +08:00
runTensorFlowNet ( " keras_learning_phase " ) ;
2018-03-02 00:47:50 +08:00
}
2020-12-03 06:48:18 +08:00
// TF case: align_corners=False, half_pixel_centers=False
2018-06-27 21:34:36 +08:00
TEST_P ( Test_TensorFlow_layers , resize_bilinear )
2018-04-24 19:59:59 +08:00
{
2021-03-24 17:28:05 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
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 ) ; // exception
# endif
2018-04-24 19:59:59 +08:00
runTensorFlowNet ( " resize_bilinear " ) ;
2020-12-03 06:48:18 +08:00
}
// TF case: align_corners=True, half_pixel_centers=False
TEST_P ( Test_TensorFlow_layers , resize_bilinear_align_corners )
{
2021-03-24 17:28:05 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021030000)
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 ) ; // exception
# endif
2020-12-03 06:48:18 +08:00
runTensorFlowNet ( " resize_bilinear " ,
false , 0.0 , 0.0 , false , // default parameters
" _align_corners " ) ;
}
// TF case: align_corners=False, half_pixel_centers=True
TEST_P ( Test_TensorFlow_layers , resize_bilinear_half_pixel )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
runTensorFlowNet ( " resize_bilinear " , false , 0.0 , 0.0 , false , " _half_pixel " ) ;
}
// TF case: align_corners=False, half_pixel_centers=False
TEST_P ( Test_TensorFlow_layers , resize_bilinear_factor )
{
2018-04-24 23:25:43 +08:00
runTensorFlowNet ( " resize_bilinear_factor " ) ;
2020-12-03 06:48:18 +08:00
}
// TF case: align_corners=False, half_pixel_centers=True
TEST_P ( Test_TensorFlow_layers , resize_bilinear_factor_half_pixel )
{
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
runTensorFlowNet ( " resize_bilinear_factor " , false , 0.0 , 0.0 , false , " _half_pixel " ) ;
}
// TF case: align_corners=True, half_pixel_centers=False
TEST_P ( Test_TensorFlow_layers , resize_bilinear_factor_align_corners )
{
runTensorFlowNet ( " resize_bilinear_factor " , false , 0.0 , 0.0 , false , " _align_corners " ) ;
}
// TF case: align_corners=False, half_pixel_centers=False
TEST_P ( Test_TensorFlow_layers , resize_bilinear_down )
{
2020-05-14 04:51:52 +08:00
runTensorFlowNet ( " resize_bilinear_down " ) ;
2018-04-24 19:59:59 +08:00
}
2021-09-03 20:32:29 +08:00
TEST_P ( Test_TensorFlow_layers , resize_concat_optimization )
{
2021-11-26 03:56:27 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH & & target ! = DNN_TARGET_CPU ) // Exception: Function contains several inputs and outputs with one friendly name! (HETERO bug?)
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_NGRAPH , CV_TEST_TAG_DNN_SKIP_IE_VERSION ) ;
# endif
2021-09-03 20:32:29 +08:00
runTensorFlowNet ( " resize_concat_optimization " ) ;
}
2020-04-05 01:27:59 +08:00
TEST_P ( Test_TensorFlow_layers , tf2_dense )
2020-03-25 20:34:28 +08:00
{
runTensorFlowNet ( " tf2_dense " ) ;
}
2020-05-27 03:01:47 +08:00
TEST_P ( Test_TensorFlow_layers , clip_by_value )
{
runTensorFlowNet ( " clip_by_value " ) ;
}
2020-04-05 01:27:59 +08:00
TEST_P ( Test_TensorFlow_layers , tf2_prelu )
{
2021-12-03 20:32:49 +08:00
if ( backend = = DNN_BACKEND_CUDA )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA ) ; // not supported; only across channels is supported
2022-03-31 03:03:38 +08:00
# if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2022010000)
// Eltwise executor got invalid input/output dims configuration
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 ) ;
// Input prelu:StatefulPartitionedCall/StatefulPartitionedCall/sequential/p_re_lu/add hasn't been found in primitiveIDs map
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
) ;
# elif defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2021040000)
2021-11-30 20:08:35 +08:00
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 ) ;
}
2022-03-31 03:03:38 +08:00
# elif 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 ) ;
2021-11-30 20:08:35 +08:00
# endif
2020-04-05 01:27:59 +08:00
runTensorFlowNet ( " tf2_prelu " ) ;
}
TEST_P ( Test_TensorFlow_layers , tf2_permute_nhwc_ncwh )
{
runTensorFlowNet ( " tf2_permute_nhwc_ncwh " ) ;
}
2019-04-12 23:40:27 +08:00
TEST_P ( Test_TensorFlow_layers , squeeze )
{
# if defined(INF_ENGINE_RELEASE)
2019-12-02 21:16:06 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 & & target = = DNN_TARGET_MYRIAD
2019-04-12 23:40:27 +08:00
& & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
)
2019-12-02 21:16:06 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_2 , CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER ) ;
2019-04-12 23:40:27 +08:00
# endif
int inpShapes [ ] [ 4 ] = { { 1 , 3 , 4 , 2 } , { 1 , 3 , 1 , 2 } , { 1 , 3 , 4 , 1 } , { 1 , 3 , 4 , 1 } } ; // TensorFlow's shape (NHWC)
int outShapes [ ] [ 3 ] = { { 3 , 4 , 2 } , { 1 , 3 , 2 } , { 1 , 3 , 4 } , { 1 , 3 , 4 } } ;
int squeeze_dims [ ] = { 0 , 2 , 3 , - 1 } ;
for ( int i = 0 ; i < 4 ; + + i )
{
SCOPED_TRACE ( format ( " i=%d " , i ) ) ;
std : : string pbtxt =
" node { name: \" input \" op: \" Placeholder \" "
" attr { key: \" data_format \" value { s: \" NHWC \" } } } "
" node { name: \" squeeze \" op: \" Squeeze \" input: \" input \" "
" attr { key: \" squeeze_dims \" value { list { i: " + format ( " %d " , squeeze_dims [ i ] ) + " }}}} " ;
Net net = readNetFromTensorflow ( 0 , 0 , pbtxt . c_str ( ) , pbtxt . size ( ) ) ;
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
Mat tfInp ( 4 , & inpShapes [ i ] [ 0 ] , CV_32F ) ;
randu ( tfInp , - 1 , 1 ) ;
// NHWC to NCHW
CV_Assert ( inpShapes [ i ] [ 0 ] = = 1 ) ;
std : : swap ( inpShapes [ i ] [ 2 ] , inpShapes [ i ] [ 3 ] ) ;
std : : swap ( inpShapes [ i ] [ 1 ] , inpShapes [ i ] [ 2 ] ) ;
Mat cvInp = tfInp . reshape ( 1 , tfInp . total ( ) / inpShapes [ i ] [ 1 ] ) . t ( ) ;
cvInp = cvInp . reshape ( 1 , 4 , & inpShapes [ i ] [ 0 ] ) ;
net . setInput ( cvInp ) ;
Mat out = net . forward ( ) ;
normAssert ( tfInp . reshape ( 1 , 3 , & outShapes [ i ] [ 0 ] ) , out , " " , default_l1 , default_lInf ) ;
}
}
2018-06-27 21:34:36 +08:00
INSTANTIATE_TEST_CASE_P ( /**/ , Test_TensorFlow_layers , dnnBackendsAndTargets ( ) ) ;
2018-06-26 18:32:28 +08:00
TEST ( Test_TensorFlow , two_inputs )
{
Net net = readNet ( path ( " two_inputs_net.pbtxt " ) ) ;
net . setPreferableBackend ( DNN_BACKEND_OPENCV ) ;
Mat firstInput ( 2 , 3 , CV_32FC1 ) , secondInput ( 2 , 3 , CV_32FC1 ) ;
randu ( firstInput , - 1 , 1 ) ;
randu ( secondInput , - 1 , 1 ) ;
net . setInput ( firstInput , " first_input " ) ;
net . setInput ( secondInput , " second_input " ) ;
Mat out = net . forward ( ) ;
normAssert ( out , firstInput + secondInput ) ;
}
2020-02-17 03:12:14 +08:00
TEST_P ( Test_TensorFlow_nets , Mask_RCNN )
2018-08-24 19:47:32 +08:00
{
2020-02-17 03:12:14 +08:00
static const double kMaskThreshold = 0.5 ;
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 ( target = = DNN_TARGET_MYRIAD & & getInferenceEngineVPUType ( ) = = CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X )
2020-02-26 22:51:18 +08:00
applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD_X , CV_TEST_TAG_DNN_SKIP_IE_NGRAPH ) ;
2020-02-17 03:12:14 +08:00
2020-02-28 18:14:37 +08:00
if ( target = = DNN_TARGET_CUDA_FP16 )
applyTestTag ( CV_TEST_TAG_DNN_SKIP_CUDA_FP16 ) ;
2019-05-27 20:14:18 +08:00
applyTestTag ( CV_TEST_TAG_MEMORY_1GB , CV_TEST_TAG_DEBUG_VERYLONG ) ;
2019-06-20 21:43:28 +08:00
Mat img = imread ( findDataFile ( " dnn/street.png " ) ) ;
std : : string proto = findDataFile ( " dnn/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt " ) ;
2018-08-24 19:47:32 +08:00
std : : string model = findDataFile ( " dnn/mask_rcnn_inception_v2_coco_2018_01_28.pb " , false ) ;
Net net = readNetFromTensorflow ( model , proto ) ;
Mat refDetections = blobFromNPY ( path ( " mask_rcnn_inception_v2_coco_2018_01_28.detection_out.npy " ) ) ;
Mat refMasks = blobFromNPY ( path ( " mask_rcnn_inception_v2_coco_2018_01_28.detection_masks.npy " ) ) ;
Mat blob = blobFromImage ( img , 1.0f , Size ( 800 , 800 ) , Scalar ( ) , true , false ) ;
2020-02-17 03:12:14 +08:00
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
2018-08-24 19:47:32 +08:00
net . setInput ( blob ) ;
// Mask-RCNN predicts bounding boxes and segmentation masks.
std : : vector < String > outNames ( 2 ) ;
outNames [ 0 ] = " detection_out_final " ;
outNames [ 1 ] = " detection_masks " ;
std : : vector < Mat > outs ;
net . forward ( outs , outNames ) ;
Mat outDetections = outs [ 0 ] ;
Mat outMasks = outs [ 1 ] ;
2020-02-17 03:12:14 +08:00
2021-11-26 03:56:27 +08:00
double scoreDiff = ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD ) ? 0.2 : 2e-5 ;
2020-02-17 03:12:14 +08:00
double iouDiff = ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD ) ? 0.018 : default_lInf ;
normAssertDetections ( refDetections , outDetections , " " , /*threshold for zero confidence*/ 1e-5 , scoreDiff , iouDiff ) ;
2018-08-24 19:47:32 +08:00
// Output size of masks is NxCxHxW where
// N - number of detected boxes
// C - number of classes (excluding background)
// HxW - segmentation shape
const int numDetections = outDetections . size [ 2 ] ;
int masksSize [ ] = { 1 , numDetections , outMasks . size [ 2 ] , outMasks . size [ 3 ] } ;
Mat masks ( 4 , & masksSize [ 0 ] , CV_32F ) ;
std : : vector < cv : : Range > srcRanges ( 4 , cv : : Range : : all ( ) ) ;
std : : vector < cv : : Range > dstRanges ( 4 , cv : : Range : : all ( ) ) ;
outDetections = outDetections . reshape ( 1 , outDetections . total ( ) / 7 ) ;
for ( int i = 0 ; i < numDetections ; + + i )
{
// Get a class id for this bounding box and copy mask only for that class.
int classId = static_cast < int > ( outDetections . at < float > ( i , 1 ) ) ;
srcRanges [ 0 ] = dstRanges [ 1 ] = cv : : Range ( i , i + 1 ) ;
srcRanges [ 1 ] = cv : : Range ( classId , classId + 1 ) ;
outMasks ( srcRanges ) . copyTo ( masks ( dstRanges ) ) ;
}
cv : : Range topRefMasks [ ] = { Range : : all ( ) , Range ( 0 , numDetections ) , Range : : all ( ) , Range : : all ( ) } ;
2020-02-17 03:12:14 +08:00
refMasks = refMasks ( & topRefMasks [ 0 ] ) ;
// make binary masks
cv : : threshold ( masks . reshape ( 1 , 1 ) , masks , kMaskThreshold , 1 , THRESH_BINARY ) ;
cv : : threshold ( refMasks . reshape ( 1 , 1 ) , refMasks , kMaskThreshold , 1 , THRESH_BINARY ) ;
double inter = cv : : countNonZero ( masks & refMasks ) ;
double area = cv : : countNonZero ( masks | refMasks ) ;
2021-11-26 03:56:27 +08:00
EXPECT_GE ( inter / area , ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD ) ? 0.98 : 0.99 ) ;
2020-02-17 03:12:14 +08:00
if ( backend = = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH )
expectNoFallbacks ( net ) ;
2018-08-24 19:47:32 +08:00
}
2020-05-26 15:51:26 +08:00
TEST_P ( Test_TensorFlow_nets , EfficientDet )
{
if ( target ! = DNN_TARGET_CPU )
{
if ( target = = DNN_TARGET_OPENCL_FP16 ) applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL_FP16 ) ;
if ( target = = DNN_TARGET_OPENCL ) applyTestTag ( CV_TEST_TAG_DNN_SKIP_OPENCL ) ;
if ( target = = DNN_TARGET_MYRIAD ) applyTestTag ( CV_TEST_TAG_DNN_SKIP_IE_MYRIAD ) ;
}
checkBackend ( ) ;
std : : string proto = findDataFile ( " dnn/efficientdet-d0.pbtxt " ) ;
2020-06-01 00:18:37 +08:00
std : : string model = findDataFile ( " dnn/efficientdet-d0.pb " , false ) ;
2020-05-26 15:51:26 +08:00
Net net = readNetFromTensorflow ( model , proto ) ;
Mat img = imread ( findDataFile ( " dnn/dog416.png " ) ) ;
Mat blob = blobFromImage ( img , 1.0 / 255 , Size ( 512 , 512 ) , Scalar ( 123.675 , 116.28 , 103.53 ) ) ;
net . setPreferableBackend ( backend ) ;
net . setPreferableTarget ( target ) ;
net . setInput ( blob ) ;
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat out = net . forward ( ) ;
// References are from test for TensorFlow model.
Mat ref = ( Mat_ < float > ( 3 , 7 ) < < 0 , 1 , 0.8437444 , 0.153996080160141 , 0.20534580945968628 , 0.7463544607162476 , 0.7414066195487976 ,
0 , 17 , 0.8245924 , 0.16657517850399017 , 0.3996818959712982 , 0.4111558794975281 , 0.9306337833404541 ,
0 , 7 , 0.8039304 , 0.6118435263633728 , 0.13175517320632935 , 0.9065558314323425 , 0.2943994700908661 ) ;
double scoreDiff = ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD ) ? 4e-3 : 1e-5 ;
double iouDiff = ( target = = DNN_TARGET_OPENCL_FP16 | | target = = DNN_TARGET_MYRIAD ) ? 2e-3 : 1e-4 ;
2020-06-11 22:01:48 +08:00
if ( target = = DNN_TARGET_CUDA_FP16 )
{
scoreDiff = 0.002 ;
2020-11-21 20:05:20 +08:00
iouDiff = 0.005 ;
2020-06-11 22:01:48 +08:00
}
2020-05-26 15:51:26 +08:00
normAssertDetections ( ref , out , " " , 0.5 , scoreDiff , iouDiff ) ;
expectNoFallbacksFromIE ( net ) ;
}
2022-05-19 04:52:56 +08:00
TEST ( Test_TensorFlow_Importer , tf_graph_simplifier_buffer_overflow_21852 )
{
uint8_t payload [ ] = { 0x08 , 0x08 , 0x0a , 0x00 , 0x0a , 0x00 } ;
EXPECT_ANY_THROW ( readNetFromTensorflow ( reinterpret_cast < const char * > ( payload ) , sizeof ( payload ) / sizeof ( payload [ 0 ] ) ) ) ;
}
// can be triggered with -fsanitize=address
TEST ( Test_TensorFlow_Importer , tf_graph_simplifier_buffer_overflow_21947 )
{
uint8_t payload [ ] = { 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 ,
0xba , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 ,
0x0a , 0xbd , 0x00 , 0x1a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0xba ,
0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 ,
0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0xba , 0x0a , 0x00 ,
0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0xba ,
0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 ,
0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x2a , 0x00 , 0xba , 0x0a , 0x00 ,
0x0a , 0x00 , 0x5d , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x00 , 0x0a , 0x40 } ;
EXPECT_ANY_THROW ( readNetFromTensorflow ( reinterpret_cast < const char * > ( payload ) , sizeof ( payload ) / sizeof ( payload [ 0 ] ) ) ) ;
}
2017-06-26 18:35:51 +08:00
}