✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
个人主页:Matlab科研工作室
个人信条:格物致知。
钢板在生产及使用过程中产生的表面缺陷不仅影响外观还会降低产品的性能,针对目前检测的效率低,误差大提出了一种结合图像处理与粒子群优化支持向量机的缺陷分类检测系统.利用融合空域的局部二值模式和频域局部相位量化两种特征提取方式的优势对工件的图像进行缺陷特征提取,建立支持向量机(SVM)缺陷分类模型.由于SVM算法参数容易陷入局部最优的问题,所以采用粒子群算法优化SVM的惩罚参数和核函数.在MATLAB 2019b平台进行实验,实验结果对比分析显示,所提算法较传统的SVM分类模型相比提高了18.33%的识别准确率.
function results=CreateAndTrainANN(x,t)
if ~isempty(x)
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. NFTOOL falls back to this in low memory situations.
trainFcn = 'trainlm'; % Levenberg-Marquardt
% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize,trainFcn);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {};
% net.plotFcns = {'plotperform','plottrainstate','ploterrhist', 'plotregression', 'plotfit'};
net.trainParam.showWindow=false;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
E = perform(net,t,y);
else
y=inf(size(t));
e=inf(size(t));
E=inf;
tr.trainInd=[];
tr.valInd=[];
tr.testInd=[];
end
% All Data
Data.x=x;
Data.t=t;
Data.y=y;
Data.e=e;
Data.E=E;
% Train Data
TrainData.x=x(:,tr.trainInd);
TrainData.t=t(:,tr.trainInd);
TrainData.y=y(:,tr.trainInd);
TrainData.e=e(:,tr.trainInd);
if ~isempty(x)
TrainData.E=perform(net,TrainData.t,TrainData.y);
else
TrainData.E=inf;
end
% Validation and Test Data
TestData.x=x(:,[tr.testInd tr.valInd]);
TestData.t=t(:,[tr.testInd tr.valInd]);
TestData.y=y(:,[tr.testInd tr.valInd]);
TestData.e=e(:,[tr.testInd tr.valInd]);
if ~isempty(x)
TestData.E=perform(net,TestData.t,TestData.y);
else
TestData.E=inf;
end
% Export Results
if ~isempty(x)
results.net=net;
else
results.net=[];
end
results.Data=Data;
results.TrainData=TrainData;
% results.ValidationData=ValidationData;
results.TestData=TestData;
end
[1]杜绪伟, 陈东. 基于LBP和LPQ特征融合的PSO-SVM缺陷分类[J]. 电子测量技术, 2020(021):043.
❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料