@@ -34,7 +34,7 @@ static void loadNet(const std::string& weights, const std::string& proto,
34
34
static void test (const std::string& weights, const std::string& proto,
35
35
const std::string& scheduler, int inWidth, int inHeight,
36
36
const std::string& outputLayer, const std::string& framework,
37
- int targetId)
37
+ int targetId, double l1 = 1e-5 , double lInf = 1e-4 )
38
38
{
39
39
Mat input (inHeight, inWidth, CV_32FC3), outputDefault, outputHalide;
40
40
randu (input, 0 .0f , 1 .0f );
@@ -43,23 +43,23 @@ static void test(const std::string& weights, const std::string& proto,
43
43
loadNet (weights, proto, framework, &netDefault);
44
44
loadNet (weights, proto, framework, &netHalide);
45
45
46
- netDefault.setInput (blobFromImage (input.clone (), 1 .0f , false ));
46
+ netDefault.setInput (blobFromImage (input.clone (), 1 .0f , Size (), Scalar (), false ));
47
47
outputDefault = netDefault.forward (outputLayer).clone ();
48
48
49
- netHalide.setInput (blobFromImage (input.clone (), 1 .0f , false ));
49
+ netHalide.setInput (blobFromImage (input.clone (), 1 .0f , Size (), Scalar (), false ));
50
50
netHalide.setPreferableBackend (DNN_BACKEND_HALIDE);
51
51
netHalide.setPreferableTarget (targetId);
52
52
netHalide.setHalideScheduler (scheduler);
53
53
outputHalide = netHalide.forward (outputLayer).clone ();
54
54
55
- normAssert (outputDefault, outputHalide);
55
+ normAssert (outputDefault, outputHalide, " First run " , l1, lInf );
56
56
57
57
// An extra test: change input.
58
58
input *= 0 .1f ;
59
- netDefault.setInput (blobFromImage (input.clone (), 1.0 , false ));
60
- netHalide.setInput (blobFromImage (input.clone (), 1.0 , false ));
59
+ netDefault.setInput (blobFromImage (input.clone (), 1.0 , Size (), Scalar (), false ));
60
+ netHalide.setInput (blobFromImage (input.clone (), 1.0 , Size (), Scalar (), false ));
61
61
62
- normAssert (outputDefault, outputHalide);
62
+ normAssert (outputDefault, outputHalide, " Second run " , l1, lInf );
63
63
64
64
// Swap backends.
65
65
netHalide.setPreferableBackend (DNN_BACKEND_DEFAULT);
@@ -71,7 +71,7 @@ static void test(const std::string& weights, const std::string& proto,
71
71
netDefault.setHalideScheduler (scheduler);
72
72
outputHalide = netDefault.forward (outputLayer).clone ();
73
73
74
- normAssert (outputDefault, outputHalide);
74
+ normAssert (outputDefault, outputHalide, " Swap backends " , l1, lInf );
75
75
}
76
76
77
77
// //////////////////////////////////////////////////////////////////////////////
@@ -119,7 +119,7 @@ TEST(Reproducibility_ENet_Halide, Accuracy)
119
119
{
120
120
test (findDataFile (" dnn/Enet-model-best.net" , false ), " " ,
121
121
findDataFile (" dnn/halide_scheduler_enet.yml" , false ),
122
- 512 , 512 , " l367_Deconvolution" , " torch" , DNN_TARGET_CPU);
122
+ 512 , 512 , " l367_Deconvolution" , " torch" , DNN_TARGET_CPU, 2e-5 , 0.15 );
123
123
};
124
124
// //////////////////////////////////////////////////////////////////////////////
125
125
// OpenCL target
@@ -166,7 +166,7 @@ TEST(Reproducibility_ENet_Halide_opencl, Accuracy)
166
166
{
167
167
test (findDataFile (" dnn/Enet-model-best.net" , false ), " " ,
168
168
findDataFile (" dnn/halide_scheduler_opencl_enet.yml" , false ),
169
- 512 , 512 , " l367_Deconvolution" , " torch" , DNN_TARGET_OPENCL);
169
+ 512 , 512 , " l367_Deconvolution" , " torch" , DNN_TARGET_OPENCL, 2e-5 , 0.14 );
170
170
};
171
171
#endif // HAVE_HALIDE
172
172
0 commit comments