Class cv::dnn::Net#

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

Collaboration diagram for cv::dnn::Net:

Friends#

Return

Name

Description

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/classification.cpp, samples/dnn/colorization.cpp, samples/dnn/object_detection.cpp, samples/dnn/openpose.cpp, and samples/dnn/segmentation.cpp.

Member Typedef Documentation#

LayerId#

typedef DictValue cv::dnn::Net::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()#

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

Python:

cv.dnn.Net.addLayer(name, type, dtype, params) -> retval

Adds new layer to the net.

Parameters

  • name — unique name of the adding layer.

  • type — typename of the adding layer (type must be registered in LayerRegister).

  • dtype — datatype of output blobs.

  • params — parameters which will be used to initialize the creating layer.

Returns

unique identifier of created layer, or -1 if a failure will happen.

addLayer()#

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

Python:

cv.dnn.Net.addLayer(name, type, dtype, params) -> retval

addLayerToPrev()#

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

Python:

cv.dnn.Net.addLayerToPrev(name, type, dtype, params) -> retval

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

See also

addLayer()

addLayerToPrev()#

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

Python:

cv.dnn.Net.addLayerToPrev(name, type, dtype, params) -> retval

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

argData()#

const ArgData & cv::dnn::Net::argData(Arg arg)

argKind()#

ArgKind cv::dnn::Net::argKind(Arg arg)

argName()#

const std::string & cv::dnn::Net::argName(Arg arg)

argTensor()#

Mat & cv::dnn::Net::argTensor(Arg arg)

argType()#

int cv::dnn::Net::argType(Arg arg)

connect()#

void cv::dnn::Net::connect(
int outLayerId,
int outNum,
int inpLayerId,
int inpNum )

Python:

cv.dnn.Net.connect(outPin, inpPin)

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

Parameters

  • outLayerId — identifier of the first layer

  • outNum — number of the first layer output

  • inpLayerId — identifier of the second layer

  • inpNum — number of the second layer input

connect()#

void cv::dnn::Net::connect(
String outPin,
String inpPin )

Python:

cv.dnn.Net.connect(outPin, inpPin)

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

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.

Parameters

  • outPin — descriptor of the first layer output.

  • inpPin — descriptor of the second layer input.

disableKVCache()#

void cv::dnn::Net::disableKVCache()

Python:

cv.dnn.Net.disableKVCache()

Disables KV-Cache for all AttentionOnnxI layers.

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

dumpArg()#

std::ostream & cv::dnn::Net::dumpArg(
std::ostream & strm,
Arg arg,
int indent,
bool comma = true,
bool dump_details = false )

dumpDim()#

std::ostream & cv::dnn::Net::dumpDim(
std::ostream & strm,
int value )

dumpToFile()#

void cv::dnn::Net::dumpToFile(CV_WRAP_FILE_PATH const String & path)

Python:

cv.dnn.Net.dumpToFile(path)

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

See also

dump()

Parameters

  • path — path to output file with .dot extension

dumpToPbtxt()#

void cv::dnn::Net::dumpToPbtxt(CV_WRAP_FILE_PATH const String & path)

Python:

cv.dnn.Net.dumpToPbtxt(path)

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

Use Netron (https://netron.app) to open the target file to visualize the model. Call method after setInput(). To see correct backend, target and fusion run after forward().

Parameters

  • path — path to output file with .pbtxt extension

dumpToStream()#

void cv::dnn::Net::dumpToStream(std::ostream & strm)

Dump net structure, hyperparameters, backend, target and fusion to the specified output stream.

Parameters

  • strm — the target stream

empty()#

bool cv::dnn::Net::empty()

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)

Enables or disables layer fusion in the network.

Parameters

  • fusion — true to enable the fusion, false to disable. The fusion is enabled by default.

enableKVCache()#

void cv::dnn::Net::enableKVCache()

Python:

cv.dnn.Net.enableKVCache()

Enables KV-Cache for all AttentionOnnxI layers.

enableWinograd()#

