OpenCV for Unity 2.6.5
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.10.0/index.html ) for the details of the argument of the method.
Loading...
Searching...
No Matches
OpenCVForUnity.DnnModule.Net Class Reference

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

Public Member Functions

 Net ()
 
void connect (string outPin, string inpPin)
 Connects output of the first layer to input of the second layer.
 
string dump ()
 Dump net to String.
 
void dumpToFile (string path)
 Dump net structure, hyperparameters, backend, target and fusion to dot file.
 
void dumpToPbtxt (string path)
 Dump net structure, hyperparameters, backend, target and fusion to pbtxt file.
 
bool empty ()
 
void enableFusion (bool fusion)
 Enables or disables layer fusion in the network.
 
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.
 
Mat forward ()
 Runs forward pass to compute output of layer with name outputName.
 
void forward (List< Mat > outputBlobs)
 Runs forward pass to compute output of layer with name outputName.
 
void forward (List< Mat > outputBlobs, List< string > outBlobNames)
 Runs forward pass to compute outputs of layers listed in outBlobNames.
 
void forward (List< Mat > outputBlobs, string outputName)
 Runs forward pass to compute output of layer with name outputName.
 
Mat forward (string outputName)
 Runs forward pass to compute output of layer with name outputName.
 
long getFLOPS (int layerId, List< MatOfInt > netInputShapes)
 
long getFLOPS (int layerId, MatOfInt netInputShape)
 
long getFLOPS (List< MatOfInt > netInputShapes)
 Computes FLOP for whole loaded model with specified input shapes.
 
long getFLOPS (MatOfInt netInputShape)
 
void getInputDetails (MatOfFloat scales, MatOfInt zeropoints)
 Returns input scale and zeropoint for a quantized Net.
 
Layer getLayer (DictValue layerId)
 
Layer getLayer (int layerId)
 Returns pointer to layer with specified id or name which the network use.
 
Layer getLayer (string layerName)
 
int getLayerId (string layer)
 Converts string name of the layer to the integer identifier.
 
List< string > getLayerNames ()
 
int getLayersCount (string layerType)
 Returns count of layers of specified type.
 
void getLayerTypes (List< string > layersTypes)
 Returns list of types for layer used in model.
 
void getMemoryConsumption (int layerId, List< MatOfInt > netInputShapes, long[] weights, long[] blobs)
 
void getMemoryConsumption (int layerId, MatOfInt netInputShape, long[] weights, long[] blobs)
 
void getMemoryConsumption (MatOfInt netInputShape, long[] weights, long[] blobs)
 
IntPtr getNativeObjAddr ()
 
void getOutputDetails (MatOfFloat scales, MatOfInt zeropoints)
 Returns output scale and zeropoint for a quantized Net.
 
Mat getParam (int layer)
 Returns parameter blob of the layer.
 
Mat getParam (int layer, int numParam)
 Returns parameter blob of the layer.
 
Mat getParam (string layerName)
 
Mat getParam (string layerName, int numParam)
 
long getPerfProfile (MatOfDouble timings)
 Returns overall time for inference and timings (in ticks) for layers.
 
MatOfInt getUnconnectedOutLayers ()
 Returns indexes of layers with unconnected outputs.
 
List< string > getUnconnectedOutLayersNames ()
 Returns names of layers with unconnected outputs.
 
Net quantize (List< Mat > calibData, int inputsDtype, int outputsDtype)
 Returns a quantized Net from a floating-point Net.
 
Net quantize (List< Mat > calibData, int inputsDtype, int outputsDtype, bool perChannel)
 Returns a quantized Net from a floating-point Net.
 
void setHalideScheduler (string scheduler)
 Compile Halide layers.
 
void setInput (Mat blob)
 Sets the new input value for the network.
 
void setInput (Mat blob, string name)
 Sets the new input value for the network.
 
void setInput (Mat blob, string name, double scalefactor)
 Sets the new input value for the network.
 
void setInput (Mat blob, string name, double scalefactor, in Vec4d mean)
 Sets the new input value for the network.
 
void setInput (Mat blob, string name, double scalefactor, in(double v0, double v1, double v2, double v3) mean)
 Sets the new input value for the network.
 
void setInput (Mat blob, string name, double scalefactor, Scalar mean)
 Sets the new input value for the network.
 
void setInputShape (string inputName, MatOfInt shape)
 Specify shape of network input.
 
void setInputsNames (List< string > inputBlobNames)
 Sets outputs names of the network input pseudo layer.
 
void setParam (int layer, int numParam, Mat blob)
 Sets the new value for the learned param of the layer.
 
void setParam (string layerName, int numParam, Mat blob)
 
