MATLAB2017a+VS2015配置LIBSVM工具箱

本文介绍如何在MATLAB中配置并使用LIBSVM工具箱。首先确保已安装MATLAB的C++编译器,然后下载LIBSVM并解压缩至所需位置,通过设置路径并运行make命令来完成配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MATLAB开源的处理SVM工具箱LIBSVM

下载地址:

https://www.csie.ntu.edu.tw/~cjlin/libsvm/#download


首先要确认一下MATLAB的C++编译器是不是装好了

输入命令:

mex -setup

这样就说明电脑上已经装好了VC编译器

把下载好的文件解压到你喜欢的地方,然后设置路径

设置路径:



按“Add Folder”键,把那两个文件添加进去

然后切换当前工作路径到下图所示的路径:


然后输入 make 命令:


即可完成配置

``` function output = getBiconcept( image ) %GETBICONCEPT Summary of this function goes here % Detailed explanation goes here % cd vlfeat-0.9.16\toolbox; % run vl_setup; % cd ..; % cd ..; if ~isdeployed addpath 'vlfeat-0.9.16\toolbox'; run vl_setup; end load('model.mat'); load('model_2000.mat'); try im = imread(image); catch disp('Failed to read image!'); output = -1; return; end [w,h,c] = size(im); if (w<10||h<h) disp('Image too small!'); output = -1; return; end if (c==1) im=gray2rgb(im); end k1=getImageDescriptor(model, im); k3=cat(2,k1); gBOW= vl_homkermap(k3, 1, 'kchi2', 'gamma', .5) ; %save([fullfile(outpath,outname) '-BOW.mat'],'gBOW'); %comingFile=image; %extract gist feature img = im; img = rgb2gray(img); imgsize=size(img); lengthTemp=imgsize(1); widthTemp=imgsize(2); if lengthTemp>widthTemp img=img(int32((lengthTemp-widthTemp)/2+1):int32((lengthTemp+widthTemp)/2),:); else img=img(:,int32((widthTemp-lengthTemp)/2+1):int32((lengthTemp+widthTemp)/2)); end imgsize=size(img); lengthTemp=imgsize(1); widthTemp=imgsize(2); img=img(1:min(lengthTemp,widthTemp),1:min(lengthTemp,widthTemp)); imgsize=size(img); lengthTemp=imgsize(1); widthTemp=imgsize(2); % Parameters: Nblocks = 4; imageSize = min(lengthTemp,widthTemp); orientationsPerScale = [8 8 4]; numberBlocks = 4; % Precompute filter transfert functions (only need to do this one, unless image size is changes): createGabor(orientationsPerScale, imageSize); % this shows the filters G = createGabor(orientationsPerScale, imageSize); % Computing gist requires 1) prefilter image, 2) filter image and collect % output energies output = prefilt(double(img), 4); gGist = gistGabor(output, numberBlocks, G); %save([fullfile(outpath,outname) '-Gist.mat'],'gGist'); % extract lbp features img = im; mapping=getmapping(8,'u2'); g=lbp(img,1,8,mapping,'h'); gLBP=g'; %save([fullfile(outpath,outname) '-LBP.mat'],'gLBP'); %%extract color hist feature I = im; nBins = 256; rHist = imhist(I(:,:,1), nBins); gHist = imhist(I(:,:,2), nBins); bHist = imhist(I(:,:,3), nBins); gColor=[rHist;gHist;bHist]; %save([fullfile(outpath,outname) '-Color.mat'],'gColor'); gBOW=normc(gBOW); gGist=normc(gGist); gLBP=normc(gLBP); gColor=normc(gColor); att = att_ext(gBOW', gLBP', gGist', gColor', model_all); gAtt = att'; %save([fullfile(outpath,outname) '-Att.mat'],'gAtt'); gAtt=normc(gAtt); gEarly=[gLBP' gBOW' gGist' gAtt' gColor']; %save([fullfile(outpath,outname) '-Early.mat'],'gEarly'); output = 1; load('classes.mat'); classnum = length(classes); biconceptVector=zeros(classnum,1); g=gEarly; targetFile='testEarlyFusion'; label=1; fileID = fopen(targetFile,'a+'); fprintf(fileID,'%d',label); fprintf(fileID,' '); [row,col]=size(g); for j = 1:col fprintf(fileID,'%d',j); fprintf(fileID,':'); if(isnan(g(j))) fprintf(fileID,'%f',0); else fprintf(fileID,'%f',g(j)); end fprintf(fileID,' '); end fprintf(fileID,'\n'); fclose(fileID); [label_descriptortest, inst_descriptortest] = libsvmread('testEarlyFusion'); for tempj=1:classnum currentClass=classes{tempj}; try load(['SVM\' currentClass '.mat']); catch exception end [predict_label, accuracy, dec_values] = predict(label_descriptortest, inst_descriptortest, modelfusion,'-b 1'); biconceptVector(tempj,1)=dec_values(1); end %biconceptVector = normc(biconceptVector); save(['result\' image(1:end-4) '-biconcept.mat'],'biconceptVector'); dlmwrite(['result\' image(1:end-4) '-biconcept.txt'],biconceptVector, ' '); delete(targetFile) end```这段代码为什么有标红的地方,导致运行错误“出错 getBiconcept (line 146) [predict_label, accuracy, dec_values] = predict(label_descriptortest, inst_descriptortest, modelfusion,'-b 1');”,为什么今天上午还能正常运行,但是现在不可以了
03-18
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值