Merge branch 'master' of github.com:ludv1x/opencv_contrib

Conflicts:
	modules/dnn/include/opencv2/dnn.hpp
pull/265/head
Vitaliy Lyudvichenko 10 years ago
commit cae0bd495d
  1. 4
      modules/dnn/CMakeLists.txt
  2. 164
      modules/dnn/include/opencv2/dnn.hpp
  3. 4
      modules/dnn/include/opencv2/dnn/dict.hpp
  4. 167
      modules/dnn/include/opencv2/dnn/dnn.hpp
  5. 11
      modules/dnn/include/opencv2/dnn/dnn.inl.hpp
  6. 21
      modules/dnn/src/dnn.cpp

@ -14,9 +14,13 @@ else()
message(FATAL_ERROR "Could not find PROTOBUF Compiler") message(FATAL_ERROR "Could not find PROTOBUF Compiler")
endif() endif()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses)
file(GLOB PROTO_FILES src/*.proto) file(GLOB PROTO_FILES src/*.proto)
PROTOBUF_GENERATE_CPP(PROTO_HDRS PROTO_SRCS ${PROTO_FILES}) PROTOBUF_GENERATE_CPP(PROTO_HDRS PROTO_SRCS ${PROTO_FILES})
include_directories(include src/caffe)
ocv_add_module(dnn opencv_imgproc opencv_core opencv_highgui WRAP python matlab) ocv_add_module(dnn opencv_imgproc opencv_core opencv_highgui WRAP python matlab)
ocv_glob_module_sources(${PROTO_SRCS} ${PROTO_HDRS}) ocv_glob_module_sources(${PROTO_SRCS} ${PROTO_HDRS})
ocv_source_group("Src\\protobuf" FILES ${PROTO_SRCS} ${PROTO_HDRS}) ocv_source_group("Src\\protobuf" FILES ${PROTO_SRCS} ${PROTO_HDRS})

@ -1,167 +1,13 @@
#ifndef __OPENCV_DNN_HPP__ #ifndef __OPENCV_DNN_HPP__
#define __OPENCV_DNN_HPP__ #define __OPENCV_DNN_HPP__
#include <opencv2/core.hpp> // This is an umbrealla header to include into you project.
#include <map> // We are free to change headers layout in dnn subfolder, so please include
#include <vector> // this header for future compartibility
#include "dnn/dict.hpp"
namespace cv #include <opencv2/dnn/dnn.hpp>
{
namespace dnn
{
class Layer;
class NetConfiguration;
class Net;
class Blob;
class LayerParams;
//wrapper over cv::Mat and cv::UMat
CV_EXPORTS class Blob
{
Mat m;
public: #endif /* __OPENCV_DNN_HPP__ */
Blob();
Blob(InputArray in);
void fill(InputArray in);
void fill(int ndims, const int *sizes, int type, void *data, bool deepCopy = true);
void create(int ndims, const int *sizes, int type = CV_32F);
bool empty() const;
Mat& getMatRef();
const Mat& getMatRef() const;
Mat getMat();
Mat getMat(int num, int channel);
int cols() const;
int rows() const;
Size size() const;
int channels() const;
int num() const;
Vec4i shape() const;
};
CV_EXPORTS class LayerParams : public Dict
{
public:
std::vector<Blob> learnedBlobs;
};
CV_EXPORTS class LayerRegister
{
public:
typedef Layer* (*Constuctor)();
CV_EXPORTS static void registerLayer(const String &type, Constuctor constructor);
CV_EXPORTS static void unregisterLayer(const String &type);
CV_EXPORTS static Ptr<Layer> createLayerInstance(const String &type);
private:
LayerRegister();
LayerRegister(const LayerRegister &lr);
static std::map<String, Constuctor> registeredLayers;
};
//this class allows to build new Layers
CV_EXPORTS class Layer
{
public:
//TODO: this field must be declared as public if we want support possibility to change these params in runtime
std::vector<Blob> learnedParams;
virtual ~Layer();
//type of Layer
virtual String type() const;
//setUp calls once (think that it's constructor)
virtual void setUp(LayerParams &params);
//maybe useless function
//shape of output blobs must be adjusted with respect to shape of input blobs
virtual void adjustShape(const std::vector<Blob> &inputs, std::vector<Blob> &outputs);
virtual void forward(std::vector<Blob> &inputs, std::vector<Blob> &outputs);
virtual int getNumInputs();
virtual int getNumOutputs();
//each input/output can be labeled to easily identify their using "layer_name.output_name"
virtual String getInputName(int inputNum);
virtual String getOutputName(int outputNum);
};
//containers for String and int
typedef DictValue LayerId;
typedef DictValue BlobId;
CV_EXPORTS class Net
{
public:
CV_EXPORTS Net();
CV_EXPORTS ~Net();
CV_EXPORTS int addLayer(const String &name, const String &type, LayerParams &params = LayerParams());
CV_EXPORTS void deleteLayer(LayerId layer);
//each output of each layer can be labeled by unique string label (as in Caffe)
//if label not specified then %layer_name%.%layer_output_id% can be used
void setOutputNames(LayerId layer, const std::vector<String> &outputNames);
CV_EXPORTS void connect(BlobId input, BlobId output);
CV_EXPORTS void connect(const std::vector<BlobId> &outputs, const std::vector<BlobId> &inputs);
CV_EXPORTS void connect(const std::vector<BlobId> &outputs, LayerId layer);
int getOutputId(LayerId layer, int outputNum);
int getInputId(LayerId layer, int inputNum);
int getLayerId(LayerId layer);
void forward();
void forward(LayerId toLayer);
void forward(LayerId startLayer, LayerId toLayer);
void forward(const std::vector<LayerId> &startLayers, const std::vector<LayerId> &toLayers);
//[Wished feature] Optimized smart forward(). Makes forward only for layers which wasn't changed after previous forward().
void forwardOpt(LayerId toLayer);
void forwardOpt(const std::vector<LayerId> &toLayers);
void setBlob(BlobId outputName, const Blob &blob);
Blob getBlob(BlobId outputName);
void setParam(LayerId layer, int numParam, const Blob &blob);
void getParam(LayerId layer, int numParam);
private:
struct Impl;
Ptr<Impl> impl;
};
CV_EXPORTS class Importer
{
public:
virtual void populateNet(Net net) = 0;
virtual ~Importer();
};
CV_EXPORTS Ptr<Importer> createCaffeImporter(const String &prototxt, const String &caffeModel);
}
}
#include "dnn/dnn.inl.hpp"
#endif

