Skip to content

SVM train fails with no warning on infeasible nu parameter #25812

@farlies

Description

@farlies

System Information

OpenCV version: 4.6..0
Operating System / Platform: Ubuntu 24.04
Compiler: GCC 13.2.0

Detailed description

A value of the nu parameter to SVM ml algorithm (type NU_SVC) that is inconsistent with the distribution of labels of the training cases triggers a silent failure in the train() method. The problem is detected, but no error or warning printed--it just fails. Suggested change would be to replace the "// TODO" line with something like :

CV_Error( cv::Error::StsBadArg, "training cases incompatible with nu parameter--try a lower value");

The same issue exists in the current source at the time of this submission.

Steps to reproduce

The dog that did not bark is on line 1462 of module/ml/svm.cpp :

                        if( nu*(ci + cj)*0.5 > std::min( ci, cj ) )
                            // TODO: add some diagnostic 
                            return false;
                    }

https://github.com/opencv/opencv/blob/11c69bb1717e2e0f37b2c25c4741aa4b18538788/modules/ml/src/svm.cpp#L1460

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions