Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
47917963
Commit
47917963
authored
Jan 23, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10655 from dkurt:dnn_tests
parents
12ea8477
a3d74704
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
242 additions
and
227 deletions
+242
-227
dnn.cpp
modules/dnn/src/dnn.cpp
+21
-20
test_backends.cpp
modules/dnn/test/test_backends.cpp
+195
-0
test_caffe_importer.cpp
modules/dnn/test/test_caffe_importer.cpp
+24
-1
test_halide_nets.cpp
modules/dnn/test/test_halide_nets.cpp
+0
-205
test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+2
-1
No files found.
modules/dnn/src/dnn.cpp
View file @
47917963
...
...
@@ -314,7 +314,7 @@ struct LayerData
{
LayerData
()
:
id
(
-
1
),
flag
(
0
)
{}
LayerData
(
int
_id
,
const
String
&
_name
,
const
String
&
_type
,
LayerParams
&
_params
)
:
id
(
_id
),
name
(
_name
),
type
(
_type
),
params
(
_params
),
flag
(
0
)
:
id
(
_id
),
name
(
_name
),
type
(
_type
),
params
(
_params
),
skip
(
false
),
flag
(
0
)
{
CV_TRACE_FUNCTION
();
...
...
@@ -343,7 +343,7 @@ struct LayerData
// Computation nodes of implemented backends (except DEFAULT).
std
::
map
<
int
,
Ptr
<
BackendNode
>
>
backendNodes
;
// Flag for skip layer computation for specific backend.
std
::
map
<
int
,
bool
>
skipFlags
;
bool
skip
;
int
flag
;
...
...
@@ -732,7 +732,7 @@ struct Net::Impl
{
LayerData
&
ld
=
it
->
second
;
Ptr
<
Layer
>
layer
=
ld
.
layerInstance
;
if
(
layer
->
supportBackend
(
DNN_BACKEND_HALIDE
)
&&
!
ld
.
skip
Flags
[
DNN_BACKEND_HALIDE
]
)
if
(
layer
->
supportBackend
(
DNN_BACKEND_HALIDE
)
&&
!
ld
.
skip
)
{
CV_Assert
(
!
ld
.
backendNodes
[
DNN_BACKEND_HALIDE
].
empty
());
bool
scheduled
=
scheduler
.
process
(
ld
.
backendNodes
[
DNN_BACKEND_HALIDE
]);
...
...
@@ -780,7 +780,7 @@ struct Net::Impl
it
->
second
.
outputBlobs
.
clear
();
it
->
second
.
internals
.
clear
();
}
it
->
second
.
skip
Flags
.
clear
()
;
it
->
second
.
skip
=
false
;
//it->second.consumers.clear();
Ptr
<
Layer
>
currLayer
=
it
->
second
.
layerInstance
;
...
...
@@ -797,7 +797,7 @@ struct Net::Impl
}
it
=
layers
.
find
(
0
);
CV_Assert
(
it
!=
layers
.
end
());
it
->
second
.
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
it
->
second
.
skip
=
true
;
layersTimings
.
clear
();
}
...
...
@@ -1041,14 +1041,15 @@ struct Net::Impl
layerTop
->
tryAttach
(
ldBot
.
backendNodes
[
preferableBackend
]);
if
(
!
fusedNode
.
empty
())
{
ldTop
.
skip
Flags
[
preferableBackend
]
=
true
;
ldTop
.
skip
=
true
;
ldBot
.
backendNodes
[
preferableBackend
]
=
fusedNode
;
ldBot
.
outputBlobsWrappers
=
ldTop
.
outputBlobsWrappers
;
continue
;
}
}
}
// No layers fusion.
ldTop
.
skip
Flags
[
preferableBackend
]
=
false
;
ldTop
.
skip
=
false
;
if
(
preferableBackend
==
DNN_BACKEND_HALIDE
)
{
ldTop
.
backendNodes
[
DNN_BACKEND_HALIDE
]
=
...
...
@@ -1173,7 +1174,7 @@ struct Net::Impl
{
int
lid
=
it
->
first
;
LayerData
&
ld
=
layers
[
lid
];
if
(
ld
.
skip
Flags
[
DNN_BACKEND_DEFAULT
]
)
if
(
ld
.
skip
)
{
printf_
((
"skipped %s: %s
\n
"
,
ld
.
layerInstance
->
name
.
c_str
(),
ld
.
layerInstance
->
type
.
c_str
()));
continue
;
...
...
@@ -1206,7 +1207,7 @@ struct Net::Impl
if
(
currLayer
->
setBatchNorm
(
nextBNormLayer
)
)
{
printf_
((
"
\t
fused with %s
\n
"
,
nextBNormLayer
->
name
.
c_str
()));
bnormData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
bnormData
->
skip
=
true
;
ld
.
outputBlobs
=
layers
[
lpNext
.
lid
].
outputBlobs
;
ld
.
outputBlobsWrappers
=
layers
[
lpNext
.
lid
].
outputBlobsWrappers
;
if
(
bnormData
->
consumers
.
size
()
==
1
)
...
...
@@ -1227,7 +1228,7 @@ struct Net::Impl
if
(
currLayer
->
setScale
(
nextScaleLayer
)
)
{
printf_
((
"
\t
fused with %s
\n
"
,
nextScaleLayer
->
name
.
c_str
()));
scaleData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
scaleData
->
skip
=
true
;
ld
.
outputBlobs
=
layers
[
lpNext
.
lid
].
outputBlobs
;
ld
.
outputBlobsWrappers
=
layers
[
lpNext
.
lid
].
outputBlobsWrappers
;
if
(
scaleData
->
consumers
.
size
()
==
1
)
...
...
@@ -1257,7 +1258,7 @@ struct Net::Impl
{
LayerData
*
activData
=
nextData
;
printf_
((
"
\t
fused with %s
\n
"
,
nextActivLayer
->
name
.
c_str
()));
activData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
activData
->
skip
=
true
;
ld
.
outputBlobs
=
layers
[
lpNext
.
lid
].
outputBlobs
;
ld
.
outputBlobsWrappers
=
layers
[
lpNext
.
lid
].
outputBlobsWrappers
;
...
...
@@ -1281,7 +1282,7 @@ struct Net::Impl
LayerData
*
eltwiseData
=
nextData
;
// go down from the second input and find the first non-skipped layer.
LayerData
*
downLayerData
=
&
layers
[
eltwiseData
->
inputBlobsId
[
1
].
lid
];
while
(
downLayerData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
)
while
(
downLayerData
->
skip
)
{
downLayerData
=
&
layers
[
downLayerData
->
inputBlobsId
[
0
].
lid
];
}
...
...
@@ -1291,7 +1292,7 @@ struct Net::Impl
{
// go down from the first input and find the first non-skipped layer
downLayerData
=
&
layers
[
eltwiseData
->
inputBlobsId
[
0
].
lid
];
while
(
downLayerData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
)
while
(
downLayerData
->
skip
)
{
if
(
!
downLayerData
->
type
.
compare
(
"Eltwise"
)
)
downLayerData
=
&
layers
[
downLayerData
->
inputBlobsId
[
1
].
lid
];
...
...
@@ -1326,8 +1327,8 @@ struct Net::Impl
ld
.
inputBlobsWrappers
.
push_back
(
firstConvLayerData
->
outputBlobsWrappers
[
0
]);
printf_
((
"
\t
fused with %s
\n
"
,
nextEltwiseLayer
->
name
.
c_str
()));
printf_
((
"
\t
fused with %s
\n
"
,
nextActivLayer
->
name
.
c_str
()));
eltwiseData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
nextData
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
eltwiseData
->
skip
=
true
;
nextData
->
skip
=
true
;
// This optimization for cases like
// some_layer conv
// | |
...
...
@@ -1419,7 +1420,7 @@ struct Net::Impl
{
LayerPin
pin
=
ld
.
inputBlobsId
[
i
];
LayerData
*
inp_i_data
=
&
layers
[
pin
.
lid
];
while
(
inp_i_data
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
&&
while
(
inp_i_data
->
skip
&&
inp_i_data
->
inputBlobsId
.
size
()
==
1
&&
inp_i_data
->
consumers
.
size
()
==
1
)
{
...
...
@@ -1430,7 +1431,7 @@ struct Net::Impl
layers
[
ld
.
inputBlobsId
[
i
].
lid
].
getLayerInstance
()
->
name
.
c_str
(),
inp_i_data
->
getLayerInstance
()
->
name
.
c_str
()));
if
(
inp_i_data
->
skip
Flags
[
DNN_BACKEND_DEFAULT
]
||
inp_i_data
->
consumers
.
size
()
!=
1
)
if
(
inp_i_data
->
skip
||
inp_i_data
->
consumers
.
size
()
!=
1
)
break
;
realinputs
[
i
]
=
pin
;
}
...
...
@@ -1460,7 +1461,7 @@ struct Net::Impl
// new data but the same Mat object.
CV_Assert
(
curr_output
.
data
==
output_slice
.
data
,
oldPtr
==
&
curr_output
);
}
ld
.
skip
Flags
[
DNN_BACKEND_DEFAULT
]
=
true
;
ld
.
skip
=
true
;
printf_
((
"
\t
optimized out Concat layer %s
\n
"
,
concatLayer
->
name
.
c_str
()));
}
}
...
...
@@ -1524,7 +1525,7 @@ struct Net::Impl
if
(
preferableBackend
==
DNN_BACKEND_DEFAULT
||
!
layer
->
supportBackend
(
preferableBackend
))
{
if
(
!
ld
.
skip
Flags
[
DNN_BACKEND_DEFAULT
]
)
if
(
!
ld
.
skip
)
{
if
(
preferableBackend
==
DNN_BACKEND_DEFAULT
&&
preferableTarget
==
DNN_TARGET_OPENCL
)
{
...
...
@@ -1554,7 +1555,7 @@ struct Net::Impl
else
tm
.
reset
();
}
else
if
(
!
ld
.
skip
Flags
[
preferableBackend
]
)
else
if
(
!
ld
.
skip
)
{
Ptr
<
BackendNode
>
node
=
ld
.
backendNodes
[
preferableBackend
];
if
(
preferableBackend
==
DNN_BACKEND_HALIDE
)
...
...
modules/dnn/test/test_backends.cpp
0 → 100644
View file @
47917963
// 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.
//
// Copyright (C) 2018, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "test_precomp.hpp"
#include "opencv2/core/ocl.hpp"
namespace
cvtest
{
using
namespace
cv
;
using
namespace
dnn
;
using
namespace
testing
;
CV_ENUM
(
DNNBackend
,
DNN_BACKEND_DEFAULT
,
DNN_BACKEND_HALIDE
)
CV_ENUM
(
DNNTarget
,
DNN_TARGET_CPU
,
DNN_TARGET_OPENCL
)
static
void
loadNet
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
const
std
::
string
&
framework
,
Net
*
net
)
{
if
(
framework
==
"caffe"
)
*
net
=
cv
::
dnn
::
readNetFromCaffe
(
proto
,
weights
);
else
if
(
framework
==
"torch"
)
*
net
=
cv
::
dnn
::
readNetFromTorch
(
weights
);
else
if
(
framework
==
"tensorflow"
)
*
net
=
cv
::
dnn
::
readNetFromTensorflow
(
weights
,
proto
);
else
CV_Error
(
Error
::
StsNotImplemented
,
"Unknown framework "
+
framework
);
}
class
DNNTestNetwork
:
public
TestWithParam
<
tuple
<
DNNBackend
,
DNNTarget
>
>
{
public
:
dnn
::
Backend
backend
;
dnn
::
Target
target
;
DNNTestNetwork
()
{
backend
=
(
dnn
::
Backend
)(
int
)
get
<
0
>
(
GetParam
());
target
=
(
dnn
::
Target
)(
int
)
get
<
1
>
(
GetParam
());
}
void
processNet
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
Size
inpSize
,
const
std
::
string
&
outputLayer
,
const
std
::
string
&
framework
,
const
std
::
string
&
halideScheduler
=
""
,
double
l1
=
1e-5
,
double
lInf
=
1e-4
)
{
// Create a common input blob.
int
blobSize
[]
=
{
1
,
3
,
inpSize
.
height
,
inpSize
.
width
};
Mat
inp
(
4
,
blobSize
,
CV_32FC1
);
randu
(
inp
,
0.0
f
,
1.0
f
);
processNet
(
weights
,
proto
,
inp
,
outputLayer
,
framework
,
halideScheduler
,
l1
,
lInf
);
}
void
processNet
(
std
::
string
weights
,
std
::
string
proto
,
Mat
inp
,
const
std
::
string
&
outputLayer
,
const
std
::
string
&
framework
,
std
::
string
halideScheduler
=
""
,
double
l1
=
1e-5
,
double
lInf
=
1e-4
)
{
if
(
backend
==
DNN_BACKEND_DEFAULT
&&
target
==
DNN_TARGET_OPENCL
)
{
#ifdef HAVE_OPENCL
if
(
!
cv
::
ocl
::
useOpenCL
())
#endif
{
throw
SkipTestException
(
"OpenCL is not available/disabled in OpenCV"
);
}
}
weights
=
findDataFile
(
weights
,
false
);
if
(
!
proto
.
empty
())
proto
=
findDataFile
(
proto
,
false
);
// Create two networks - with default backend and target and a tested one.
Net
netDefault
,
net
;
loadNet
(
weights
,
proto
,
framework
,
&
netDefault
);
loadNet
(
weights
,
proto
,
framework
,
&
net
);
netDefault
.
setInput
(
inp
);
Mat
outDefault
=
netDefault
.
forward
(
outputLayer
).
clone
();
net
.
setInput
(
inp
);
net
.
setPreferableBackend
(
backend
);
net
.
setPreferableTarget
(
target
);
if
(
backend
==
DNN_BACKEND_HALIDE
&&
!
halideScheduler
.
empty
())
{
halideScheduler
=
findDataFile
(
halideScheduler
,
false
);
net
.
setHalideScheduler
(
halideScheduler
);
}
Mat
out
=
net
.
forward
(
outputLayer
).
clone
();
if
(
outputLayer
==
"detection_out"
)
checkDetections
(
outDefault
,
out
,
"First run"
,
l1
,
lInf
);
else
normAssert
(
outDefault
,
out
,
"First run"
,
l1
,
lInf
);
// Test 2: change input.
inp
*=
0.1
f
;
netDefault
.
setInput
(
inp
);
net
.
setInput
(
inp
);
outDefault
=
netDefault
.
forward
(
outputLayer
).
clone
();
out
=
net
.
forward
(
outputLayer
).
clone
();
if
(
outputLayer
==
"detection_out"
)
checkDetections
(
outDefault
,
out
,
"Second run"
,
l1
,
lInf
);
else
normAssert
(
outDefault
,
out
,
"Second run"
,
l1
,
lInf
);
}
void
checkDetections
(
const
Mat
&
out
,
const
Mat
&
ref
,
const
std
::
string
&
msg
,
float
l1
,
float
lInf
,
int
top
=
5
)
{
top
=
std
::
min
(
std
::
min
(
top
,
out
.
size
[
2
]),
out
.
size
[
3
]);
std
::
vector
<
cv
::
Range
>
range
(
4
,
cv
::
Range
::
all
());
range
[
2
]
=
cv
::
Range
(
0
,
top
);
normAssert
(
out
(
range
),
ref
(
range
));
}
};
TEST_P
(
DNNTestNetwork
,
AlexNet
)
{
processNet
(
"dnn/bvlc_alexnet.caffemodel"
,
"dnn/bvlc_alexnet.prototxt"
,
Size
(
227
,
227
),
"prob"
,
"caffe"
,
target
==
DNN_TARGET_OPENCL
?
"dnn/halide_scheduler_opencl_alexnet.yml"
:
"dnn/halide_scheduler_alexnet.yml"
);
}
TEST_P
(
DNNTestNetwork
,
ResNet_50
)
{
processNet
(
"dnn/ResNet-50-model.caffemodel"
,
"dnn/ResNet-50-deploy.prototxt"
,
Size
(
224
,
224
),
"prob"
,
"caffe"
,
target
==
DNN_TARGET_OPENCL
?
"dnn/halide_scheduler_opencl_resnet_50.yml"
:
"dnn/halide_scheduler_resnet_50.yml"
);
}
TEST_P
(
DNNTestNetwork
,
SqueezeNet_v1_1
)
{
processNet
(
"dnn/squeezenet_v1.1.caffemodel"
,
"dnn/squeezenet_v1.1.prototxt"
,
Size
(
227
,
227
),
"prob"
,
"caffe"
,
target
==
DNN_TARGET_OPENCL
?
"dnn/halide_scheduler_opencl_squeezenet_v1_1.yml"
:
"dnn/halide_scheduler_squeezenet_v1_1.yml"
);
}
TEST_P
(
DNNTestNetwork
,
GoogLeNet
)
{
processNet
(
"dnn/bvlc_googlenet.caffemodel"
,
"dnn/bvlc_googlenet.prototxt"
,
Size
(
224
,
224
),
"prob"
,
"caffe"
);
}
TEST_P
(
DNNTestNetwork
,
Inception_5h
)
{
processNet
(
"dnn/tensorflow_inception_graph.pb"
,
""
,
Size
(
224
,
224
),
"softmax2"
,
"tensorflow"
,
target
==
DNN_TARGET_OPENCL
?
"dnn/halide_scheduler_opencl_inception_5h.yml"
:
"dnn/halide_scheduler_inception_5h.yml"
);
}
TEST_P
(
DNNTestNetwork
,
ENet
)
{
processNet
(
"dnn/Enet-model-best.net"
,
""
,
Size
(
512
,
512
),
"l367_Deconvolution"
,
"torch"
,
target
==
DNN_TARGET_OPENCL
?
"dnn/halide_scheduler_opencl_enet.yml"
:
"dnn/halide_scheduler_enet.yml"
,
2e-5
,
0.15
);
}
TEST_P
(
DNNTestNetwork
,
MobileNetSSD
)
{
Mat
sample
=
imread
(
findDataFile
(
"dnn/street.png"
,
false
));
Mat
inp
=
blobFromImage
(
sample
,
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
false
);
processNet
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
"dnn/MobileNetSSD_deploy.prototxt"
,
inp
,
"detection_out"
,
"caffe"
);
}
TEST_P
(
DNNTestNetwork
,
SSD_VGG16
)
{
if
(
backend
==
DNN_BACKEND_DEFAULT
&&
target
==
DNN_TARGET_OPENCL
||
backend
==
DNN_BACKEND_HALIDE
&&
target
==
DNN_TARGET_CPU
)
throw
SkipTestException
(
""
);
processNet
(
"dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel"
,
"dnn/ssd_vgg16.prototxt"
,
Size
(
300
,
300
),
"detection_out"
,
"caffe"
);
}
const
tuple
<
DNNBackend
,
DNNTarget
>
testCases
[]
=
{
#ifdef HAVE_HALIDE
tuple
<
DNNBackend
,
DNNTarget
>
(
DNN_BACKEND_HALIDE
,
DNN_TARGET_CPU
),
tuple
<
DNNBackend
,
DNNTarget
>
(
DNN_BACKEND_HALIDE
,
DNN_TARGET_OPENCL
),
#endif
tuple
<
DNNBackend
,
DNNTarget
>
(
DNN_BACKEND_DEFAULT
,
DNN_TARGET_OPENCL
)
};
INSTANTIATE_TEST_CASE_P
(
/*nothing*/
,
DNNTestNetwork
,
ValuesIn
(
testCases
));
}
// namespace cvtest
modules/dnn/test/test_caffe_importer.cpp
View file @
47917963
...
...
@@ -396,7 +396,7 @@ TEST(Reproducibility_GoogLeNet_fp16, Accuracy)
// https://github.com/richzhang/colorization
TEST
(
Reproducibility_Colorization
,
Accuracy
)
{
const
float
l1
=
1
e-5
;
const
float
l1
=
3
e-5
;
const
float
lInf
=
3e-3
;
Mat
inp
=
blobFromNPY
(
_tf
(
"colorization_inp.npy"
));
...
...
@@ -460,4 +460,27 @@ TEST(Test_Caffe, multiple_inputs)
normAssert
(
out
,
first_image
+
second_image
);
}
TEST
(
Test_Caffe
,
opencv_face_detector
)
{
std
::
string
proto
=
findDataFile
(
"dnn/opencv_face_detector.prototxt"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/opencv_face_detector.caffemodel"
,
false
);
Net
net
=
readNetFromCaffe
(
proto
,
model
);
Mat
img
=
imread
(
findDataFile
(
"gpu/lbpcascade/er.png"
,
false
));
Mat
blob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
104.0
,
177.0
,
123.0
),
false
,
false
);
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
();
Mat
ref
=
(
Mat_
<
float
>
(
6
,
5
)
<<
0.99520785
,
0.80997437
,
0.16379407
,
0.87996572
,
0.26685631
,
0.9934696
,
0.2831718
,
0.50738752
,
0.345781
,
0.5985168
,
0.99096733
,
0.13629119
,
0.24892329
,
0.19756334
,
0.3310290
,
0.98977017
,
0.23901358
,
0.09084064
,
0.29902688
,
0.1769477
,
0.97203469
,
0.67965847
,
0.06876482
,
0.73999709
,
0.1513494
,
0.95097077
,
0.51901293
,
0.45863652
,
0.5777427
,
0.5347801
);
normAssert
(
out
.
reshape
(
1
,
out
.
total
()
/
7
).
rowRange
(
0
,
6
).
colRange
(
2
,
7
),
ref
);
}
}
modules/dnn/test/test_halide_nets.cpp
deleted
100644 → 0
View file @
12ea8477
// 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.
//
// Copyright (C) 2017, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "test_precomp.hpp"
namespace
cvtest
{
#ifdef HAVE_HALIDE
using
namespace
cv
;
using
namespace
dnn
;
static
void
loadNet
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
const
std
::
string
&
framework
,
Net
*
net
)
{
if
(
framework
==
"caffe"
)
{
*
net
=
cv
::
dnn
::
readNetFromCaffe
(
proto
,
weights
);
}
else
if
(
framework
==
"torch"
)
{
*
net
=
cv
::
dnn
::
readNetFromTorch
(
weights
);
}
else
if
(
framework
==
"tensorflow"
)
{
*
net
=
cv
::
dnn
::
readNetFromTensorflow
(
weights
);
}
else
CV_Error
(
Error
::
StsNotImplemented
,
"Unknown framework "
+
framework
);
}
static
void
test
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
const
std
::
string
&
scheduler
,
int
inWidth
,
int
inHeight
,
const
std
::
string
&
outputLayer
,
const
std
::
string
&
framework
,
int
targetId
,
double
l1
=
1e-5
,
double
lInf
=
1e-4
)
{
Mat
input
(
inHeight
,
inWidth
,
CV_32FC3
),
outputDefault
,
outputHalide
;
randu
(
input
,
0.0
f
,
1.0
f
);
Net
netDefault
,
netHalide
;
loadNet
(
weights
,
proto
,
framework
,
&
netDefault
);
loadNet
(
weights
,
proto
,
framework
,
&
netHalide
);
netDefault
.
setInput
(
blobFromImage
(
input
.
clone
(),
1.0
f
,
Size
(),
Scalar
(),
false
));
outputDefault
=
netDefault
.
forward
(
outputLayer
).
clone
();
netHalide
.
setInput
(
blobFromImage
(
input
.
clone
(),
1.0
f
,
Size
(),
Scalar
(),
false
));
netHalide
.
setPreferableBackend
(
DNN_BACKEND_HALIDE
);
netHalide
.
setPreferableTarget
(
targetId
);
netHalide
.
setHalideScheduler
(
scheduler
);
outputHalide
=
netHalide
.
forward
(
outputLayer
).
clone
();
normAssert
(
outputDefault
,
outputHalide
,
"First run"
,
l1
,
lInf
);
// An extra test: change input.
input
*=
0.1
f
;
netDefault
.
setInput
(
blobFromImage
(
input
.
clone
(),
1.0
,
Size
(),
Scalar
(),
false
));
netHalide
.
setInput
(
blobFromImage
(
input
.
clone
(),
1.0
,
Size
(),
Scalar
(),
false
));
normAssert
(
outputDefault
,
outputHalide
,
"Second run"
,
l1
,
lInf
);
std
::
cout
<<
"."
<<
std
::
endl
;
// Swap backends.
netHalide
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
netHalide
.
setPreferableTarget
(
DNN_TARGET_CPU
);
outputDefault
=
netHalide
.
forward
(
outputLayer
).
clone
();
netDefault
.
setPreferableBackend
(
DNN_BACKEND_HALIDE
);
netDefault
.
setPreferableTarget
(
targetId
);
netDefault
.
setHalideScheduler
(
scheduler
);
outputHalide
=
netDefault
.
forward
(
outputLayer
).
clone
();
normAssert
(
outputDefault
,
outputHalide
,
"Swap backends"
,
l1
,
lInf
);
}
////////////////////////////////////////////////////////////////////////////////
// CPU target
////////////////////////////////////////////////////////////////////////////////
TEST
(
Reproducibility_MobileNetSSD_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
),
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
),
""
,
300
,
300
,
"detection_out"
,
"caffe"
,
DNN_TARGET_CPU
);
};
// TODO: Segmentation fault from time to time.
// TEST(Reproducibility_SSD_Halide, Accuracy)
// {
// test(findDataFile("dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel", false),
// findDataFile("dnn/ssd_vgg16.prototxt", false),
// "", 300, 300, "detection_out", "caffe", DNN_TARGET_CPU);
// };
TEST
(
Reproducibility_GoogLeNet_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/bvlc_googlenet.caffemodel"
,
false
),
findDataFile
(
"dnn/bvlc_googlenet.prototxt"
,
false
),
""
,
224
,
224
,
"prob"
,
"caffe"
,
DNN_TARGET_CPU
);
};
TEST
(
Reproducibility_AlexNet_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/bvlc_alexnet.caffemodel"
,
false
),
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_alexnet.yml"
,
false
),
227
,
227
,
"prob"
,
"caffe"
,
DNN_TARGET_CPU
);
};
TEST
(
Reproducibility_ResNet_50_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
),
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_resnet_50.yml"
,
false
),
224
,
224
,
"prob"
,
"caffe"
,
DNN_TARGET_CPU
);
};
TEST
(
Reproducibility_SqueezeNet_v1_1_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
),
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_squeezenet_v1_1.yml"
,
false
),
227
,
227
,
"prob"
,
"caffe"
,
DNN_TARGET_CPU
);
};
TEST
(
Reproducibility_Inception_5h_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/tensorflow_inception_graph.pb"
,
false
),
""
,
findDataFile
(
"dnn/halide_scheduler_inception_5h.yml"
,
false
),
224
,
224
,
"softmax2"
,
"tensorflow"
,
DNN_TARGET_CPU
);
};
TEST
(
Reproducibility_ENet_Halide
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/Enet-model-best.net"
,
false
),
""
,
findDataFile
(
"dnn/halide_scheduler_enet.yml"
,
false
),
512
,
512
,
"l367_Deconvolution"
,
"torch"
,
DNN_TARGET_CPU
,
2e-5
,
0.15
);
};
////////////////////////////////////////////////////////////////////////////////
// OpenCL target
////////////////////////////////////////////////////////////////////////////////
TEST
(
Reproducibility_MobileNetSSD_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
),
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
),
""
,
300
,
300
,
"detection_out"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_SSD_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel"
,
false
),
findDataFile
(
"dnn/ssd_vgg16.prototxt"
,
false
),
""
,
300
,
300
,
"detection_out"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_GoogLeNet_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/bvlc_googlenet.caffemodel"
,
false
),
findDataFile
(
"dnn/bvlc_googlenet.prototxt"
,
false
),
""
,
227
,
227
,
"prob"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_AlexNet_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/bvlc_alexnet.caffemodel"
,
false
),
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_opencl_alexnet.yml"
,
false
),
227
,
227
,
"prob"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_ResNet_50_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
),
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_opencl_resnet_50.yml"
,
false
),
224
,
224
,
"prob"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_SqueezeNet_v1_1_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
),
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
findDataFile
(
"dnn/halide_scheduler_opencl_squeezenet_v1_1.yml"
,
false
),
227
,
227
,
"prob"
,
"caffe"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_Inception_5h_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/tensorflow_inception_graph.pb"
,
false
),
""
,
findDataFile
(
"dnn/halide_scheduler_opencl_inception_5h.yml"
,
false
),
224
,
224
,
"softmax2"
,
"tensorflow"
,
DNN_TARGET_OPENCL
);
};
TEST
(
Reproducibility_ENet_Halide_opencl
,
Accuracy
)
{
test
(
findDataFile
(
"dnn/Enet-model-best.net"
,
false
),
""
,
findDataFile
(
"dnn/halide_scheduler_opencl_enet.yml"
,
false
),
512
,
512
,
"l367_Deconvolution"
,
"torch"
,
DNN_TARGET_OPENCL
,
2e-5
,
0.14
);
};
#endif // HAVE_HALIDE
}
// namespace cvtest
modules/dnn/test/test_tf_importer.cpp
View file @
47917963
...
...
@@ -244,12 +244,13 @@ TEST(Test_TensorFlow, MobileNet_SSD)
net
.
forward
(
output
,
outNames
);
normAssert
(
target
[
0
].
reshape
(
1
,
1
),
output
[
0
].
reshape
(
1
,
1
));
normAssert
(
target
[
1
].
reshape
(
1
,
1
),
output
[
1
].
reshape
(
1
,
1
),
""
,
1e-5
,
2
e-4
);
normAssert
(
target
[
1
].
reshape
(
1
,
1
),
output
[
1
].
reshape
(
1
,
1
),
""
,
1e-5
,
3
e-4
);
normAssert
(
target
[
2
].
reshape
(
1
,
1
),
output
[
2
].
reshape
(
1
,
1
),
""
,
4e-5
,
1e-2
);
}
OCL_TEST
(
Test_TensorFlow
,
MobileNet_SSD
)
{
throw
SkipTestException
(
"TODO: test is failed"
);
std
::
string
netPath
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pb"
,
false
);
std
::
string
netConfig
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pbtxt"
,
false
);
std
::
string
imgPath
=
findDataFile
(
"dnn/street.png"
,
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment