基于CNN卷积神经网络动物识别系统(GUI界面)【源码24期】
一、项目简介
本系统基于MATLAB平台,结合卷积神经网络(CNN)与GUI界面,实现对猫、狗、猪等三类动物的图像识别。系统包含训练和识别两大模块:训练模块使用自定义CNN(含卷积、池化、全连接层,输出3类)对图像提取特征,按8:2划分训练集与测试集;GUI模块支持图像选取、模型载入、单张实时识别(结果以弹窗显示)及测试集总体准确率评估,交互直观。
二、部分源码
function pushbutton1_Callback(hObject, eventdata, handles) % 选取图像
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[fn,pn,~]=uigetfile('*.bmp','请选择所要识别的图像');
I = imread([pn fn]);
axes(handles.axes1);
imshow(I,[]);
title('所选图像');
handles.I = I;
guidata(gcbo,handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) % 进行识别
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load("CNNnet.mat");
y_pred = classify(CNNnet,handles.I);
% disp(y_pred);
%set(handles.edit1,'string',y_pred);
set(handles.edit1,'String',y_pred);
result=strcat('动物种类:',string(y_pred),'');
msgbox(result,'识别结果','warn')
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles) % 显示整个测试集的结果
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 加载数据
allImages = imageDatastore('dbx', ...
'IncludeSubfolders' ,true, ...
'LabelSource' , 'foldernames' );% 图像加载为图像数据存储
% imageDatastore函数会根据文件夹名称自动标记图像
% 划分训练集(80%)和测试集(20%)
[imgsTrain,imgsTest] = splitEachLabel(allImages,0.8,'randomized');
load("CNNnet.mat");
y_pred = classify(CNNnet,imgsTest); % 使用训练好的网络测试
accuracy = mean(y_pred == imgsTest.Labels);% 计算准确率
set(handles.text2,'string',['总体准确率: ',num2str(100*accuracy),'%'],'FontSize',12);
三、运行结果



四、总结
测试集总体准确率达88.89%,验证了CNN在动物分类任务中的有效性。系统操作简便,具备实用与教学价值。但网络结构较浅,类别数仅3类,泛化能力有限;支持BMP格式输入。后续可通过增加数据量、引入迁移学习或数据增强提升鲁棒性,并扩展支持更多动物类别和图像格式。
五、代码获取
接matlab程序定制和论文设计,方向如下:
图像处理|语音识别|图像识别|目标检测|深度学习|神经网络|强化学习|机器学习|通信系统|信号处理|时频分析|小波降噪|路径规划|优化算法|智能算法|数据处理|数学建模|文献复现|算法复现|模型复现等
程序包运行成功,零基础的可以远程帮你运行,赠送安装包。
作为初学者,遇见不会的问题是非常正常的事情,具体代码仿真可通过主页 私信博主。
更多推荐



所有评论(0)