| OpenCV 4.3.0 Open Source Computer Vision

Public Member Functions | Protected Attributes | List of all members
cv::dnn::Model Class Reference
Deep Neural Network module

This class is presented high-level API for neural networks. More...

`#include <opencv2/dnn/dnn.hpp>`

Inheritance diagram for cv::dnn::Model:

## Public Member Functions
| Model ()
| Default constructor. More...
| Model (const String &model, const String &config="")
| Create model from deep learning network represented in one of the supported formats. An order of `model` and `config` arguments does not matter. More...
| Model (const Net &network)
| Create model from deep learning network. More...
void | predict (InputArray frame, OutputArrayOfArrays outs)
| Given the `input` frame, create input blob, run net and return the output `blobs`. More...
Model & | setInputCrop (bool crop)
| Set flag crop for frame. More...
Model & | setInputMean (const Scalar &mean)
| Set mean value for frame. More...
void | setInputParams (double scale=1.0, const Size &size=Size(), const Scalar &mean=Scalar(), bool swapRB=false, bool crop=false)
| Set preprocessing parameters for frame. More...
Model & | setInputScale (double scale)
| Set scalefactor value for frame. More...
Model & | setInputSize (const Size &size)
| Set input size for frame. More...
Model & | setInputSize (int width, int height)
| Set input size for frame. More...
Model & | setInputSwapRB (bool swapRB)
| Set flag swapRB for frame. More...
Public Member Functions inherited from cv::dnn::Net
| Net ()
| Default constructor. More...
| ~Net ()
| Destructor frees the net only if there aren't references to the net anymore. More...
int | addLayer (const String &name, const String &type, LayerParams &params)
| Adds new layer to the net. More...
int | addLayerToPrev (const String &name, const String &type, LayerParams &params)
| Adds new layer and connects its first input to the first output of previously added layer. More...
void | connect (String outPin, String inpPin)
| Connects output of the first layer to input of the second layer. More...
void | connect (int outLayerId, int outNum, int inpLayerId, int inpNum)
| Connects #`outNum` output of the first layer to #`inNum` input of the second layer. More...
String | dump ()
| Dump net to String. More...
void | dumpToFile (const String &path)
| Dump net structure, hyperparameters, backend, target and fusion to dot file. More...
bool | empty () const
void | enableFusion (bool fusion)
| Enables or disables layer fusion in the network. More...
Mat | forward (const String &outputName=String())
| Runs forward pass to compute output of layer with name `outputName`. More...
void | forward (OutputArrayOfArrays outputBlobs, const String &outputName=String())
| Runs forward pass to compute output of layer with name `outputName`. More...
void | forward (OutputArrayOfArrays outputBlobs, const std::vector< String > &outBlobNames)
| Runs forward pass to compute outputs of layers listed in `outBlobNames`. More...
void | forward (std::vector< std::vector< Mat > > &outputBlobs, const std::vector< String > &outBlobNames)
| Runs forward pass to compute outputs of layers listed in `outBlobNames`. More...
AsyncArray | forwardAsync (const String &outputName=String())
| Runs forward pass to compute output of layer with name `outputName`. More...
int64 | getFLOPS (const std::vector< MatShape > &netInputShapes) const
| Computes FLOP for whole loaded model with specified input shapes. More...
int64 | getFLOPS (const MatShape &netInputShape) const
int64 | getFLOPS (const int layerId, const std::vector< MatShape > &netInputShapes) const
int64 | getFLOPS (const int layerId, const MatShape &netInputShape) const
Ptr< Layer > | getLayer (LayerId layerId)
| Returns pointer to layer with specified id or name which the network use. More...
int | getLayerId (const String &layer)
| Converts string name of the layer to the integer identifier. More...
std::vector< Ptr< Layer > > | getLayerInputs (LayerId layerId)
| Returns pointers to input layers of specific layer. More...
std::vector< String > | getLayerNames () const
int | getLayersCount (const String &layerType) const
| Returns count of layers of specified type. More...
void | getLayerShapes (const MatShape &netInputShape, const int layerId, std::vector< MatShape > &inLayerShapes, std::vector< MatShape > &outLayerShapes) const
| Returns input and output shapes for layer with specified id in loaded model; preliminary inferencing isn't necessary. More...
void | getLayerShapes (const std::vector< MatShape > &netInputShapes, const int layerId, std::vector< MatShape > &inLayerShapes, std::vector< MatShape > &outLayerShapes) const
void | getLayersShapes (const std::vector< MatShape > &netInputShapes, std::vector< int > &layersIds, std::vector< std::vector< MatShape > > &inLayersShapes, std::vector< std::vector< MatShape > > &outLayersShapes) const
| Returns input and output shapes for all layers in loaded model; preliminary inferencing isn't necessary. More...
void | getLayersShapes (const MatShape &netInputShape, std::vector< int > &layersIds, std::vector< std::vector< MatShape > > &inLayersShapes, std::vector< std::vector< MatShape > > &outLayersShapes) const
void | getLayerTypes (std::vector< String > &layersTypes) const
| Returns list of types for layer used in model. More...
void | getMemoryConsumption (const std::vector< MatShape > &netInputShapes, size_t &weights, size_t &blobs) const
| Computes bytes number which are required to store all weights and intermediate blobs for model. More...
void | getMemoryConsumption (const MatShape &netInputShape, size_t &weights, size_t &blobs) const
void | getMemoryConsumption (const int layerId, const std::vector< MatShape > &netInputShapes, size_t &weights, size_t &blobs) const
void | getMemoryConsumption (const int layerId, const MatShape &netInputShape, size_t &weights, size_t &blobs) const
void | getMemoryConsumption (const std::vector< MatShape > &netInputShapes, std::vector< int > &layerIds, std::vector< size_t > &weights, std::vector< size_t > &blobs) const
| Computes bytes number which are required to store all weights and intermediate blobs for each layer. More...
void | getMemoryConsumption (const MatShape &netInputShape, std::vector< int > &layerIds, std::vector< size_t > &weights, std::vector< size_t > &blobs) const
Mat | getParam (LayerId layer, int numParam=0)
| Returns parameter blob of the layer. More...
int64 | getPerfProfile (std::vector< double > &timings)
| Returns overall time for inference and timings (in ticks) for layers. Indexes in returned vector correspond to layers ids. Some layers can be fused with others, in this case zero ticks count will be return for that skipped layers. More...
std::vector< int > | getUnconnectedOutLayers () const
| Returns indexes of layers with unconnected outputs. More...
std::vector< String > | getUnconnectedOutLayersNames () const
| Returns names of layers with unconnected outputs. More...
void | setHalideScheduler (const String &scheduler)
| Compile Halide layers. More...
void | setInput (InputArray blob, const String &name="", double scalefactor=1.0, const Scalar &mean=Scalar())
| Sets the new input value for the network. More...
void | setInputShape (const String &inputName, const MatShape &shape)
| Specify shape of network input. More...
void | setInputsNames (const std::vector< String > &inputBlobNames)
| Sets outputs names of the network input pseudo layer. More...
void | setParam (LayerId layer, int numParam, const Mat &blob)
| Sets the new value for the learned param of the layer. More...
void | setPreferableBackend (int backendId)
| Ask network to use specific computation backend where it supported. More...
void | setPreferableTarget (int targetId)
| Ask network to make computations on specific target device. More...

