[][src]Trait opencv::prelude::NetTrait

pub trait NetTrait {
    pub fn as_raw_Net(&self) -> *const c_void;
pub fn as_raw_mut_Net(&mut self) -> *mut c_void; pub fn empty(&self) -> Result<bool> { ... }
pub fn dump(&mut self) -> Result<String> { ... }
pub fn dump_to_file(&mut self, path: &str) -> Result<()> { ... }
pub fn add_layer(
        &mut self,
        name: &str,
        typ: &str,
        params: &mut LayerParams
    ) -> Result<i32> { ... }
pub fn add_layer_to_prev(
        &mut self,
        name: &str,
        typ: &str,
        params: &mut LayerParams
    ) -> Result<i32> { ... }
pub fn get_layer_id(&mut self, layer: &str) -> Result<i32> { ... }
pub fn get_layer_names(&self) -> Result<Vector<String>> { ... }
pub fn get_layer(&mut self, layer_id: Net_LayerId) -> Result<Ptr<Layer>> { ... }
pub fn get_layer_inputs(
        &mut self,
        layer_id: Net_LayerId
    ) -> Result<Vector<Ptr<Layer>>> { ... }
pub fn connect_first_second(
        &mut self,
        out_pin: &str,
        inp_pin: &str
    ) -> Result<()> { ... }
pub fn connect(
        &mut self,
        out_layer_id: i32,
        out_num: i32,
        inp_layer_id: i32,
        inp_num: i32
    ) -> Result<()> { ... }
pub fn set_inputs_names(
        &mut self,
        input_blob_names: &Vector<String>
    ) -> Result<()> { ... }
pub fn set_input_shape(
        &mut self,
        input_name: &str,
        shape: &MatShape
    ) -> Result<()> { ... }
pub fn forward_single(&mut self, output_name: &str) -> Result<Mat> { ... }
pub fn forward_async(&mut self, output_name: &str) -> Result<AsyncArray> { ... }
pub fn forward_layer(
        &mut self,
        output_blobs: &mut dyn ToOutputArray,
        output_name: &str
    ) -> Result<()> { ... }
pub fn forward(
        &mut self,
        output_blobs: &mut dyn ToOutputArray,
        out_blob_names: &Vector<String>
    ) -> Result<()> { ... }
pub fn forward_and_retrieve(
        &mut self,
        output_blobs: &mut Vector<Vector<Mat>>,
        out_blob_names: &Vector<String>
    ) -> Result<()> { ... }
pub fn set_halide_scheduler(&mut self, scheduler: &str) -> Result<()> { ... }
pub fn set_preferable_backend(&mut self, backend_id: i32) -> Result<()> { ... }
pub fn set_preferable_target(&mut self, target_id: i32) -> Result<()> { ... }
pub fn set_input(
        &mut self,
        blob: &dyn ToInputArray,
        name: &str,
        scalefactor: f64,
        mean: Scalar
    ) -> Result<()> { ... }
pub fn set_param(
        &mut self,
        layer: Net_LayerId,
        num_param: i32,
        blob: &Mat
    ) -> Result<()> { ... }
pub fn get_param(
        &mut self,
        layer: Net_LayerId,
        num_param: i32
    ) -> Result<Mat> { ... }
pub fn get_unconnected_out_layers(&self) -> Result<Vector<i32>> { ... }
pub fn get_unconnected_out_layers_names(&self) -> Result<Vector<String>> { ... }
pub fn get_layers_shapes(
        &self,
        net_input_shapes: &Vector<MatShape>,
        layers_ids: &mut Vector<i32>,
        in_layers_shapes: &mut Vector<Vector<MatShape>>,
        out_layers_shapes: &mut Vector<Vector<MatShape>>
    ) -> Result<()> { ... }
pub fn get_layers_shapes_1(
        &self,
        net_input_shape: &MatShape,
        layers_ids: &mut Vector<i32>,
        in_layers_shapes: &mut Vector<Vector<MatShape>>,
        out_layers_shapes: &mut Vector<Vector<MatShape>>
    ) -> Result<()> { ... }
pub fn get_layer_shapes(
        &self,
        net_input_shape: &MatShape,
        layer_id: i32,
        in_layer_shapes: &mut Vector<MatShape>,
        out_layer_shapes: &mut Vector<MatShape>
    ) -> Result<()> { ... }
pub fn get_layer_shapes_1(
        &self,
        net_input_shapes: &Vector<MatShape>,
        layer_id: i32,
        in_layer_shapes: &mut Vector<MatShape>,
        out_layer_shapes: &mut Vector<MatShape>
    ) -> Result<()> { ... }
pub fn get_flops(&self, net_input_shapes: &Vector<MatShape>) -> Result<i64> { ... }
pub fn get_flops_1(&self, net_input_shape: &MatShape) -> Result<i64> { ... }
pub fn get_flops_2(
        &self,
        layer_id: i32,
        net_input_shapes: &Vector<MatShape>
    ) -> Result<i64> { ... }
pub fn get_flops_3(
        &self,
        layer_id: i32,
        net_input_shape: &MatShape
    ) -> Result<i64> { ... }
pub fn get_layer_types(
        &self,
        layers_types: &mut Vector<String>
    ) -> Result<()> { ... }
pub fn get_layers_count(&self, layer_type: &str) -> Result<i32> { ... }
pub fn get_memory_consumption(
        &self,
        net_input_shapes: &Vector<MatShape>,
        weights: &mut size_t,
        blobs: &mut size_t
    ) -> Result<()> { ... }
pub fn get_memory_consumption_1(
        &self,
        net_input_shape: &MatShape,
        weights: &mut size_t,
        blobs: &mut size_t
    ) -> Result<()> { ... }
pub fn get_memory_consumption_for_layer(
        &self,
        layer_id: i32,
        net_input_shapes: &Vector<MatShape>,
        weights: &mut size_t,
        blobs: &mut size_t
    ) -> Result<()> { ... }
pub fn get_memory_consumption_2(
        &self,
        layer_id: i32,
        net_input_shape: &MatShape,
        weights: &mut size_t,
        blobs: &mut size_t
    ) -> Result<()> { ... }
pub fn get_memory_consumption_for_layers(
        &self,
        net_input_shapes: &Vector<MatShape>,
        layer_ids: &mut Vector<i32>,
        weights: &mut Vector<size_t>,
        blobs: &mut Vector<size_t>
    ) -> Result<()> { ... }
pub fn get_memory_consumption_3(
        &self,
        net_input_shape: &MatShape,
        layer_ids: &mut Vector<i32>,
        weights: &mut Vector<size_t>,
        blobs: &mut Vector<size_t>
    ) -> Result<()> { ... }
pub fn enable_fusion(&mut self, fusion: bool) -> Result<()> { ... }
pub fn get_perf_profile(&mut self, timings: &mut Vector<f64>) -> Result<i64> { ... } }

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.

