[][src]Trait opencv::dnn::Layer

pub trait Layer: Algorithm {
    fn as_raw_Layer(&self) -> *mut c_void;

    fn blobs(&mut self) -> Result<VectorOfMat> { ... }
fn set_blobs(&mut self, val: VectorOfMat) -> Result<()> { ... }
fn name(&mut self) -> Result<String> { ... }
fn set_name(&mut self, val: &str) -> Result<()> { ... }
fn _type(&mut self) -> Result<String> { ... }
fn set_type(&mut self, val: &str) -> Result<()> { ... }
fn preferable_target(&self) -> Result<i32> { ... }
fn finalize_to(
        &mut self,
        inputs: &dyn ToInputArray,
        outputs: &mut dyn ToOutputArray
    ) -> Result<()> { ... }
fn forward(
        &mut self,
        inputs: &dyn ToInputArray,
        outputs: &mut dyn ToOutputArray,
        internals: &mut dyn ToOutputArray
    ) -> Result<()> { ... }
fn forward_fallback(
        &mut self,
        inputs: &dyn ToInputArray,
        outputs: &mut dyn ToOutputArray,
        internals: &mut dyn ToOutputArray
    ) -> Result<()> { ... }
fn finalize(&mut self, inputs: &VectorOfMat) -> Result<VectorOfMat> { ... }
fn run(
        &mut self,
        inputs: &VectorOfMat,
        outputs: &mut VectorOfMat,
        internals: &mut VectorOfMat
    ) -> Result<()> { ... }
fn input_name_to_index(&mut self, input_name: &str) -> Result<i32> { ... }
fn output_name_to_index(&mut self, output_name: &str) -> Result<i32> { ... }
fn support_backend(&mut self, backend_id: i32) -> Result<bool> { ... }
fn init_halide(
        &mut self,
        inputs: &VectorOfPtrOfBackendWrapper
    ) -> Result<PtrOfBackendNode> { ... }
fn init_inf_engine(
        &mut self,
        inputs: &VectorOfPtrOfBackendWrapper
    ) -> Result<PtrOfBackendNode> { ... }
fn try_attach(
        &mut self,
        node: &PtrOfBackendNode
    ) -> Result<PtrOfBackendNode> { ... }
fn set_activation(&mut self, layer: &PtrOfActivationLayer) -> Result<bool> { ... }
fn try_fuse(&mut self, top: &mut PtrOfLayer) -> Result<bool> { ... }
fn get_scale_shift(&self, scale: &mut Mat, shift: &mut Mat) -> Result<()> { ... }
fn unset_attached(&mut self) -> Result<()> { ... }
fn get_memory_shapes(
        &self,
        inputs: &VectorOfVectorOfint,
        required_outputs: i32,
        outputs: &mut VectorOfVectorOfint,
        internals: &mut VectorOfVectorOfint
    ) -> Result<bool> { ... }
fn get_flops(
        &self,
        inputs: &VectorOfVectorOfint,
        outputs: &VectorOfVectorOfint
    ) -> Result<i64> { ... }
fn set_params_from(&mut self, params: &LayerParams) -> Result<()> { ... } }

This interface class allows to build new Layers - are building blocks of networks.

Each class, derived from Layer, must implement allocate() methods to declare own outputs and forward() to compute outputs. Also before using the new layer into networks you must register your layer by using one of @ref dnnLayerFactory "LayerFactory" macros.

Required methods

Loading content...

Provided methods

fn blobs(&mut self) -> Result<VectorOfMat>

List of learned parameters must be stored here to allow read them by using Net::getParam().

fn set_blobs(&mut self, val: VectorOfMat) -> Result<()>

List of learned parameters must be stored here to allow read them by using Net::getParam().

fn name(&mut self) -> Result<String>

Name of the layer instance, can be used for logging or other internal purposes.

fn set_name(&mut self, val: &str) -> Result<()>

Name of the layer instance, can be used for logging or other internal purposes.

fn _type(&mut self) -> Result<String>

Type name which was used for creating layer by layer factory.

fn set_type(&mut self, val: &str) -> Result<()>

Type name which was used for creating layer by layer factory.

fn preferable_target(&self) -> Result<i32>

prefer target for layer forwarding

fn finalize_to(
    &mut self,
    inputs: &dyn ToInputArray,
    outputs: &mut dyn ToOutputArray
) -> Result<()>

Computes and sets internal parameters according to inputs, outputs and blobs.

Parameters

  • inputs: vector of already allocated input blobs
  • outputs: [out] vector of already allocated output blobs

If this method is called after network has allocated all memory for input and output blobs and before inferencing.

fn forward(
    &mut self,
    inputs: &dyn ToInputArray,
    outputs: &mut dyn ToOutputArray,
    internals: &mut dyn ToOutputArray
) -> Result<()>

Given the @p input blobs, computes the output @p blobs.

Parameters

  • inputs: the input blobs.
  • outputs: [out] allocated output blobs, which will store results of the computation.
  • internals: [out] allocated internal blobs

fn forward_fallback(
    &mut self,
    inputs: &dyn ToInputArray,
    outputs: &mut dyn ToOutputArray,
    internals: &mut dyn ToOutputArray
) -> Result<()>

Given the @p input blobs, computes the output @p blobs.

Parameters

  • inputs: the input blobs.
  • outputs: [out] allocated output blobs, which will store results of the computation.
  • internals: [out] allocated internal blobs

fn finalize(&mut self, inputs: &VectorOfMat) -> Result<VectorOfMat>

Deprecated:

Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead

Deprecated: Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead

fn run(
    &mut self,
    inputs: &VectorOfMat,
    outputs: &mut VectorOfMat,
    internals: &mut VectorOfMat
) -> Result<()>

Deprecated:

This method will be removed in the future release.

Allocates layer and computes output. Deprecated: This method will be removed in the future release.

fn input_name_to_index(&mut self, input_name: &str) -> Result<i32>

Returns index of input blob into the input array.

Parameters

  • inputName: label of input blob

Each layer input and output can be labeled to easily identify them using "%<layer_name%>[.output_name]" notation. This method maps label of input blob to its index into input vector.

fn output_name_to_index(&mut self, output_name: &str) -> Result<i32>

Returns index of output blob in output array. @see inputNameToIndex()

fn support_backend(&mut self, backend_id: i32) -> Result<bool>

Ask layer if it support specific backend for doing computations.

Parameters

  • backendId: computation backend identifier. @see Backend

fn init_halide(
    &mut self,
    inputs: &VectorOfPtrOfBackendWrapper
) -> Result<PtrOfBackendNode>

Returns Halide backend node.

Parameters

  • inputs: Input Halide buffers. @see BackendNode, BackendWrapper

Input buffers should be exactly the same that will be used in forward invocations. Despite we can use Halide::ImageParam based on input shape only, it helps prevent some memory management issues (if something wrong, Halide tests will be failed).

fn init_inf_engine(
    &mut self,
    inputs: &VectorOfPtrOfBackendWrapper
) -> Result<PtrOfBackendNode>

fn try_attach(&mut self, node: &PtrOfBackendNode) -> Result<PtrOfBackendNode>

Implement layers fusing.

Parameters

  • node: Backend node of bottom layer. @see BackendNode

Actual for graph-based backends. If layer attached successfully, returns non-empty cv::Ptr to node of the same backend. Fuse only over the last function.

fn set_activation(&mut self, layer: &PtrOfActivationLayer) -> Result<bool>

Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial case.

Parameters

  • layer: The subsequent activation layer.

Returns true if the activation layer has been attached successfully.

fn try_fuse(&mut self, top: &mut PtrOfLayer) -> Result<bool>

Try to fuse current layer with a next one

Parameters

  • top: Next layer to be fused.

Returns

True if fusion was performed.

fn get_scale_shift(&self, scale: &mut Mat, shift: &mut Mat) -> Result<()>

Returns parameters of layers with channel-wise multiplication and addition.

Parameters

  • scale: [out] Channel-wise multipliers. Total number of values should be equal to number of channels.
  • shift: [out] Channel-wise offsets. Total number of values should be equal to number of channels.

Some layers can fuse their transformations with further layers. In example, convolution + batch normalization. This way base layer use weights from layer after it. Fused layer is skipped. By default, @p scale and @p shift are empty that means layer has no element-wise multiplications or additions.

fn unset_attached(&mut self) -> Result<()>

"Deattaches" all the layers, attached to particular layer.

fn get_memory_shapes(
    &self,
    inputs: &VectorOfVectorOfint,
    required_outputs: i32,
    outputs: &mut VectorOfVectorOfint,
    internals: &mut VectorOfVectorOfint
) -> Result<bool>

fn get_flops(
    &self,
    inputs: &VectorOfVectorOfint,
    outputs: &VectorOfVectorOfint
) -> Result<i64>

fn set_params_from(&mut self, params: &LayerParams) -> Result<()>

Initializes only #name, #type and #blobs fields.

Loading content...

Implementors

impl Layer for AbsLayer[src]

impl Layer for BNLLLayer[src]

impl Layer for BatchNormLayer[src]

impl Layer for BlankLayer[src]

impl Layer for ChannelsPReLULayer[src]

impl Layer for ConcatLayer[src]

impl Layer for ConstLayer[src]

impl Layer for ConvolutionLayer[src]

impl Layer for CropAndResizeLayer[src]

impl Layer for CropLayer[src]

impl Layer for DeconvolutionLayer[src]

impl Layer for DetectionOutputLayer[src]

impl Layer for ELULayer[src]

impl Layer for EltwiseLayer[src]

impl Layer for FlattenLayer[src]

impl Layer for InnerProductLayer[src]

impl Layer for InterpLayer[src]

impl Layer for LRNLayer[src]

impl Layer for MVNLayer[src]

impl Layer for MaxUnpoolLayer[src]

impl Layer for NormalizeBBoxLayer[src]

impl Layer for PaddingLayer[src]

impl Layer for PermuteLayer[src]

impl Layer for PoolingLayer[src]

impl Layer for PowerLayer[src]

impl Layer for PriorBoxLayer[src]

impl Layer for ProposalLayer[src]

impl Layer for ReLU6Layer[src]

impl Layer for ReLULayer[src]

impl Layer for RegionLayer[src]

impl Layer for ReorgLayer[src]

impl Layer for ReshapeLayer[src]

impl Layer for ResizeLayer[src]

impl Layer for ScaleLayer[src]

impl Layer for ShiftLayer[src]

impl Layer for ShuffleChannelLayer[src]

impl Layer for SigmoidLayer[src]

impl Layer for SliceLayer[src]

impl Layer for SoftmaxLayer[src]

impl Layer for SplitLayer[src]

impl Layer for TanHLayer[src]

impl Layer for PtrOfActivationLayer[src]

impl Layer for PtrOfBaseConvolutionLayer[src]

impl Layer for PtrOfLSTMLayer[src]

impl Layer for PtrOfLayer[src]

impl Layer for PtrOfRNNLayer[src]

Loading content...