m Matlab simulation of smoke detection system based on Faster R-CNN network, with GUI operation interface

Table of contents

1. Algorithm simulation effect

2. Algorithms involve an overview of theoretical knowledge

3. MATLAB core program

4. Complete algorithm code file


1. Algorithm simulation effect

The matlab2022a simulation results are as follows:

2. Algorithms involve an overview of theoretical knowledge

       After the accumulation of R-CNN and Fast RCNN, Ross B. Girshick proposed a new Faster RCNN in 2016. Structurally, Faster RCNN has integrated feature extraction (feature extraction), proposal extraction, bounding box regression (rect refine), The classification is integrated in a network, which greatly improves the overall performance, especially in the detection speed.       

Faster RCNN can actually be divided into 4 main contents:

  1. Conv layers. As a CNN network target detection method, Faster RCNN first uses a set of basic conv+relu+pooling layers to extract the feature maps of the image. The feature maps are shared for subsequent RPN layers and fully connected layers.
  2. Region Proposal Networks. The RPN network is used to generate region proposals. This layer judges whether the anchors are positive or negative through softmax, and then uses the bounding box regression to correct the anchors to obtain accurate proposals.
  3. Roi Pooling. This layer collects the input feature maps and proposals, extracts the proposal feature maps after synthesizing these information, and sends them to the subsequent fully connected layer to determine the target category.
  4. Classification. Use the proposal feature maps to calculate the category of the proposal, and at the same time bounding box regression again to obtain the final precise position of the detection frame.

Therefore, this article uses the above four contents as an entry point to introduce the Faster R-CNN network.

        The smoke detection system based on Faster R-CNN (Region Convolutional Neural Network) is a system that uses a deep learning model to automatically detect the presence of smoke in an image. When performing simulation implementation in Matlab, the following steps are required:

1. Data preparation: Collect smoke and non-smoke image data and label them as positive and negative samples. This data will be used to train and evaluate the model.

2. Install Deep Learning Toolbox: Make sure you have installed Matlab's Deep Learning Toolbox, which provides many deep learning models and functions.

3. Download the pre-trained model: In Faster R-CNN, a pre-trained model on a large-scale image dataset is usually used. You can download the Faster R-CNN model pre-trained on the COCO dataset, and then fine-tune it for the smoke detection task.

4. Build data storage: use Matlab's data storage to load and manage training and testing data. You need to organize the image data and corresponding annotations into the format required by the data store.

5. Build Faster R-CNN network: In Matlab, you can use Deep Learning Toolbox to build Faster R-CNN network. You can use a pre-trained ResNet or other backbone network, and then add the detection head of Faster R-CNN.

6. Training model: Use the prepared data memory and the constructed Faster R-CNN network to train the model. You need to define training options such as learning rate, batch size, and number of training iterations.

7. Evaluate the model: After training is complete, use the test dataset to evaluate the model. Calculate metrics such as precision, recall, and F1 score of the model.

8. Do smoke detection simulation: Load the trained model and apply it to the image that needs to be smoke detected. The model returns the coordinates and confidence of detected smoke regions.

3. MATLAB core program

...........................................................................
% 预处理训练数据
data           = read(trainingData);
In_layer_Size  = [224 224 3];

% 估计锚框
pre_train_data = transform(trainingData, @(data)preprocessData(data,In_layer_Size));
NAnchor        = 3;
NBoxes         = estimateAnchorBoxes(pre_train_data,NAnchor);
numClasses     = width(vehicleDataset)-1;
% 创建Faster R-CNN网络
lgraph         = fasterRCNNLayers(In_layer_Size,numClasses,NBoxes,Initial_nn,featureLayer);
% 数据增强
aug_train_data = transform(trainingData,@augmentData);
augmentedData  = cell(4,1);
 
% 预处理数据并显示标注
trainingData   = transform(aug_train_data,@(data)preprocessData(data,In_layer_Size));
validationData = transform(validationData,@(data)preprocessData(data,In_layer_Size));
data           = read(trainingData);


I              = data{1};
bbox           = data{2};
 
% 设置训练参数
options = trainingOptions('sgdm',...
    'MaxEpochs',240,...
    'MiniBatchSize',2,...
    'InitialLearnRate',3e-5,...
    'CheckpointPath',tempdir,...
    'ValidationData',validationData);
% 训练Faster R-CNN目标检测器
[detector, info] = trainFasterRCNNObjectDetector(trainingData,lgraph,options,'NegativeOverlapRange',[0 0.3],'PositiveOverlapRange',[0.3 1]);
0Y_002m

4. Complete algorithm code file

V

Guess you like

Origin blog.csdn.net/hlayumi1234567/article/details/132570642