Class cv::ml::ANN_MLP#

Artificial Neural Networks - Multi-Layer Perceptrons. View details

#include <opencv2/ml.hpp>

Collaboration diagram for cv::ml::ANN_MLP:

Public Types#

enum TrainingMethods {
    BACKPROP =0,
    RPROP = 1,
    ANNEAL = 2
}
Public Types inherited from cv::ml::StatModel

Return

Name

Description

Flags

Public Member Functions#

Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

float

calcError(
    const Ptr< TrainData > & data,
    bool test,
    OutputArray resp )

Computes error on the training or test dataset.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

int

getVarCount()

Returns the number of variables in training samples.

bool

isClassifier()

Returns true if the model is classifier.

bool

isTrained()

Returns true if the model is trained.

float

predict(
    InputArray samples,
    OutputArray results = noArray(),
    int flags = 0 )

Predicts response(s) for the provided sample(s)

bool

train(
    const Ptr< TrainData > & trainData,
    int flags = 0 )

Trains the statistical model.

bool

train(
    InputArray samples,
    int layout,
    InputArray responses )

Trains the statistical model.

Public Member Functions inherited from cv::Algorithm

Return

Name

Description

Algorithm()

~Algorithm()

void

clear()

Clears the algorithm state.

bool

empty()

Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.

String

getDefaultName()

void

read(const FileNode & fn)

Reads algorithm parameters from a file storage.

void

save(const String & filename)

void

write(
    const Ptr< FileStorage > & fs,
    const String & name = String() )

void

write(FileStorage & fs)

Stores algorithm parameters in a file storage.

void

write(
    FileStorage & fs,
    const String & name )

Static Public Member Functions#

Static Public Member Functions inherited from cv::ml::StatModel

Return

Name

Description

static Ptr< _Tp >

train(
    const Ptr< TrainData > & data,
    int flags = 0 )

Create and train model with default parameters.

Static Public Member Functions inherited from cv::Algorithm

Return

Name

Description

static Ptr< _Tp >

load(
    const String & filename,
    const String & objname = String() )

Loads algorithm from the file.

static Ptr< _Tp >

loadFromString(
    const String & strModel,
    const String & objname = String() )

Loads algorithm from a String.

static Ptr< _Tp >

read(const FileNode & fn)

Reads algorithm from the file node.

Additional Inherited Members#

Protected Member Functions inherited from cv::Algorithm

Return

Name

Description

void

writeFormat(FileStorage & fs)

Detailed Description#

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 also

ml_intro_ann

Member Enumeration Documentation#

enum ActivationFunctions

IDENTITY
Python: cv.ml.ANN_MLP_IDENTITY

Identity function: \(f(x)=x\)

SIGMOID_SYM
Python: cv.ml.ANN_MLP_SIGMOID_SYM

Symmetrical sigmoid: \(f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x})\)

Note

If you are using the default sigmoid activation function with the default parameter values fparam1=0 and fparam2=0 then the function used is y = 1.7159*tanh(2/3 * x), so the output will range from [-1.7159, 1.7159], instead of [0,1].

GAUSSIAN
Python: cv.ml.ANN_MLP_GAUSSIAN

Gaussian function: \(f(x)=\beta e^{-\alpha x*x}\)

RELU
Python: cv.ml.ANN_MLP_RELU

ReLU function: \(f(x)=max(0,x)\)

LEAKYRELU
Python: cv.ml.ANN_MLP_LEAKYRELU

Leaky ReLU function: for x>0 \(f(x)=x \) and x<=0 \(f(x)=\alpha x \)

enum TrainFlags

UPDATE_WEIGHTS
Python: cv.ml.ANN_MLP_UPDATE_WEIGHTS

Update the network weights, rather than compute them from scratch. In the latter case the weights are initialized using the Nguyen-Widrow algorithm.

NO_INPUT_SCALE
Python: cv.ml.ANN_MLP_NO_INPUT_SCALE

