【问题标题】:How to save matlab trained model in libsvm如何在 libsvm 中保存 matlab 训练的模型
【发布时间】:2014-02-28 16:43:11
【问题描述】:

我是 libsvm 和 matlab 的新手。我已经从网站下载了 libsvm 3.17 并使用 Matlab 训练了我的数据集。我想保存文件,我使用了 svm_savemodel.c 拒绝在 matlab 中编译。这是我收到的信息

mex svm_savemodel.c
Creating library C:\Users\mark\AppData\Local\Temp\mex_zcr67j\templib.x and object C:\Users\mark\AppData\Local\Temp\mex_zcr67j\templib.exp 
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_free_and_destroy_model referenced in function _mexFunction 
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_save_model referenced in function _mexFunction 
svm_savemodel.obj : error LNK2019: unresolved external symbol _matlab_matrix_to_model referenced in function _mexFunction 
svm_savemodel.mexw32 : fatal error LNK1120: 3 unresolved externals 

C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'svm_savemodel.mexw32' failed. 

Error using mex (line 206)
Unable to complete successfully.

那么谁能帮我解决这个问题? 我已经包含了 svm.h、mex.h、svm_model_matlab.h 但它拒绝了....

这就是我所做的

    >> mex -setup

Welcome to mex -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2011b/win32.html 

Please choose your compiler for building MEX-files: 

Would you like mex to locate installed compilers [y]/n? y

Select a compiler: 
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2011b\sys\lcc 
[2] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0 

[0] None 

Compiler: 2

Please verify your choices: 

Compiler: Microsoft Visual C++ 2010  
Location: C:\Program Files\Microsoft Visual Studio 10.0 

Are these correct [y]/n? y

*************************************************************************** 
  Warning: MEX-files generated using Microsoft Visual C++ 2010 require 
           that Microsoft Visual Studio 2010 run-time libraries be  
           available on the computer they are run on. 
           If you plan to redistribute your MEX-files to other MATLAB 
           users, be sure that they have the run-time libraries. 
*************************************************************************** 


Trying to update options file: C:\Users\michael\AppData\Roaming\MathWorks\MATLAB\R2011b\mexopts.bat 
From template:              C:\PROGRA~1\MATLAB\R2011b\bin\win32\mexopts\msvc100opts.bat 

Done . . . 

************************************************************************** 
  Warning: The MATLAB C and Fortran API has changed to support MATLAB 
           variables with more than 2^32-1 elements.  In the near future 
           you will be required to update your code to utilize the new 
           API. You can find more information about this at: 
           http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9 
           Building with the -largeArrayDims option enables the new API. 
************************************************************************** 

>> cd('C:\libsvm-3.17\libsvm-3.17\matlab');
>> make
>> mex svm_savemodel.c
   Creating library C:\Users\michael\AppData\Local\Temp\mex_coX2K1\templib.x and object C:\Users\michael\AppData\Local\Temp\mex_coX2K1\templib.exp 
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_free_and_destroy_model referenced in function _mexFunction 
svm_savemodel.obj : error LNK2019: unresolved external symbol _svm_save_model referenced in function _mexFunction 
svm_savemodel.obj : error LNK2019: unresolved external symbol _matlab_matrix_to_model referenced in function _mexFunction 
svm_savemodel.mexw32 : fatal error LNK1120: 3 unresolved externals 

  C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'svm_savemodel.mexw32' failed. 

Error using mex (line 206)
Unable to complete successfully.

>> 

【问题讨论】:

  • 您是否阅读了有关如何构建库的文档。如果不是,我强烈推荐它。 github.com/cjlin1/libsvm/tree/master/matlab 我也针对任何关于 SO 的进一步问题提出此建议。在提出可以通过这样做轻松回答的问题之前阅读文档。
  • 是的,我已阅读在 ZIP 中找到的 README 文件。实际上,在 matlab 文件夹中找到的其他 C 文件编译成功。正是这个文件返回了这个错误。
  • 仅供参考,我使用的是 libsvm 3.17、matlab R2011B 和 Microsoft Visual C++ 2010 编译器。
  • 我使用了svm_savemodel.c 文件。

标签: c++ matlab machine-learning libsvm


【解决方案1】:

将此添加到您的 make.m 文件中(您可以将它们添加到 ifelse 部分):

mex CFLAGS="$CFLAGS -std=c99" -largeArrayDims svm_savemodel.c ../svm.cpp svm_model_matlab.c

【讨论】:

    猜你喜欢
    • 2013-01-11
    • 2013-10-10
    • 1970-01-01
    • 2019-05-25
    • 2019-11-17
    • 2016-02-18
    • 2017-01-27
    • 2020-08-06
    相关资源
    最近更新 更多