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
bc348eb8
Commit
bc348eb8
authored
Oct 31, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9963 from dkurt:fix_caffe_shrinker
parents
6e4dacc0
e1ebc4e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
dnn.hpp
modules/dnn/include/opencv2/dnn/dnn.hpp
+5
-1
caffe_shrinker.cpp
modules/dnn/src/caffe/caffe_shrinker.cpp
+13
-2
No files found.
modules/dnn/include/opencv2/dnn/dnn.hpp
View file @
bc348eb8
...
...
@@ -726,13 +726,17 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
* @param src Path to origin model from Caffe framework contains single
* precision floating point weights (usually has `.caffemodel` extension).
* @param dst Path to destination model with updated weights.
* @param layersTypes Set of layers types which parameters will be converted.
* By default, converts only Convolutional and Fully-Connected layers'
* weights.
*
* @note Shrinked model has no origin float32 weights so it can't be used
* in origin Caffe framework anymore. However the structure of data
* is taken from NVidia's Caffe fork: https://github.com/NVIDIA/caffe.
* So the resulting model may be used there.
*/
CV_EXPORTS_W
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
);
CV_EXPORTS_W
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
,
const
std
::
vector
<
String
>&
layersTypes
=
std
::
vector
<
String
>
());
/** @brief Performs non maximum suppression given boxes and corresponding scores.
...
...
modules/dnn/src/caffe/caffe_shrinker.cpp
View file @
bc348eb8
...
...
@@ -17,16 +17,27 @@ CV__DNN_EXPERIMENTAL_NS_BEGIN
#ifdef HAVE_PROTOBUF
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
)
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
,
const
std
::
vector
<
String
>&
layersTypes
)
{
CV_TRACE_FUNCTION
();
std
::
vector
<
String
>
types
(
layersTypes
);
if
(
types
.
empty
())
{
types
.
push_back
(
"Convolution"
);
types
.
push_back
(
"InnerProduct"
);
}
caffe
::
NetParameter
net
;
ReadNetParamsFromBinaryFileOrDie
(
src
.
c_str
(),
&
net
);
for
(
int
i
=
0
;
i
<
net
.
layer_size
();
++
i
)
{
caffe
::
LayerParameter
*
lp
=
net
.
mutable_layer
(
i
);
if
(
std
::
find
(
types
.
begin
(),
types
.
end
(),
lp
->
type
())
==
types
.
end
())
{
continue
;
}
for
(
int
j
=
0
;
j
<
lp
->
blobs_size
();
++
j
)
{
caffe
::
BlobProto
*
blob
=
lp
->
mutable_blobs
(
j
);
...
...
@@ -54,7 +65,7 @@ void shrinkCaffeModel(const String& src, const String& dst)
#else
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
)
void
shrinkCaffeModel
(
const
String
&
src
,
const
String
&
dst
,
const
std
::
vector
<
String
>&
types
)
{
CV_Error
(
cv
::
Error
::
StsNotImplemented
,
"libprotobuf required to import data from Caffe models"
);
}
...
...
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