void cv::dnn::Net::enableWinograd(bool useWinograd)

Python:

cv.dnn.Net.enableWinograd(useWinograd)

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

Parameters

  • useWinograd — true to enable the Winograd compute branch. The default is true.

finalizeNet()#

void cv::dnn::Net::finalizeNet()

Python:

cv.dnn.Net.finalizeNet()

Finalizes the network configuration and prepares it for inference.

This method must be called after setting backend/target via setPreferableBackend() and setPreferableTarget(), and before the first forward() call. It creates the underlying execution session (e.g. ONNX Runtime session) on the configured backend/target. If not called explicitly, the first forward() will call it automatically.

Calling finalizeNet() early lets you pay the one-time setup cost at a predictable point and catch configuration errors before inference.

findDim()#

int cv::dnn::Net::findDim(
const std::string & name,
bool insert = false )

forward()#

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.

By default runs forward pass for the whole network.

Parameters

  • outputName — name for layer which output is needed to get

Returns

blob for first output of specified layer.

forward()#

void cv::dnn::Net::forward(
CV_ND 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

  • outputBlobs — contains blobs for first outputs of specified layers.

  • outBlobNames — names for layers which outputs are needed to get

forward()#

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

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

Parameters

  • outputBlobs — contains all output blobs for specified layer.

  • outputName — name for layer which output is needed to get

forward()#

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

  • outputBlobs — contains all output blobs for each layer specified in outBlobNames.

  • outBlobNames — names 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.

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.

Parameters

  • outputName — name for layer which output is needed to get

getArg()#

Arg cv::dnn::Net::getArg(const std::string & name)

getFLOPS()#

int64 cv::dnn::Net::getFLOPS(
const int layerId,
const MatShape & netInputShape,
const int & netInputType )

Python:

cv.dnn.Net.getFLOPS(netInputShapes, netInputTypes) -> retval

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

getFLOPS()#

int64 cv::dnn::Net::getFLOPS(
const int layerId,
const std::vector< MatShape > & netInputShapes,
const std::vector< int > & netInputTypes )

Python:

cv.dnn.Net.getFLOPS(netInputShapes, netInputTypes) -> retval

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

getFLOPS()#

int64 cv::dnn::Net::getFLOPS(
const MatShape & netInputShape,
const int & netInputType )

Python:

cv.dnn.Net.getFLOPS(netInputShapes, netInputTypes) -> retval

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

getFLOPS()#

int64 cv::dnn::Net::getFLOPS(
const std::vector< MatShape > & netInputShapes,
const std::vector< int > & netInputTypes )

Python:

cv.dnn.Net.getFLOPS(netInputShapes, netInputTypes) -> retval

Computes FLOP for whole loaded model with specified input shapes.

Parameters

  • netInputShapes — vector of shapes for all net inputs.

  • netInputTypes — vector of types for all net inputs.

Returns

computed FLOP.

getImpl()#

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

getImplRef()#

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

getLayer()#

Ptr< Layer > cv::dnn::Net::getLayer(const LayerId & layerId)

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

getLayer()#

Ptr< Layer > cv::dnn::Net::getLayer(const String & layerName)

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)

Here is the call graph for this function:

cv::dnn::Net::getLayer Node1 cv::dnn::Net::getLayer Node1->Node1

cv::dnn::Net::getLayer Node1 cv::dnn::Net::getLayer Node1->Node1

getLayer()#

Ptr< Layer > cv::dnn::Net::getLayer(int layerId)

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.

getLayerId()#

int cv::dnn::Net::getLayerId(const String & layer)

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)

Returns pointers to input layers of specific layer.

getLayerNames()#

std::vector< String > cv::dnn::Net::getLayerNames()

Python:

cv.dnn.Net.getLayerNames() -> retval

getLayersCount()#

int cv::dnn::Net::getLayersCount(const String & layerType)

Python:

cv.dnn.Net.getLayersCount(layerType) -> retval

Returns count of layers of specified type.

