OpenCV  4.9.0
Open Source Computer Vision
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
cv::dnn::Net Class Reference

This class allows to create and manipulate comprehensive artificial neural networks. More...

#include <opencv2/dnn/dnn.hpp>

Public Types

typedef DictValue LayerId
 Container for strings and integers. More...
 

Public Member Functions

 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, const int &dtype, LayerParams &params)
 Adds new layer to the net. More...
 
int addLayer (const String &name, const String &type, LayerParams &params)
 
int addLayerToPrev (const String &name, const String &type, const int &dtype, LayerParams &params)
 Adds new layer and connects its first input to the first output of previously added layer. More...
 
int addLayerToPrev (const String &name, const String &type, LayerParams &params)
 
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...
 
void enableWinograd (bool useWinograd)
 Enables or disables the Winograd compute branch. The Winograd compute branch can speed up 3x3 Convolution at a small loss of accuracy. 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
 
Impl * getImpl () const
 
Impl & getImplRef () const
 
void getInputDetails (std::vector< float > &scales, std::vector< int > &zeropoints) const
 Returns input scale and zeropoint for a quantized Net. More...
 
Ptr< LayergetLayer (int layerId) const
 Returns pointer to layer with specified id or name which the network use. More...
 
Ptr< LayergetLayer (const String &layerName) const
 
Ptr< LayergetLayer (const LayerId &layerId) const
 
int getLayerId (const String &layer) const
 Converts string name of the layer to the integer identifier. More...
 
std::vector< Ptr< Layer > > getLayerInputs (int layerId) const
 Returns pointers to input layers of specific layer. More...
 
std::vector< StringgetLayerNames () 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
 
void getOutputDetails (std::vector< float > &scales, std::vector< int > &zeropoints) const
 Returns output scale and zeropoint for a quantized Net. More...
 
Mat getParam (int layer, int numParam=0) const
 Returns parameter blob of the layer. More...
 
Mat getParam (const String &layerName, int numParam=0) const
 
int64 getPerfProfile (std::vector< double > &timings)
 Returns overall time for inference and timings (in ticks) for layers. More...
 
std::vector< int > getUnconnectedOutLayers () const
 Returns indexes of layers with unconnected outputs. More...
 
std::vector< StringgetUnconnectedOutLayersNames () const
 Returns names of layers with unconnected outputs. More...
 
Net quantize (InputArrayOfArrays calibData, int inputsDtype, int outputsDtype, bool perChannel=true)
 Returns a quantized Net from a floating-point Net. More...
 
int registerOutput (const std::string &outputName, int layerId, int outputPort)
 Registers network output with name. 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 (int layer, int numParam, const Mat &blob)
 Sets the new value for the learned param of the layer. More...
 
void setParam (const String &layerName, int numParam, const Mat &blob)
 
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...
 

Static Public Member Functions

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...
 

Protected Attributes

Ptr< Impl > impl
 

Friends

class accessor::DnnNetAccessor
 

Detailed Description

This class allows to create and manipulate comprehensive artificial neural networks.

Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances, and edges specify relationships between layers inputs and outputs.

Each network layer has unique integer id and unique string name inside its network. LayerId can store either layer name or layer id.

This class supports reference counting of its instances, i. e. copies point to the same instance.

Examples:
samples/dnn/colorization.cpp, and samples/dnn/openpose.cpp.

Member Typedef Documentation

◆ LayerId

Container for strings and integers.

Deprecated:
Use getLayerId() with int result.

Constructor & Destructor Documentation

◆ Net()

cv::dnn::Net::Net ( )
Python:
cv.dnn.Net() -> <dnn_Net object>

Default constructor.

◆ ~Net()

cv::dnn::Net::~Net ( )

Destructor frees the net only if there aren't references to the net anymore.

Member Function Documentation

◆ addLayer() [1/2]

int cv::dnn::Net::addLayer ( const String name,
const String type,
const int &  dtype,
LayerParams params 
)

Adds new layer to the net.

