(Đồ án hcmute) huấn luyện máy tính bằng mạng nơ ron để nhận dạng vật thể

127 1 0
(Đồ án hcmute) huấn luyện máy tính bằng mạng nơ ron để nhận dạng vật thể

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP NGÀNH CNKT ĐIỀU KHIỂN VÀ TỰ ĐỘNG HÓA HUẤN LUYỆN MÁY TÍNH BẰNG MẠNG NƠ-RON ĐỂ NHẬN DẠNG VẬT THỂ GVHD: TS LÊ MỸ HÀ SVTH: PHẠM ĐỨC ĐẠI SKL010021 Tp Hồ Chí Minh, tháng 07/2017 BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP.HCM  KHOA CHẤT LƯỢNG CAO ĐỒ ÁN TỐT NGHIỆP Đề tài: HUẤN LUYỆN MÁY TÍNH BẰNG MẠNG NƠ-RON ĐỂ NHẬN DẠNG VẬT THỂ GIẢNG VIÊN HƯỚNG DẪN : SINH VIÊN THỰC HIỆN: TS LÊ MỸ HÀ PHẠM ĐỨC ĐẠI MSSV: 13151020 LỚP: 13151CLC NGÀNH: CÔNG NGHỆ KTDK VÀ TỰ ĐỘNG HĨA KHĨA: 2013 – 2017 Tp Hồ Chí Minh, tháng 7/2017 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 PHẦN A: GIỚI THIỆU i Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 TRƯỜNG ĐH SPKT TP HCM CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM KHOA CHẤT LƯỢNG CAO ĐỘC LẬP - TỰ DO - HẠNH PHÚC Tp.HCM, ngày tháng năm 2017 NHIỆM VỤ ĐỒ ÁN TỐT NGHIỆP Họ tên sinh viên: Phạm Đức Đại MSSV: 13151020 Chuyên ngành: Công nghệ Kỹ thuật điều khiển Tự động hóa Mã ngành: 13151 Hệ đào tạo: Đại học quy Khóa: 2013-2017 Lớp: 13151CLC I TÊN ĐỀ TÀI: HUẤN LUYỆN MÁY TÍNH NHẬN BIẾT ẢNH BẰNG PHƯƠNG PHÁP CNN-MẠNG NƠ-RON TÍCH CHẬP Thời gian thực từ / /2016 đến / /2017 II NHIỆM VỤ Các yêu cầu cụ thể đề tài: - Tìm hiểu mạng nơ-ron nhân tạo, mạng nơ-ron tích chập - Tìm hiểu khâu mạng nơ-ron tích chập - Từ kiến thức mạng nơ-ron tích chập viết chương trình mơ bước mạng nơ-ron tích chập - Áp dụng để huấn luyện máy tính nhận dạng số vật định - Củng cố, thay đổi, phát triển chương trình huấn luyện để máy tính nhận dạng vật huấn luyện cách xác Lời cam đoan cuả sinh viên: Tôi cam đoan Đồ án tốt nghiệp cơng trình nghiên cứu tơi theo hướng dẫn T.S Lê Mỹ Hà Các kết công bố đồ án trung thực khơng chép từ cơng trình khác Tp.HCM, ngày Xác nhận môn tháng năm 2017 Giáo viên hướng dẫn ii Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 TRƯỜNG ĐẠI HỌC SPKT CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM TP.HCM Độc lập - Tự - Hạnh phúc Khoa Chất lượng cao Bộ Môn Tự động điều khiển Tp Hồ Chí Minh, ngày tháng năm 2017 LỊCH TRÌNH THỰC HIỆN ĐỒ ÁN TỐT NGHIỆP Họ tên sinh viên: PHẠM ĐỨC ĐẠI Lớp: 13151CLC MSSV: 13151020 Tên đề tài: HUẤN LUYỆN MÁY TÍNH NHẬN BIẾT ẢNH BẰNG PHƯƠNG PHÁP CNN - MẠNG NƠ-RON TÍCH CHẬP Tuần/ngày Nội dung Tuần Gặp giáo viên hướng dẫn Tham khảo ý kiến giáo viên Xác nhận GVHD chọn đề tài Tuần Tìm hiểu khái niệm mạng nơ-ron nhân tạo, mạng nơron tích chập Tìm hiểu, biết thành phần khâu, nhiệm vụ, công Tuần thức khâu huấn luyện máy tính mạng nơ-ron tích chập Tìm kiếm áp dụng kiến thức biết để viết chương Tuần trình đơn giản huấn luyện máy tính nhận biết chữ X O Tìm kiếm chương trình huấn luyện máy tính mạng Tuần nơ-ron tích chập cụ thể Chạy huấn luyện thành cơng chương trình tìm Đọc nghiên cứu để hiểu rõ cách lệnh, bước Tuần 6,7 chương trình Dựa vào lý thuyết để giải thích thơng số, lệnh, thứ tự xếp lệnh chương trình iii Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 Dựa vào kiến thức chương trình tìm tự viết Tuần 8,9 chương trình huấn luyện máy tính khác cho tập liệu khác mạng nơ-ron truyền thống Tuần 10, 11 Tuần 12 Tạo tập liệu để huấn luyện Nâng cấp chương trình huấn luyện máy tính từ mạng truyền thông sang phương pháp Deep learning mạng nơ-ron tích chập Chỉnh sửa, thay đổi để huấn luyện thành công tập liệu Huấn luyện tập liệu phương pháp khác để so Tuần 13 sánh Kiểm tra chất lượng việc huấn luyện phương pháp Deep learning làm Tuần 14 Viết báo cáo Tuần 15 Chỉnh sửa hồn thiện chương trình báo cáo GV HƯỚNG DẪN TS LÊ MỸ HÀ iv Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH KHOA CHẤT LƯỢNG CAO CỘNG HỒ XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh Phúc BẢNG NHẬN XÉT CỦA GIÁO VIÊN HƯỚNG DẪN Họ tên Sinh viên: MSSV: Ngành: Tên đề tài: Họ tên giáo viên hướng dẫn: NHẬN XÉT Về nội dung đề tài & khối lượng thực hiện: Ưu điểm: Khuyết điểm: Đề nghị cho bảo vệ hay không? Đánh giá loại: Điểm…………… (Bằng chữ: ) Tp Hồ Chí Minh, ngày tháng năm 20… Giáo viên hướng dẫn (Ký & ghi rõ họ tên) v Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH KHOA CHẤT LƯỢNG CAO CỘNG HOÀ XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh Phúc BẢNG NHẬN XÉT CỦA GIÁO VIÊN PHẢN BIỆN Họ tên Sinh viên: MSSV: Ngành: Tên đề tài: Họ tên giáo viên phản biện: NHẬN XÉT Về nội dung đề tài & khối lượng thực hiện: Ưu điểm: Khuyết điểm: Đề nghị cho bảo vệ hay không? Đánh giá loại: Điểm………… (Bằng chữ: ) Tp Hồ Chí Minh, ngày tháng năm 20… Giáo viên phản biện (Ký & ghi rõ họ tên) vi Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 vii Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 LỜI NÓI ĐẦU  Kiến thức tư người ngày phát triển rộng lớn Để cải thiện sống người suy nghĩ, sáng tạo, sử dụng nhiều thành tựu khoa học - kỹ thuật vào tất hoạt động đời sống Công nghệ kỹ thuật tự động hóa lĩnh vực vô mạnh mẽ khoa học - kỹ thuật Nó góp phần khơng nhỏ việc cải thiện đời sống ứng dụng nhiều hoạt động quan trọng như: sản xuất, vận chuyển, y tế, giáo dục … Một mơ hình, hệ thống tự động hóa tân tiến, hiệu trung tâm điều khiển hệ thống thơng minh Tầm nhìn, nhận biết yếu tố then chốt để tăng cường thông minh nhạy bén trung tâm điều khiển trở thành đề tài đề cập việc phát triển khoa học - kỹ thuật viii Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 % % Returns: % convolvedFeatures - matrix of convolved features in the form % convolvedFeatures(imageRow, imageCol, featureNum, imageNum) [filterDimRow,filterDimCol,channel,numFilters] = size(W); if ~exist('con_matrix','var') || isempty(con_matrix) con_matrix = ones(channel, numFilters); end if ~exist('nonlineartype','var') nonlineartype = 'sigmoid'; end if ~exist('shape','var') shape = 'valid'; end [imageDimRow, imageDimCol,numChannel, numImages] = size(images); convDimRow = imageDimRow - filterDimRow + 1; convDimCol = imageDimCol - filterDimCol + 1; convolvedFeatures = zeros(convDimRow, convDimCol, numFilters*numChannel, numImages); % Convolve every filter with every image here to produce the convolvedFeatures, such that % convolvedFeatures(imageRow, imageCol, featureNum, imageNum) for imageNum = 1:numImages for channelNum = 1:numChannel for soanhconv = 1:numFilters convolvedImage = zeros(convDimRow, convDimCol); for filterNum = 1:channel if con_matrix(channelNum,filterNum) ~= % Obtain the feature (filterDim x filterDim) needed during the convolution filter = W(:,:,channel,soanhconv); % Flip the feature matrix because of the definition of convolution, as explained later filter = rot90(squeeze(filter),2); % Obtain the image im = squeeze(images(:, :, channelNum ,imageNum)); 97 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 % Convolve "filter" with "im", adding the result to convolvedImage % be sure to a 'valid' convolution convolvedImage = convolvedImage + conv2(im, filter, shape); end % Add the bias unit end convolvedImage = convolvedImage + b(filterNum); convolvedFeatures(:, :, channelNum*numFilters - numFilters + soanhconv, imageNum) = convolvedImage; end end end linTrans = convolvedFeatures; switch nonlineartype case 'sigmoid' convolvedFeatures = 1./(1+exp(-convolvedFeatures)); case 'relu' convolvedFeatures = max(0,convolvedFeatures); case 'tanh' convolvedFeatures = tanh(convolvedFeatures); case 'softsign' convolvedFeatures = convolvedFeatures / (1 + abs(convolvedFeatures)); case 'none' % don't nonlinearty otherwise fprintf('error: no such nonlieartype%s',nonlineartype); end end ********************** Hàm thực lớp Pooling ******************** function [pooledFeatures, weights] = cnnPool(poolDim, convolvedFeatures, pooltypes) %cnnPool Pools the given convolved features % % Parameters: % poolDim - dimension of pooling region, is a * vector(poolDimRow poolDimCol); % convolvedFeatures - convolved features to pool (as given by cnnConvolve) % convolvedFeatures(imageRow, imageCol, featureNum, imageNum) % % Returns: % pooledFeatures - matrix of pooled features in the form 98 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 % % weights % pooledFeatures(poolRow, poolCol, featureNum, imageNum) - how much the input contributes to the output if nargin < pooltypes = 'meanpool'; end numImages = size(convolvedFeatures, 4); numFilters = size(convolvedFeatures, 3); convolvedDimRow = size(convolvedFeatures, 1); convolvedDimCol = size(convolvedFeatures, 2); pooledDimRow = floor(convolvedDimRow / poolDim(1)); pooledDimCol = floor(convolvedDimCol / poolDim(2)); weights = zeros(size(convolvedFeatures)); featuresTrim = convolvedFeatures(1:pooledDimRow*poolDim(1),1:pooledDimCol*poolDim(2) ,:,:); if strcmp(pooltypes, 'meanpool') weights(1:pooledDimRow*poolDim(1), 1:pooledDimCol*poolDim(2),:,:) = ones(size(featuresTrim)) / poolDim(1) / poolDim(2); end pooledFeatures = zeros(pooledDimRow, pooledDimCol, numFilters, numImages); poolFilter = ones(poolDim) * 1/poolDim(1)/poolDim(2); for imageNum = 1:numImages for filterNum = 1:numFilters features = featuresTrim(:,:,filterNum, imageNum); switch pooltypes case 'meanpool' poolConvolvedFeatures = conv2(features,poolFilter,'valid'); pooledFeatures(:,:,filterNum,imageNum) = poolConvolvedFeatures(1:poolDim:end,1:poolDim:end); % case 'maxpool' % % Todo : this is need to be optimized % pooledFeatures(:,:,filterNum,imageNum) = blockproc(features,poolDim,@maxblock); case 'maxpool' temp = im2col(features, poolDim, 'distinct'); [m, i] = max(temp); temp = zeros(size(temp)); temp(sub2ind(size(temp),i,1:size(i,2))) = 1; 99 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 weights(1:pooledDimRow*poolDim(1),1:pooledDimCol*poolDim(2),filterNum, imageNum) = col2im(temp, poolDim,[pooledDimRow*poolDim(1) pooledDimCol*poolDim(2)], 'distinct'); pooledFeatures(:,:,filterNum,imageNum) = reshape(m, size(pooledFeatures,1), size(pooledFeatures,2)); otherwise error('wrongLayertype: %s',pooltypes); end end end end function b= maxblock(a) b = max(max(a.data)); end ****************** Hàm thực lớp Fully connected ****************** function [output, linTrans] = nonlinear(input,W,b,type,norm) %sigmoid computes nonlinear transformation of the input % % Parameters: % input : matrix, inputDim * Num % W : matrix, OutputDim * inputDim % b : vector, OutputDim * % type : string, could be 'relu', 'sigmoid', 'tanh', 'softmax', % 'softsign' % % Returns: % output : matrix, OutputDim * Num if ~exist('type','var') type = 'sigmoid'; end linTrans = W * input + repmat(b,[1 size(input,2)]); switch type case 'sigmoid' output = / (1 + exp(- linTrans)); case 'relu' output = max(0, linTrans); case 'tanh' output = tanh(linTrans); case 'softmax' 100 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 % Attention: the softmax() in neural network toolbox can not be used here expLinTrans = exp(linTrans); output = expLinTrans / repmat(sum(expLinTrans),size(expLinTrans,1),1); case 'softsign' output = linTrans / (1 + abs(linTrans)); end if exist('norm','var') % Todo end end ************************* Hàm chỉnh đổi liệu ********************* function newTheta = thetaChange(oldTheta, meta, type, cnnConfig) %thetaChange change theta from the old form to the new form based on type % type - change type % 'stack2vec' % 'vec2stack' if ~exist('type', 'var') type = 'stack2vec'; end switch type case 'stack2vec' newTheta = zeros(meta.numTotalParams, 1); cur = 1; for i = : meta.numLayers if meta.numParams(i,1) ~= newTheta(cur:cur+meta.numParams(i,1)-1) = oldTheta{i}.W(:); cur = cur + meta.numParams(i,1); newTheta(cur:cur+meta.numParams(i,2)-1) = oldTheta{i}.b(:); cur = cur + meta.numParams(i,2); end end case 'vec2stack' newTheta = cell(meta.numLayers,1); for i = : meta.numLayers tempLayer = cnnConfig.layer{i}; switch tempLayer.type case 'input' newTheta{i}.W = []; newTheta{i}.b = []; row = tempLayer.dimension(1); 101 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 col = tempLayer.dimension(2); channel = tempLayer.dimension(3); case 'conv11' row = row + - tempLayer.filterDim(1); col = col + - tempLayer.filterDim(2); newTheta{i}.W = reshape(oldTheta(1:meta.numParams(i,1)),meta.paramsize{i}); oldTheta(1:meta.numParams(i,1))=[]; channel = tempLayer.numFilters; newTheta{i}.b = oldTheta(1:channel); oldTheta(1:channel) = []; case 'pool11' newTheta{i}.W = []; newTheta{i}.b = []; row = int32(row/tempLayer.poolDim(1)); col = int32(col/tempLayer.poolDim(2)); case 'conv22' row = row + - tempLayer.filterDim(1); col = col + - tempLayer.filterDim(2); newTheta{i}.W = reshape(oldTheta(1:meta.numParams(i,1)),meta.paramsize{i}); oldTheta(1:meta.numParams(i,1))=[]; channel = tempLayer.numFilters; newTheta{i}.b = oldTheta(1:channel); oldTheta(1:channel) = []; case 'pool22' newTheta{i}.W = []; newTheta{i}.b = []; row = int32(row/tempLayer.poolDim(1)); col = int32(col/tempLayer.poolDim(2)); case 'stack2line' newTheta{i}.W = []; newTheta{i}.b = []; row = row * col * channel * channel; col = 1; channel = 1; %dimension = row; case {'sigmoid','tanh','relu','softmax','softsign'} % initialisation of dnn method newTheta{i}.W = reshape(oldTheta(1:meta.numParams(i,1)),meta.paramsize{i}); oldTheta(1:meta.numParams(i,1)) = []; dimension = tempLayer.dimension; newTheta{i}.b = oldTheta(1:dimension); oldTheta(1:dimension) = []; end end 102 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 assert(isempty(oldTheta), 'Error: oldTheta is not empty!\n'); end end **********************Giao diện trực tuyến GUI ****************** function varargout = nhandanganh(varargin) % NHANDANGANH MATLAB code for nhandanganh.fig % NHANDANGANH, by itself, creates a new NHANDANGANH or raises the existing % singleton* % % H = NHANDANGANH returns the handle to a new NHANDANGANH or the handle to % the existing singleton* % % NHANDANGANH('CALLBACK',hObject,eventData,handles, ) calls the local % function named CALLBACK in NHANDANGANH.M with the given input arguments % % NHANDANGANH('Property','Value', ) creates a new NHANDANGANH or raises the % existing singleton* Starting from the left, property value pairs are % applied to the GUI before nhandanganh_OpeningFcn gets called An % unrecognized property name or invalid value makes property application % stop All inputs are passed to nhandanganh_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 nhandanganh % Last Modified by GUIDE v2.5 23-Jul-2017 00:45:44 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, 'gui_Singleton', gui_Singleton, 'gui_OpeningFcn', @nhandanganh_OpeningFcn, 'gui_OutputFcn', @nhandanganh_OutputFcn, 'gui_LayoutFcn', [] , 103 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 '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 nhandanganh is made visible function nhandanganh_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 nhandanganh (see VARARGIN) % Choose default command line output for nhandanganh handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes nhandanganh wait for user response (see UIRESUME) % uiwait(handles.figure1); % - Outputs from this function are returned to the command line function varargout = nhandanganh_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; % - Executes on button press in nhapanh function nhapanh_Callback(hObject, eventdata, handles) % hObject handle to nhapanh (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) 104 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 [tenanh, duongdan] = uigetfile ( {'*.jpg'}); noi = strcat(duongdan,tenanh); anhnhandang = imread(noi); imshow(anhnhandang); set(handles.luudl,'string',noi); % - Executes on button press in nhandang function nhandang_Callback(hObject, eventdata, handles) % hObject handle to nhandang (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % [tenanh, duongdan] = uigetfile ( % {'*.jpg'}); % noi = strcat(duongdan,tenanh); % anhnhandang = imread(noi); % imshow(anhnhandang); load('ghiam.mat'); noi = get(handles.luudl,'string'); anhnhandang = imread(noi); load('D:\matlab\bin\Demo\nhandangbangdeep.mat'); d = cnnConfig.layer{1}.dimension; a = anhnhandang; b =imresize ( a,[32 32]); images = b(:,:,1); labels = 0; theta = thetaChange(opttheta,meta,'vec2stack',cnnConfig); numLayers = size(theta, 1); temp = cell(numLayers, 1); grad = cell(numLayers, 1); temp{1}.after = images; for l = : numLayers tempLayer = cnnConfig.layer{l}; tempTheta = theta{l}; switch tempLayer.type case 'conv11' [temp{l}.after, temp{l}.linTrans] = cnnConvolve(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.nonLinearType, tempLayer.conMatrix); case 'pool11' [temp{l}.after, temp{l}.weights] = cnnPool(tempLayer.poolDim, temp{l1}.after, tempLayer.poolType); case 'conv22' 105 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 [temp{l}.after, temp{l}.linTrans] = cnnConvolve(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.nonLinearType, tempLayer.conMatrix); case 'pool22' [temp{l}.after, temp{l}.weights] = cnnPool(tempLayer.poolDim, temp{l1}.after, tempLayer.poolType); case 'stack2line' temp{l}.after = reshape(temp{l-1}.after, [],1); case {'sigmoid','tanh','relu','softmax'} temp{l}.after = nonlinear(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.type); case 'softsign' [temp{l}.after, temp{l}.linTrans] = nonlinear(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.type); end % assert(isequal(size(temp{l}.after),[layersizes{l} numImages]),'layersize not match at layer %d\n',l); end [~,preds] = max(temp{numLayers}.after,[],1); switch preds case set(handles.text6,'string','Day la may bay'); sound(codmaybay,44100,16); case set(handles.text6,'string','Day la may anh'); sound(codmayanh,44100,16); case set(handles.text6,'string','Day la to tien'); sound(codtotien,44100,16); case set(handles.text6,'string','Day la dan piano'); sound(codpiano,44100,16); case set(handles.text6,'string','Day la tai nghe'); sound(codtainghe,44100,16); case set(handles.text6,'string','Day la laptop'); sound(codlaptop,44100,16); case set(handles.text6,'string','Day la xe moto'); sound(codmoto,44100,16); case set(handles.text6,'string','Day la khau sung'); sound(codsung,44100,16); case set(handles.text6,'string','Day la trai bong'); 106 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 sound(codbong,44100,16); case 10 set(handles.text6,'string','Day la bong hoa'); sound(codhoa,44100,16); end % - Executes during object creation, after setting all properties function figure1_CreateFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % - Executes on button press in pushbutton4 function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) load('ghiam.mat'); noi = get(handles.luudl,'string'); anhnhandang = imread(noi); load('D:\matlab\bin\Demo\nhandangbangtruyenthong.mat'); d = cnnConfig.layer{1}.dimension; a = anhnhandang; b =imresize ( a,[32 32]); images = b(:,:,1); labels = 0; theta = thetaChange1(opttheta,meta,'vec2stack',cnnConfig); numLayers = size(theta, 1); temp = cell(numLayers, 1); grad = cell(numLayers, 1); temp{1}.after = images; for l = : numLayers tempLayer = cnnConfig.layer{l}; tempTheta = theta{l}; switch tempLayer.type case 'conv' [temp{l}.after, temp{l}.linTrans] = cnnConvolve(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.nonLinearType, tempLayer.conMatrix); case 'pool' [temp{l}.after, temp{l}.weights] = cnnPool(tempLayer.poolDim, temp{l1}.after, tempLayer.poolType); 107 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 case 'stack2line' temp{l}.after = reshape(temp{l-1}.after, [],1); case {'sigmoid','tanh','relu','softmax'} temp{l}.after = nonlinear(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.type); case 'softsign' [temp{l}.after, temp{l}.linTrans] = nonlinear(temp{l-1}.after, tempTheta.W, tempTheta.b, tempLayer.type); end end [~,preds] = max(temp{numLayers}.after,[],1); switch preds case set(handles.text12,'string','Day la may bay'); sound(codmaybay,44100,16); case set(handles.text12,'string','Day la may anh'); sound(codmayanh,44100,16); case set(handles.text12,'string','Day la to tien'); sound(codtotien,44100,16); case set(handles.text12,'string','Day la dan piano'); sound(codpiano,44100,16); case set(handles.text12,'string','Day la tai nghe'); sound(codtainghe,44100,16); case set(handles.text12,'string','Day la laptop'); sound(codlaptop,44100,16); case set(handles.text12,'string','Day la xe moto'); sound(codmoto,44100,16); case set(handles.text12,'string','Day la khau sung'); sound(codsung,44100,16); case set(handles.text12,'string','Day la trai bong'); sound(codbong,44100,16); case 10 set(handles.text12,'string','Day la bong hoa'); sound(codhoa,44100,16); end 108 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 109 Đồ án tốt nghiệp - Phạm Đức Đại - 13151020 TÀI LIỆU THAM KHẢO [1] GidHub.Inc [Ú] [2] https://tiendv.wordpress.com/2016/12/25/convolutional-neuralnetworks/ [3] http://bis.net.vn/forums/t/482.aspx [4] https://ongxuanhong.wordpress.com/2015/12/29/convolutional-neuralnetworks-la-gi/#comment-838 [5] http://neuralnetworksanddeeplearning.com/chap3.html [6] https://techtalk.vn/ [7] Luận văn thạc sỹ Lê Thị Thu Hằng Trường đại học Công nghệ (đại học quốc gia Hà Nội) [8] http://nhiethuyettre.me/mang-no-ron-nhan-tao-truyen-thangfeedforward-neural-network/ [9] https://www.analyticsvidhya.com/ 110 S K L 0

Ngày đăng: 25/09/2023, 15:00

Tài liệu cùng người dùng

Tài liệu liên quan