Do not normalize the input vectors. If this flag is not set, the training algorithm normalizes each input feature independently, shifting its mean value to 0 and making the standard deviation equal to 1. If the network is assumed to be updated frequently, the new training data could be much different from original one. In this case, you should take care of proper normalization.

NO_OUTPUT_SCALE
Python: cv.ml.ANN_MLP_NO_OUTPUT_SCALE

Do not normalize the output vectors. If the flag is not set, the training algorithm normalizes each output feature independently, by transforming it to the certain range depending on the used activation function.

enum TrainingMethods

BACKPROP
Python: cv.ml.ANN_MLP_BACKPROP

The back-propagation algorithm.

RPROP
Python: cv.ml.ANN_MLP_RPROP

The RPROP algorithm. See [251] for details.

ANNEAL
Python: cv.ml.ANN_MLP_ANNEAL

The simulated annealing algorithm. See [166] for details.

Member Function Documentation#

getAnnealCoolingRatio()#

double cv::ml::ANN_MLP::getAnnealCoolingRatio()

Python:

cv.ml.ANN_MLP.getAnnealCoolingRatio() -> retval

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

getAnnealFinalT()#

double cv::ml::ANN_MLP::getAnnealFinalT()

Python:

cv.ml.ANN_MLP.getAnnealFinalT() -> retval

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

See also

setAnnealFinalT

getAnnealInitialT()#

double cv::ml::ANN_MLP::getAnnealInitialT()

Python:

cv.ml.ANN_MLP.getAnnealInitialT() -> retval

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

getAnnealItePerStep()#

int cv::ml::ANN_MLP::getAnnealItePerStep()

Python:

cv.ml.ANN_MLP.getAnnealItePerStep() -> retval

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

getBackpropMomentumScale()#

double cv::ml::ANN_MLP::getBackpropMomentumScale()

Python:

cv.ml.ANN_MLP.getBackpropMomentumScale() -> retval

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.

getBackpropWeightScale()#

double cv::ml::ANN_MLP::getBackpropWeightScale()

Python:

cv.ml.ANN_MLP.getBackpropWeightScale() -> retval

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

getLayerSizes()#

cv::Mat cv::ml::ANN_MLP::getLayerSizes()

Python:

cv.ml.ANN_MLP.getLayerSizes() -> retval

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 also

setLayerSizes

getRpropDW0()#

double cv::ml::ANN_MLP::getRpropDW0()

Python:

cv.ml.ANN_MLP.getRpropDW0() -> retval

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

See also

setRpropDW0

getRpropDWMax()#

double cv::ml::ANN_MLP::getRpropDWMax()

Python:

cv.ml.ANN_MLP.getRpropDWMax() -> retval

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

See also

setRpropDWMax

getRpropDWMin()#

double cv::ml::ANN_MLP::getRpropDWMin()

Python:

cv.ml.ANN_MLP.getRpropDWMin() -> retval

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

See also

setRpropDWMin

getRpropDWMinus()#

double cv::ml::ANN_MLP::getRpropDWMinus()

Python:

cv.ml.ANN_MLP.getRpropDWMinus() -> retval

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

See also

setRpropDWMinus

getRpropDWPlus()#

double cv::ml::ANN_MLP::getRpropDWPlus()

Python:

cv.ml.ANN_MLP.getRpropDWPlus() -> retval

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

See also

setRpropDWPlus

getTermCriteria()#

TermCriteria cv::ml::ANN_MLP::getTermCriteria()

Python:

cv.ml.ANN_MLP.getTermCriteria() -> retval

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 also

setTermCriteria

getTrainMethod()#

int cv::ml::ANN_MLP::getTrainMethod()

Python:

cv.ml.ANN_MLP.getTrainMethod() -> retval

Returns current training method

getWeights()#

Mat cv::ml::ANN_MLP::getWeights(int layerIdx)

Python:

cv.ml.ANN_MLP.getWeights(layerIdx) -> retval

