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
6eba1a4d
Commit
6eba1a4d
authored
Feb 05, 2020
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dnn: auto network dump through parameter
parent
fa4871b0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
3 deletions
+54
-3
dnn.cpp
modules/dnn/src/dnn.cpp
+54
-3
No files found.
modules/dnn/src/dnn.cpp
View file @
6eba1a4d
...
@@ -62,6 +62,8 @@ namespace cv {
...
@@ -62,6 +62,8 @@ namespace cv {
namespace
dnn
{
namespace
dnn
{
CV__DNN_EXPERIMENTAL_NS_BEGIN
CV__DNN_EXPERIMENTAL_NS_BEGIN
static
size_t
DNN_NETWORK_DUMP
=
utils
::
getConfigurationParameterSizeT
(
"OPENCV_DNN_NETWORK_DUMP"
,
0
);
// this option is useful to run valgrind memory errors detection
// this option is useful to run valgrind memory errors detection
static
bool
DNN_DISABLE_MEMORY_OPTIMIZATIONS
=
utils
::
getConfigurationParameterBool
(
"OPENCV_DNN_DISABLE_MEMORY_OPTIMIZATIONS"
,
false
);
static
bool
DNN_DISABLE_MEMORY_OPTIMIZATIONS
=
utils
::
getConfigurationParameterBool
(
"OPENCV_DNN_DISABLE_MEMORY_OPTIMIZATIONS"
,
false
);
...
@@ -1055,12 +1057,19 @@ static Ptr<BackendWrapper> wrapMat(int backendId, int targetId, cv::Mat& m)
...
@@ -1055,12 +1057,19 @@ static Ptr<BackendWrapper> wrapMat(int backendId, int targetId, cv::Mat& m)
return
Ptr
<
BackendWrapper
>
();
// TODO Error?
return
Ptr
<
BackendWrapper
>
();
// TODO Error?
}
}
static
int
g_networkId
=
0
;
struct
Net
::
Impl
struct
Net
::
Impl
{
{
typedef
std
::
map
<
int
,
LayerShapes
>
LayersShapesMap
;
typedef
std
::
map
<
int
,
LayerShapes
>
LayersShapesMap
;
typedef
std
::
map
<
int
,
LayerData
>
MapIdToLayerData
;
typedef
std
::
map
<
int
,
LayerData
>
MapIdToLayerData
;
const
int
networkId
;
// network global identifier
int
networkDumpCounter
;
// dump counter
Impl
()
Impl
()
:
networkId
(
CV_XADD
(
&
g_networkId
,
1
))
,
networkDumpCounter
(
0
)
{
{
//allocate fake net input layer
//allocate fake net input layer
netInputLayer
=
Ptr
<
DataLayer
>
(
new
DataLayer
());
netInputLayer
=
Ptr
<
DataLayer
>
(
new
DataLayer
());
...
@@ -1224,6 +1233,11 @@ struct Net::Impl
...
@@ -1224,6 +1233,11 @@ struct Net::Impl
{
{
CV_TRACE_FUNCTION
();
CV_TRACE_FUNCTION
();
if
(
DNN_NETWORK_DUMP
>
0
&&
networkDumpCounter
==
0
)
{
dumpNetworkToFile
();
}
if
(
preferableBackend
==
DNN_BACKEND_DEFAULT
)
if
(
preferableBackend
==
DNN_BACKEND_DEFAULT
)
preferableBackend
=
(
Backend
)
PARAM_DNN_BACKEND_DEFAULT
;
preferableBackend
=
(
Backend
)
PARAM_DNN_BACKEND_DEFAULT
;
#ifdef HAVE_INF_ENGINE
#ifdef HAVE_INF_ENGINE
...
@@ -1300,6 +1314,11 @@ struct Net::Impl
...
@@ -1300,6 +1314,11 @@ struct Net::Impl
netWasAllocated
=
true
;
netWasAllocated
=
true
;
this
->
blobsToKeep
=
blobsToKeep_
;
this
->
blobsToKeep
=
blobsToKeep_
;
if
(
DNN_NETWORK_DUMP
>
0
)
{
dumpNetworkToFile
();
}
}
}
}
}
...
@@ -2980,6 +2999,31 @@ struct Net::Impl
...
@@ -2980,6 +2999,31 @@ struct Net::Impl
static
static
Net
createNetworkFromModelOptimizer
(
InferenceEngine
::
CNNNetwork
&
ieNet
);
Net
createNetworkFromModelOptimizer
(
InferenceEngine
::
CNNNetwork
&
ieNet
);
#endif
#endif
string
dump
();
void
dumpNetworkToFile
()
{
#ifndef OPENCV_DNN_DISABLE_NETWORK_AUTO_DUMP
String
dumpFileName
=
cv
::
format
(
"ocv_dnn_net_%05d_%02d.dot"
,
networkId
,
networkDumpCounter
++
);
try
{
string
dumpStr
=
dump
();
std
::
ofstream
out
(
dumpFileName
.
c_str
(),
std
::
ios
::
out
|
std
::
ios
::
binary
);
out
<<
dumpStr
;
}
catch
(
const
std
::
exception
&
e
)
{
std
::
ofstream
out
((
dumpFileName
+
".error"
).
c_str
(),
std
::
ios
::
out
);
out
<<
"Exception: "
<<
e
.
what
()
<<
std
::
endl
;
}
catch
(...)
{
std
::
ofstream
out
((
dumpFileName
+
".error"
).
c_str
(),
std
::
ios
::
out
);
out
<<
"Can't dump: unknown exception"
<<
std
::
endl
;
}
#endif
}
};
};
Net
::
Net
()
:
impl
(
new
Net
::
Impl
)
Net
::
Net
()
:
impl
(
new
Net
::
Impl
)
...
@@ -3532,10 +3576,17 @@ String Net::dump()
...
@@ -3532,10 +3576,17 @@ String Net::dump()
impl
->
setUpNet
();
impl
->
setUpNet
();
}
}
return
impl
->
dump
();
}
string
Net
::
Impl
::
dump
()
{
bool
hasInput
=
!
netInputLayer
->
inputsData
.
empty
();
std
::
ostringstream
out
;
std
::
ostringstream
out
;
const
std
::
map
<
int
,
LayerData
>&
map
=
impl
->
layers
;
const
std
::
map
<
int
,
LayerData
>&
map
=
layers
;
Backend
prefBackend
=
(
Backend
)
impl
->
preferableBackend
;
Backend
prefBackend
=
(
Backend
)
preferableBackend
;
std
::
vector
<
std
::
vector
<
int
>
>
skippedLayers
;
std
::
vector
<
std
::
vector
<
int
>
>
skippedLayers
;
std
::
vector
<
int
>
skipId
;
std
::
vector
<
int
>
skipId
;
std
::
vector
<
int
>
allLayers
(
map
.
size
(),
-
1
);
std
::
vector
<
int
>
allLayers
(
map
.
size
(),
-
1
);
...
@@ -3736,7 +3787,7 @@ String Net::dump()
...
@@ -3736,7 +3787,7 @@ String Net::dump()
}
}
out
<<
'\n'
;
out
<<
'\n'
;
// Add edges
// Add edges
int
inputsSize
=
hasInput
?
impl
->
netInputLayer
->
outNames
.
size
()
:
0
;
int
inputsSize
=
hasInput
?
netInputLayer
->
outNames
.
size
()
:
0
;
for
(
std
::
map
<
int
,
LayerData
>::
const_iterator
it
=
map
.
begin
();
it
!=
map
.
end
();
++
it
)
for
(
std
::
map
<
int
,
LayerData
>::
const_iterator
it
=
map
.
begin
();
it
!=
map
.
end
();
++
it
)
{
{
const
LayerData
&
ld
=
it
->
second
;
const
LayerData
&
ld
=
it
->
second
;
...
...
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