Updated CMakeLists.txt to support protobuf Messages auto generation.

pull/265/head
Vitaliy Lyudvichenko 10 years ago
parent cfb9cfab9b
commit a6963b4abb
  1. 28
      modules/dnn/CMakeLists.txt
  2. 19563
      modules/dnn/src/caffe.pb.cpp
  3. 14544
      modules/dnn/src/caffe.pb.h
  4. 1109
      modules/dnn/src/caffe.proto
  5. 57
      modules/dnn/src/caffe_importer.cpp
  6. 47
      modules/dnn/src/dnn.cpp
  7. 1
      modules/matlab/CMakeLists.txt
  8. BIN
      modules/matlab/generator/filters.pyc
  9. BIN
      modules/matlab/generator/parse_tree.pyc

@ -1,19 +1,25 @@
set(the_description "Deep neural network module. Allow load models and make forward pass")
set(OPENCV_MODULE_IS_PART_OF_WORLD OFF)
ocv_define_module(dnn opencv_imgproc opencv_core opencv_highgui WRAP python)
option(WITH_PROTOBUF "Build with libprotobuf" ON)
if(NOT WITH_PROTOBUF)
message(ERROR "libprotobuf required for dnn module")
message(FATAL_ERROR "libprotobuf is required for dnn module")
endif()
find_package( Protobuf REQUIRED )
if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
message(STATUS "Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
else()
message(STATUS "Find protobuf")
find_package( Protobuf REQUIRED )
target_include_directories(opencv_dnn PUBLIC ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(opencv_dnn ${PROTOBUF_LIBRARIES})
message(STATUS "Protobuf:" ${PROTOBUF_INCLUDE_DIR})
message(STATUS "Protobuf:" ${PROTOBUF_LIBRARIES})
message(FATAL_ERROR "Could not find PROTOBUF Compiler")
endif()
target_link_libraries(opencv_dnn)
file(GLOB PROTO_FILES src/*.proto)
PROTOBUF_GENERATE_CPP(PROTO_HDRS PROTO_SRCS ${PROTO_FILES})
ocv_add_module(dnn opencv_imgproc opencv_core opencv_highgui WRAP python matlab)
ocv_glob_module_sources(${PROTO_SRCS} ${PROTO_HDRS})
ocv_source_group("Src\\protobuf" FILES ${PROTO_SRCS} ${PROTO_HDRS})
ocv_module_include_directories(${PROTOBUF_INCLUDE_DIR})
ocv_create_module()
target_link_libraries(opencv_dnn ${PROTOBUF_LIBRARIES})

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,57 @@
#include "opencv2/dnn.hpp"
#include "caffe.pb.h"
#include <iostream>
#include <fstream>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
using namespace cv;
using namespace cv::dnn;
namespace
{
class CaffeImporter : public Importer
{
public:
CaffeImporter(const char *pototxt, const char *caffeModel)
{
std::ifstream proto_ifs(pototxt, std::ifstream::in);
std::ifstream model_ifs(caffeModel, std::ifstream::in);
CV_Assert(proto_ifs.is_open() && model_ifs.is_open());
google::protobuf::io::IstreamInputStream proto_zcs(&proto_ifs);
google::protobuf::io::IstreamInputStream model_zcs(&model_ifs);
//google::protobuf::Message msg_weights;
caffe::NetParameter msg_arch;
CV_Assert(google::protobuf::TextFormat::Parse(&proto_zcs, &msg_arch));
//CV_Assert( msg_weights.ParseFromZeroCopyStream(model_zcs) );
const google::protobuf::Descriptor *desc_arch = msg_arch.GetDescriptor();
CV_Assert(desc_arch);
}
void populateNetConfiguration(Ptr<NetConfiguration> config)
{
}
~CaffeImporter()
{
}
};
}
Ptr<Importer> cv::dnn::createCaffeImporter(const String &prototxt, const String &caffeModel)
{
return Ptr<Importer>(new CaffeImporter(prototxt.c_str(), caffeModel.c_str()));
}

@ -1,15 +1,6 @@
#include "opencv2/dnn.hpp"
#include <iostream>
#include <fstream>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include "caffe.pb.h"
namespace
{
}
using namespace cv;
using namespace cv::dnn;
namespace cv
{
@ -37,41 +28,15 @@ Blob::Blob(const UMat &in) : _InputOutputArray(in)
}
class CaffeImporter : public Importer
Importer::~Importer()
{
public:
CaffeImporter(const char *pototxt, const char *caffeModel)
{
std::ifstream proto_ifs(pototxt, std::ifstream::in);
std::ifstream model_ifs(caffeModel, std::ifstream::in);
CV_Assert(proto_ifs.is_open() && model_ifs.is_open());
google::protobuf::io::IstreamInputStream proto_zcs(&proto_ifs);
google::protobuf::io::IstreamInputStream model_zcs(&model_ifs);
//google::protobuf::Message msg_arch;
//google::protobuf::Message msg_weights;
caffe::NetParameter msg_arch;
CV_Assert( google::protobuf::TextFormat::Parse(&proto_zcs, &msg_arch) );
//CV_Assert( msg_weights.ParseFromZeroCopyStream(model_zcs) );
const google::protobuf::Descriptor *desc_arch = msg_arch.GetDescriptor();
CV_Assert(desc_arch);
}
void populateNetConfiguration(Ptr<NetConfiguration> config)
{
}
}
};
Ptr<Importer> createCaffeImporter(const String &prototxt, const String &caffeModel)
Net::~Net()
{
return Ptr<Importer>(new CaffeImporter(prototxt.c_str(), caffeModel.c_str()));
}
}

@ -92,6 +92,7 @@ ocv_add_module(matlab BINDINGS
opencv_calib opencv_calib3d
opencv_stitching opencv_superres
opencv_xfeatures2d
opencv_ximgproc
)
# get the commit information

Loading…
Cancel
Save