Parameters
nameunique name of the adding layer.
typetypename of the adding layer (type must be registered in LayerRegister).
dtypedatatype of output blobs.
paramsparameters which will be used to initialize the creating layer.
Returns
unique identifier of created layer, or -1 if a failure will happen.

◆ addLayer() [2/2]

int cv::dnn::Net::addLayer ( const String name,
const String type,
LayerParams params 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ addLayerToPrev() [1/2]

int cv::dnn::Net::addLayerToPrev ( const String name,
const String type,
const int &  dtype,
LayerParams params 
)

Adds new layer and connects its first input to the first output of previously added layer.

See also
addLayer()

◆ addLayerToPrev() [2/2]

int cv::dnn::Net::addLayerToPrev ( const String name,
const String type,
LayerParams params 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ connect() [1/2]

void cv::dnn::Net::connect ( String  outPin,
String  inpPin 
)
Python:
cv.dnn.Net.connect(outPin, inpPin) -> None

Connects output of the first layer to input of the second layer.

Parameters
outPindescriptor of the first layer output.
inpPindescriptor of the second layer input.

Descriptors have the following template <layer_name>[.input_number]:

  • the first part of the template layer_name is string name of the added layer. If this part is empty then the network input pseudo layer will be used;
  • the second optional part of the template input_number is either number of the layer input, either label one. If this part is omitted then the first layer input will be used.

    See also
    setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex()

◆ connect() [2/2]

void cv::dnn::Net::connect ( int  outLayerId,
int  outNum,
int  inpLayerId,
int  inpNum 
)
Python:
cv.dnn.Net.connect(outPin, inpPin) -> None

Connects #outNum output of the first layer to #inNum input of the second layer.

Parameters
outLayerIdidentifier of the first layer
outNumnumber of the first layer output
inpLayerIdidentifier of the second layer
inpNumnumber of the second layer input

◆ dump()

String cv::dnn::Net::dump ( )
Python:
cv.dnn.Net.dump() -> retval

Dump net to String.

Returns
String with structure, hyperparameters, backend, target and fusion Call method after setInput(). To see correct backend, target and fusion run after forward().

◆ dumpToFile()

void cv::dnn::Net::dumpToFile ( const String path)
Python:
cv.dnn.Net.dumpToFile(path) -> None

Dump net structure, hyperparameters, backend, target and fusion to dot file.

Parameters
pathpath to output file with .dot extension
See also
dump()

◆ empty()

bool cv::dnn::Net::empty ( ) const
Python:
cv.dnn.Net.empty() -> retval

Returns true if there are no layers in the network.

◆ enableFusion()

void cv::dnn::Net::enableFusion ( bool  fusion)
Python:
cv.dnn.Net.enableFusion(fusion) -> None

Enables or disables layer fusion in the network.

Parameters
fusiontrue to enable the fusion, false to disable. The fusion is enabled by default.

◆ enableWinograd()

void cv::dnn::Net::enableWinograd ( bool  useWinograd)
Python:
cv.dnn.Net.enableWinograd(useWinograd) -> None

Enables or disables the Winograd compute branch. The Winograd compute branch can speed up 3x3 Convolution at a small loss of accuracy.

Parameters
useWinogradtrue to enable the Winograd compute branch. The default is true.

◆ forward() [1/4]

Mat cv::dnn::Net::forward ( const String outputName = String())
Python:
cv.dnn.Net.forward([, outputName]) -> retval
cv.dnn.Net.forward([, outputBlobs[, outputName]]) -> outputBlobs
cv.dnn.Net.forward(outBlobNames[, outputBlobs]) -> outputBlobs
cv.dnn.Net.forwardAndRetrieve(outBlobNames) -> outputBlobs

Runs forward pass to compute output of layer with name outputName.

Parameters
outputNamename for layer which output is needed to get
Returns
blob for first output of specified layer.

By default runs forward pass for the whole network.

Examples:
samples/dnn/colorization.cpp, and samples/dnn/openpose.cpp.

◆ forward() [2/4]

void cv::dnn::Net::forward ( OutputArrayOfArrays  outputBlobs,
const String outputName = String() 
)
Python:
cv.dnn.Net.forward([, outputName]) -> retval
cv.dnn.Net.forward([, outputBlobs[, outputName]]) -> outputBlobs
cv.dnn.Net.forward(outBlobNames[, outputBlobs]) -> outputBlobs
cv.dnn.Net.forwardAndRetrieve(outBlobNames) -> outputBlobs

Runs forward pass to compute output of layer with name outputName.

Parameters
outputBlobscontains all output blobs for specified layer.
outputNamename for layer which output is needed to get

If outputName is empty, runs forward pass for the whole network.

◆ forward() [3/4]

void cv::dnn::Net::forward ( OutputArrayOfArrays  outputBlobs,
const std::vector< String > &  outBlobNames 
)
Python:
cv.dnn.Net.forward([, outputName]) -> retval
cv.dnn.Net.forward([, outputBlobs[, outputName]]) -> outputBlobs
cv.dnn.Net.forward(outBlobNames[, outputBlobs]) -> outputBlobs
cv.dnn.Net.forwardAndRetrieve(outBlobNames) -> outputBlobs

Runs forward pass to compute outputs of layers listed in outBlobNames.

Parameters
outputBlobscontains blobs for first outputs of specified layers.
outBlobNamesnames for layers which outputs are needed to get

◆ forward() [4/4]

void cv::dnn::Net::forward ( std::vector< std::vector< Mat > > &  outputBlobs,
const std::vector< String > &  outBlobNames 
)
Python:
cv.dnn.Net.forward([, outputName]) -> retval
cv.dnn.Net.forward([, outputBlobs[, outputName]]) -> outputBlobs
cv.dnn.Net.forward(outBlobNames[, outputBlobs]) -> outputBlobs
cv.dnn.Net.forwardAndRetrieve(outBlobNames) -> outputBlobs

Runs forward pass to compute outputs of layers listed in outBlobNames.

Parameters
outputBlobscontains all output blobs for each layer specified in outBlobNames.
outBlobNamesnames for layers which outputs are needed to get

◆ forwardAsync()

AsyncArray cv::dnn::Net::forwardAsync ( const String outputName = String())
Python:
cv.dnn.Net.forwardAsync([, outputName]) -> retval

Runs forward pass to compute output of layer with name outputName.

Parameters
outputNamename for layer which output is needed to get

By default runs forward pass for the whole network.

This is an asynchronous version of forward(const String&). dnn::DNN_BACKEND_INFERENCE_ENGINE backend is required.

◆ getFLOPS() [1/4]

int64 cv::dnn::Net::getFLOPS ( const std::vector< MatShape > &  netInputShapes) const
Python:
cv.dnn.Net.getFLOPS(netInputShapes) -> retval
cv.dnn.Net.getFLOPS(netInputShape) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShapes) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShape) -> retval

Computes FLOP for whole loaded model with specified input shapes.

Parameters
netInputShapesvector of shapes for all net inputs.
Returns
computed FLOP.

◆ getFLOPS() [2/4]

int64 cv::dnn::Net::getFLOPS ( const MatShape netInputShape) const
Python:
cv.dnn.Net.getFLOPS(netInputShapes) -> retval
cv.dnn.Net.getFLOPS(netInputShape) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShapes) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShape) -> retval

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getFLOPS() [3/4]

int64 cv::dnn::Net::getFLOPS ( const int  layerId,
const std::vector< MatShape > &  netInputShapes 
) const
Python:
cv.dnn.Net.getFLOPS(netInputShapes) -> retval
cv.dnn.Net.getFLOPS(netInputShape) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShapes) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShape) -> retval

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getFLOPS() [4/4]

int64 cv::dnn::Net::getFLOPS ( const int  layerId,
const MatShape netInputShape 
) const
Python:
cv.dnn.Net.getFLOPS(netInputShapes) -> retval
cv.dnn.Net.getFLOPS(netInputShape) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShapes) -> retval
cv.dnn.Net.getFLOPS(layerId, netInputShape) -> retval

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getImpl()

Impl* cv::dnn::Net::getImpl ( ) const
inline

