OpenCV for Unity 2.6.4
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.
|
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] |
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.
OpenCVForUnity.DnnModule.Net.Net | ( | ) |
|
static |
void OpenCVForUnity.DnnModule.Net.connect | ( | string | outPin, |
string | inpPin ) |
Connects output of the first layer to input of the second layer.
outPin | descriptor of the first layer output. |
inpPin | descriptor of the second layer input. |
Descriptors have the following template <DFN><layer_name>[.input_number]</DFN>:
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.
|
protectedvirtual |
Reimplemented from OpenCVForUnity.DisposableOpenCVObject.
string OpenCVForUnity.DnnModule.Net.dump | ( | ) |
Dump net to String.
void OpenCVForUnity.DnnModule.Net.dumpToFile | ( | string | path | ) |
Dump net structure, hyperparameters, backend, target and fusion to dot file.
path | path to output file with .dot extension |
void OpenCVForUnity.DnnModule.Net.dumpToPbtxt | ( | string | path | ) |
Dump net structure, hyperparameters, backend, target and fusion to pbtxt file.
path | path 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().
bool OpenCVForUnity.DnnModule.Net.empty | ( | ) |
Returns true if there are no layers in the network.
void OpenCVForUnity.DnnModule.Net.enableFusion | ( | bool | fusion | ) |
Enables or disables layer fusion in the network.
fusion | true to enable the fusion, false to disable. The fusion is enabled by default. |
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.
useWinograd | true to enable the Winograd compute branch. The default is true. |
Mat OpenCVForUnity.DnnModule.Net.forward | ( | ) |
Runs forward pass to compute output of layer with name outputName
.
outputName | name for layer which output is needed to get |
blob for first output of specified layer.
By default runs forward pass for the whole network.
void OpenCVForUnity.DnnModule.Net.forward | ( | List< Mat > | outputBlobs | ) |
Runs forward pass to compute output of layer with name outputName
.
outputBlobs | contains all output blobs for specified layer. |
outputName | name for layer which output is needed to get |
If outputName
is empty, runs forward pass for the whole network.
void OpenCVForUnity.DnnModule.Net.forward | ( | List< Mat > | outputBlobs, |
List< string > | outBlobNames ) |
Runs forward pass to compute outputs of layers listed in outBlobNames
.
outputBlobs | contains blobs for first outputs of specified layers. |
outBlobNames | names for layers which outputs are needed to get |
void OpenCVForUnity.DnnModule.Net.forward | ( | List< Mat > | outputBlobs, |
string | outputName ) |
Runs forward pass to compute output of layer with name outputName
.
outputBlobs | contains all output blobs for specified layer. |
outputName | name for layer which output is needed to get |
If outputName
is empty, runs forward pass for the whole network.
Mat OpenCVForUnity.DnnModule.Net.forward | ( | string | outputName | ) |
Runs forward pass to compute output of layer with name outputName
.
outputName | name for layer which output is needed to get |
blob for first output of specified layer.
By default runs forward pass for the whole network.
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.
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.
long OpenCVForUnity.DnnModule.Net.getFLOPS | ( | List< MatOfInt > | netInputShapes | ) |
Computes FLOP for whole loaded model with specified input shapes.
netInputShapes | vector of shapes for all net inputs. |
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.
void OpenCVForUnity.DnnModule.Net.getInputDetails | ( | MatOfFloat | scales, |
MatOfInt | zeropoints ) |
Returns input scale and zeropoint for a quantized Net.
scales | output parameter for returning input scales. |
zeropoints | output parameter for returning input zeropoints. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Layer OpenCVForUnity.DnnModule.Net.getLayer | ( | int | layerId | ) |
Returns pointer to layer with specified id or name which the network use.
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.
int OpenCVForUnity.DnnModule.Net.getLayerId | ( | string | layer | ) |
Converts string name of the layer to the integer identifier.
List< string > OpenCVForUnity.DnnModule.Net.getLayerNames | ( | ) |
int OpenCVForUnity.DnnModule.Net.getLayersCount | ( | string | layerType | ) |
Returns count of layers of specified type.
layerType | type. |
void OpenCVForUnity.DnnModule.Net.getLayerTypes | ( | List< string > | layersTypes | ) |
Returns list of types for layer used in model.
layersTypes | output parameter for returning types. |
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.
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.
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.
IntPtr OpenCVForUnity.DnnModule.Net.getNativeObjAddr | ( | ) |
void OpenCVForUnity.DnnModule.Net.getOutputDetails | ( | MatOfFloat | scales, |
MatOfInt | zeropoints ) |
Returns output scale and zeropoint for a quantized Net.
scales | output parameter for returning output scales. |
zeropoints | output parameter for returning output zeropoints. |
Mat OpenCVForUnity.DnnModule.Net.getParam | ( | int | layer | ) |
Returns parameter blob of the layer.
layer | name or id of the layer. |
numParam | index of the layer parameter in the Layer::blobs array. |
Layer::blobs
Mat OpenCVForUnity.DnnModule.Net.getParam | ( | int | layer, |
int | numParam ) |
Returns parameter blob of the layer.
layer | name or id of the layer. |
numParam | index of the layer parameter in the Layer::blobs array. |
Layer::blobs
Mat OpenCVForUnity.DnnModule.Net.getParam | ( | string | layerName | ) |
Mat OpenCVForUnity.DnnModule.Net.getParam | ( | string | layerName, |
int | numParam ) |
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.
MatOfInt OpenCVForUnity.DnnModule.Net.getUnconnectedOutLayers | ( | ) |
Returns indexes of layers with unconnected outputs.
FIXIT: Rework API to registerOutput() approach, deprecate this call
List< string > OpenCVForUnity.DnnModule.Net.getUnconnectedOutLayersNames | ( | ) |
Returns names of layers with unconnected outputs.
FIXIT: Rework API to registerOutput() approach, deprecate this call
Net OpenCVForUnity.DnnModule.Net.quantize | ( | List< Mat > | calibData, |
int | inputsDtype, | ||
int | outputsDtype ) |
Returns a quantized Net from a floating-point Net.
calibData | Calibration data to compute the quantization parameters. |
inputsDtype | Datatype of quantized net's inputs. Can be CV_32F or CV_8S. |
outputsDtype | Datatype of quantized net's outputs. Can be CV_32F or CV_8S. |
perChannel | Quantization 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). |
Net OpenCVForUnity.DnnModule.Net.quantize | ( | List< Mat > | calibData, |
int | inputsDtype, | ||
int | outputsDtype, | ||
bool | perChannel ) |
Returns a quantized Net from a floating-point Net.
calibData | Calibration data to compute the quantization parameters. |
inputsDtype | Datatype of quantized net's inputs. Can be CV_32F or CV_8S. |
outputsDtype | Datatype of quantized net's outputs. Can be CV_32F or CV_8S. |
perChannel | Quantization 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). |
|
static |
Create a network from Intel's Model Optimizer intermediate representation (IR).
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.
void OpenCVForUnity.DnnModule.Net.setInput | ( | Mat | blob | ) |
Sets the new input value for the network.
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. |
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)\]
void OpenCVForUnity.DnnModule.Net.setInput | ( | Mat | blob, |
string | name ) |
Sets the new input value for the network.
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. |
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)\]
void OpenCVForUnity.DnnModule.Net.setInput | ( | Mat | blob, |
string | name, | ||
double | scalefactor ) |
Sets the new input value for the network.
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. |
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)\]
void OpenCVForUnity.DnnModule.Net.setInput | ( | Mat | blob, |
string | name, | ||
double | scalefactor, | ||
in Vec4d | mean ) |
Sets the new input value for the network.
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. |
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)\]
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.
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. |
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)\]
void OpenCVForUnity.DnnModule.Net.setInput | ( | Mat | blob, |
string | name, | ||
double | scalefactor, | ||
Scalar | mean ) |
Sets the new input value for the network.
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. |
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)\]
void OpenCVForUnity.DnnModule.Net.setInputShape | ( | string | inputName, |
MatOfInt | shape ) |
Specify shape of network input.
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.
void OpenCVForUnity.DnnModule.Net.setParam | ( | int | layer, |
int | numParam, | ||
Mat | blob ) |
Sets the new value for the learned param of the layer.
layer | name or id of the layer. |
numParam | index of the layer parameter in the Layer::blobs array. |
blob | the new value. |
Layer::blobs
void OpenCVForUnity.DnnModule.Net.setParam | ( | string | layerName, |
int | numParam, | ||
Mat | blob ) |
void OpenCVForUnity.DnnModule.Net.setPreferableBackend | ( | int | backendId | ) |
Ask network to use specific computation backend where it supported.
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 | + |