View Source Evision.DNN.Net (Evision v0.1.13)

Link to this section Summary

Types

t()

Type that represents an Evision.DNN.Net struct.

Functions

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

Dump net to String

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

Return
  • retval: bool

Returns true if there are no layers in the network.

Enables or disables layer fusion in the network.

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

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

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

Positional Arguments
  • netInputShape: MatShape
Return
  • retval: int64

Has overloading in C++

Positional Arguments
  • layerId: int
  • netInputShape: MatShape
Return
  • retval: int64

Has overloading in C++

Returns input scale and zeropoint for a quantized Net.

Variant 1:

Positional Arguments
Return

Has overloading in C++

Converts string name of the layer to the integer identifier.

Return
  • retval: std::vector<String>

Python prototype (for reference):

Positional Arguments
  • netInputShapes: [MatShape]
  • layerId: int
Return
  • inLayerShapes: [MatShape]
  • outLayerShapes: [MatShape]

Has overloading in C++

Returns count of layers of specified type.

Positional Arguments
  • netInputShape: MatShape
Return
  • layersIds: [int]
  • inLayersShapes: [[MatShape]]
  • outLayersShapes: [[MatShape]]

Has overloading in C++

Returns list of types for layer used in model.

Positional Arguments
  • netInputShape: MatShape
Return
  • weights: size_t
  • blobs: size_t

Has overloading in C++

Positional Arguments
  • layerId: int
  • netInputShape: MatShape
Return
  • weights: size_t
  • blobs: size_t

Has overloading in C++

Returns output scale and zeropoint for a quantized Net.

Variant 1:

Positional Arguments
Keyword Arguments
  • numParam: int.
Return

Python prototype (for reference):

Variant 1:

Positional Arguments
Keyword Arguments
  • numParam: int.
Return

Python prototype (for reference):

Returns overall time for inference and timings (in ticks) for layers.

Returns indexes of layers with unconnected outputs.

Returns names of layers with unconnected outputs.

Return

Python prototype (for reference):

Returns a quantized Net from a floating-point Net.

Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).

Compile Halide layers.

Sets the new input value for the network

Sets the new input value for the network

Specify shape of network input.

Sets outputs names of the network input pseudo layer.

Variant 1:

Positional Arguments

Python prototype (for reference):

Ask network to use specific computation backend where it supported.

Ask network to make computations on specific target device.

Link to this section Types

@type t() :: %Evision.DNN.Net{ref: reference()}

Type that represents an Evision.DNN.Net struct.

  • ref. reference()

    The underlying erlang resource variable.

Link to this section Functions

Link to this function

connect(self, outPin, inpPin)

View Source
@spec connect(t(), binary(), binary()) :: :ok | {:error, String.t()}

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

Positional Arguments
  • outPin: String.

    descriptor of the first layer output.

  • inpPin: String.

    descriptor of the second layer input.

Descriptors have the following template <DFN>&lt;layer_name&gt;[.input_number]</DFN>:

  • the first part of the template <DFN>layer_name</DFN> 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 <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.

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

Python prototype (for reference):

connect(outPin, inpPin) -> None
@spec dump(t()) :: binary() | {:error, String.t()}

Dump net to String

Return

@returns String with structure, hyperparameters, backend, target and fusion Call method after setInput(). To see correct backend, target and fusion run after forward().

Python prototype (for reference):

dump() -> retval
@spec dumpToFile(t(), binary()) :: :ok | {:error, String.t()}

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

Positional Arguments
  • path: String.

    path to output file with .dot extension

@see dump()

Python prototype (for reference):

dumpToFile(path) -> None
@spec empty(t()) :: boolean() | {:error, String.t()}
Return
  • retval: bool

Returns true if there are no layers in the network.

Python prototype (for reference):

empty() -> retval
Link to this function

enableFusion(self, fusion)

View Source
@spec enableFusion(t(), boolean()) :: :ok | {:error, String.t()}

Enables or disables layer fusion in the network.

Positional Arguments
  • fusion: bool.

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

Python prototype (for reference):

enableFusion(fusion) -> None
Link to this function

forward(self, opts \\ nil)

View Source
@spec forward(Evision.Net.t(), [{atom(), term()}, ...] | nil) ::
  [Evision.Mat.t()] | {:error, String.t()}

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

Positional Arguments
  • outBlobNames: [String].

    names for layers which outputs are needed to get

Return
  • outputBlobs: [Evision.Mat].

    contains blobs for first outputs of specified layers.

Python prototype (for reference):

forward(outBlobNames[, outputBlobs]) -> outputBlobs
Link to this function

forwardAndRetrieve(self, outBlobNames)