## Protected Attributes
Ptr< Impl > | impl

## Additional Inherited Members
Public Types inherited from cv::dnn::Net
typedef DictValue | LayerId
| Container for strings and integers. More...
Static Public Member Functions inherited from cv::dnn::Net
static Net | readFromModelOptimizer (const String &xml, const String &bin)
| Create a network from Intel's Model Optimizer intermediate representation (IR). More...
static Net | readFromModelOptimizer (const std::vector< uchar > &bufferModelConfig, const std::vector< uchar > &bufferWeights)
| Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR). More...
static Net | readFromModelOptimizer (const uchar *bufferModelConfigPtr, size_t bufferModelConfigSize, const uchar *bufferWeightsPtr, size_t bufferWeightsSize)
| Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR). More...

## Detailed Description

This class is presented high-level API for neural networks.

Model allows to set params for preprocessing input image. Model creates net from file with trained weights and config, sets preprocessing input and runs forward pass.

## Constructor & Destructor Documentation

## ◆ Model() [1/3]

cv::dnn::Model::Model | ( |  | ) |

Python:
| <dnn_Model object> | = | cv.dnn_Model( | model[, config] | )
| <dnn_Model object> | = | cv.dnn_Model( | network | )

Default constructor.

## ◆ Model() [2/3]

cv::dnn::Model::Model | ( | const String & | model,
|  | const String & | config = `""`
| ) |  |