Required methods

pub fn as_raw_Net(&self) -> *const c_void[src]

pub fn as_raw_mut_Net(&mut self) -> *mut c_void[src]

Loading content...

Provided methods

pub fn empty(&self) -> Result<bool>[src]

Returns true if there are no layers in the network.

pub fn dump(&mut self) -> Result<String>[src]

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

pub fn dump_to_file(&mut self, path: &str) -> Result<()>[src]

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

Parameters

  • path: path to output file with .dot extension

See also

dump()

pub fn add_layer(
    &mut self,
    name: &str,
    typ: &str,
    params: &mut LayerParams
) -> Result<i32>
[src]

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).
  • params: parameters which will be used to initialize the creating layer.

Returns

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

pub fn add_layer_to_prev(
    &mut self,
    name: &str,
    typ: &str,
    params: &mut LayerParams
) -> Result<i32>
[src]

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

See also

addLayer()

pub fn get_layer_id(&mut self, layer: &str) -> Result<i32>[src]

Converts string name of the layer to the integer identifier.

Returns

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

pub fn get_layer_names(&self) -> Result<Vector<String>>[src]

pub fn get_layer(&mut self, layer_id: Net_LayerId) -> Result<Ptr<Layer>>[src]

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

pub fn get_layer_inputs(
    &mut self,
    layer_id: Net_LayerId
) -> Result<Vector<Ptr<Layer>>>
[src]

Returns pointers to input layers of specific layer.

pub fn connect_first_second(
    &mut self,
    out_pin: &str,
    inp_pin: &str
) -> Result<()>
[src]

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

Parameters

  • outPin: descriptor of the first layer output.
  • inpPin: descriptor of the second layer input.

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.

See also

setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex()

pub fn connect(
    &mut self,
    out_layer_id: i32,
    out_num: i32,
    inp_layer_id: i32,
    inp_num: i32
) -> Result<()>
[src]

Connects #@p outNum output of the first layer to #@p 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