void setPreferableBackend (int backendId)
 Ask network to use specific computation backend where it supported.
 
void setPreferableTarget (int targetId)
 Ask network to make computations on specific target device.
 
- Public Member Functions inherited from OpenCVForUnity.DisposableObject
void Dispose ()
 
void ThrowIfDisposed ()
 

Static Public Member Functions

static Net __fromPtr__ (IntPtr addr)
 
static Net readFromModelOptimizer (MatOfByte bufferModelConfig, MatOfByte bufferWeights)
 Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).
 
static Net readFromModelOptimizer (string xml, string bin)
 Create a network from Intel's Model Optimizer intermediate representation (IR).
 
- Static Public Member Functions inherited from OpenCVForUnity.DisposableObject
static IntPtr ThrowIfNullIntPtr (IntPtr ptr)
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject
 DisposableOpenCVObject ()
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- Package Attributes inherited from OpenCVForUnity.DisposableOpenCVObject
- Properties inherited from OpenCVForUnity.DisposableObject
bool IsDisposed [get, protected set]
 
bool IsEnabledDispose [get, set]
 

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.

Constructor & Destructor Documentation

◆ Net()

OpenCVForUnity.DnnModule.Net.Net ( )

Member Function Documentation

◆ __fromPtr__()

static Net OpenCVForUnity.DnnModule.Net.__fromPtr__ ( IntPtr addr)
static

◆ connect()

void OpenCVForUnity.DnnModule.Net.connect ( string outPin,
string inpPin )

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 <DFN>&lt;layer_name&gt;[.input_number]</DFN>:

  • the first part of the template <DFN>layer_name</DFN> 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 <DFN>input_number</DFN> 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()

◆ Dispose()

override void OpenCVForUnity.DnnModule.Net.Dispose ( bool disposing)
protectedvirtual

◆ dump()

string OpenCVForUnity.DnnModule.Net.dump ( )

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 OpenCVForUnity.DnnModule.Net.dumpToFile ( string path)

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

Parameters
pathpath to output file with .dot extension

dump()

◆ dumpToPbtxt()

void OpenCVForUnity.DnnModule.Net.dumpToPbtxt ( string path)

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

Parameters
pathpath to output file with .pbtxt extension

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

◆ empty()

bool OpenCVForUnity.DnnModule.Net.empty ( )

Returns true if there are no layers in the network.

◆ enableFusion()

void OpenCVForUnity.DnnModule.Net.enableFusion ( bool fusion)

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 OpenCVForUnity.DnnModule.Net.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.

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

◆ forward() [1/5]

Mat OpenCVForUnity.DnnModule.Net.forward ( )

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.

◆ forward() [2/5]

void OpenCVForUnity.DnnModule.Net.forward ( List< Mat > 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/5]

void OpenCVForUnity.DnnModule.Net.forward ( List< Mat > outputBlobs,
List< string > outBlobNames )

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/5]

void OpenCVForUnity.DnnModule.Net.forward ( List< Mat > outputBlobs,
string outputName )

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() [5/5]

Mat OpenCVForUnity.DnnModule.Net.forward ( string outputName)

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.

◆ getFLOPS() [1/4]

long OpenCVForUnity.DnnModule.Net.getFLOPS ( int layerId,
List< MatOfInt > netInputShapes )

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

◆ getFLOPS() [2/4]

long OpenCVForUnity.DnnModule.Net.getFLOPS ( int layerId,
MatOfInt netInputShape )

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]

long OpenCVForUnity.DnnModule.Net.getFLOPS ( List< MatOfInt > netInputShapes)

Computes FLOP for whole loaded model with specified input shapes.

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

◆ getFLOPS() [4/4]

long OpenCVForUnity.DnnModule.Net.getFLOPS ( MatOfInt netInputShape)

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

◆ getInputDetails()

void OpenCVForUnity.DnnModule.Net.getInputDetails ( MatOfFloat scales,
MatOfInt 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]

Layer OpenCVForUnity.DnnModule.Net.getLayer ( DictValue layerId)

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() [2/3]

Layer OpenCVForUnity.DnnModule.Net.getLayer ( int layerId)

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

◆ getLayer() [3/3]

Layer OpenCVForUnity.DnnModule.Net.getLayer ( string layerName)

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)

◆ getLayerId()

int OpenCVForUnity.DnnModule.Net.getLayerId ( string layer)

Converts string name of the layer to the integer identifier.

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

◆ getLayerNames()

List< string > OpenCVForUnity.DnnModule.Net.getLayerNames ( )

◆ getLayersCount()

int OpenCVForUnity.DnnModule.Net.getLayersCount ( string layerType)

Returns count of layers of specified type.

