-
-
Notifications
You must be signed in to change notification settings - Fork 55.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protobuf parser for DNN module #9106
Conversation
21f431a
to
25b0325
Compare
777799b
to
20011c2
Compare
@dkurt, I suggest you to remove the word "w i p" from the PR description. We all know that this is experimental patch; but without this keyword your PR will be automatically checked by buildbot as soon as you put new commits. |
@vpisarev, would it be OK if I made this usage as a single module @ opencv_contrib for a while? It let us:
|
@dkurt, I'm fine with it |
c72266e
to
d8f35d3
Compare
b27326e
to
4065806
Compare
4065806
to
09dd64f
Compare
@dkurt, let's merge the patch. But could you please fix the merge conflicts first? |
b58841c
to
3e22e30
Compare
e24c537
to
b77f128
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMake conditions should be re-worked, for example this doesn't work properly (without contrib at least):
cmake -DBUILD_PROTOBUF=OFF <opencv_dir>
make opencv_test_dnn # compilation errors
Previously it uses system external protobuf with protoc (required for updating pb file to new version).
How to switch on this "parser"?
cmake <opencv_dir>
make opencv_test_dnn # still using libprotobuf
USE_PROTOBUF
is broken and doesn't work at all.
modules/dnn/misc/caffe/caffe_proto.pb
modules/dnn/misc/tensorflow/graph_proto.pb
Custom binary blobs should be avoided, because there is no way to maintain/track changes (no tools)
I believe there is no problem to write/store parsed "AST" as C++ code instead.
modules/dnn/CMakeLists.txt
Outdated
ocv_option(${the_module}_USE_PROTOBUF "Force use of Protobuf library instead OpenCV's protobuf parser" OFF) | ||
|
||
# One and only way if dnn module will be disabled - failed to link to system protobuf. | ||
if (DEFINED BUILD_PROTOBUF AND NOT BUILD_PROTOBUF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
should be used without space in CMake here and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced
modules/dnn/CMakeLists.txt
Outdated
/wd4456 /wd4510 /wd4610 /wd4800 | ||
-wd858 -wd2196 | ||
) | ||
if (${USE_PROTOBUF}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(USE_PROTOBUF)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced
modules/dnn/CMakeLists.txt
Outdated
include(${OpenCV_SOURCE_DIR}/cmake/OpenCVFindLibProtobuf.cmake) | ||
if(NOT Protobuf_FOUND) | ||
ocv_module_disable(opencv_dnn) | ||
ocv_option(${the_module}_USE_PROTOBUF "Force use of Protobuf library instead OpenCV's protobuf parser" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is "_USE_PROTOBUF" because "the_module" is not defined here (before ocv_add_module()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced under the ocv_add_module
.
May I ask you to show version of system protobuf to reproduce it?
Added text descriptors parsing. So now we generate .pb
from .proto
using protoc. Then print it as text. I've found only one way to use python:
from google.protobuf import descriptor_pb2
msg = descriptor_pb2.FileDescriptorSet()
with open('/path/to/example.pb', 'rb') as f:
msg.ParseFromString(f.read())
print msg
} | ||
DictValue dict; | ||
if (typeid(T) == typeid(int32_t) || typeid(T) == typeid(uint32_t) || | ||
typeid(T) == typeid(int64_t) || typeid(T) == typeid(uint64_t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use template specializations / type traits instead.
I believe this "if" must be handled by DictValue
itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Replaced to is_integer
and is_specialized
for non-integers but floats and doubles.
|
||
using namespace pb; | ||
|
||
class CaffeImporter : public Importer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need another one Caffe importer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alalek, Thanks! It's possible to use a single Caffe importer. I'll do it.
#ifndef HAVE_PROTOBUF | ||
#include <typeinfo> | ||
|
||
#include "../precomp.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
precomp.hpp
must be the first include without any #if
s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
e2b14f2
to
0ead211
Compare
c492db7
to
386dfc2
Compare
Hi, have you taken a look to: protocolbuffers/protobuf#1489 ? |
8ecc554
to
bc525a1
Compare
bc525a1
to
5a6af44
Compare
5a6af44
to
b71fd67
Compare
I think we can close it for now. |
This pullrequest changes
-Dopencv_dnn_USE_PROTOBUF=ON
or disable parser by-DBUILD_opencv_protobuf_parser=OFF
if it isn't used somewhere.caffe.proto
andgraph.proto
by proto compiler (seeprotoc --descriptor_set_out
).caffe_importer
logic was completely rewritten.tensorflow_importer
was modified to support parser usage.Merge with contrib: opencv/opencv_contrib#1291
Merge with extra: opencv/opencv_extra#356
There are issues related to libprotobuf. This PR isn't solve them but it may help avoid them.
close opencv/opencv_contrib#823
close opencv/opencv_contrib#854
close opencv/opencv_contrib#1242
close #9549
http://answers.opencv.org/question/138047/opencv-32-includes-libmirprotobuf-and-protobuf-26-which-is-conflicting-with-protobuf-31/