@@ -12,14 +12,18 @@ namespace cvtest
12
12
using namespace cv ;
13
13
using namespace dnn ;
14
14
15
- static void loadNet (const std::string& weights, const std::string& proto,
16
- const std::string& scheduler, int inWidth, int inHeight,
17
- const std::string& outputLayer, const std::string& framework,
18
- int targetId, Net* net, int * outputLayerId)
15
+ static void loadNet (std::string weights, std::string proto, std::string scheduler,
16
+ int inWidth, int inHeight, const std::string& outputLayer,
17
+ const std::string& framework, int targetId, Net* net)
19
18
{
20
19
Mat input (inHeight, inWidth, CV_32FC3);
21
20
randu (input, 0 .0f , 1 .0f );
22
21
22
+ weights = findDataFile (weights, false );
23
+ if (!proto.empty ())
24
+ proto = findDataFile (proto, false );
25
+ if (!scheduler.empty ())
26
+ scheduler = findDataFile (scheduler, false );
23
27
if (framework == " caffe" )
24
28
{
25
29
*net = cv::dnn::readNetFromCaffe (proto, weights);
@@ -35,106 +39,116 @@ static void loadNet(const std::string& weights, const std::string& proto,
35
39
else
36
40
CV_Error (Error::StsNotImplemented, " Unknown framework " + framework);
37
41
38
- net->setBlob ( " " , cv::dnn:: blobFromImage (input, 1.0 , false ));
42
+ net->setInput ( blobFromImage (input, 1.0 , false ));
39
43
net->setPreferableBackend (DNN_BACKEND_HALIDE);
40
- net->compileHalide (scheduler);
41
- *outputLayerId = net->getLayerId (outputLayer);
42
- net->forward (*outputLayerId);
44
+ net->setHalideScheduler (scheduler);
45
+ net->forward (outputLayer);
43
46
}
44
47
45
48
PERF_TEST (GoogLeNet, HalidePerfTest)
46
49
{
47
- Net net;
48
- int outputLayerId;
49
- loadNet (findDataFile (" dnn/bvlc_googlenet.caffemodel" ),
50
- findDataFile (" dnn/bvlc_googlenet.prototxt" ),
51
- " " , 227 , 227 , " prob" , " caffe" , DNN_TARGET_CPU, &net, &outputLayerId);
52
-
53
- TEST_CYCLE_N (10 )
54
- {
55
- net.forward (outputLayerId);
50
+ try {
51
+ Net net;
52
+ loadNet (" dnn/bvlc_googlenet.caffemodel" , " dnn/bvlc_googlenet.prototxt" ,
53
+ " " , 227 , 227 , " prob" , " caffe" , DNN_TARGET_CPU, &net);
54
+
55
+ TEST_CYCLE_N (10 )
56
+ {
57
+ net.forward ();
58
+ }
59
+ SANITY_CHECK_NOTHING ();
60
+ } catch (SkipTestException& e) {
61
+ throw PerfSkipTestException ();
56
62
}
57
- SANITY_CHECK_NOTHING ();
58
63
}
59
64
60
65
PERF_TEST (AlexNet, HalidePerfTest)
61
66
{
62
- Net net;
63
- int outputLayerId;
64
- loadNet (findDataFile (" dnn/bvlc_alexnet.caffemodel" ),
65
- findDataFile (" dnn/bvlc_alexnet.prototxt" ),
66
- findDataFile (" dnn/halide_scheduler_alexnet.yml" ),
67
- 227 , 227 , " prob" , " caffe" , DNN_TARGET_CPU, &net, &outputLayerId);
68
-
69
- TEST_CYCLE_N (10 )
70
- {
71
- net.forward (outputLayerId);
67
+ try {
68
+ Net net;
69
+ loadNet (" dnn/bvlc_alexnet.caffemodel" , " dnn/bvlc_alexnet.prototxt" ,
70
+ " dnn/halide_scheduler_alexnet.yml" , 227 , 227 , " prob" , " caffe" ,
71
+ DNN_TARGET_CPU, &net);
72
+
73
+ TEST_CYCLE_N (10 )
74
+ {
75
+ net.forward ();
76
+ }
77
+ SANITY_CHECK_NOTHING ();
78
+ } catch (SkipTestException& e) {
79
+ throw PerfSkipTestException ();
72
80
}
73
- SANITY_CHECK_NOTHING ();
74
81
}
75
82
76
- // PERF_TEST(ResNet50, HalidePerfTest)
77
- // {
78
- // Net net;
79
- // int outputLayerId;
80
- // loadNet(findDataFile("dnn/ResNet-50-model.caffemodel"),
81
- // findDataFile("dnn/ResNet-50-deploy.prototxt"),
82
- // findDataFile("dnn/halide_scheduler_resnet_50.yml"),
83
- // 224, 224, "prob", "caffe", DNN_TARGET_CPU, &net, &outputLayerId);
84
- //
85
- // TEST_CYCLE_N(10)
86
- // {
87
- // net.forward(outputLayerId);
88
- // }
89
- // SANITY_CHECK_NOTHING();
90
- // }
91
-
92
- // PERF_TEST(SqueezeNet_v1_1, HalidePerfTest)
93
- // {
94
- // Net net;
95
- // int outputLayerId;
96
- // loadNet(findDataFile("dnn/squeezenet_v1_1.caffemodel"),
97
- // findDataFile("dnn/squeezenet_v1_1.prototxt"),
98
- // findDataFile("dnn/halide_scheduler_squeezenet_v1_1.yml"),
99
- // 227, 227, "prob", "caffe", DNN_TARGET_CPU, &net, &outputLayerId);
100
- //
101
- // TEST_CYCLE_N(10)
102
- // {
103
- // net.forward(outputLayerId);
104
- // }
105
- // SANITY_CHECK_NOTHING();
106
- // }
83
+ PERF_TEST (ResNet50, HalidePerfTest)
84
+ {
85
+ try {
86
+ Net net;
87
+ loadNet (" dnn/ResNet-50-model.caffemodel" , " dnn/ResNet-50-deploy.prototxt" ,
88
+ " dnn/halide_scheduler_resnet_50.yml" , 224 , 224 , " prob" , " caffe" ,
89
+ DNN_TARGET_CPU, &net);
90
+
91
+ TEST_CYCLE_N (10 )
92
+ {
93
+ net.forward ();
94
+ }
95
+ SANITY_CHECK_NOTHING ();
96
+ } catch (SkipTestException& e) {
97
+ throw PerfSkipTestException ();
98
+ }
99
+ }
100
+
101
+ PERF_TEST (SqueezeNet_v1_1, HalidePerfTest)
102
+ {
103
+ try {
104
+ Net net;
105
+ loadNet (" dnn/squeezenet_v1_1.caffemodel" , " dnn/squeezenet_v1_1.prototxt" ,
106
+ " dnn/halide_scheduler_squeezenet_v1_1.yml" , 227 , 227 , " prob" ,
107
+ " caffe" , DNN_TARGET_CPU, &net);
108
+
109
+ TEST_CYCLE_N (10 )
110
+ {
111
+ net.forward ();
112
+ }
113
+ SANITY_CHECK_NOTHING ();
114
+ } catch (SkipTestException& e) {
115
+ throw PerfSkipTestException ();
116
+ }
117
+ }
107
118
108
119
PERF_TEST (Inception_5h, HalidePerfTest)
109
120
{
110
- Net net;
111
- int outputLayerId;
112
- loadNet (findDataFile (" dnn/tensorflow_inception_graph.pb" ), " " ,
113
- findDataFile (" dnn/halide_scheduler_inception_5h.yml" ),
114
- 224 , 224 , " softmax2" , " tensorflow" , DNN_TARGET_CPU,
115
- &net, &outputLayerId);
116
-
117
- TEST_CYCLE_N (10 )
118
- {
119
- net.forward (outputLayerId);
121
+ try {
122
+ Net net;
123
+ loadNet (" dnn/tensorflow_inception_graph.pb" , " " ,
124
+ " dnn/halide_scheduler_inception_5h.yml" ,
125
+ 224 , 224 , " softmax2" , " tensorflow" , DNN_TARGET_CPU, &net);
126
+
127
+ TEST_CYCLE_N (10 )
128
+ {
129
+ net.forward (" softmax2" );
130
+ }
131
+ SANITY_CHECK_NOTHING ();
132
+ } catch (SkipTestException& e) {
133
+ throw PerfSkipTestException ();
120
134
}
121
- SANITY_CHECK_NOTHING ();
122
135
}
123
136
124
137
PERF_TEST (ENet, HalidePerfTest)
125
138
{
126
- Net net;
127
- int outputLayerId;
128
- loadNet (findDataFile (" dnn/Enet-model-best.net" ), " " ,
129
- findDataFile (" dnn/halide_scheduler_enet.yml" ),
130
- 512 , 256 , " l367_Deconvolution" , " torch" , DNN_TARGET_CPU,
131
- &net, &outputLayerId);
132
-
133
- TEST_CYCLE_N (10 )
134
- {
135
- net.forward (outputLayerId);
139
+ try {
140
+ Net net;
141
+ loadNet (" dnn/Enet-model-best.net" , " " , " dnn/halide_scheduler_enet.yml" ,
142
+ 512 , 256 , " l367_Deconvolution" , " torch" , DNN_TARGET_CPU, &net);
143
+
144
+ TEST_CYCLE_N (10 )
145
+ {
146
+ net.forward (" l367_Deconvolution" );
147
+ }
148
+ SANITY_CHECK_NOTHING ();
149
+ } catch (SkipTestException& e) {
150
+ throw PerfSkipTestException ();
136
151
}
137
- SANITY_CHECK_NOTHING ();
138
152
}
139
153
#endif // HAVE_HALIDE
140
154
0 commit comments