setActivationFunction()#

void cv::ml::ANN_MLP::setActivationFunction(
int type,
double param1 = 0,
double param2 = 0 )

Python:

cv.ml.ANN_MLP.setActivationFunction(type[, param1[, param2]])

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

Parameters

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

setAnnealCoolingRatio()#

void cv::ml::ANN_MLP::setAnnealCoolingRatio(double val)

Python:

cv.ml.ANN_MLP.setAnnealCoolingRatio(val)

setAnnealEnergyRNG()#

void cv::ml::ANN_MLP::setAnnealEnergyRNG(const RNG & rng)

Set/initialize anneal RNG.

setAnnealFinalT()#

void cv::ml::ANN_MLP::setAnnealFinalT(double val)

Python:

cv.ml.ANN_MLP.setAnnealFinalT(val)

See also

getAnnealFinalT

setAnnealInitialT()#

void cv::ml::ANN_MLP::setAnnealInitialT(double val)

Python:

cv.ml.ANN_MLP.setAnnealInitialT(val)

setAnnealItePerStep()#

void cv::ml::ANN_MLP::setAnnealItePerStep(int val)

Python:

cv.ml.ANN_MLP.setAnnealItePerStep(val)

setBackpropMomentumScale()#

void cv::ml::ANN_MLP::setBackpropMomentumScale(double val)

Python:

cv.ml.ANN_MLP.setBackpropMomentumScale(val)

setBackpropWeightScale()#

void cv::ml::ANN_MLP::setBackpropWeightScale(double val)

Python:

cv.ml.ANN_MLP.setBackpropWeightScale(val)

setLayerSizes()#

void cv::ml::ANN_MLP::setLayerSizes(InputArray _layer_sizes)

Python:

cv.ml.ANN_MLP.setLayerSizes(_layer_sizes)

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 also

getLayerSizes

setRpropDW0()#

void cv::ml::ANN_MLP::setRpropDW0(double val)

Python:

cv.ml.ANN_MLP.setRpropDW0(val)

See also

getRpropDW0

setRpropDWMax()#

void cv::ml::ANN_MLP::setRpropDWMax(double val)

Python:

cv.ml.ANN_MLP.setRpropDWMax(val)

See also

getRpropDWMax

setRpropDWMin()#

void cv::ml::ANN_MLP::setRpropDWMin(double val)

Python:

cv.ml.ANN_MLP.setRpropDWMin(val)

See also

getRpropDWMin

setRpropDWMinus()#

void cv::ml::ANN_MLP::setRpropDWMinus(double val)

Python:

cv.ml.ANN_MLP.setRpropDWMinus(val)

See also

getRpropDWMinus

setRpropDWPlus()#

void cv::ml::ANN_MLP::setRpropDWPlus(double val)

Python:

cv.ml.ANN_MLP.setRpropDWPlus(val)

See also

getRpropDWPlus

setTermCriteria()#

void cv::ml::ANN_MLP::setTermCriteria(TermCriteria val)

Python:

cv.ml.ANN_MLP.setTermCriteria(val)

See also

getTermCriteria

setTrainMethod()#

void cv::ml::ANN_MLP::setTrainMethod(
int method,
double param1 = 0,
double param2 = 0 )

Python:

cv.ml.ANN_MLP.setTrainMethod(method[, param1[, param2]])

Sets training method and common parameters.

Parameters

create()#

static Ptr< ANN_MLP > cv::ml::ANN_MLP::create()

Python:

cv.ml.ANN_MLP.create() -> retval
cv.ml.ANN_MLP_create() -> retval

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.

load()#

static Ptr< ANN_MLP > cv::ml::ANN_MLP::load(const String & filepath)

Python:

cv.ml.ANN_MLP.load(filepath) -> retval
cv.ml.ANN_MLP_load(filepath) -> retval

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.

Parameters

  • filepath — path to serialized ANN

Source file#

The documentation for this class was generated from the following file: