Skip to content

dnn_Model

Deep neural networksclassOpenCV 5.0.0
import { dnn_Model } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSdnn_Model
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods.

This class is presented high-level API for neural networks.

Model allows to set params for preprocessing input image. Model creates net from file with trained weights and config, sets preprocessing input and runs forward pass.

Constructors and members

static new

Create model from deep learning network represented in one of the supported formats. An order of model and config arguments does not matter.

new(model: EmbindString, config: EmbindString): dnn_Model;
2 available overloads
new(network: EmbindString): dnn_Model;
new(model: EmbindString, config: EmbindString): dnn_Model;
network

Net object.

model

Binary file contains trained weights.

config

Text file contains network configuration.

Returns

The dnn_Model result.

static from1

Create an owned dnn_Model instance with the supplied configuration.

This class is presented high-level API for neural networks.

from1(_0: dnn_Net): dnn_Model | null;
_0

0 argument (dnn_Net).

Returns

The dnn_Model | null result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

setInputSize

Set input size for frame.

Note: If shape of the new blob less than 0, then frame size not change.

setInputSize(size: Size): dnn_Model;
size

New input size.

Returns

The dnn_Model result.

setInputSize1

Set input size for frame.

Note: If shape of the new blob less than 0, then frame size not change.

setInputSize1(width: number, height: number): dnn_Model;
width

New input width.

height

New input height.

Returns

The dnn_Model result.

setInputMean

Set mean value for frame.

setInputMean(mean: Scalar): dnn_Model;
mean

Scalar with mean values which are subtracted from channels.

Returns

The dnn_Model result.

setInputScale

Set scalefactor value for frame.

setInputScale(scale: Scalar): dnn_Model;
scale

Multiplier for frame values.

Returns

The dnn_Model result.

setInputCrop

Set flag crop for frame.

setInputCrop(crop: boolean): dnn_Model;
crop

Flag which indicates whether image will be cropped after resize or not.

Returns

The dnn_Model result.

setInputSwapRB

Set flag swapRB for frame.

setInputSwapRB(swapRB: boolean): dnn_Model;
swapRB

Flag which indicates that swap first and last channels.

Returns

The dnn_Model result.

setOutputNames

Set output names for frame.

setOutputNames(outNames: StringVector): dnn_Model;
outNames

Names for output layers.

Returns

The dnn_Model result.

setInputParams

Set preprocessing parameters for frame.

setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean, crop: boolean): void;
6 available overloads
setInputParams(): void;
setInputParams(scale: number): void;
setInputParams(scale: number, size: Size): void;
setInputParams(scale: number, size: Size, mean: Scalar): void;
setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean): void;
setInputParams(scale: number, size: Size, mean: Scalar, swapRB: boolean, crop: boolean): void;
scale

Multiplier for frame values.

size

New input size.

mean

Scalar with mean values which are subtracted from channels.

swapRB

Flag which indicates that swap first and last channels.

crop

Flag which indicates whether image will be cropped after resize or not. blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) )

predict

Given the input frame, create input blob, run net and return the output blobs.

predict(frame: Mat, outs: MatVector): void;
frame

The input image.

outs

Output destination, filled by the native operation. Allocated output blobs, which will store results of the computation.

setPreferableBackend

============================== Net proxy methods ============================== Never expose methods with network implementation details, like:

  • addLayer, addLayerToPrev, connect, setInputsNames, setInputShape, setParam, getParam
  • getLayer*, getUnconnectedOutLayers, getUnconnectedOutLayersNames, getLayersShapes
  • forward* methods, setInput See: Net::setPreferableBackend
setPreferableBackend(backendId: number): dnn_Model;
backendId

backend id argument (number).

Returns

The dnn_Model result.

setPreferableTarget

See: Net::setPreferableTarget

setPreferableTarget(targetId: number): dnn_Model;
targetId

target id argument (number).

Returns

The dnn_Model result.

enableWinograd

See: Net::enableWinograd

enableWinograd(useWinograd: boolean): dnn_Model;
useWinograd

use winograd argument (boolean).

Returns

The dnn_Model result.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.