View Source
@spec forwardAndRetrieve(t(), [binary()]) ::
  [[Evision.Mat.t()]] | {:error, String.t()}

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

Positional Arguments
  • outBlobNames: [String].

    names for layers which outputs are needed to get

Return
  • outputBlobs: [[Evision.Mat]].

    contains all output blobs for each layer specified in @p outBlobNames.

Python prototype (for reference):

forwardAndRetrieve(outBlobNames) -> outputBlobs
@spec forwardAsync(t()) :: Evision.AsyncArray.t() | {:error, String.t()}

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

Keyword Arguments
  • outputName: String.

    name for layer which output is needed to get

Return

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

Python prototype (for reference):

forwardAsync([, outputName]) -> retval
Link to this function

getFLOPS(self, netInputShape)

View Source
@spec getFLOPS(t(), [integer()]) :: integer() | {:error, String.t()}
Positional Arguments
  • netInputShape: MatShape
Return
  • retval: int64

Has overloading in C++

Python prototype (for reference):

getFLOPS(netInputShape) -> retval
Link to this function

getFLOPS(self, layerId, netInputShape)

View Source
@spec getFLOPS(t(), integer(), [integer()]) :: integer() | {:error, String.t()}
Positional Arguments
  • layerId: int
  • netInputShape: MatShape
Return
  • retval: int64

Has overloading in C++

Python prototype (for reference):

getFLOPS(layerId, netInputShape) -> retval
@spec getInputDetails(t()) :: {[number()], [integer()]} | {:error, String.t()}

Returns input scale and zeropoint for a quantized Net.

Return
  • scales: [float].

    output parameter for returning input scales.

  • zeropoints: [int].

    output parameter for returning input zeropoints.

Python prototype (for reference):

getInputDetails() -> scales, zeropoints
Link to this function

getLayer(self, layerName)

View Source
@spec getLayer(t(), binary()) :: Evision.DNN.Layer.t() | {:error, String.t()}
@spec getLayer(t(), integer()) :: Evision.DNN.Layer.t() | {:error, String.t()}
@spec getLayer(t(), term()) :: Evision.DNN.Layer.t() | {:error, String.t()}

Variant 1:

Positional Arguments
Return

Has overloading in C++

@deprecated Use int getLayerId(const String &layer)

Python prototype (for reference):

getLayer(layerName) -> retval

Variant 2:

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

Positional Arguments
  • layerId: int
Return

Python prototype (for reference):

getLayer(layerId) -> retval

Variant 3:

Positional Arguments
  • layerId: LayerId
Return

Has overloading in C++

@deprecated to be removed

Python prototype (for reference):

getLayer(layerId) -> retval
@spec getLayerId(t(), binary()) :: integer() | {:error, String.t()}

Converts string name of the layer to the integer identifier.

Positional Arguments
Return
  • retval: int

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

Python prototype (for reference):

getLayerId(layer) -> retval
@spec getLayerNames(t()) :: [binary()] | {:error, String.t()}
Return
  • retval: std::vector<String>

Python prototype (for reference):

getLayerNames() -> retval
Link to this function

getLayerShapes(self, opts \\ nil)

View Source
@spec getLayerShapes(Evision.Net.t(), [{{atom(), term()}}, ...] | nil) ::
  {[[integer()]], [[integer()]]} | {:error, String.t()}
@spec getLayerShapes(Evision.Net.t(), [{{atom(), term()}}, ...] | nil) ::
  {[integer()], [[[integer()]]], [[[integer()]]]} | {:error, String.t()}
Positional Arguments
  • netInputShapes: [MatShape]
  • layerId: int
Return
  • inLayerShapes: [MatShape]
  • outLayerShapes: [MatShape]

Has overloading in C++

Python prototype (for reference):

getLayerShapes(netInputShapes, layerId) -> inLayerShapes, outLayerShapes
Link to this function

getLayersCount(self, layerType)

View Source
@spec getLayersCount(t(), binary()) :: integer() | {:error, String.t()}

Returns count of layers of specified type.

Positional Arguments
Return
  • retval: int

@returns count of layers

Python prototype (for reference):

getLayersCount(layerType) -> retval
Link to this function

getLayersShapes(self, opts \\ nil)

View Source
Positional Arguments
  • netInputShape: MatShape
Return
  • layersIds: [int]
  • inLayersShapes: [[MatShape]]
  • outLayersShapes: [[MatShape]]

Has overloading in C++

Python prototype (for reference):

getLayersShapes(netInputShape) -> layersIds, inLayersShapes, outLayersShapes
@spec getLayerTypes(t()) :: [binary()] | {:error, String.t()}

Returns list of types for layer used in model.