@ -57,14 +57,14 @@ public:
} }
template <typename T> template <typename T>
const T &get(const String &name, const T &default) const const T &get(const String &name, const T &default_value) const
{ {
_Dict::const_iterator i = dict.find(name); _Dict::const_iterator i = dict.find(name);
if (i != dict.end()) if (i != dict.end())
return i->second.get<T>(); return i->second.get<T>();
else else
return default; return default_value;
} }
template<typename T> template<typename T>

@ -0,0 +1,167 @@
#ifndef __OPENCV_DNN_DNN_HPP__
#define __OPENCV_DNN_DNN_HPP__
#include <opencv2/core.hpp>
#include <map>
#include <vector>
#include <opencv2/dnn/dict.hpp>
namespace cv
{
namespace dnn
{
class Layer;
class NetConfiguration;
class Net;
class Blob;
class LayerParams;
//wrapper over cv::Mat and cv::UMat
class CV_EXPORTS Blob
{
public:
Blob();
Blob(InputArray in);
void fill(InputArray in);
void fill(int ndims, const int *sizes, int type, void *data, bool deepCopy = true);
void create(int ndims, const int *sizes, int type = CV_32F);
bool empty() const;
Mat& getMatRef();
const Mat& getMatRef() const;
Mat getMat();
Mat getMat(int num, int channel);
int cols() const;
int rows() const;
Size size() const;
int channels() const;
int num() const;
Vec4i shape() const;
private:
Mat m;
};
class CV_EXPORTS LayerParams : public Dict
{
public:
std::vector<Blob> learnedBlobs;
};
class CV_EXPORTS LayerRegister
{
public:
typedef Layer* (*Constuctor)();
static void registerLayer(const String &type, Constuctor constructor);
static void unregisterLayer(const String &type);
static Ptr<Layer> createLayerInstance(const String &type);
private:
LayerRegister();
LayerRegister(const LayerRegister &lr);
static std::map<String, Constuctor> registeredLayers;
};
//this class allows to build new Layers
class CV_EXPORTS Layer
{
public:
//TODO: this field must be declared as public if we want support possibility to change these params in runtime
std::vector<Blob> learnedParams;
virtual ~Layer();
//type of Layer
virtual String type() const = 0;
//setUp calls once (think that it's constructor)
virtual void setUp(LayerParams &params) = 0;
//maybe useless function
//shape of output blobs must be adjusted with respect to shape of input blobs
virtual void adjustShape(const std::vector<Blob> &inputs, std::vector<Blob> &outputs) = 0;
virtual void forward(std::vector<Blob> &inputs, std::vector<Blob> &outputs) = 0;
virtual int getNumInputs();
virtual int getNumOutputs();
//each input/output can be labeled to easily identify their using "layer_name.output_name"
virtual String getInputName(int inputNum);
virtual String getOutputName(int outputNum);
};
//containers for String and int
typedef DictValue LayerId;
typedef DictValue BlobId;
class CV_EXPORTS Net
{
public:
Net();
~Net();
int addLayer(const String &name, const String &type, LayerParams &params = LayerParams());
void deleteLayer(LayerId layer);
//each output of each layer can be labeled by unique string label (as in Caffe)
//if label not specified then %layer_name%.%layer_output_id% can be used
void setOutputNames(LayerId layer, const std::vector<String> &outputNames);
void connect(BlobId input, BlobId output);
void connect(const std::vector<BlobId> &outputs, const std::vector<BlobId> &inputs);
void connect(const std::vector<BlobId> &outputs, LayerId layer);
int getOutputId(LayerId layer, int outputNum);
int getInputId(LayerId layer, int inputNum);
int getLayerId(LayerId layer);
void forward();
void forward(LayerId toLayer);
void forward(LayerId startLayer, LayerId toLayer);
void forward(const std::vector<LayerId> &startLayers, const std::vector<LayerId> &toLayers);
//[Wished feature] Optimized smart forward(). Makes forward only for layers which wasn't changed after previous forward().
void forwardOpt(LayerId toLayer);
void forwardOpt(const std::vector<LayerId> &toLayers);
void setBlob(BlobId outputName, const Blob &blob);
Blob getBlob(BlobId outputName);
void setParam(LayerId layer, int numParam, const Blob &blob);
void getParam(LayerId layer, int numParam);
private:
struct Impl;
Ptr<Impl> impl;
};
class CV_EXPORTS Importer
{
public:
virtual void populateNet(Net net) = 0;
virtual ~Importer();
};
CV_EXPORTS Ptr<Importer> createCaffeImporter(const String &prototxt, const String &caffeModel);
}
}
#include <opencv2/dnn/dnn.inl.hpp>
#endif /* __OPENCV_DNN_DNN_HPP__ */

@ -7,26 +7,23 @@ namespace cv
{ {
namespace dnn namespace dnn
{ {
inline inline Mat& Blob::getMatRef()
Mat& Blob::getMatRef()
{ {
return m; return m;
} }
inline inline const Mat& Blob::getMatRef() const
const Mat& Blob::getMatRef() const
{ {
return m; return m;
} }
inline inline Mat Blob::getMat()
Mat Blob::getMat()
{ {
return m; return m;
} }
Mat Blob::getMat(int num, int channel) inline Mat Blob::getMat(int num, int channel)
{ {
CV_Assert(false); CV_Assert(false);
return Mat(); return Mat();

@ -90,10 +90,31 @@ String toString(const T &v)
return ss.str(); return ss.str();
} }
int Layer::getNumInputs()
{
return 1;
}
int Layer::getNumOutputs()
{
return 1;
}
cv::String Layer::getInputName(int inputNum) cv::String Layer::getInputName(int inputNum)
{ {
return "input" + toString(inputNum); return "input" + toString(inputNum);
} }
cv::String Layer::getOutputName(int outputNum)
{
return "output" + toString(outputNum);
}
Layer::~Layer()
{
}
} }
} }
Loading…
Cancel
Save