Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
266692e1
Commit
266692e1
authored
Aug 11, 2016
by
Vitaliy Lyudvichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving of Caffe importer compatibility
parent
8ecae046
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
caffe_importer.cpp
modules/dnn/src/caffe/caffe_importer.cpp
+30
-11
dnn.cpp
modules/dnn/src/dnn.cpp
+1
-1
No files found.
modules/dnn/src/caffe/caffe_importer.cpp
View file @
266692e1
...
...
@@ -48,6 +48,7 @@ using namespace cv::dnn;
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
...
...
@@ -63,12 +64,21 @@ using ::google::protobuf::Reflection;
namespace
{
class
CaffeImporter
:
public
Importer
{
template
<
typename
T
>
static
cv
::
String
toString
(
const
T
&
v
)
{
std
::
ostringstream
ss
;
ss
<<
v
;
return
ss
.
str
();
}
class
CaffeImporter
:
public
Importer
{
caffe
::
NetParameter
net
;
caffe
::
NetParameter
netBinary
;
public
:
public
:
CaffeImporter
(
const
char
*
pototxt
,
const
char
*
caffeModel
)
{
...
...
@@ -250,10 +260,14 @@ namespace
int
layerId
,
outNum
;
};
std
::
vector
<
BlobNote
>
addedBlobs
;
std
::
map
<
String
,
int
>
layerCounter
;
void
populateNet
(
Net
dstNet
)
{
int
layersSize
=
net
.
layer_size
();
std
::
vector
<
BlobNote
>
addedBlobs
;
layerCounter
.
clear
();
addedBlobs
.
clear
();
addedBlobs
.
reserve
(
layersSize
+
1
);
//setup input layer names
...
...
@@ -277,17 +291,23 @@ namespace
extractLayerParams
(
layer
,
layerParams
);
extractBinaryLayerParms
(
layer
,
layerParams
);
int
repetitions
=
layerCounter
[
name
]
++
;
if
(
repetitions
)
name
+=
String
(
"_"
)
+
toString
(
repetitions
);
int
id
=
dstNet
.
addLayer
(
name
,
type
,
layerParams
);
for
(
int
inNum
=
0
;
inNum
<
layer
.
bottom_size
();
inNum
++
)
addInput
(
layer
.
bottom
(
inNum
),
id
,
inNum
,
dstNet
,
addedBlobs
);
addInput
(
layer
.
bottom
(
inNum
),
id
,
inNum
,
dstNet
);
for
(
int
outNum
=
0
;
outNum
<
layer
.
top_size
();
outNum
++
)
addOutput
(
layer
,
id
,
outNum
,
addedBlobs
);
addOutput
(
layer
,
id
,
outNum
);
}
addedBlobs
.
clear
();
}
void
addOutput
(
const
caffe
::
LayerParameter
&
layer
,
int
layerId
,
int
outNum
,
std
::
vector
<
BlobNote
>
&
addedBlobs
)
void
addOutput
(
const
caffe
::
LayerParameter
&
layer
,
int
layerId
,
int
outNum
)
{
const
std
::
string
&
name
=
layer
.
top
(
outNum
);
...
...
@@ -311,7 +331,7 @@ namespace
addedBlobs
.
push_back
(
BlobNote
(
name
,
layerId
,
outNum
));
}
void
addInput
(
const
std
::
string
&
name
,
int
layerId
,
int
inNum
,
Net
&
dstNet
,
std
::
vector
<
BlobNote
>
&
addedBlobs
)
void
addInput
(
const
std
::
string
&
name
,
int
layerId
,
int
inNum
,
Net
&
dstNet
)
{
int
idx
;
for
(
idx
=
(
int
)
addedBlobs
.
size
()
-
1
;
idx
>=
0
;
idx
--
)
...
...
@@ -322,7 +342,7 @@ namespace
if
(
idx
<
0
)
{
CV_Error
(
Error
::
StsObjectNotFound
,
"Can't fou
nd output blob
\"
"
+
name
+
"
\"
"
);
CV_Error
(
Error
::
StsObjectNotFound
,
"Can't fi
nd output blob
\"
"
+
name
+
"
\"
"
);
return
;
}
...
...
@@ -334,8 +354,7 @@ namespace
}
};
};
}
...
...
modules/dnn/src/dnn.cpp
View file @
266692e1
...
...
@@ -60,7 +60,7 @@ namespace dnn
{
template
<
typename
T
>
String
toString
(
const
T
&
v
)
static
String
toString
(
const
T
&
v
)
{
std
::
ostringstream
ss
;
ss
<<
v
;
...
...
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