Skip to content

ml_ANN_MLP

mlclassOpenCV 5.0.0
import { ml_ANN_MLP } from '@banou/opencv-wasm'

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

ARGUMENTSConstructor or factory
CLASSml_ANN_MLP
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 ml_StatModel.


Gradient Boosted Trees * *************************************************************************************** class CV_EXPORTS_W GBTrees : public DTrees { public: struct CV_EXPORTS_W_MAP Params : public DTrees::Params { CV_PROP_RW int weakCount; CV_PROP_RW int lossFunctionType; CV_PROP_RW float subsamplePortion; CV_PROP_RW float shrinkage;

    Params();
    Params( int lossFunctionType, int weakCount, float shrinkage,
            float subsamplePortion, int maxDepth, bool useSurrogates );
};

enum {SQUARED_LOSS=0, ABSOLUTE_LOSS, HUBER_LOSS=3, DEVIANCE_LOSS};

virtual void setK(int k) = 0;

virtual float predictSerial( InputArray samples,
                             OutputArray weakResponses, int flags) const = 0;

static Ptr<GBTrees> create(const Params& p);

};
Artificial Neural Networks (ANN) * *************************************************************************************** Multi-Layer Perceptrons ////////////////////////////// Artificial Neural Networks - Multi-Layer Perceptrons.

Unlike many other models in ML that are constructed and trained at once, in the MLP model these steps are separated. First, a network with the specified topology is created using the non-default constructor or the method ANN_MLP::create. All the weights are set to zeros. Then, the network is trained using a set of input and output vectors. The training procedure can be repeated more than once, that is, the weights can be adjusted based on the new training data.

Additional flags for StatModel::train are available: ANN_MLP::TrainFlags.

See: ml_intro_ann

Constructors and members

static create

Creates empty model

Use StatModel::train to train the model, Algorithm::load\<ANN_MLP\>(filename) to load the pre-trained model.
Note that the train method has optional flags: ANN_MLP::TrainFlags.
create(): ml_ANN_MLP | null;
Returns

The ml_ANN_MLP | null result.

static load

Loads and creates a serialized ANN from a file

Use ANN::save to serialize and store an ANN to disk. Load the ANN from this file again, by calling this function with the path to the file.

load(filepath: EmbindString): ml_ANN_MLP | null;
filepath

path to serialized ANN

Returns

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

setTrainMethod

Sets training method and common parameters.

setTrainMethod(method: number, param1: number, param2: number): void;
3 available overloads
setTrainMethod(method: number): void;
setTrainMethod(method: number, param1: number): void;
setTrainMethod(method: number, param1: number, param2: number): void;
method

Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods.

param1

passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL.

param2

passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL.

getTrainMethod

Returns current training method

getTrainMethod(): number;
Returns

The number result.

setActivationFunction

Initialize the activation function for each neuron. Currently the default and the only fully supported activation function is ANN_MLP::SIGMOID_SYM.

setActivationFunction(type_: number, param1: number, param2: number): void;
3 available overloads
setActivationFunction(type_: number): void;
setActivationFunction(type_: number, param1: number): void;
setActivationFunction(type_: number, param1: number, param2: number): void;
type_

The type of activation function. See ANN_MLP::ActivationFunctions.

param1

The first parameter of the activation function, \alpha. Default value is 0.

param2

The second parameter of the activation function, \beta. Default value is 0.

setLayerSizes

Integer vector specifying the number of neurons in each layer including the input and output layers. The very first element specifies the number of elements in the input layer. The last element - number of elements in the output layer. Default value is empty Mat. See: getLayerSizes

setLayerSizes(_layer_sizes: Mat): void;
_layer_sizes

layer sizes argument (Mat).

getLayerSizes

Integer vector specifying the number of neurons in each layer including the input and output layers. The very first element specifies the number of elements in the input layer. The last element - number of elements in the output layer. See: setLayerSizes

getLayerSizes(): Mat;
Returns

The Mat result. Release returned native handles with using or delete(), including handles nested in results.

getTermCriteria

Termination criteria of the training algorithm. You can specify the maximum number of iterations (maxCount) and/or how much the error could change between the iterations to make the algorithm continue (epsilon). Default value is TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, 0.01). See: setTermCriteria

getTermCriteria(): TermCriteria;
Returns

The TermCriteria result.

setTermCriteria

Termination criteria of the training algorithm. You can specify the maximum number of iterations (maxCount) and/or how much the error could change between the iterations to make the algorithm continue (epsilon). Default value is TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, 0.01). See: setTermCriteria See: getTermCriteria

setTermCriteria(val: TermCriteria): void;
val

val argument (TermCriteria).

getBackpropWeightScale

BPROP: Strength of the weight gradient term. The recommended value is about 0.1. Default value is 0.1. See: setBackpropWeightScale

getBackpropWeightScale(): number;
Returns

The number result.

setBackpropWeightScale

BPROP: Strength of the weight gradient term. The recommended value is about 0.1. Default value is 0.1. See: setBackpropWeightScale See: getBackpropWeightScale

