Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi all,

I'll give the answer myself:

The problem is the already mentioned difference between the support vector indices. Within the implementation of the SVMs write and read methods (modules/ml/src/svm.cpp, lines 2022 ff and 2139 ff), the author makes the assumption, that support vector indices are not required in 2-class problems. That is probably correct if a linear kernel is used (i.e., when you have only one support vector). But with other kernels (in my case with an RBF kernel), the support vector indices are definitly required.

I've added a git diff where I commented this questionable conditions out. Now everything works fine! IMHO the lines should be removed.

I posted a bug report on this issue right now.

Btw.: That new users must wait 2 days to answer their own questions sucks!!!

Jens

diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp
index 9318085..b9f1c51 100644
--- a/modules/ml/src/svm.cpp
+++ b/modules/ml/src/svm.cpp
@@ -2066,14 +2066,14 @@ public:
                << "alpha" << "[:";
              fs.writeRaw("d", (const uchar*)&df_alpha[df.ofs], sv_count*sizeof(df_alpha[0]));
              fs << "]";
-            if( class_count > 2 )
-            {
+//            if( class_count > 2 )
+//            {
                  fs << "index" << "[:";
                  fs.writeRaw("i", (const uchar*)&df_index[df.ofs], sv_count*sizeof(df_index[0]));
                  fs << "]";
-            }
-            else
-                CV_Assert( sv_count == sv_total );
+//            }
+//            else
+//                CV_Assert( sv_count == sv_total );
              fs << "}";
          }
          fs << "]";
@@ -2191,12 +2191,12 @@ public:
              df_index.resize(ofs + sv_count);
              df_alpha.resize(ofs + sv_count);
              dfi["alpha"].readRaw("d", (uchar*)&df_alpha[ofs], sv_count*sizeof(df_alpha[0]));
-            if( class_count > 2 )
+//            if( class_count > 2 )
                  dfi["index"].readRaw("i", (uchar*)&df_index[ofs], sv_count*sizeof(df_index[0]));
              decision_func.push_back(df);
          }
-        if( class_count <= 2 )
-            setRangeVector(df_index, sv_total);
+//        if( class_count <= 2 )
+//            setRangeVector(df_index, sv_total);
          if( (int)fn["optimize_linear"] != 0 )
              optimize_linear_svm();
      }