OpenCV for Unity  2.6.0
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.9.0/index.html ) for the details of the argument of the method.
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
OpenCVForUnity.DnnModule.Net Class Reference

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

Inheritance diagram for OpenCVForUnity.DnnModule.Net:
OpenCVForUnity.DisposableOpenCVObject OpenCVForUnity.DisposableObject

Public Member Functions

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

Static Public Member Functions

static Net __fromPtr__ (IntPtr addr)
 
static Net readFromModelOptimizer (string xml, string bin)
 Create a network from Intel's Model Optimizer intermediate representation (IR). More...
 
static Net readFromModelOptimizer (MatOfByte bufferModelConfig, MatOfByte bufferWeights)
 Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR). More...
 
- 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 (IntPtr ptr)
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- 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 &lt;DFN&gt;&amp;lt;layer_name&amp;gt;[.input_number]&lt;/DFN&gt;:
       - the first part of the template &lt;DFN&gt;layer_name&lt;/DFN&gt; 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 &lt;DFN&gt;input_number&lt;/DFN&gt;
         is either number of the layer input, either label one.
         If this part is omitted then the first layer input will be used.

        @see 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
See also
dump()

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

◆ forward() [2/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() [3/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() [4/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() [5/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

◆ getFLOPS() [1/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() [2/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.

◆ getFLOPS() [3/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() [4/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.

◆ 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 ( int  layerId)

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

◆ getLayer() [2/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)

◆ getLayer() [3/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

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

◆ 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,
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.
See also
Layer::blobs

◆ getParam() [2/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.
See also
Layer::blobs

◆ getParam() [3/4]

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

◆ getParam() [4/4]

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

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

Parameters
[out]timingsvector for tick timings for all layers.
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,
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).

◆ quantize() [2/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).

◆ readFromModelOptimizer() [1/2]

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

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

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

◆ setHalideScheduler()

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

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

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

◆ setInput() [2/4]

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

◆ setInput() [3/4]

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

◆ setInput() [4/4]

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

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

Parameters
[in]backendIdbackend identifier.
See also
Backend

◆ setPreferableTarget()

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

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 +

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