OpenCV  3.1.0
Open Source Computer Vision
Modules | Classes | Functions
Deep Neural Network module

Modules

 Utilities for new layers registration
 

Classes

class  cv::dnn::Blob
 This class provides methods for continuous n-dimensional CPU and GPU array processing. More...
 
struct  cv::dnn::BlobShape
 Lightweight class for storing and processing a shape of blob (or anything else). More...
 
class  cv::dnn::Dict
 This class implements name-value dictionary, values are instances of DictValue. More...
 
struct  cv::dnn::DictValue
 This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64. More...
 
class  cv::dnn::Importer
 Small interface class for loading trained serialized models of different dnn-frameworks. More...
 
struct  cv::dnn::Layer
 This interface class allows to build new Layers - are building blocks of networks. More...
 
struct  cv::dnn::LayerParams
 This class provides all data needed to initialize layer. More...
 
class  cv::dnn::Net
 This class allows to create and manipulate comprehensive artificial neural networks. More...
 

Functions

Ptr< Importer > cv::dnn::createCaffeImporter (const String &prototxt, const String &caffeModel=String())
 Creates the importer of Caffe framework network. More...
 
Ptr< Importer > cv::dnn::createTorchImporter (const String &filename, bool isBinary=true)
 Creates the importer of Torch7 framework network. More...
 
void cv::dnn::initModule ()
 Initialize dnn module and built-in layers. More...
 
Blob cv::dnn::readTorchBlob (const String &filename, bool isBinary=true)
 Loads blob which was serialized as torch.Tensor object of Torch7 framework. More...
 

Detailed Description

This module contains:

Functionality of this module is designed only for forward pass computations (i. e. network testing). A network training is in principle not supported.

Function Documentation

Ptr<Importer> cv::dnn::createCaffeImporter ( const String prototxt,
const String caffeModel = String() 
)

Creates the importer of Caffe framework network.

Parameters
prototxtpath to the .prototxt file with text description of the network architecture.
caffeModelpath to the .caffemodel file with learned network.
Returns
Pointer to the created importer, NULL in failure cases.
Ptr<Importer> cv::dnn::createTorchImporter ( const String filename,
bool  isBinary = true 
)

Creates the importer of Torch7 framework network.

Parameters
filenamepath to the file, dumped from Torch by using torch.save() function.
isBinaryspecifies whether the network was serialized in ascii mode or binary.
Returns
Pointer to the created importer, NULL in failure cases.
Warning
Torch7 importer is experimental now, you need explicitly set CMake opencv_dnn_BUILD_TORCH_IMPORTER flag to compile its.
Note
Ascii mode of Torch serializer is more preferable, because binary mode extensively use long type of C language, which has different bit-length on different systems.

The loading file must contain serialized nn.Module object with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.

List of supported layers (i.e. object instances derived from Torch nn.Module class):

  • nn.Sequential
  • nn.Parallel
  • nn.Concat
  • nn.Linear
  • nn.SpatialConvolution
  • nn.SpatialMaxPooling, nn.SpatialAveragePooling
  • nn.ReLU, nn.TanH, nn.Sigmoid
  • nn.Reshape

Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.

void cv::dnn::initModule ( )

Initialize dnn module and built-in layers.

This function automatically called on most of OpenCV builds, but you need to call it manually on some specific configurations (iOS for example).

Blob cv::dnn::readTorchBlob ( const String filename,
bool  isBinary = true 
)

Loads blob which was serialized as torch.Tensor object of Torch7 framework.

Warning
This function has the same limitations as createTorchImporter().