在Android中训练SVM算法 [英] training SVM algorithm in android

查看:224
本文介绍了在Android中训练SVM算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在android上训练我的SVM算法时遇到了一些问题.这是我的代码

hi every one i have a little problem training my SVM algorithm in android.here is my code

Imgproc.calcHist(list, channels, new Mat(), hist, histSize, ranges);
          Imgproc.calcHist(lis, channels, new Mat(), his, histSize, ranges);
         // tl.setText(his.toString());
          Mat train_data = new Mat(2, 0, CvType.CV_32FC1);
          train_data.push_back(hist);
          train_data.push_back(his);
          Mat train_dat = new Mat(2, 0, CvType.CV_32FC1);
          train_dat.put(2, 0, labelArray);
           CvSVM svm = new CvSVM();
          CvSVMParams params = new CvSVMParams();
          params.set_svm_type(CvSVM.C_SVC);
          params.set_kernel_type(CvSVM.LINEAR);
          params.set_term_crit(new TermCriteria(TermCriteria.EPS, 100, 1e-6));
          svm.train_auto(train_data, train_dat, new Mat(), new Mat(), params);

当我运行它时,会出现此类错误

when i run it i get errors of this sort

03-15 13:08:30.065: E/cv::error()(381): OpenCV Error: Bad argument (Invalid response array) in cvPreprocessCategoricalResponses, file /home/reports/ci/slave/50-SDK/opencv/modules/ml/src/inner_functions.cpp, line 664
03-15 13:08:30.120: E/AndroidRuntime(381): CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/ml/src/inner_functions.cpp:664: error: (-5) Invalid response array in function cvPreprocessCategoricalResponses
03-15 13:08:30.120: E/AndroidRuntime(381):  at org.opencv.ml.CvSVM.train_auto_1(Native Method)
03-15 13:08:30.120: E/AndroidRuntime(381):  at org.opencv.ml.CvSVM.train_auto(CvSVM.java:395)

我需要您的帮助pliz.thnx

i need your help pliz.thnx

推荐答案

您正在创建两个具有2行和零列的Mat,这非常可疑.最终,OpenCV抱怨传递给train_auto的第二个数组的形状不正确.根据您所展示的内容,这就是可以说的全部.您需要了解传递给train_auto的Mats的预期形状.

You're creating two Mats with 2 rows and zero columns, that is highly suspicious. In the end OpenCV is complaining that the second array passed into train_auto has an incorrect shape. With what you're showing this is all than can be said. You need to understand the expected shapes of the Mats passed into train_auto.

这是一个很好的示例,显示了传递给train auto的两个参数的大小应为:

Here is a good example that shows what the size of the two parameters passed into train auto should be:

http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html

也不清楚是否有充分的理由使用这种奇特的设置(在Android中训练SVM),这可能对您尝试在真实的机器上进行编程直到您完全理解为止可能有用吗?我敢肯定这些错误将对您有所帮助.

Also it is unclear if there is a good reason to be using such an exotic setup (training an SVM in Android) it may be useful for you to try to do the programming in a real machine until you fully understand things? I'm pretty sure the errors will be more helpful there.

这篇关于在Android中训练SVM算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