Return
  • layersTypes: [String].

    output parameter for returning types.

Python prototype (for reference):

getLayerTypes() -> layersTypes
Link to this function

getMemoryConsumption(self, netInputShape)

View Source
@spec getMemoryConsumption(t(), [integer()]) ::
  {integer(), integer()} | {:error, String.t()}
Positional Arguments
  • netInputShape: MatShape
Return
  • weights: size_t
  • blobs: size_t

Has overloading in C++

Python prototype (for reference):

getMemoryConsumption(netInputShape) -> weights, blobs
Link to this function

getMemoryConsumption(self, layerId, netInputShape)

View Source
@spec getMemoryConsumption(t(), integer(), [integer()]) ::
  {integer(), integer()} | {:error, String.t()}
Positional Arguments
  • layerId: int
  • netInputShape: MatShape
Return
  • weights: size_t
  • blobs: size_t

Has overloading in C++

Python prototype (for reference):

getMemoryConsumption(layerId, netInputShape) -> weights, blobs
@spec getOutputDetails(t()) :: {[number()], [integer()]} | {:error, String.t()}

Returns output scale and zeropoint for a quantized Net.

Return
  • scales: [float].

    output parameter for returning output scales.

  • zeropoints: [int].

    output parameter for returning output zeropoints.

Python prototype (for reference):

getOutputDetails() -> scales, zeropoints
Link to this function

getParam(self, layerName)

View Source
@spec getParam(t(), binary()) :: Evision.Mat.t() | {:error, String.t()}
@spec getParam(t(), integer()) :: Evision.Mat.t() | {:error, String.t()}

Variant 1:

Positional Arguments
Keyword Arguments
  • numParam: int.
Return

Python prototype (for reference):

getParam(layerName[, numParam]) -> retval

Variant 2:

Returns parameter blob of the layer.

Positional Arguments
  • layer: int.

    name or id of the layer.

Keyword Arguments
  • numParam: int.

    index of the layer parameter in the Layer::blobs array.

Return

@see Layer::blobs

Python prototype (for reference):

getParam(layer[, numParam]) -> retval
Link to this function

getParam(self, layerName, opts)

View Source
@spec getParam(t(), binary(), [{atom(), term()}, ...] | nil) ::
  Evision.Mat.t() | {:error, String.t()}
@spec getParam(t(), integer(), [{atom(), term()}, ...] | nil) ::
  Evision.Mat.t() | {:error, String.t()}

Variant 1:

Positional Arguments
Keyword Arguments
  • numParam: int.
Return

Python prototype (for reference):

getParam(layerName[, numParam]) -> retval

Variant 2:

Returns parameter blob of the layer.

Positional Arguments
  • layer: int.

    name or id of the layer.

Keyword Arguments
  • numParam: int.

    index of the layer parameter in the Layer::blobs array.

Return

@see Layer::blobs

Python prototype (for reference):

getParam(layer[, numParam]) -> retval
@spec getPerfProfile(t()) :: {integer(), [number()]} | {:error, String.t()}

Returns overall time for inference and timings (in ticks) for layers.

Return
  • retval: int64

  • timings: [double].

    vector for tick timings for all 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. @return overall ticks for model inference.

Python prototype (for reference):

getPerfProfile() -> retval, timings
Link to this function

getUnconnectedOutLayers(self)

View Source
@spec getUnconnectedOutLayers(t()) :: [integer()] | {:error, String.t()}

Returns indexes of layers with unconnected outputs.

Return
  • retval: std::vector<int>

FIXIT: Rework API to registerOutput() approach, deprecate this call

Python prototype (for reference):

getUnconnectedOutLayers() -> retval
Link to this function

getUnconnectedOutLayersNames(self)

View Source
@spec getUnconnectedOutLayersNames(t()) :: [binary()] | {:error, String.t()}

Returns names of layers with unconnected outputs.

Return
  • retval: std::vector<String>

FIXIT: Rework API to registerOutput() approach, deprecate this call

Python prototype (for reference):

getUnconnectedOutLayersNames() -> retval
@spec net() :: t() | {:error, String.t()}
Return

Python prototype (for reference):

Net() -> <dnn_Net object>
Link to this function

quantize(self, calibData, inputsDtype, outputsDtype)

View Source
@spec quantize(t(), [Evision.Mat.maybe_mat_in()], integer(), integer()) ::
  t() | {:error, String.t()}

Returns a quantized Net from a floating-point Net.

Positional Arguments
  • calibData: [Evision.Mat].

    Calibration data to compute the quantization parameters.

  • inputsDtype: int.

    Datatype of quantized net's inputs. Can be CV_32F or CV_8S.

  • outputsDtype: int.

    Datatype of quantized net's outputs. Can be CV_32F or CV_8S.