◆ getImplRef()

Impl& cv::dnn::Net::getImplRef ( ) const
inline

◆ getInputDetails()

void cv::dnn::Net::getInputDetails ( std::vector< float > &  scales,
std::vector< int > &  zeropoints 
) const
Python:
cv.dnn.Net.getInputDetails() -> scales, zeropoints

Returns input scale and zeropoint for a quantized Net.

Parameters
scalesoutput parameter for returning input scales.
zeropointsoutput parameter for returning input zeropoints.

◆ getLayer() [1/3]

Ptr<Layer> cv::dnn::Net::getLayer ( int  layerId) const
Python:
cv.dnn.Net.getLayer(layerId) -> retval
cv.dnn.Net.getLayer(layerName) -> retval

Returns pointer to layer with specified id or name which the network use.

Examples:
samples/dnn/colorization.cpp.

◆ getLayer() [2/3]

Ptr<Layer> cv::dnn::Net::getLayer ( const String layerName) const
inline
Python:
cv.dnn.Net.getLayer(layerId) -> retval
cv.dnn.Net.getLayer(layerName) -> retval

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated:
Use int getLayerId(const String &layer)

◆ getLayer() [3/3]

Ptr<Layer> cv::dnn::Net::getLayer ( const LayerId layerId) const
Python:
cv.dnn.Net.getLayer(layerId) -> retval
cv.dnn.Net.getLayer(layerName) -> retval

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated:
to be removed

◆ getLayerId()

int cv::dnn::Net::getLayerId ( const String layer) const
Python:
cv.dnn.Net.getLayerId(layer) -> retval

Converts string name of the layer to the integer identifier.

Returns
id of the layer, or -1 if the layer wasn't found.

◆ getLayerInputs()

std::vector<Ptr<Layer> > cv::dnn::Net::getLayerInputs ( int  layerId) const

Returns pointers to input layers of specific layer.

◆ getLayerNames()

std::vector<String> cv::dnn::Net::getLayerNames ( ) const
Python:
cv.dnn.Net.getLayerNames() -> retval

◆ getLayersCount()

int cv::dnn::Net::getLayersCount ( const String layerType) const
Python:
cv.dnn.Net.getLayersCount(layerType) -> retval

Returns count of layers of specified type.

Parameters
layerTypetype.
Returns
count of layers

◆ getLayerShapes() [1/2]

void cv::dnn::Net::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.

Parameters
netInputShapeshape input blob in net input layer.
layerIdid for layer.
inLayerShapesoutput parameter for input layers shapes; order is the same as in layersIds
outLayerShapesoutput parameter for output layers shapes; order is the same as in layersIds

◆ getLayerShapes() [2/2]