Python:
| <dnn_Model object> | = | cv.dnn_Model( | model[, config] | )
| <dnn_Model object> | = | cv.dnn_Model( | network | )

Create model from deep learning network represented in one of the supported formats. An order of `model` and `config` arguments does not matter.

Parameters

  [in] | model | Binary file contains trained weights.
  [in] | config | Text file contains network configuration.

## ◆ Model() [3/3]

cv::dnn::Model::Model | ( | const Net & | network | ) |

Python:
| <dnn_Model object> | = | cv.dnn_Model( | model[, config] | )
| <dnn_Model object> | = | cv.dnn_Model( | network | )

Create model from deep learning network.

Parameters

  [in] | network | Net object.

## Member Function Documentation

## ◆ predict()

void cv::dnn::Model::predict | ( | InputArray | frame,
|  | OutputArrayOfArrays | outs
| ) |  |

Python:
| outs | = | cv.dnn_Model.predict( | frame[, outs] | )

Given the `input` frame, create input blob, run net and return the output `blobs`.

Parameters

  [in] | frame | The input image.
  [out] | outs | Allocated output blobs, which will store results of the computation.

## ◆ setInputCrop()

Model& cv::dnn::Model::setInputCrop | ( | bool | crop | ) |

Python:
| retval | = | cv.dnn_Model.setInputCrop( | crop | )

Set flag crop for frame.

Parameters

  [in] | crop | Flag which indicates whether image will be cropped after resize or not.

## ◆ setInputMean()

Model& cv::dnn::Model::setInputMean | ( | const Scalar & | mean | ) |

Python:
| retval | = | cv.dnn_Model.setInputMean( | mean | )

Set mean value for frame.

Parameters

  [in] | mean | Scalar with mean values which are subtracted from channels.

## ◆ setInputParams()

void cv::dnn::Model::setInputParams | ( | double | scale = `1.0`,
|  | const Size & | size = `Size()`,
|  | const Scalar & | mean = `Scalar()`,
|  | bool | swapRB = `false`,
|  | bool | crop = `false`
| ) |  |

Python:
| None | = | cv.dnn_Model.setInputParams( | [, scale[, size[, mean[, swapRB[, crop]]]]] | )

Set preprocessing parameters for frame.

Parameters

  [in] | size | New input size.
  [in] | mean | Scalar with mean values which are subtracted from channels.
  [in] | scale | Multiplier for frame values.
  [in] | swapRB | Flag which indicates that swap first and last channels.
  [in] | crop | Flag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

## ◆ setInputScale()

Model& cv::dnn::Model::setInputScale | ( | double | scale | ) |

Python:
| retval | = | cv.dnn_Model.setInputScale( | scale | )

Set scalefactor value for frame.

Parameters

  [in] | scale | Multiplier for frame values.

## ◆ setInputSize() [1/2]

Model& cv::dnn::Model::setInputSize | ( | const Size & | size | ) |

Python:
| retval | = | cv.dnn_Model.setInputSize( | size | )
| retval | = | cv.dnn_Model.setInputSize( | width, height | )

Set input size for frame.

Parameters

  [in] | size | New input size.

Note
  If shape of the new blob less than 0, then frame size not change.

## ◆ setInputSize() [2/2]

Model& cv::dnn::Model::setInputSize | ( | int | width,
|  | int | height
| ) |  |

Python:
| retval | = | cv.dnn_Model.setInputSize( | size | )
| retval | = | cv.dnn_Model.setInputSize( | width, height | )

Set input size for frame.

Parameters

  [in] | width | New input width.
  [in] | height | New input height.

Note
  If shape of the new blob less than 0, then frame size not change.

## ◆ setInputSwapRB()

Model& cv::dnn::Model::setInputSwapRB | ( | bool | swapRB | ) |

Python:
| retval | = | cv.dnn_Model.setInputSwapRB( | swapRB | )

Set flag swapRB for frame.

Parameters

  [in] | swapRB | Flag which indicates that swap first and last channels.

## Member Data Documentation

## ◆ impl

Ptr<Impl> cv::dnn::Model::impl
| protected

The documentation for this class was generated from the following file:

- opencv2/dnn/dnn.hpp