Supprt Vector Machine works in matlab, doesn't work in c++

后端 未结 2 1651
抹茶落季
抹茶落季 2021-01-07 09:38

I\'m writing an application that uses an SVM to do classification on some images (specifically these). My Matlab implementation works really well. Using a SIFT bag-of-words

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 10:19

    There is nothing magical about the Matlab version of the libraries, other that it runs in Matlab which makes it harder to shoot yourself on the foot.

    A check list:

    1. Are you normalizing your data, making all values lie between 0 and 1 (or between -1 and 1), either linearly or using the mean and the standard deviation?
    2. Are you parameter searching for a good value of C (or C and gamma in the case of an RBF kernel)? Doing cross validation or on a hold out set?
    3. Are you sure that your're handling NaN, and all other floating point nastiness? Matlab is very good at hiding this from you, C++ not so much.
    4. Could it be that you're loading your data incorrectly, reading a "%s" into a double or something that is adding noise to your input data?
    5. Could it be that libsvm/dlib expects the data in row major order and your're sending it in in column major (or the other way around)? Again Matlab makes this almost impossible, C++ not so much.
    6. 32-64 bit nastiness one version of the library, executable compiled with the other?

    Some other things:

    1. Could it be that in Matlab you're somehow leaking the class (y) into the preprocessing? no one does this on purpose, but I've seen it happen. If you make almost any f(y) a feature, you'll get almost 100% everytime.
    2. Sometimes it helps to verify that everything is numerically identical by printing to file before training both in C++ and Matlab.

提交回复
热议问题