pub fn set_inputs_names(
    &mut self,
    input_blob_names: &Vector<String>
) -> Result<()>
[src]

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.

pub fn set_input_shape(
    &mut self,
    input_name: &str,
    shape: &MatShape
) -> Result<()>
[src]

Specify shape of network input.

pub fn forward_single(&mut self, output_name: &str) -> Result<Mat>[src]

Runs forward pass to compute output of layer with name @p outputName.

Parameters

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

Returns

blob for first output of specified layer. @details By default runs forward pass for the whole network.

C++ default parameters

  • output_name: String()

pub fn forward_async(&mut self, output_name: &str) -> Result<AsyncArray>[src]

Runs forward pass to compute output of layer with name @p outputName.

Parameters

  • outputName: name for layer which output is needed to get @details 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.

C++ default parameters

  • output_name: String()

pub fn forward_layer(
    &mut self,
    output_blobs: &mut dyn ToOutputArray,
    output_name: &str
) -> Result<()>
[src]

Runs forward pass to compute output of layer with name @p outputName.

Parameters

  • outputBlobs: contains all output blobs for specified layer.
  • outputName: name for layer which output is needed to get @details If @p outputName is empty, runs forward pass for the whole network.

C++ default parameters

  • output_name: String()

pub fn forward(
    &mut self,
    output_blobs: &mut dyn ToOutputArray,
    out_blob_names: &Vector<String>
) -> Result<()>
[src]

Runs forward pass to compute outputs of layers listed in @p outBlobNames.

Parameters

  • outputBlobs: contains blobs for first outputs of specified layers.
  • outBlobNames: names for layers which outputs are needed to get

pub fn forward_and_retrieve(
    &mut self,
    output_blobs: &mut Vector<Vector<Mat>>,
    out_blob_names: &Vector<String>
) -> Result<()>
[src]

Runs forward pass to compute outputs of layers listed in @p outBlobNames.

Parameters

  • outputBlobs: contains all output blobs for each layer specified in @p outBlobNames.
  • outBlobNames: names for layers which outputs are needed to get

pub fn set_halide_scheduler(&mut self, scheduler: &str) -> Result<()>[src]

Compile Halide layers.

Parameters

  • scheduler: Path 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.

pub fn set_preferable_backend(&mut self, backend_id: i32) -> Result<()>[src]

Ask network to use specific computation backend where it supported.

Parameters

  • backendId: backend identifier.

See also

Backend

If OpenCV is compiled with Intel's Inference Engine library, DNN_BACKEND_DEFAULT means DNN_BACKEND_INFERENCE_ENGINE. Otherwise it equals to DNN_BACKEND_OPENCV.

pub fn set_preferable_target(&mut self, target_id: i32) -> Result<()>[src]

Ask network to make computations on specific target device.

Parameters

  • targetId: target 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 | | + | | |

pub fn set_input(
    &mut self,
    blob: &dyn ToInputArray,
    name: &str,
    scalefactor: f64,
    mean: Scalar
) -> Result<()>
[src]

Sets the new input value for the network

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.

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: block formula

C++ default parameters

  • name: ""
  • scalefactor: 1.0
  • mean: Scalar()

pub fn set_param(
    &mut self,
    layer: Net_LayerId,
    num_param: i32,
    blob: &Mat
) -> Result<()>
[src]

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

Parameters

  • layer: name or id of the layer.
  • numParam: index of the layer parameter in the Layer::blobs array.
  • blob: the 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.

pub fn get_param(&mut self, layer: Net_LayerId, num_param: i32) -> Result<Mat>[src]

Returns parameter blob of the layer.

Parameters

  • layer: name or id of the layer.
  • numParam: index of the layer parameter in the Layer::blobs array.

See also

Layer::blobs

C++ default parameters

  • num_param: 0

pub fn get_unconnected_out_layers(&self) -> Result<Vector<i32>>[src]

Returns indexes of layers with unconnected outputs.

pub fn get_unconnected_out_layers_names(&self) -> Result<Vector<String>>[src]

Returns names of layers with unconnected outputs.

