Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

termination criteria broken if you want to specify number of epochs

cv::Ptr<cv::ml::ann_mlp> network = cv::ml::ANN_MLP::create(); network->setTermCriteria(cv::TermCriteria(cv::TermCriteria::COUNT, 1000, 0.01); network->train(…);

This should terminate after 1000 epochs no matter what because I specified cv::TermCriteria::COUNT. Not the case. It will terminate based on the default epsilon value.

Problem found in the source code when setting epsilon here: https://github.com/opencv/opencv/blob/9787ab598b6609a6ca6652a12441d741cb15f695/modules/ml/src/ann_mlp.cpp#L867

And in the training loop when deciding to terminate training here: https://github.com/opencv/opencv/blob/9787ab598b6609a6ca6652a12441d741cb15f695/modules/ml/src/ann_mlp.cpp#L949

Only way to do it is specifically set epsilon to 0: network->setTermCriteria(cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 1000, 0);

Which totally nullifies the purpose of cv::TermCriteria::COUNT.

After setting epsilon to 0 the training worked how it was supposed to and terminated only after the specified number of epochs (1000 in this example).

Bug fix please?