Parameters

  • layerType — type.

Returns

count of layers

getLayerShapes()#

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

Python:

cv.dnn.Net.getLayerShapes(netInputShapes, netInputTypes, layerId) -> inLayerShapes, outLayerShapes

Returns input and output shapes for layer with specified id in loaded model; preliminary inferencing isn’t necessary.

This overload should be deprecated

Parameters

  • netInputShape — shape input blob in net input layer.

  • netInputType — input type in net input layer.

  • layerId — id for layer.

  • inLayerShapes — output parameter for input layers shapes; order is the same as in layersIds

  • outLayerShapes — output parameter for output layers shapes; order is the same as in layersIds

getLayerShapes()#

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

Python:

cv.dnn.Net.getLayerShapes(netInputShapes, netInputTypes, layerId) -> inLayerShapes, outLayerShapes

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

The only overload of getLayerShapes that should be kept in 5.x

getLayersShapes()#

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

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

This overload should be deprecated

getLayersShapes()#

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

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

This overload should be deprecated

Parameters

  • netInputShapes — shapes for all input blobs in net input layer.

  • netInputTypes — types for all input blobs in net input layer.

  • layersIds — output parameter for layer IDs.

  • inLayersShapes — output parameter for input layers shapes; order is the same as in layersIds

  • outLayersShapes — output parameter for output layers shapes; order is the same as in layersIds.

getLayerTypes()#

void cv::dnn::Net::getLayerTypes(std::vector< String > & layersTypes)

Python:

cv.dnn.Net.getLayerTypes() -> layersTypes

Returns list of types for layer used in model.

Parameters

  • layersTypes — output parameter for returning types.

getMainGraph()#

Ptr< Graph > cv::dnn::Net::getMainGraph()

getMemoryConsumption()#

void cv::dnn::Net::getMemoryConsumption(
const int layerId,
const MatShape & netInputShape,
const int & netInputType,
size_t & weights,
size_t & blobs )

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

getMemoryConsumption()#

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

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

getMemoryConsumption()#

void cv::dnn::Net::getMemoryConsumption(
const MatShape & netInputShape,
const int & netInputType,
size_t & weights,
size_t & blobs )

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

getMemoryConsumption()#

void cv::dnn::Net::getMemoryConsumption(
const MatShape & netInputShape,
const int & netInputType,
std::vector< int > & layerIds,
std::vector< size_t > & weights,
std::vector< size_t > & blobs )

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

It should be deprecated

getMemoryConsumption()#

void cv::dnn::Net::getMemoryConsumption(
const std::vector< MatShape > & netInputShapes,
const std::vector< int > & netInputTypes,
size_t & weights,
size_t & blobs )

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

Parameters

  • netInputShapes — vector of shapes for all net inputs.

  • netInputTypes — vector of types for all net inputs.

  • weights — output parameter to store resulting bytes for weights.

  • blobs — output parameter to store resulting bytes for intermediate blobs.

getMemoryConsumption()#

void cv::dnn::Net::getMemoryConsumption(
const std::vector< MatShape > & netInputShapes,
const std::vector< int > & netInputTypes,
std::vector< int > & layerIds,
std::vector< size_t > & weights,
std::vector< size_t > & blobs )

Python:

cv.dnn.Net.getMemoryConsumption(netInputShapes, netInputTypes) -> weights, blobs

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

It should be deprecated

Parameters

  • netInputShapes — vector of shapes for all net inputs.

  • netInputTypes — vector of types for all net inputs.

  • layerIds — output vector to save layer IDs.

  • weights — output parameter to store resulting bytes for weights.

  • blobs — output parameter to store resulting bytes for intermediate blobs.

getModelFormat()#

ModelFormat cv::dnn::Net::getModelFormat()

Python:

cv.dnn.Net.getModelFormat() -> retval

Retrieve the current model format, see DNN_MODEL_*.

getParam()#

Mat cv::dnn::Net::getParam(
const String & layerName,
int numParam = 0 )

Python:

cv.dnn.Net.getParam(layer[, numParam]) -> retval
cv.dnn.Net.getParam(layerName[, numParam]) -> retval

Here is the call graph for this function:

cv::dnn::Net::getParam Node1 cv::dnn::Net::getParam Node1->Node1

cv::dnn::Net::getParam Node1 cv::dnn::Net::getParam Node1->Node1

getParam()#

Mat cv::dnn::Net::getParam(
int layer,
int numParam = 0 )

Python:

cv.dnn.Net.getParam(layer[, numParam]) -> retval
cv.dnn.Net.getParam(layerName[, numParam]) -> retval

Returns parameter blob of the layer.

See also

Layer::blobs

Parameters

  • layer — name or id of the layer.

  • numParam — index of the layer parameter in the Layer::blobs array.

getPerfProfile()#

int64 cv::dnn::Net::getPerfProfile(std::vector< double > & timings)

Python:

cv.dnn.Net.getPerfProfile() -> retval, timings
cv.dnn.Net.getPerfProfile() -> names, timems, counts

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

  • timings — vector for tick timings for all layers.

Returns

overall ticks for model inference.

getPerfProfile()#

void cv::dnn::Net::getPerfProfile(
std::vector< std::string > & names,
std::vector< std::string > & timems,
std::vector< std::string > & counts )

Python:

cv.dnn.Net.getPerfProfile() -> retval, timings
cv.dnn.Net.getPerfProfile() -> names, timems, counts

Returns profiling data captured during the last forward pass.

Entries are sorted by time in descending order. Empty vectors are returned if profiling is disabled (DNN_PROFILE_NONE).

getProfilingMode()#

ProfilingMode cv::dnn::Net::getProfilingMode()

Python:

cv.dnn.Net.getProfilingMode() -> retval

Retrieve the current profiling mode.

getTracingMode()#

TracingMode cv::dnn::Net::getTracingMode()

Python:

cv.dnn.Net.getTracingMode() -> retval

Retrieve the current tracing mode.

getUnconnectedOutLayers()#

std::vector< int > cv::dnn::Net::getUnconnectedOutLayers()

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()

Python:

cv.dnn.Net.getUnconnectedOutLayersNames() -> retval

Returns names of layers with unconnected outputs.

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

haveArg()#

bool cv::dnn::Net::haveArg(const std::string & name)

isConstArg()#

bool cv::dnn::Net::isConstArg(Arg arg)

printPerfProfile()#

void cv::dnn::Net::printPerfProfile()

Python:

cv.dnn.Net.printPerfProfile()

Prints the profile captured during the last forward pass in a formatted table using CV_LOG_INFO.

In DNN_PROFILE_DETAILED mode, prints per-layer label, time, and percentage. In DNN_PROFILE_SUMMARY mode, prints per-type count, time, and percentage. Does nothing if profiling is disabled (DNN_PROFILE_NONE) or all timings are zero.

registerOutput()#

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

Python:

cv.dnn.Net.registerOutput(outputName, layerId, outputPort) -> retval

Registers network output with name.

Function may create additional ‘Identity’ layer.

Parameters

  • outputName — identifier of the output

  • layerId — identifier of the second layer

  • outputPort — number of the second layer input

Returns

index of bound layer (the same as layerId or newly created)

resetKVCache()#

void cv::dnn::Net::resetKVCache()

Python:

cv.dnn.Net.resetKVCache()

Resets KV-Cache for all AttentionOnnxI layers.

setInput()#

void cv::dnn::Net::setInput(
CV_ND InputArray blob,
const String & name = “”,
double scalefactor = 1.0,
const Scalar & mean = Scalar() )

Python:

cv.dnn.Net.setInput(blob[, name[, scalefactor[, mean]]])

Sets the new input value for the network.

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) \]

Parameters

  • blob — A new blob. Should have CV_32F or CV_8U depth.

  • name — A name of input layer.

  • scalefactor — An optional normalization scale.

  • mean — An optional mean subtraction values.

setInputShape()#

void cv::dnn::Net::setInputShape(
const String & inputName,
const MatShape & shape )

Python:

cv.dnn.Net.setInputShape(inputName, shape)

Specify shape of network input.

setInputsNames()#

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

Python:

cv.dnn.Net.setInputsNames(inputBlobNames)

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()#

void cv::dnn::Net::setParam(
const String & layerName,
int numParam,
CV_ND const Mat & blob )

Python:

cv.dnn.Net.setParam(layer, numParam, blob)
cv.dnn.Net.setParam(layerName, numParam, blob)

Sets the parameter blob of a layer identified by its name or output tensor name.

Parameters

  • layerName — layer name (classic engine) or raw ONNX output tensor name (ENGINE_NEW).

  • numParam — index of the constant weight input to update (0 = kernel, 1 = bias, etc.).

  • blob — the new parameter value.

setParam()#

void cv::dnn::Net::setParam(
int layer,
int numParam,
CV_ND const Mat & blob )

Python:

cv.dnn.Net.setParam(layer, numParam, blob)
cv.dnn.Net.setParam(layerName, numParam, blob)

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

See also

Layer::blobs

Note

If shape of the new blob differs from the previous shape, then the following forward pass may fail.

Parameters

  • layer — name or id of the layer.

  • numParam — index of the layer parameter in the Layer::blobs array.

  • blob — the new value.

setPreferableBackend()#

void cv::dnn::Net::setPreferableBackend(int backendId)

Python:

cv.dnn.Net.setPreferableBackend(backendId)

Ask network to use specific computation backend where it supported.

See also

Backend

Parameters

  • backendId — backend identifier.

setPreferableTarget()#

void cv::dnn::Net::setPreferableTarget(int targetId)

Python:

cv.dnn.Net.setPreferableTarget(targetId)

Ask network to make computations on specific target device.

See also

Target

List of supported combinations backend / target:

DNN_BACKEND_OPENCV

DNN_BACKEND_INFERENCE_ENGINE

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

+

Parameters

  • targetId — target identifier.

setProfilingMode()#

void cv::dnn::Net::setProfilingMode(ProfilingMode profilingMode)

Python:

cv.dnn.Net.setProfilingMode(profilingMode)

Set the profiling mode.

Parameters

  • profilingMode — the profiling mode, see DNN_PROFILE_*

setTracingMode()#

void cv::dnn::Net::setTracingMode(TracingMode tracingMode)

Python:

cv.dnn.Net.setTracingMode(tracingMode)

Set the tracing mode.

Parameters

  • tracingMode — the tracing mode, see DNN_TRACE_*

readFromModelOptimizer()#

static Net cv::dnn::Net::readFromModelOptimizer(
const std::vector< uchar > & bufferModelConfig,
const std::vector< uchar > & bufferWeights )

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

  • bufferModelConfig — buffer with model’s configuration.

  • bufferWeights — buffer with model’s trained weights.

Returns

Net object.

readFromModelOptimizer()#

static Net cv::dnn::Net::readFromModelOptimizer(
const uchar * bufferModelConfigPtr,
size_t bufferModelConfigSize,
const uchar * bufferWeightsPtr,
size_t bufferWeightsSize )

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

  • bufferModelConfigPtr — buffer pointer of model’s configuration.

  • bufferModelConfigSize — buffer size of model’s configuration.

  • bufferWeightsPtr — buffer pointer of model’s trained weights.

  • bufferWeightsSize — buffer size of model’s trained weights.

Returns

Net object.

readFromModelOptimizer()#

static Net cv::dnn::Net::readFromModelOptimizer(
CV_WRAP_FILE_PATH const String & xml,
CV_WRAP_FILE_PATH const String & bin )

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

  • xml — XML configuration file with network’s topology.

  • bin — Binary file with trained weights. Networks imported from Intel’s Model Optimizer are launched in Intel’s Inference Engine backend.

Member Data Documentation#

impl#

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

Source file#

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