Return

Python prototype (for reference):

quantize(calibData, inputsDtype, outputsDtype) -> retval
Link to this function

readFromModelOptimizer(bufferModelConfig, bufferWeights)

View Source
@spec readFromModelOptimizer(binary(), binary()) :: t() | {:error, String.t()}

Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR).

Positional Arguments
  • bufferModelConfig: [uchar].

    buffer with model's configuration.

  • bufferWeights: [uchar].

    buffer with model's trained weights.

Return

@returns Net object.

Python prototype (for reference):

readFromModelOptimizer(bufferModelConfig, bufferWeights) -> retval
Link to this function

setHalideScheduler(self, scheduler)

View Source
@spec setHalideScheduler(t(), binary()) :: :ok | {:error, String.t()}

Compile Halide layers.

Positional Arguments
  • scheduler: String.

    Path to YAML file with scheduling directives.

@see setPreferableBackend/2 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.

Python prototype (for reference):

setHalideScheduler(scheduler) -> None
@spec setInput(t(), Evision.Mat.maybe_mat_in()) :: :ok | {:error, String.t()}

Sets the new input value for the network

Positional Arguments
  • blob: Evision.Mat.

    A new blob. Should have CV_32F or CV_8U depth.

Keyword Arguments
  • name: String.

    A name of input layer.

  • scalefactor: double.

    An optional normalization scale.

  • mean: Scalar.

    An optional mean subtraction values.

@see connect(String, String) to know format of the descriptor. If scale or mean values are specified, a final input blob is computed as: \f[input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\f]

Python prototype (for reference):

setInput(blob[, name[, scalefactor[, mean]]]) -> None
Link to this function

setInput(self, blob, opts)

View Source
@spec setInput(t(), Evision.Mat.maybe_mat_in(), [{atom(), term()}, ...] | nil) ::
  :ok | {:error, String.t()}

Sets the new input value for the network

Positional Arguments
  • blob: Evision.Mat.

    A new blob. Should have CV_32F or CV_8U depth.

Keyword Arguments
  • name: String.

    A name of input layer.

  • scalefactor: double.

    An optional normalization scale.

  • mean: Scalar.

    An optional mean subtraction values.

@see connect(String, String) to know format of the descriptor. If scale or mean values are specified, a final input blob is computed as: \f[input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\f]

Python prototype (for reference):

setInput(blob[, name[, scalefactor[, mean]]]) -> None
Link to this function

setInputShape(self, inputName, shape)

View Source
@spec setInputShape(t(), binary(), [integer()]) :: :ok | {:error, String.t()}

Specify shape of network input.

Positional Arguments
  • inputName: String
  • shape: MatShape

Python prototype (for reference):

setInputShape(inputName, shape) -> None
Link to this function

setInputsNames(self, inputBlobNames)

View Source
@spec setInputsNames(t(), [binary()]) :: :ok | {:error, String.t()}

Sets outputs names of the network input pseudo layer.

Positional Arguments
  • inputBlobNames: [String]

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.

Python prototype (for reference):

setInputsNames(inputBlobNames) -> None
Link to this function

setParam(self, layerName, numParam, blob)

View Source
@spec setParam(t(), binary(), integer(), Evision.Mat.maybe_mat_in()) ::
  :ok | {:error, String.t()}
@spec setParam(t(), integer(), integer(), Evision.Mat.maybe_mat_in()) ::
  :ok | {:error, String.t()}

Variant 1:

Positional Arguments

Python prototype (for reference):

setParam(layerName, numParam, blob) -> None

Variant 2:

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

Positional Arguments
  • layer: int.

    name or id of the layer.

  • numParam: int.

    index of the layer parameter in the Layer::blobs array.

  • blob: Evision.Mat.

    the new value.

@see Layer::blobs Note: If shape of the new blob differs from the previous shape, then the following forward pass may fail.

Python prototype (for reference):

setParam(layer, numParam, blob) -> None
Link to this function

setPreferableBackend(self, backendId)

View Source
@spec setPreferableBackend(t(), integer()) :: :ok | {:error, String.t()}

Ask network to use specific computation backend where it supported.

Positional Arguments
  • backendId: int.

    backend identifier.

@see 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.

Python prototype (for reference):

setPreferableBackend(backendId) -> None
Link to this function

setPreferableTarget(self, targetId)

View Source
@spec setPreferableTarget(t(), integer()) :: :ok | {:error, String.t()}

Ask network to make computations on specific target device.

Positional Arguments
  • targetId: int.

    target identifier.

@see 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 | | + | | |

Python prototype (for reference):

setPreferableTarget(targetId) -> None