m基于深度学习网络的美食识别系统matlab仿真,带GUI界面

126 阅读4分钟

1.算法仿真效果

matlab2022a仿真结果如下:

1.png

2.jpeg

3.jpeg

4.jpeg

5.jpeg

6.jpeg

7.jpeg

 

2.算法涉及理论知识概要

       基于深度学习网络的美食识别系统是一个复杂的机器视觉应用,它结合了深度学习、图像处理、模式识别等多个领域的知识。GoogleNet是一种深度卷积神经网络(CNN),它由多个卷积层、池化层和全连接层组成。该模型可以自动学习和提取图像特征,从而实现对图像中目标物体的检测和分类。

 

      GoogleNet算法的核心思想是采用一种称为“Inception”的网络结构,通过在多个尺度上提取图像特征,从而实现对目标物体的检测和分类。在疲劳检测中,GoogleNet模型首先对驾驶员面部图像进行预处理,然后通过多个卷积层和池化层提取面部特征,最后使用全连接层进行分类输出。

 

GoogleNet模型的数学公式主要包括以下几个部分:

 

(1)卷积层计算:对于每个卷积层,计算输入图像与卷积核的卷积结果。公式如下:

 

         C = Conv2D(F, I) (3)

 

其中,C表示卷积结果,F表示卷积核,I表示输入图像。

 

(2)池化层计算:对于每个池化层,将输入特征图进行下采样,从而降低特征图的维度。公式如下:

 

      P = MaxPooling2D(C) (4)

 

其中,P表示池化结果,C表示输入特征图。

 

(3)全连接层计算:对于每个全连接层,将输入特征与权重进行线性组合,然后添加偏置项,并通过激活函数进行非线性变换。公式如下:

 

Z = W * P + B (5)

 

其中,Z表示全连接层的输出结果,W表示权重矩阵,P表示输入特征图,B表示偏置向量。

 

(4)分类输出:最后,将全连接层的输出结果进行softmax归一化,得到每个类别的概率值。公式如下:

 

y = Softmax(Z) (6)

 

其中,y表示每个类别的概率值,Z表示全连接层的输出结果。

 

3.MATLAB核心程序 `function edit5_Callback(hObject, eventdata, handles)

% hObject    handle to edit5 (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 edit5 as text

%        str2double(get(hObject,'String')) returns contents of edit5 as a double

 

 

% --- Executes during object creation, after setting all properties.

function edit5_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit5 (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

 

 

 

function edit6_Callback(hObject, eventdata, handles)

% hObject    handle to edit6 (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 edit6 as text

%        str2double(get(hObject,'String')) returns contents of edit6 as a double

 

 

% --- Executes during object creation, after setting all properties.

function edit6_CreateFcn(hObject, eventdata, handles)

% hObject    handle to edit6 (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 pushbutton6.

function pushbutton6_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton6 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

 

 

Name1   = get(handles.edit7, 'String');

NEpochs = str2num(get(handles.edit8, 'String'));

NMB     = str2num(get(handles.edit9, 'String'));

LR      = str2num(get(handles.edit10, 'String'));

Rate    = str2num(get(handles.edit11, 'String'));

 

 

% 使用 imageDatastore 加载图像数据集

Dataset = imageDatastore(Name1, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');

% 将数据集分割为训练集、验证集和测试集

[Training_Dataset, Validation_Dataset, Testing_Dataset] = splitEachLabel(Dataset, Rate, (1-Rate)/2, (1-Rate)/2);

% 加载预训练的 GoogleNet 网络

load googlenet.mat

 

 

% 获取输入层的大小

Input_Layer_Size = net.Layers(1).InputSize(1:2);

 

% 将图像数据集调整为预训练网络的输入尺寸

Resized_Training_Dataset   = augmentedImageDatastore(Input_Layer_Size ,Training_Dataset);

Resized_Validation_Dataset = augmentedImageDatastore(Input_Layer_Size ,Validation_Dataset);

Resized_Testing_Dataset    = augmentedImageDatastore(Input_Layer_Size ,Testing_Dataset);

 

 

 

 

 

% 获取特征学习层和分类器层的名称

Feature_Learner   = net.Layers(142).Name;

Output_Classifier = net.Layers(144).Name;

% 计算数据集的类别数目

Number_of_Classes = numel(categories(Training_Dataset.Labels));

% 创建新的全连接特征学习层

New_Feature_Learner = fullyConnectedLayer(Number_of_Classes, ...

    'Name', 'Coal Feature Learner', ...

    'WeightLearnRateFactor', 10, ...

    'BiasLearnRateFactor', 10);

% 创建新的分类器层

New_Classifier_Layer = classificationLayer('Name', 'Coal Classifier');

% 获取完整网络架构

Network_Architecture = layerGraph(net);

% 替换网络中的特征学习层和分类器层

New_Network = replaceLayer(Network_Architecture, Feature_Learner, New_Feature_Learner);

New_Network = replaceLayer(New_Network, Output_Classifier, New_Classifier_Layer);`