Parameters
layerTypetype.
Returns
count of layers

◆ getLayerTypes()

void OpenCVForUnity.DnnModule.Net.getLayerTypes ( List< string > layersTypes)

Returns list of types for layer used in model.

Parameters
layersTypesoutput parameter for returning types.

◆ getMemoryConsumption() [1/3]

void OpenCVForUnity.DnnModule.Net.getMemoryConsumption ( int layerId,
List< MatOfInt > netInputShapes,
long[] weights,
long[] blobs )

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

◆ getMemoryConsumption() [2/3]

void OpenCVForUnity.DnnModule.Net.getMemoryConsumption ( int layerId,
MatOfInt netInputShape,
long[] weights,
long[] 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/3]

void OpenCVForUnity.DnnModule.Net.getMemoryConsumption ( MatOfInt netInputShape,
long[] weights,
long[] blobs )

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

◆ getNativeObjAddr()

IntPtr OpenCVForUnity.DnnModule.Net.getNativeObjAddr ( )

◆ getOutputDetails()

void OpenCVForUnity.DnnModule.Net.getOutputDetails ( MatOfFloat scales,
MatOfInt 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/4]

Mat OpenCVForUnity.DnnModule.Net.getParam ( int layer)

Returns parameter blob of the layer.

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

Layer::blobs

◆ getParam() [2/4]

Mat OpenCVForUnity.DnnModule.Net.getParam ( int layer,
int numParam )

Returns parameter blob of the layer.

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

Layer::blobs

◆ getParam() [3/4]

Mat OpenCVForUnity.DnnModule.Net.getParam ( string layerName)

◆ getParam() [4/4]

Mat OpenCVForUnity.DnnModule.Net.getParam ( string layerName,
int numParam )

◆ getPerfProfile()

long OpenCVForUnity.DnnModule.Net.getPerfProfile ( MatOfDouble 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.

Returns
overall ticks for model inference.

◆ getUnconnectedOutLayers()

MatOfInt OpenCVForUnity.DnnModule.Net.getUnconnectedOutLayers ( )

Returns indexes of layers with unconnected outputs.

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

◆ getUnconnectedOutLayersNames()

List< string > OpenCVForUnity.DnnModule.Net.getUnconnectedOutLayersNames ( )

Returns names of layers with unconnected outputs.

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

◆ quantize() [1/2]

Net OpenCVForUnity.DnnModule.Net.quantize ( List< Mat > calibData,
int inputsDtype,
int outputsDtype )

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

◆ quantize() [2/2]

Net OpenCVForUnity.DnnModule.Net.quantize ( List< Mat > calibData,
int inputsDtype,
int outputsDtype,
bool perChannel )

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/2]

static Net OpenCVForUnity.DnnModule.Net.readFromModelOptimizer ( MatOfByte bufferModelConfig,
MatOfByte bufferWeights )
static

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

Returns
Net object.

◆ readFromModelOptimizer() [2/2]

static Net OpenCVForUnity.DnnModule.Net.readFromModelOptimizer ( string xml,
string bin )
static

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

◆ setHalideScheduler()

void OpenCVForUnity.DnnModule.Net.setHalideScheduler ( string scheduler)

Compile Halide layers.

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() [1/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob)

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.

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

◆ setInput() [2/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob,
string name )

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.

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

◆ setInput() [3/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob,
string name,
double scalefactor )

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.

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

◆ setInput() [4/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob,
string name,
double scalefactor,
in Vec4d mean )

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.

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

◆ setInput() [5/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob,
string name,
double scalefactor,
in(double v0, double v1, double v2, double v3) mean )

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.

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

◆ setInput() [6/6]

void OpenCVForUnity.DnnModule.Net.setInput ( Mat blob,
string name,
double scalefactor,
Scalar mean )

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.

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

◆ setInputShape()

void OpenCVForUnity.DnnModule.Net.setInputShape ( string inputName,
MatOfInt shape )

Specify shape of network input.

◆ setInputsNames()

void OpenCVForUnity.DnnModule.Net.setInputsNames ( List< string > 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() [1/2]

void OpenCVForUnity.DnnModule.Net.setParam ( int layer,
int numParam,
Mat blob )

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.

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 OpenCVForUnity.DnnModule.Net.setParam ( string layerName,
int numParam,
Mat blob )

◆ setPreferableBackend()

void OpenCVForUnity.DnnModule.Net.setPreferableBackend ( int backendId)

Ask network to use specific computation backend where it supported.

◆ setPreferableTarget()

void OpenCVForUnity.DnnModule.Net.setPreferableTarget ( int targetId)

Ask network to make computations on specific target device.

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 +

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