【手寫數(shù)字識別】基于RBM神經(jīng)網(wǎng)絡(luò)手寫數(shù)字識別含Matlab源碼
1 簡介
【手寫數(shù)字識別】基于RBM神經(jīng)網(wǎng)絡(luò)手寫數(shù)字識別含Matlab源碼
2 部分代碼
function varargout = core_Test_gui2(varargin)
% CORE_TEST_GUI2 MATLAB code for core_Test_gui2.fig
% ? ? ?CORE_TEST_GUI2, by itself, creates a new CORE_TEST_GUI2 or raises the existing
% ? ? ?singleton*.
%
% ? ? ?H = CORE_TEST_GUI2 returns the handle to a new CORE_TEST_GUI2 or the handle to
% ? ? ?the existing singleton*.
%
% ? ? ?CORE_TEST_GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% ? ? ?function named CALLBACK in CORE_TEST_GUI2.M with the given input arguments.
%
% ? ? ?CORE_TEST_GUI2('Property','Value',...) creates a new CORE_TEST_GUI2 or raises the
% ? ? ?existing singleton*. ?Starting from the left, property value pairs are
% ? ? ?applied to the GUI before core_Test_gui2_OpeningFcn gets called. ?An
% ? ? ?unrecognized property name or invalid value makes property application
% ? ? ?stop. ?All inputs are passed to core_Test_gui2_OpeningFcn via varargin.
%
% ? ? ?*See GUI Options on GUIDE's Tools menu. ?Choose "GUI allows only one
% ? ? ?instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help core_Test_gui2
% Last Modified by GUIDE v2.5 17-Apr-2021 07:50:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', ? ? ? mfilename, ...
? ? ? ? ? ? ? ? ? 'gui_Singleton', ?gui_Singleton, ...
? ? ? ? ? ? ? ? ? 'gui_OpeningFcn', @core_Test_gui2_OpeningFcn, ...
? ? ? ? ? ? ? ? ? 'gui_OutputFcn', ?@core_Test_gui2_OutputFcn, ...
? ? ? ? ? ? ? ? ? 'gui_LayoutFcn', ?[] , ...
? ? ? ? ? ? ? ? ? 'gui_Callback', ? []);
if nargin && ischar(varargin{1})
? ?gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
? ?[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
? ?gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before core_Test_gui2 is made visible.
function core_Test_gui2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject ? ?handle to figure
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
% varargin ? command line arguments to core_Test_gui2 (see VARARGIN)
% Choose default command line output for core_Test_gui2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes core_Test_gui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = core_Test_gui2_OutputFcn(hObject, eventdata, handles)
% varargout ?cell array for returning output args (see VARARGOUT);
% hObject ? ?handle to figure
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function result_Callback(hObject, eventdata, handles)
% hObject ? ?handle to result (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of result as text
% ? ? ? ?str2double(get(hObject,'String')) returns contents of result as a double
% --- Executes during object creation, after setting all properties.
function result_CreateFcn(hObject, eventdata, handles)
% hObject ? ?handle to result (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% ? ? ? See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
? ?set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in classify.
function classify_Callback(hObject, eventdata, handles)
% hObject ? ?handle to classify (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
data = handles.data;
?data_new=[data data];
?load linear_classify_weights2;% w1為(2*22*22+1)*256,w_class為(256+1)*10
?N=1; %每次只有1幅圖像測試
?%下面的計算方式通過矩陣拼湊,把偏置的計算也融入矩陣中
?dataprobs = [data_new ones(N,1)]; %融入偏置后dataprobs為1*(2*22*22+1)
?w1probs = (dataprobs*w1)>0; %未融入偏置時w1probs為1*256
?w1probs = [w1probs ?ones(N,1)];%融入偏置后,w1probs為1*(256+1)
?targetout = exp(w1probs*w_class);%輸出層為0*10
?%將輸出層輸出100*10,除以每行的總和以求得歸一化比值
?targetout = targetout./repmat(sum(targetout,2),1,10);
?%比較每行中的最大產(chǎn)生10*1的列向量,I每行最大值,J每行最大值序號,
?%代表識別的數(shù)字結(jié)果,1-10(分別代表數(shù)字0-9)
?[I J]=max(targetout,[],2);
?classify_result_str = num2str(J-1);%識別的結(jié)果轉(zhuǎn)換為字符串
?set(handles.result,'String',classify_result_str);
?clear data data_new dataprobs w1probs targetout w1 w_class;
% --- Executes on button press in select.
function select_Callback(hObject, eventdata, handles)
% hObject ? ?handle to select (see GCBO)
% eventdata ?reserved - to be defined in a future version of MATLAB
% handles ? ?structure with handles and user data (see GUIDATA)
load testbatchdata;%加載測試圖像集,100*(22*22)*100
batch_index = randint(1,1,[1,100]);%產(chǎn)生隨機批次號,1-100
image_index = randint(1,1,[1,100]);%產(chǎn)生該批圖像中的隨機測試圖像號,1-100
data = testbatchdata(image_index,:,batch_index);%獲取隨機的一副測試圖像,1*(22*22)
clear testbatchdata;
image_disp = zeros(22,22);
image_disp = reshape(data,22,22);
imagesc(image_disp',[0 1]);%顯示欲測試圖像
set(handles.result,'String','');
handles.data = data;
guidata(hObject,handles);
3 仿真結(jié)果




4 參考文獻
[1]劉東澤. 基于BP神經(jīng)網(wǎng)絡(luò)的手寫數(shù)字識別[D].? 2011.
博主簡介:擅長智能優(yōu)化算法、神經(jīng)網(wǎng)絡(luò)預測、信號處理、元胞自動機、圖像處理、路徑規(guī)劃、無人機等多種領(lǐng)域的Matlab仿真,相關(guān)matlab代碼問題可私信交流。
部分理論引用網(wǎng)絡(luò)文獻,若有侵權(quán)聯(lián)系博主刪除。