void cv::dnn::Net::getLayerShapes ( const std::vector< MatShape > &  netInputShapes,
const int  layerId,
std::vector< MatShape > &  inLayerShapes,
std::vector< MatShape > &  outLayerShapes 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getLayersShapes() [1/2]

void cv::dnn::Net::getLayersShapes ( const std::vector< MatShape > &  netInputShapes,
std::vector< int > &  layersIds,
std::vector< std::vector< MatShape > > &  inLayersShapes,
std::vector< std::vector< MatShape > > &  outLayersShapes 
) const
Python:
cv.dnn.Net.getLayersShapes(netInputShapes) -> layersIds, inLayersShapes, outLayersShapes
cv.dnn.Net.getLayersShapes(netInputShape) -> layersIds, inLayersShapes, outLayersShapes

Returns input and output shapes for all layers in loaded model; preliminary inferencing isn't necessary.

Parameters
netInputShapesshapes for all input blobs in net input layer.
layersIdsoutput parameter for layer IDs.
inLayersShapesoutput parameter for input layers shapes; order is the same as in layersIds
outLayersShapesoutput parameter for output layers shapes; order is the same as in layersIds

◆ getLayersShapes() [2/2]

void cv::dnn::Net::getLayersShapes ( const MatShape netInputShape,
std::vector< int > &  layersIds,
std::vector< std::vector< MatShape > > &  inLayersShapes,
std::vector< std::vector< MatShape > > &  outLayersShapes 
) const
Python:
cv.dnn.Net.getLayersShapes(netInputShapes) -> layersIds, inLayersShapes, outLayersShapes
cv.dnn.Net.getLayersShapes(netInputShape) -> layersIds, inLayersShapes, outLayersShapes

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getLayerTypes()

void cv::dnn::Net::getLayerTypes ( std::vector< String > &  layersTypes) const
Python:
cv.dnn.Net.getLayerTypes() -> layersTypes

Returns list of types for layer used in model.

Parameters
layersTypesoutput parameter for returning types.

◆ getMemoryConsumption() [1/6]

void cv::dnn::Net::getMemoryConsumption ( const std::vector< MatShape > &  netInputShapes,
size_t &  weights,
size_t &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

Computes bytes number which are required to store all weights and intermediate blobs for model.

Parameters
netInputShapesvector of shapes for all net inputs.
weightsoutput parameter to store resulting bytes for weights.
blobsoutput parameter to store resulting bytes for intermediate blobs.

◆ getMemoryConsumption() [2/6]

void cv::dnn::Net::getMemoryConsumption ( const MatShape netInputShape,
size_t &  weights,
size_t &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getMemoryConsumption() [3/6]

void cv::dnn::Net::getMemoryConsumption ( const int  layerId,
const std::vector< MatShape > &  netInputShapes,
size_t &  weights,
size_t &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getMemoryConsumption() [4/6]

void cv::dnn::Net::getMemoryConsumption ( const int  layerId,
const MatShape netInputShape,
size_t &  weights,
size_t &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getMemoryConsumption() [5/6]

void cv::dnn::Net::getMemoryConsumption ( const std::vector< MatShape > &  netInputShapes,
std::vector< int > &  layerIds,
std::vector< size_t > &  weights,
std::vector< size_t > &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

Computes bytes number which are required to store all weights and intermediate blobs for each layer.

Parameters
netInputShapesvector of shapes for all net inputs.
layerIdsoutput vector to save layer IDs.
weightsoutput parameter to store resulting bytes for weights.
blobsoutput parameter to store resulting bytes for intermediate blobs.

◆ getMemoryConsumption() [6/6]

void cv::dnn::Net::getMemoryConsumption ( const MatShape netInputShape,
std::vector< int > &  layerIds,
std::vector< size_t > &  weights,
std::vector< size_t > &  blobs 
) const
Python:
cv.dnn.Net.getMemoryConsumption(netInputShape) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShapes) -> weights, blobs
cv.dnn.Net.getMemoryConsumption(layerId, netInputShape) -> weights, blobs

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getOutputDetails()

void cv::dnn::Net::getOutputDetails ( std::vector< float > &  scales,
std::vector< int > &  zeropoints 
) const
Python:
cv.dnn.Net.getOutputDetails() -> scales, zeropoints

Returns output scale and zeropoint for a quantized Net.

Parameters
scalesoutput parameter for returning output scales.
zeropointsoutput parameter for returning output zeropoints.

◆ getParam() [1/2]

Mat cv::dnn::Net::getParam ( int  layer,
int  numParam = 0 
) const
Python:
cv.dnn.Net.getParam(layer[, numParam]) -> retval
cv.dnn.Net.getParam(layerName[, numParam]) -> retval

Returns parameter blob of the layer.

Parameters
layername or id of the layer.
numParamindex of the layer parameter in the Layer::blobs array.
See also
Layer::blobs

◆ getParam() [2/2]

Mat cv::dnn::Net::getParam ( const String layerName,
int  numParam = 0 
) const
inline
Python:
cv.dnn.Net.getParam(layer[, numParam]) -> retval
cv.dnn.Net.getParam(layerName[, numParam]) -> retval

◆ getPerfProfile()

int64 cv::dnn::Net::getPerfProfile ( std::vector< double > &  timings)
Python:
cv.dnn.Net.getPerfProfile() -> retval, 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. Supported by DNN_BACKEND_OPENCV on DNN_TARGET_CPU only.

Parameters
[out]timingsvector for tick timings for all layers.
Returns
overall ticks for model inference.

◆ getUnconnectedOutLayers()

std::vector<int> cv::dnn::Net::getUnconnectedOutLayers ( ) const
Python:
cv.dnn.Net.getUnconnectedOutLayers() -> retval

Returns indexes of layers with unconnected outputs.

FIXIT: Rework API to registerOutput() approach, deprecate this call

◆ getUnconnectedOutLayersNames()

std::vector<String> cv::dnn::Net::getUnconnectedOutLayersNames ( ) const
Python:
cv.dnn.Net.getUnconnectedOutLayersNames() -> retval

Returns names of layers with unconnected outputs.

FIXIT: Rework API to registerOutput() approach, deprecate this call

◆ quantize()

Net cv::dnn::Net::quantize ( InputArrayOfArrays  calibData,
int  inputsDtype,
int  outputsDtype,
bool  perChannel = true 
)
Python:
cv.dnn.Net.quantize(calibData, inputsDtype, outputsDtype[, perChannel]) -> retval

Returns a quantized Net from a floating-point Net.

Parameters
calibDataCalibration data to compute the quantization parameters.
inputsDtypeDatatype of quantized net's inputs. Can be CV_32F or CV_8S.
outputsDtypeDatatype of quantized net's outputs. Can be CV_32F or CV_8S.
perChannelQuantization granularity of quantized Net. The default is true, that means quantize model in per-channel way (channel-wise). Set it false to quantize model in per-tensor way (or tensor-wise).

◆ readFromModelOptimizer() [1/3]

static Net cv::dnn::Net::readFromModelOptimizer ( const String xml,
const String bin 
)
static
Python:
cv.dnn.Net.readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net.readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval
cv.dnn.Net_readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net_readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval

Create a network from Intel's Model Optimizer intermediate representation (IR).

Parameters
[in]xmlXML configuration file with network's topology.
[in]binBinary file with trained weights. Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine backend.

◆ readFromModelOptimizer() [2/3]

static Net cv::dnn::Net::readFromModelOptimizer ( const std::vector< uchar > &  bufferModelConfig,
const std::vector< uchar > &  bufferWeights 
)
static
Python:
cv.dnn.Net.readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net.readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval
cv.dnn.Net_readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net_readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval

Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).

Parameters
[in]bufferModelConfigbuffer with model's configuration.
[in]bufferWeightsbuffer with model's trained weights.
Returns
Net object.

◆ readFromModelOptimizer() [3/3]

static Net cv::dnn::Net::readFromModelOptimizer ( const uchar bufferModelConfigPtr,
size_t  bufferModelConfigSize,
const uchar bufferWeightsPtr,
size_t  bufferWeightsSize 
)
static
Python:
cv.dnn.Net.readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net.readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval
cv.dnn.Net_readFromModelOptimizer(xml, bin) -> retval
cv.dnn.Net_readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval

Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).

Parameters
[in]bufferModelConfigPtrbuffer pointer of model's configuration.
[in]bufferModelConfigSizebuffer size of model's configuration.
[in]bufferWeightsPtrbuffer pointer of model's trained weights.
[in]bufferWeightsSizebuffer size of model's trained weights.
Returns
Net object.

◆ registerOutput()

int cv::dnn::Net::registerOutput ( const std::string &  outputName,
int  layerId,
int  outputPort 
)

Registers network output with name.

Function may create additional 'Identity' layer.

Parameters
outputNameidentifier of the output
layerIdidentifier of the second layer
outputPortnumber of the second layer input
Returns
index of bound layer (the same as layerId or newly created)

◆ setHalideScheduler()

void cv::dnn::Net::setHalideScheduler ( const String scheduler)
Python:
cv.dnn.Net.setHalideScheduler(scheduler) -> None

Compile Halide layers.

Parameters
[in]schedulerPath to YAML file with scheduling directives.
See also
setPreferableBackend

Schedule layers that support Halide backend. Then compile them for specific target. For layers that not represented in scheduling file or if no manual scheduling used at all, automatic scheduling will be applied.

◆ setInput()

void cv::dnn::Net::setInput ( InputArray  blob,
const String name = "",
double  scalefactor = 1.0,
const Scalar mean = Scalar() 
)
Python:
cv.dnn.Net.setInput(blob[, name[, scalefactor[, mean]]]) -> None

Sets the new input value for the network.

Parameters
blobA new blob. Should have CV_32F or CV_8U depth.
nameA name of input layer.
scalefactorAn optional normalization scale.
meanAn optional mean subtraction values.
See also
connect(String, String) to know format of the descriptor.

If scale or mean values are specified, a final input blob is computed as:

\[input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\]

Examples:
samples/dnn/colorization.cpp, and samples/dnn/openpose.cpp.

◆ setInputShape()

void cv::dnn::Net::setInputShape ( const String inputName,
const MatShape shape 
)
Python:
cv.dnn.Net.setInputShape(inputName, shape) -> None

Specify shape of network input.

◆ setInputsNames()

void cv::dnn::Net::setInputsNames ( const std::vector< String > &  inputBlobNames)
Python:
cv.dnn.Net.setInputsNames(inputBlobNames) -> None

Sets outputs names of the network input pseudo layer.

Each net always has special own the network input pseudo layer with id=0. This layer stores the user blobs only and don't make any computations. In fact, this layer provides the only way to pass user data into the network. As any other layer, this layer can label its outputs and this function provides an easy way to do this.

◆ setParam() [1/2]

void cv::dnn::Net::setParam ( int  layer,
int  numParam,
const Mat blob 
)
Python:
cv.dnn.Net.setParam(layer, numParam, blob) -> None
cv.dnn.Net.setParam(layerName, numParam, blob) -> None

Sets the new value for the learned param of the layer.

Parameters
layername or id of the layer.
numParamindex of the layer parameter in the Layer::blobs array.
blobthe new value.
See also
Layer::blobs
Note
If shape of the new blob differs from the previous shape, then the following forward pass may fail.

◆ setParam() [2/2]

void cv::dnn::Net::setParam ( const String layerName,
int  numParam,
const Mat blob 
)
inline
Python:
cv.dnn.Net.setParam(layer, numParam, blob) -> None
cv.dnn.Net.setParam(layerName, numParam, blob) -> None

◆ setPreferableBackend()

void cv::dnn::Net::setPreferableBackend ( int  backendId)
Python:
cv.dnn.Net.setPreferableBackend(backendId) -> None

Ask network to use specific computation backend where it supported.

Parameters
[in]backendIdbackend identifier.
See also
Backend

◆ setPreferableTarget()

void cv::dnn::Net::setPreferableTarget ( int  targetId)
Python:
cv.dnn.Net.setPreferableTarget(targetId) -> None

Ask network to make computations on specific target device.

Parameters
[in]targetIdtarget identifier.
See also
Target

List of supported combinations backend / target:

DNN_BACKEND_OPENCV DNN_BACKEND_INFERENCE_ENGINE DNN_BACKEND_HALIDE DNN_BACKEND_CUDA
DNN_TARGET_CPU + + +
DNN_TARGET_OPENCL + + +
DNN_TARGET_OPENCL_FP16 + +
DNN_TARGET_MYRIAD +
DNN_TARGET_FPGA +
DNN_TARGET_CUDA +
DNN_TARGET_CUDA_FP16 +
DNN_TARGET_HDDL +
Examples:
samples/dnn/colorization.cpp.

Friends And Related Function Documentation

◆ accessor::DnnNetAccessor

friend class accessor::DnnNetAccessor
friend

Member Data Documentation

◆ impl

Ptr<Impl> cv::dnn::Net::impl
protected

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