Skip to content

dnn_ClassificationModel

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

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

ARGUMENTSConstructor or factory
CLASSdnn_ClassificationModel
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. Inherits dnn_Model.

This class represents high-level API for classification models.

ClassificationModel allows to set params for preprocessing input image. ClassificationModel creates net from file with trained weights and config, sets preprocessing input, runs forward pass and return top-1 prediction.

Constructors and members

static new

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

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

Net object.

model

Binary file contains trained weights.

config

Text file contains network configuration.

Returns

The dnn_ClassificationModel result.

static from1

Create an owned dnn_ClassificationModel instance with the supplied configuration.

This class represents high-level API for classification models.

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

0 argument (dnn_Net).

Returns

The dnn_ClassificationModel | 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.

setEnableSoftmaxPostProcessing

Set enable/disable softmax post processing option.

If this option is true, softmax is applied after forward inference within the classify() function to convert the confidences range to [0.0-1.0]. This function allows you to toggle this behavior. Please turn true when not contain softmax layer in model.

setEnableSoftmaxPostProcessing(enable: boolean): dnn_ClassificationModel;
enable

Set enable softmax post processing within the classify() function.

Returns

The dnn_ClassificationModel result.

getEnableSoftmaxPostProcessing

Get enable/disable softmax post processing option.

This option defaults to false, softmax post processing is not applied within the classify() function.

getEnableSoftmaxPostProcessing(): boolean;
Returns

The boolean result.

classify

Given the input frame, create input blob, run net and return top-1 prediction.

classify(frame: Mat): dnn_ClassificationModel_classifyResult;
frame

The input image.

Returns

The dnn_ClassificationModel_classifyResult result. Scalar output parameters are returned as named fields in this object. Release returned native handles with using or delete(), including handles nested in results.

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.