setBackpropWeightScale(val: number): void;
val

val argument (number).

getBackpropMomentumScale

BPROP: Strength of the momentum term (the difference between weights on the 2 previous iterations). This parameter provides some inertia to smooth the random fluctuations of the weights. It can vary from 0 (the feature is disabled) to 1 and beyond. The value 0.1 or so is good enough. Default value is 0.1. See: setBackpropMomentumScale

getBackpropMomentumScale(): number;
Returns

The number result.

setBackpropMomentumScale

BPROP: Strength of the momentum term (the difference between weights on the 2 previous iterations). This parameter provides some inertia to smooth the random fluctuations of the weights. It can vary from 0 (the feature is disabled) to 1 and beyond. The value 0.1 or so is good enough. Default value is 0.1. See: setBackpropMomentumScale See: getBackpropMomentumScale

setBackpropMomentumScale(val: number): void;
val

val argument (number).

getRpropDW0

RPROP: Initial value \Delta_0 of update-values \Delta_{ij}. Default value is 0.1. See: setRpropDW0

getRpropDW0(): number;
Returns

The number result.

setRpropDW0

RPROP: Initial value \Delta_0 of update-values \Delta_{ij}. Default value is 0.1. See: setRpropDW0 See: getRpropDW0

setRpropDW0(val: number): void;
val

val argument (number).

getRpropDWPlus

RPROP: Increase factor \eta^+. It must be >1. Default value is 1.2. See: setRpropDWPlus

getRpropDWPlus(): number;
Returns

The number result.

setRpropDWPlus

RPROP: Increase factor \eta^+. It must be >1. Default value is 1.2. See: setRpropDWPlus See: getRpropDWPlus

setRpropDWPlus(val: number): void;
val

val argument (number).

getRpropDWMinus

RPROP: Decrease factor \eta^-. It must be <1. Default value is 0.5. See: setRpropDWMinus

getRpropDWMinus(): number;
Returns

The number result.

setRpropDWMinus

RPROP: Decrease factor \eta^-. It must be <1. Default value is 0.5. See: setRpropDWMinus See: getRpropDWMinus

setRpropDWMinus(val: number): void;
val

val argument (number).

getRpropDWMin

RPROP: Update-values lower limit \Delta_{min}. It must be positive. Default value is FLT_EPSILON. See: setRpropDWMin

getRpropDWMin(): number;
Returns

The number result.

setRpropDWMin

RPROP: Update-values lower limit \Delta_{min}. It must be positive. Default value is FLT_EPSILON. See: setRpropDWMin See: getRpropDWMin

setRpropDWMin(val: number): void;
val

val argument (number).

getRpropDWMax

RPROP: Update-values upper limit \Delta_{max}. It must be >1. Default value is 50. See: setRpropDWMax

getRpropDWMax(): number;
Returns

The number result.

setRpropDWMax

RPROP: Update-values upper limit \Delta_{max}. It must be >1. Default value is 50. See: setRpropDWMax See: getRpropDWMax

setRpropDWMax(val: number): void;
val

val argument (number).

getAnnealInitialT

ANNEAL: Update initial temperature. It must be >=0. Default value is 10. See: setAnnealInitialT

getAnnealInitialT(): number;
Returns

The number result.

setAnnealInitialT

ANNEAL: Update initial temperature. It must be >=0. Default value is 10. See: setAnnealInitialT See: getAnnealInitialT

setAnnealInitialT(val: number): void;
val

val argument (number).

getAnnealFinalT

ANNEAL: Update final temperature. It must be >=0 and less than initialT. Default value is 0.1. See: setAnnealFinalT

getAnnealFinalT(): number;
Returns

The number result.

setAnnealFinalT

ANNEAL: Update final temperature. It must be >=0 and less than initialT. Default value is 0.1. See: setAnnealFinalT See: getAnnealFinalT

setAnnealFinalT(val: number): void;
val

val argument (number).

getAnnealCoolingRatio

ANNEAL: Update cooling ratio. It must be >0 and less than 1. Default value is 0.95. See: setAnnealCoolingRatio

getAnnealCoolingRatio(): number;
Returns

The number result.

setAnnealCoolingRatio

ANNEAL: Update cooling ratio. It must be >0 and less than 1. Default value is 0.95. See: setAnnealCoolingRatio See: getAnnealCoolingRatio

setAnnealCoolingRatio(val: number): void;
val

val argument (number).

getAnnealItePerStep

ANNEAL: Update iteration per step. It must be >0 . Default value is 10. See: setAnnealItePerStep

getAnnealItePerStep(): number;
Returns

The number result.

setAnnealItePerStep

ANNEAL: Update iteration per step. It must be >0 . Default value is 10. See: setAnnealItePerStep See: getAnnealItePerStep

setAnnealItePerStep(val: number): void;
val

val argument (number).

getWeights

Return the weights configured on this ml_ANN_MLP object.

getWeights(layerIdx: number): Mat;
layerIdx

layer idx argument (number).

Returns

The Mat result. 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.