pub fn get_layers_shapes(
    &self,
    net_input_shapes: &Vector<MatShape>,
    layers_ids: &mut Vector<i32>,
    in_layers_shapes: &mut Vector<Vector<MatShape>>,
    out_layers_shapes: &mut Vector<Vector<MatShape>>
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: shapes 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

pub fn get_layers_shapes_1(
    &self,
    net_input_shape: &MatShape,
    layers_ids: &mut Vector<i32>,
    in_layers_shapes: &mut Vector<Vector<MatShape>>,
    out_layers_shapes: &mut Vector<Vector<MatShape>>
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: shapes 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

Overloaded parameters

pub fn get_layer_shapes(
    &self,
    net_input_shape: &MatShape,
    layer_id: i32,
    in_layer_shapes: &mut Vector<MatShape>,
    out_layer_shapes: &mut Vector<MatShape>
) -> Result<()>
[src]

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

Parameters

  • netInputShape: shape input blob 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

pub fn get_layer_shapes_1(
    &self,
    net_input_shapes: &Vector<MatShape>,
    layer_id: i32,
    in_layer_shapes: &mut Vector<MatShape>,
    out_layer_shapes: &mut Vector<MatShape>
) -> Result<()>
[src]

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

Parameters

  • netInputShape: shape input blob 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

Overloaded parameters

pub fn get_flops(&self, net_input_shapes: &Vector<MatShape>) -> Result<i64>[src]

Computes FLOP for whole loaded model with specified input shapes.

Parameters

  • netInputShapes: vector of shapes for all net inputs.

Returns

computed FLOP.

pub fn get_flops_1(&self, net_input_shape: &MatShape) -> Result<i64>[src]

Computes FLOP for whole loaded model with specified input shapes.

Parameters

  • netInputShapes: vector of shapes for all net inputs.

Returns

computed FLOP.

Overloaded parameters

pub fn get_flops_2(
    &self,
    layer_id: i32,
    net_input_shapes: &Vector<MatShape>
) -> Result<i64>
[src]

Computes FLOP for whole loaded model with specified input shapes.

Parameters

  • netInputShapes: vector of shapes for all net inputs.

Returns

computed FLOP.

Overloaded parameters

pub fn get_flops_3(
    &self,
    layer_id: i32,
    net_input_shape: &MatShape
) -> Result<i64>
[src]

Computes FLOP for whole loaded model with specified input shapes.

Parameters

  • netInputShapes: vector of shapes for all net inputs.

Returns

computed FLOP.

Overloaded parameters

pub fn get_layer_types(&self, layers_types: &mut Vector<String>) -> Result<()>[src]

Returns list of types for layer used in model.

Parameters

  • layersTypes: output parameter for returning types.

pub fn get_layers_count(&self, layer_type: &str) -> Result<i32>[src]

Returns count of layers of specified type.

Parameters

  • layerType: type.

Returns

count of layers

pub fn get_memory_consumption(
    &self,
    net_input_shapes: &Vector<MatShape>,
    weights: &mut size_t,
    blobs: &mut size_t
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes for all net inputs.
  • weights: output parameter to store resulting bytes for weights.
  • blobs: output parameter to store resulting bytes for intermediate blobs.

pub fn get_memory_consumption_1(
    &self,
    net_input_shape: &MatShape,
    weights: &mut size_t,
    blobs: &mut size_t
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes 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.

Overloaded parameters

pub fn get_memory_consumption_for_layer(
    &self,
    layer_id: i32,
    net_input_shapes: &Vector<MatShape>,
    weights: &mut size_t,
    blobs: &mut size_t
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes 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.

Overloaded parameters

pub fn get_memory_consumption_2(
    &self,
    layer_id: i32,
    net_input_shape: &MatShape,
    weights: &mut size_t,
    blobs: &mut size_t
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes 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.

Overloaded parameters

pub fn get_memory_consumption_for_layers(
    &self,
    net_input_shapes: &Vector<MatShape>,
    layer_ids: &mut Vector<i32>,
    weights: &mut Vector<size_t>,
    blobs: &mut Vector<size_t>
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes 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.

pub fn get_memory_consumption_3(
    &self,
    net_input_shape: &MatShape,
    layer_ids: &mut Vector<i32>,
    weights: &mut Vector<size_t>,
    blobs: &mut Vector<size_t>
) -> Result<()>
[src]

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

Parameters

  • netInputShapes: vector of shapes 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.

Overloaded parameters

pub fn enable_fusion(&mut self, fusion: bool) -> Result<()>[src]

Enables or disables layer fusion in the network.

Parameters

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

pub fn get_perf_profile(&mut self, timings: &mut Vector<f64>) -> Result<i64>[src]

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.

Parameters

  • timings: vector for tick timings for all layers.

Returns

overall ticks for model inference.

Loading content...

Implementors

impl NetTrait for Net[src]

Loading content...