資源簡介
BP神經網絡實現圖像識別(BP神經網絡實現圖像識別,批量輸入圖像得到識別結果。)

代碼片段和文件信息
%?clear?all;close?all;
%?%讀取訓練數據
%?[f1f2f3f4class]?=?textread(‘floTrainData.txt‘??‘%f%f%f%f%f‘150);
tic;
clc;clear?all;close?all;
%?%?listing=dir(‘F:\桌面\ELM數據集\1(*).jpg‘);
%?Files1?=?dir(fullfile(‘C:\Users\Administrator\Desktop\AUV聲吶論文\BP\數據\正\‘‘*.jpg‘));
%?Length?=?length(Files1);
%?for?i=1:?Length
%??I?=?imread(strcat(‘C:\Users\Administrator\Desktop\AUV聲吶論文\BP\數據\正\‘Files1(i).name));
%?I=imresize(I[100?100]);
%?x1(:i)=reshape(I100*1001);
%?end
%?Files2?=?dir(fullfile(‘C:\Users\Administrator\Desktop\AUV聲吶論文\BP\數據\負\‘‘*.jpg‘));
%?Length?=?length(Files2);
%?for?i=1:?Length
%??I?=?imread(strcat(‘C:\Users\Administrator\Desktop\AUV聲吶論文\BP\數據\負\‘Files2(i).name));
%?I=imresize(I[100?100]);
%?x2(:i)=reshape(I100*1001);
%?end
%?t=ones(1Length);
%?jzcs_9ping40=cat(1tx);
%---------------------------------------------------
%輸入輸出數據
%---------------------------------------------------
load(‘F:\程序\膠州灣識別\程序\BPcode\JZtest_70pingcd_jhbw_bp.mat‘)
load(‘F:\程序\膠州灣識別\程序\BPcode\JZtrain_70pingcd_jhbw_bp.mat‘)
x=JZtrain_70pingcd_jhbw_bp(2:end:);
label=JZtrain_70pingcd_jhbw_bp(1:);
x_test=JZtest_70pingcd_jhbw_bp(2:end:);
label_test=JZtest_70pingcd_jhbw_bp(1:);
%?x=[x1?x2];
%?label=[1?1?1?1?1?1?1?2?2?2?2?2?2?2];
%?x=double(x);
%?x_test=x(:6:9);
%?label_test=label(:6:9);
%特征值歸一化
[inputminImaxI]?=?premnmx(x)?;
%構造輸出矩陣
class=label‘;
s?=?length(?class)?;
output?=?zeros(?s??1?)?;%改標簽類型
for?i?=?1?:?s?
???output(?i??class(?i1?))?=?1?;
end
%創建神經網絡
net?=?newff(?minmax(input)??[10?2]??{?‘logsig‘?‘purelin‘?}??‘traingdx‘?)?;?
%設置訓練參數
net.trainparam.show?=?50?;
net.trainparam.epochs?=?500?;
net.trainparam.goal?=?0.01?;
net.trainParam.lr?=?0.01?;
%開始訓練
net?=?train(?net?input??output‘?)?;
%讀取測試數據
%?[t1?t2?t3?t4?c]?=?textread(‘floTestData.txt‘??‘%f%f%f%f%f‘150);
%測試數據歸一化
testInput?=?tramnmx?(?x_test??minI?maxI?)?;
c=label_test‘;
%仿真
Y?=?sim(?net??testInput?)?
%統計識別正確率
[s1??s2]?=?size(?Y?)?;
hitNum?=?0?;
for?i?=?1?:?s2
????[m??Index]?=?max(?Y(?:???i?)?)?;
????if(?Index??==?c(i)???)?
????????hitNum?=?hitNum?+?1?;?
????end
end
sprintf(‘識別率是?%3.3f%%‘100?*?hitNum?/?s2?)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2318??2017-03-17?19:56??BP.m
- 上一篇:用回溯法解決TSP問題
- 下一篇:中國電信筆試題資料通信類
評論
共有 條評論