Class Net
- Namespace
- OpenCvSharp.Dnn
- Assembly
- OpenCvSharp.dll
Base class for objects that own a single native OpenCV pointer through an OpenCvSafeHandle. The SafeHandle is the single source of truth for the native handle value and is responsible for releasing it (including from its own finalizer when the managed object is dropped without Dispose()).
[SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
public class Net : CvObject, IDisposable
- Inheritance
-
Net
- Implements
- Inherited Members
Remarks
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.
Constructors
- Net()
Default constructor
- Net(nint)
Constructor (backward compatibility). Wraps the pointer in a non-owning SafeHandle. Derived classes that own the native resource should call SetSafeHandle(OpenCvSafeHandle) to replace it with an owning handle.
Properties
- ProfilingMode
Gets or sets the profiling mode of the new DNN engine (OpenCV 5).
- TracingMode
Gets or sets the tracing mode of the new DNN engine (OpenCV 5).
Methods
- Connect(int, int, int, int)
Connects #@p outNum output of the first layer to #@p inNum input of the second layer.
- Connect(string, string)
Connects output of the first layer to input of the second layer.
- DisableKVCache()
Disables the Key-Value (KV) cache.
- Dump()
Dump net to String. Call method after setInput(). To see correct backend, target and fusion run after forward().
- DumpToFile(string)
Dump net structure, hyperparameters, backend, target and fusion to dot file
- DumpToPbtxt(string)
Dump net structure, hyperparameters, backend, target and fusion to a pbtxt file.
- Empty()
Returns true if there are no layers in the network.
- EnableFusion(bool)
Enables or disables layer fusion in the network.
- EnableKVCache()
Enables the Key-Value (KV) cache, used to accelerate inference of transformer / LLM models.
- EnableWinograd(bool)
Enables or disables the Winograd convolution optimization.
- FinalizeNet()
Finalizes the network (new DNN engine, OpenCV 5). The first forward() does this automatically; calling it early pays the one-time setup cost at a predictable point and surfaces configuration errors before inference.
- Forward(IEnumerable<Mat>, IEnumerable<string>)
Runs forward pass to compute outputs of layers listed in @p outBlobNames.
- Forward(IEnumerable<Mat>, string?)
Runs forward pass to compute output of layer with name @p outputName.
- Forward(string?)
Runs forward pass to compute output of layer with name @p outputName. By default runs forward pass for the whole network.
- ForwardAndRetrieve(IEnumerable<string>)
Runs forward pass to compute outputs of layers listed in @p outBlobNames, retrieving all output blobs for each layer specified in @p outBlobNames.
- GetFLOPS(MatShape, MatType)
Computes FLOP for whole loaded model with the specified single input shape and type (OpenCV 5).
- GetFLOPS(IEnumerable<MatShape>, IEnumerable<MatType>)
Computes FLOP for whole loaded model with specified input shapes (OpenCV 5).
- GetFLOPS(int, IEnumerable<MatShape>, IEnumerable<MatType>)
Computes FLOP for a specific layer with specified input shapes (OpenCV 5).
- GetLayer(int)
Returns pointer to layer with specified id which the network use.
- GetLayer(string)
Returns pointer to layer with specified name which the network use.
- GetLayerId(string)
Converts string name of the layer to the integer identifier.
- GetLayerShapes(IEnumerable<MatShape>, IEnumerable<MatType>, int, out MatShape[], out MatShape[])
Returns input and output shapes for the layer with the specified id; preliminary inferencing isn't necessary (OpenCV 5).
- GetLayerTypes()
Returns list of types for layer used in model.
- GetLayersCount(string)
Returns count of layers of specified type.
- GetLayersShapes(IEnumerable<MatShape>, IEnumerable<MatType>, out int[], out MatShape[][], out MatShape[][])
Returns input and output shapes for all layers in the loaded model; preliminary inferencing isn't necessary (OpenCV 5).
- GetMemoryConsumption(IEnumerable<MatShape>, IEnumerable<MatType>, out int[], out long[], out long[])
Computes the number of bytes required to store all weights and intermediate blobs for each layer (OpenCV 5).
- GetMemoryConsumption(IEnumerable<MatShape>, IEnumerable<MatType>, out long, out long)
Computes the number of bytes required to store all weights and intermediate blobs for the model (OpenCV 5).
- GetModelFormat()
Returns the original framework format the network was loaded from.
- GetParam(int, int)
Returns parameter blob of the layer.
- GetParam(string, int)
Returns parameter blob of the layer.
- GetPerfProfile(out double[])
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.
- GetPerfProfileDetailed(out string[], out string[], out string[])
Returns the detailed per-layer performance profile (new DNN engine, OpenCV 5): for each reported layer, its name, execution time and call count (all as strings).
- GetUnconnectedOutLayers()
Returns indexes of layers with unconnected outputs.
- GetUnconnectedOutLayersNames()
Returns names of layers with unconnected outputs.
- PrintPerfProfile()
Prints per-layer performance profile to the standard output.
- ReadFromModelOptimizer(string, string)
Create a network from Intel's Model Optimizer intermediate representation (IR). Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine backend.
- ReadNet(string, string, string, EngineType)
Read deep learning network represented in one of the supported formats.
This function automatically detects an origin framework of trained model and calls an appropriate function such @ref readNetFromTensorflow, @ref readNetFromONNX, or @ref readNetFromModelOptimizer. The Caffe, Darknet and Torch parsers were removed in OpenCV 5.
- ReadNetFromModelOptimizer(string, string)
Load a network from Intel's Model Optimizer intermediate representation. Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine backend.
- ReadNetFromONNX(byte[], EngineType)
Reads a network model ONNX https://onnx.ai/ from memory
- ReadNetFromONNX(ReadOnlySpan<byte>, EngineType)
Reads a network model ONNX https://onnx.ai/ from memory
- ReadNetFromONNX(string, EngineType)
Reads a network model ONNX https://onnx.ai/
- ReadNetFromTFLite(byte[], EngineType)
Reads a network model stored in TFLite framework's format from memory.
- ReadNetFromTFLite(ReadOnlySpan<byte>, EngineType)
Reads a network model stored in TFLite framework's format from memory.
- ReadNetFromTFLite(string, EngineType)
Reads a network model stored in TFLite (https://www.tensorflow.org/lite) framework's format.
- ReadNetFromTensorflow(byte[], byte[]?, EngineType)
Reads a network model stored in Tensorflow model from memory.
- ReadNetFromTensorflow(ReadOnlySpan<byte>, ReadOnlySpan<byte>, EngineType)
Reads a network model stored in Tensorflow model from memory.
- ReadNetFromTensorflow(string, string?, EngineType)
Reads a network model stored in Tensorflow model file.
- RegisterOutput(string, int, int)
Registers a network output by name (new DNN engine, OpenCV 5).
- ResetKVCache()
Resets the Key-Value (KV) cache contents.
- SetInput(Mat, string)
Sets the new value for the layer output blob
- SetInputShape(string, IEnumerable<int>)
Specify shape of network input.
- SetInputsNames(IEnumerable<string>)
Sets outputs names of the network input pseudo layer.
- SetParam(int, int, Mat)
Sets the new value for the learned param of the layer.
- SetParam(string, int, Mat)
Sets the new value for the learned param of the layer.
- SetPreferableBackend(Backend)
Ask network to use specific computation backend where it supported.
- SetPreferableTarget(Target)
Ask network to make computations on specific target device.