A method and system for detecting illegal buildings in urban and rural areas

By improving the RetinaNet model, adding an attention module and a parallel dilated convolution module, and replacing the activation function with Gelu, the problem of low detection accuracy of illegal buildings and missed detection of small targets in the urban-rural fringe area has been solved, achieving high accuracy and low parameter quantity. detection effect.

CN118015469BActive Publication Date: 2024-09-10CHONGQING UNIVERSITY OF SCIENCE AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410276667.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-12
Publication Date
2024-09-10
Estimated Expiration
2044-03-12

AI Technical Summary

Technical Problem

Existing detection methods for illegal buildings in urban-rural fringe areas, such as satellite remote sensing and drone aerial photography, have problems such as low detection accuracy, poor timeliness and being affected by weather factors. In particular, the detection of small targets is more serious and the phenomenon of missed detection is more serious.

Method used

Improve the RetinaNet model by adding attention modules to the Stage 1 and Stage 2 stages of the feature extraction network ResNet50, and adding a parallel atrous convolution module to the Stage 3 stage. Combined with the Gelu activation function, an illegal building detection model is constructed to improve detection accuracy.

Benefits of technology

It improves the average accuracy of urban and rural illegal building detection to 93.28%, reduces the number of parameters, reduces the missed detection rate of small targets, and enhances the algorithm's ability to perceive complex scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118015469B
    Figure CN118015469B
Patent Text Reader

Abstract

The present invention relates to the field of artificial intelligence technology, and specifically discloses a method and system for detecting illegal buildings in urban and rural areas. Aiming at the problem that the RetinaNet algorithm still misses small targets to be detected at the edge of the image in the data set, the method and system add an attention module to the Stage1 and Stage2 modules (stages) of the feature extraction network ResNet50, and add a parallel hole convolution module to the Stage3 module to perform multi-scale feature fusion to obtain global feature information, thereby improving the detection accuracy of the algorithm for illegal buildings in urban and rural areas; in order to avoid the problem of gradient explosion during training, the activation function in the network is replaced by Gelu. The feasibility and effectiveness of the method and system have been verified by experiments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and system for detecting illegal buildings in urban and rural areas. Background Art

[0002] The complex geographical environment of the urban-rural fringe has led to a variety of architectural forms. The buildings are mainly small-property houses, which are distributed in a relatively concentrated manner, resulting in a variety of illegal buildings that are difficult to detect. Building a house is a continuous process. If it can be discovered and stopped in time during the construction process, it can reduce conflicts and reduce citizens' property losses. In addition to relying on public reports and on-site inspections by management personnel, the investigation of illegal buildings also includes satellite remote sensing technology combined with deep learning, drone aerial photography technology combined with deep learning, and fixed-point monitoring video combined with deep learning.

[0003] Satellite remote sensing image technology has a long monitoring cycle, poor timeliness, is restricted by weather factors, and has poor quality of remote sensing image data, resulting in low detection accuracy. With the development of drone aerial photography technology, urban illegal building detection based on drone aerial photography technology has gradually become mainstream. The drone aerial photography method requires a lot of manpower and material resources, and is also restricted by weather and cannot monitor specific areas in real time. Compared with satellite remote sensing technology and drone aerial photography technology, the fixed-point monitoring video method is less affected by weather factors, has low monitoring costs, and can monitor in real time, making it more suitable for real-time monitoring of illegal buildings in urban and rural areas.

[0004] RetinaNet is a one-stage detector designed by Tsung-Yi Lin in 2017 to verify the effectiveness of Focal Loss. The RetinaNet network structure is shown in the figure below: Figure 1 As shown. Figure 1 It can be seen that the RetinaNet algorithm mainly includes two parts: the backbone network and the classification and regression subnetworks. The backbone network includes the ResNet feature extraction network and the FPN (Feature Pyramid Network, including the five-layer structure of P1 to P5) feature fusion network. The ResNet feature extraction network generally uses ResNet50 or ResNet101. C1 to C5 are the output feature layers of each stage of the feature extraction network. The output features of C3 to C5 are extracted by the FPN feature fusion network to achieve multi-scale features. The feature map is then input into the predictor part for category judgment and position regression. The feature map size output by the classification subnetwork is W×H×KA, where K is the number of predicted categories, A=9 is the number of prediction boxes generated for each feature point, and W and H are the width and height of the input image, respectively.

[0005] The RetinaNet algorithm dynamically adjusts parameters to make the model pay more attention to samples that are difficult to classify, thereby improving the detection accuracy of minority samples in urban and rural illegal buildings. However, there is still a phenomenon of missed detection of small targets on the edge of images in the dataset. Summary of the invention

[0006] The present invention provides a method and system for detecting illegal buildings in urban-rural fringe areas, and solves the technical problem of how to improve the detection accuracy of illegal buildings in urban-rural fringe areas.

[0007] In order to solve the above technical problems, the present invention provides a method for detecting illegal buildings in urban-rural fringe areas, comprising the steps of:

[0008] S1. Improve the RetinaNet model to build an illegal building detection model;

[0009] The illegal building detection model includes a backbone network and a classification regression sub-network, wherein the backbone network includes a ResNet feature extraction network and a feature fusion network; the ResNet feature extraction network includes five modules of Stage0, Stage1, Stage2, Stage3, and Stage4 connected in sequence, and the output features of the modules of Stage2, Stage3, and Stage4 are input into the feature fusion network for multi-scale feature fusion, and the obtained fusion feature map is input into the classification regression sub-network for category judgment and position regression;

[0010] The Stage0 module preprocesses the input image and then inputs it into the Stage1 module after passing through the maximum pooling layer; the Stage1 module includes 1 first BlockA module, N1 BlockB modules and 1 attention module, N1≥2; the Stage2 module includes 1 second BlockA module, N2 BlockB modules and 1 attention module, N2≥2; the Stage3 module includes 1 second BlockA module, N3 BlockB modules and 1 parallel void convolution module, N3≥2; the Stage4 module includes 1 second BlockA module and N4 BlockB modules, N4≥2;

[0011] The first BlockA module and the second BlockA module adopt the structure of BlockA modules with different convolution step sizes, and the BlockA module downsamples the input feature map according to the convolution step size to achieve feature map scale transformation; the convolution step size of the BlockB module is 1, and the width and height of the input feature map are not changed, only the number of channels is changed;

[0012] The attention module encodes the position information of the retained features in the horizontal direction and the vertical direction respectively;

[0013] The parallel dilated convolution module uses multiple parallel dilated convolution modules to perform multi-scale feature extraction;

[0014] S2, build a data set;

[0015] S3, using the data set to train and verify the illegal building detection model;

[0016] S4. Deploy the trained illegal building detection model.

[0017] Furthermore, the operations performed by the parallel atrous convolution module are:

[0018] First, the C×H×W input feature Input is subjected to a 1×1 convolution to change the number of input feature channels, and then normalized by the BN layer to obtain feature I. At the same time, the first-scale feature A is obtained by normalizing by the BN layer and adding a nonlinear activation function. At the same time, the second-scale feature B is obtained by normalizing by the BN layer and adding a nonlinear activation function. At the same time, the third-scale feature C is obtained by normalizing by the BN layer and adding a nonlinear activation function.

[0019] Then, the first dilated convolution module is used to perform dilated convolution on feature A, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature D; the second dilated convolution module is used to perform dilated convolution on feature B, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature E; the third dilated convolution module is used to perform dilated convolution on feature C, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature F;

[0020] Then, the multi-scale features D, E, and F are concat-operated in the depth direction to obtain the multi-scale fusion feature G;

[0021] Finally, the multi-scale fusion feature G is added to the feature I, and then passes through a nonlinear activation function to obtain the C×H×W output feature Output.

[0022] Furthermore, the convolution kernel sizes of the first dilated convolution module, the second dilated convolution module and the third dilated convolution module are all 3×3, the step sizes are all 1, and the padding values ​​are 1, 2, and 5 respectively.

[0023] Furthermore, the operation performed by the attention module is:

[0024] First, the C×H×W input features are averagely pooled in the horizontal and vertical directions to obtain C×H×1 and C×1×W output features, respectively. C, H, and W represent the number of channels, height, and width, respectively.

[0025] Then, the output features of the horizontal direction C×H×1 are transformed in dimension and concat operation is performed with the output features of the vertical direction C×1×W to obtain the merged features of C×1×(W+H);

[0026] Then, the merged features of C×1×(W+H) are convolved, normalized by the BN layer, and subjected to a nonlinear activation function to obtain the output features of C / r×1×(W+H), where r is the reduction rate.

[0027] Then, convolution is used along the spatial dimension to transform the output features of C / r×1×(W+H) into C×H×1 and C×1×W, and then the sigmoid activation function is used to obtain the corresponding attention weight g h , g w ;

[0028] Finally, the C×H×W input feature Input and the attention weight g h , g w Multiply them together to get the output feature Output of C×H×W.

[0029] Furthermore, first, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer to obtain a first intermediate feature. At the same time, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of S1, and then normalized by a BN layer and a nonlinear activation function is added to obtain a second intermediate feature.

[0030] Then, the first intermediate feature and the second intermediate feature are added together, and then passed through a nonlinear activation function to obtain the output feature Output.

[0031] Furthermore, in the first BlockA module, the step length S1 is set to 1; and in the second BlockA module, the step length S2 is set to 2.

[0032] Furthermore, the operations performed by the BlockB module are:

[0033] First, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 3×3 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer to obtain the first intermediate feature.

[0034] Then, the first intermediate feature is added to the input feature Input, and then passed through a nonlinear activation function to obtain the output feature Output.

[0035] Furthermore, the nonlinear activation functions used in the ResNet feature extraction network are all Gelu activation functions; N1=2, N2=3, N3=5, N4=2.

[0036] Furthermore, step S2 specifically includes the steps of:

[0037] S21, obtain the real-time images of urban and rural illegal buildings taken by high-definition surveillance cameras, and crop each real-time image into multiple images of the same size according to a fixed cropping position, and remove the images that do not contain the detection target information to construct an urban and rural illegal building image dataset;

[0038] S22, resizing the image downloaded from the network to be consistent with the image cropped in step S1 and adding it to the urban and rural illegal building image dataset to obtain the original dataset;

[0039] S23. Expand and annotate the original data set to obtain a data set containing 9 types of features: bricks, steel bars, people, color steel buildings, house frames, brick structures, breeding farms, adobe houses, and abandoned houses.

[0040] The present invention also provides an illegal building detection system in urban-rural fringe areas, the key of which is that it includes an illegal building detection model construction unit, a data set construction unit, an illegal building detection model training unit, and an illegal building detection model application unit, which are respectively used to execute steps S1, S2, S3, and S4 described in the above method.

[0041] The present invention provides a method and system for detecting illegal buildings in urban and rural areas. In order to enhance the algorithm's perception of small targets in complex scenes, an attention module is added to the Stage1 and Stage2 modules (stages) of the feature extraction network ResNet50, and a parallel hole convolution module is added to the Stage3 module to perform multi-scale feature fusion to obtain global feature information, thereby improving the algorithm's detection accuracy for illegal buildings in urban and rural areas. In order to avoid the gradient explosion problem during training, the activation function in the network is replaced with Gelu. Experiments have shown that the average accuracy of the improved illegal building detection model in detecting illegal buildings in urban and rural areas reaches 93.28%, and the number of parameters is reduced by 16247552, which verifies the feasibility and effectiveness of the method and system. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a structural diagram of the RetinaNet network provided by the background technology of the present invention;

[0043] Figure 2 is a structural diagram of an improved ResNet50 network provided in an embodiment of the present invention;

[0044] Figure 3 is a structural diagram of an attention module provided by an embodiment of the present invention;

[0045] Figure 4 is a structural diagram of a parallel atrous convolution module provided in an embodiment of the present invention;

[0046] Figure 5 is a structural diagram of the BlockA module provided in an embodiment of the present invention;

[0047] Figure 6 is a structural diagram of a BlockB module provided in an embodiment of the present invention;

[0048] Figure 7 is an example diagram of image cutting provided by an embodiment of the present invention;

[0049] Figure 8 is an example diagram of 9 categories of images in the data set provided by the embodiment of the present invention;

[0050] Fig. 9 It is a cluster diagram of illegal building marking frames in urban and rural fringe areas provided by an embodiment of the present invention;

[0051] Fig.10 It is a comparison diagram of the training loss convergence effect using activation functions Relu and Gelu provided in an embodiment of the present invention;

[0052] Fig.11 This is a comparison chart of model mAP during the training process provided by an embodiment of the present invention;

[0053] Fig.12 is a comparison diagram of detection effects of the original RetinaNet model and the improved RetinaNet model provided by an embodiment of the present invention on the first example image;

[0054] Fig.13 is a comparison diagram of detection effects of the original RetinaNet model and the improved RetinaNet model provided by an embodiment of the present invention on the second example image;

[0055] Fig.14 is a comparison diagram of detection effects of the original RetinaNet model and the improved RetinaNet model provided by an embodiment of the present invention on the third example image;

[0056] Fig.15 It is a comparison diagram of the detection effects of the original RetinaNet model and the improved RetinaNet model provided by an embodiment of the present invention on the fourth example image. DETAILED DESCRIPTION

[0057] The following specifically illustrates the implementation mode of the present invention in conjunction with the accompanying drawings. The embodiments are provided for illustrative purposes only and cannot be understood as limiting the present invention. The accompanying drawings are provided for reference and illustration only and do not constitute a limitation on the scope of patent protection of the present invention, because many changes can be made to the present invention without departing from the spirit and scope of the present invention.

[0058] The RetinaNet algorithm uses Focal Loss to adjust the weight of classified samples, making difficult-to-classify samples more prominent in the loss function, thereby better handling the situation of class imbalance. The calculation method of Focal Loss is shown in the following formula:

[0059] FL(p t )=-α t (1-p t ) γ ×log(p t ) (1)

[0060] In formula (1), α t ∈[0,1] is the weighting factor, (1-p t ) γ is the modulation factor, p t is the predicted probability of the model for the sample, and γ is the focusing parameter (γ∈[0,5]). t The closer the value is to 1, the more accurate the classification is, and the smaller the corresponding loss value is. t The smaller the value, the more difficult it is to classify the sample. For difficult-to-classify samples, by increasing γ, the loss of difficult-to-classify samples is increased, so that the model pays more attention to difficult-to-classify samples and improves model performance.

[0061] The RetinaNet algorithm dynamically adjusts parameters to make the model pay more attention to samples that are difficult to classify, thereby improving the detection accuracy of minority samples in urban and rural illegal buildings. However, there is still a phenomenon of missed detection of small targets to be detected at the edge of the image in the data set. To address this problem, an embodiment of the present invention provides a method for detecting illegal buildings in urban and rural areas, including the following steps:

[0062] S1. Improve the RetinaNet model to build an illegal building detection model;

[0063] S2, build a data set;

[0064] S3, using the data set to train and verify the illegal building detection model;

[0065] S4. Deploy the trained illegal building detection model.

[0066] (1) Step S1

[0067] like Figure 1 As shown in Figure 2, the structure of the illegal building detection model obtained by improving the RetinaNet model is as follows: Figure 2 As shown in the figure, the illegal building detection model includes a backbone network and a classification regression sub-network. The backbone network includes a ResNet feature extraction network and a feature fusion network. The ResNet feature extraction network includes five modules (or five stages) connected sequentially, namely Stage0, Stage1, Stage2, Stage3, and Stage4. The output features of the Stage2, Stage3, and Stage4 modules are input into the feature fusion network for multi-scale feature fusion, and the fused feature map is input into the classification regression sub-network for category judgment and position regression.

[0068] This method adds an attention module in Stage 1 and Stage 2, and adds a parallel dilated convolution module in Stage 3 to improve the detection accuracy of the algorithm for illegal urban and rural buildings. Among them, Stage 0 mainly preprocesses the input image, and the output features are input to Stage 1 after passing through the maximum pooling layer. In addition to the attention module and parallel dilated convolution module added in this paper, Stage 1 to Stage 4 only contain one BlockA and several BlockB modules.

[0069] The Stage0 module preprocesses the input image (Input) (convolution with kernel size K of 7×7, step size s of 2, padding value of 3, BN layer normalization plus nonlinear activation function Gelu), and then inputs it into the Stage1 module after passing through the maximum pooling layer (MaxPooling, convolution kernel size of 3×3, step size of 2). The Stage1 module includes 1 first BlockA module, N1 BlockB modules and 1 attention module, N1≥2. The Stage2 module includes 1 second BlockA module, N2 BlockB modules and 1 attention module, N2≥2. The Stage3 module includes 1 second BlockA module, N3 BlockB modules and 1 parallel void convolution module, N3≥2. The Stage4 module includes 1 second BlockA module and N4 BlockB modules, N4≥2. In this embodiment, N1=2, N2=3, N3=5, N4=2. In addition, in the Stage 4 module, the feature map output by the last Block B module passes through the average pooling layer (AveragePooling) and the fully connected layer (FC) to obtain the final output feature.

[0070] The first BlockA module and the second BlockA module use the structure of BlockA modules with different convolution steps. In the Stage 1 stage, there is no need to change the size of the input feature map. The S1 step in BlockA is set to 1. In the Stage 2 to Stage 4 stages, the S1 step in BlockA is set to 2, and the width and height of the input feature are reduced to half of the original. BlockA and BlockB are two different residual structures. The BlockA residual block downsamples the input feature map according to the convolution step to achieve feature map scale transformation. The BlockB residual block has a convolution step of 1, which does not change the width and height of the input feature map but only changes the number of channels.

[0071] Combination Figure 1 As shown in the RetinaNet network structure diagram, the ResNet feature extraction network of the present invention is improved based on ResNet50. The output feature layers of each stage of Stage0 to Stage4 in the ResNet50 network structure can be visualized as C1 to C5 layers, among which C1 and C2 layers are the main shallow feature layers. In order to reduce the number of parameters of the algorithm, the RetinaNet algorithm performs multi-scale feature fusion from the C3 layer. The data set used in this article contains a large number of small targets to be detected. Because small targets account for a small proportion in the image and their features are not obvious, relevant semantic information is easily lost during the network training process, making it difficult for the model to accurately locate small targets. In order to improve the detection accuracy of the RetinaNet algorithm for small target illegal buildings, the present invention adds attention modules to the Stage1 and Stage2 stages of the feature extraction network ResNet50. The addition of attention modules in the Stage1 and Stage2 stages allows the network model to pay more attention to the shallow feature information of the C2 layer and enhance the algorithm's perception of small targets. In the Stage 3 stage, an additional layer of parallel dilated convolution module is added to perform multi-scale fusion of the output features of the attention module to obtain global context information and further improve the detection accuracy of the algorithm.

[0072] The network structure diagram of the attention module is as follows Figure 3 As shown. The attention module encodes the position information of the features in the horizontal direction (X) and the vertical direction (Y) respectively. The input features are averaged and pooled in the horizontal and vertical directions to obtain an output feature respectively. The horizontal output feature is dimensionally transformed and then concat-operated with the vertical output feature to merge the width and height features. The merged features are then convolved, normalized by the BN layer, and subjected to a nonlinear activation function (Gelu) to obtain the output features, whose dimensions are C / r×1×(W+H), where r is the reduction rate, which is used to reduce the complexity of the algorithm. In this paper, r=16 is set. Then, convolution is used along the spatial dimension to convert the input features back into C×H×1 and C×1×W, and the sigmoid activation function is used to obtain the corresponding attention weight g.h , g w . Input features and weights g h , g w Multiply them together to get the final output features.

[0073] The network structure of the parallel hole convolution module is as follows: Figure 4 As shown in the figure, the input features are subjected to 1×1 convolution to change the number of input feature channels, and are respectively subjected to BN layer standardization or BN layer standardization plus nonlinear activation function (Gelu) to obtain output features I, A, B, and C. Features A, B, and C are subjected to dilated convolution, BN layer standardization, and nonlinear activation function (Gelu) to obtain multi-scale output features D, E, and F. The multi-scale features D, E, and F are concat-operated in the depth direction to obtain the multi-scale fusion feature G, and the multi-scale fusion feature G is added to the feature I to obtain the final output feature Output.

[0074] Three parallel dilated convolution modules are used in the parallel dilated convolution module, with the convolution kernel size of 3×3, the step size of 1, and the padding values ​​of 1, 2, and 5. Compared with ordinary convolution, dilated convolution can expand the receptive field but will cause local information loss. To solve this problem, hybrid dilated convolution (HDC) is used to set the dilation rate R to 1, 2, and 5 respectively.

[0075] The network structure of BlockA module is as follows Figure 5 As shown, we can see that the operations performed by the BlockA module are:

[0076] First, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer to obtain the first intermediate feature. At the same time, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of S1, and then normalized by a BN layer and a nonlinear activation function is added to obtain the second intermediate feature.

[0077] Then, the first intermediate feature and the second intermediate feature are added together, and then passed through a nonlinear activation function to obtain the output feature Output.

[0078] Among them, in the first BlockA module (Stage1), the step size S1 is set to 1; in the second BlockA module (Stage2, Stage3, Stage4), the step size S2 is set to 2.

[0079] The network structure of BlockB module is as follows Figure 6As shown, we can see that the operations performed by the BlockB module are:

[0080] First, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 3×3 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer to obtain the first intermediate feature.

[0081] Then, the first intermediate feature is added to the input feature Input, and then passed through a nonlinear activation function to obtain the output feature Output.

[0082] (2) Step S2

[0083] Step S2 specifically includes the following steps:

[0084] S21, obtain the real-time images of urban and rural illegal buildings taken by high-definition surveillance cameras, and crop each real-time image into multiple images of the same size according to a fixed cropping position, and remove the images that do not contain the detection target information to construct an urban and rural illegal building image dataset;

[0085] S22, resizing the image downloaded from the network to be consistent with the image cropped in step S1 and adding it to the urban and rural illegal building image dataset to obtain the original dataset;

[0086] S23. Expand and annotate the original data set to obtain a data set containing 9 types of features: bricks, steel bars, people, color steel buildings, house frames, brick structures, breeding farms, adobe houses, and abandoned houses.

[0087] Since there is no public dataset of illegal buildings in rural areas, most of the experimental datasets used in this paper are real-time images taken by high-definition surveillance cameras installed on 16 signal towers in the surrounding area of ​​a city, and some scene pictures are high-altitude images downloaded from the Internet. The size of the real-time collected images is 1920×1080. When training the network model, it is necessary to keep the input image size consistent. At the same time, in order to expand the proportion of related illegal building features in the image, each 1920×1080 image is cropped into 8 640×540 images according to fixed cropping points, and images that do not contain detection target information are removed to construct an urban and rural illegal building image dataset. The specific cropping method is as follows: Figure 7 As shown, cut into two rows and three columns to get 6 pictures, and then cut the 2 pictures in the center. Figure 7 In the figure, the text in the upper left corner indicates preset point 3, the text in the upper right corner indicates the timestamp: 2023-04-02 12:46:59, and the text in the lower left corner indicates the camera model: IP PTZ Camera.

[0088] The images downloaded from the Internet were resized to 640×540 and added to the urban and rural illegal building image dataset. The original dataset constructed contains 526 images of the detection target. In order to improve the accuracy of the algorithm, the dataset was expanded to 3156 images by translation, noise addition, random brightness adjustment, random rotation, and adding random points. The constructed dataset contains 9 types of features: ZK (brick), GJ (steel), Person (people), CGJZ (color steel building), FWKJ (house frame), ZTJG (brick structure), YZC (breeding farm), TPF (adobe house), and FQFW (abandoned house). The sample size of each type of data is shown in Table 1. Examples of various data samples in the dataset are shown in Table 1. Figure 8 shown.

[0089] Table 1 Dataset types and number of categories

[0090]

[0091] Cluster analysis of the annotation boxes of the urban and rural illegal building dataset shows that the urban and rural illegal building dataset contains a large number of small targets to be detected. Fig. 9 shown.

[0092] According to Table 1, the difference in the number of samples between categories in the urban and rural illegal building dataset is too large, that is, the dataset has a category imbalance problem. In deep learning, OHEM (online difficult sample mining) and the introduction of Focal Loss method are generally used to solve the problem of data category imbalance. OHEM dynamically selects difficult samples by calculating the loss of the region of interest of each image, so that the model pays more attention to difficult samples, thereby improving the performance of the model. OHEM can improve the sample imbalance problem, but there are also some problems such as increasing the complexity of calculation, resulting in slower model training speed; increasing the risk of model overfitting; the model pays more attention to difficult samples, ignoring some easy samples, resulting in worse overall model effect. Focal Loss solves the problem of data category imbalance from the perspective of sample classification difficulty. This paper adopts the Focal Loss method to solve the problem of data set category imbalance.

[0093] (3) Step S3

[0094] The relevant configuration of this experiment is shown in Table 2.

[0095] Table 2 Experimental environment configuration table

[0096]

[0097] This article uses the mean average accuracy (mAP) as the main evaluation indicator of the model, and the number of parameters as the auxiliary evaluation indicator of the model. The formula for the mean average accuracy (mAP) is as follows:

[0098]

[0099]

[0100]

[0101]

[0102] Where P is the precision, R is the recall, TP is the correctly classified samples, FP is the number of negative samples identified as positive samples, FN is the number of positive samples identified as negative samples, AP is the average precision, which is the area of ​​the curve with the precision P as the Y-axis and the recall R as the X-axis, n is the sample type, and mAP is the average AP value of the 9 types of illegal buildings.

[0103] This experiment sets the training rounds to 300 times, the input image size is 640×540, the number of images processed in each batch is 6, the initial learning rate is 0.0001, the Adam optimizer is used to optimize the network parameters, the momentum parameter is set to 0.9, the learning rate decay strategy adopts the cos descent adjustment strategy, and the weight parameters are saved every 10 rounds of training. In the ResNet50 network, the original model uses the Relu activation function, and its formula is as follows:

[0104] Relu(x)=max(0,X) (6)

[0105] The improved ResNet50 network model has a deeper number of network layers. During the experiment, it was found that when the network model was trained using the Relu activation function, the network model occasionally had a gradient explosion phenomenon after 100 iterations, resulting in model training failure. To address this problem, the activation function in the model was replaced with Gelu (Gaussian error linear unit activation function), and its formula is as follows:

[0106]

[0107] Compared with the Relu activation function, the Gelu activation function introduces nonlinear transformation, which can prevent the weight parameters from not updating when the input is less than 0, and at the same time improve the generalization ability of the model and the convergence speed of the model. The comparison of the loss convergence effect of using the two activation functions to train the network model is shown in the figure below. Fig.10 As shown. Fig.10 It can be clearly seen that using Gelu instead of Relu activation function can accelerate the convergence of the model and make the loss curve smoother. Experiments have shown that changing the activation function can improve the gradient explosion problem of the model but will not improve the model detection accuracy.

[0108] Adding extra layers to the backbone feature extraction network will increase the complexity of the model. Adding different modules to the ResNet50 network, the mAP change curve during training is as follows: Fig.11 As shown in the figure, the average accuracy of the feature extraction network after adding the extra network is improved compared to the original model. After changing the network model, the pre-trained weights do not match the network. Therefore, the improved model needs more rounds of training to reach a stable state compared to the original model.

[0109] To verify the model improvement effect, this paper uses the same training parameters to train the network model and uses the test set to verify the model. The results are shown in Table 3:

[0110] Table 3 Ablation experiment

[0111]

[0112] According to Table 3, in the comparative experiment, ResNet50 is used as the baseline network. The improved network model has improved the detection accuracy of rural illegal buildings compared with the original model. Among them, adding the attention module in the Stage 1 and Stage 2 stages of the ResNet50 network improves the accuracy by 1.46%; adding the parallel hole convolution module in the Stage 3 stage of the ResNet50 network alone improves the model accuracy by 1.24%; adding the attention module in the Stage 1 and Stage 2 stages of the ResNet50 network and adding the parallel hole convolution module in the Stage 3 stage improves the model accuracy by 2.19%. When the RetinaNet algorithm uses ResNet50 as the feature extraction network, the model parameter amount is 5.55×10 7 , the network parameters of the three improved ResNet50 feature extraction are 3.955×10 7 ,3.918×10 7 ,3.924×10 7 Compared with the original model, the improved final network model RetinaNet algorithm has a reduced number of parameters by 16247552.

[0113] The experimental comparison results of different algorithms are shown in Table 4. According to Table 4, the SSD algorithm has the least number of parameters, but the recognition accuracy of rural illegal buildings is low. YOLO-V3 is a new network structure published after RetinaNet. Compared with the RetinaNet algorithm, it not only has more parameters but also has lower detection accuracy than the RetinaNet algorithm. The improved RetinaNet algorithm not only improves the detection accuracy of the algorithm for urban and rural illegal buildings, but also reduces the number of parameters of the algorithm.

[0114] Table 4 Comparison of detection effects of different algorithms

[0115]

[0116] The comparison of the detection effects of the original RetinaNet model and the improved RetinaNet model on four example images is shown in the following figure. Fig.12 , Fig.13 , Fig.14 , Fig.15 As shown, the left side is the detection result of the original RetinaNet model, and the right side is the detection result of the improved model of the present invention. By comparison, it can be seen that the improved model has higher detection accuracy and lower missed detection rate for small targets to be detected at the edge of the image.

[0117] (4) Step S4

[0118] After the model training and testing are completed, it can be directly deployed on any deployable device to detect illegal buildings in the input images.

[0119] Corresponding to the above method, the embodiment of the present invention also provides an illegal building detection system in the urban-rural junction, including an illegal building detection model construction unit, a data set construction unit, an illegal building detection model training unit, and an illegal building detection model application unit, which are respectively used to execute steps S1, S2, S3, and S4 in the above method. These four units can operate independently from other units.

[0120] In summary, the embodiment of the present invention provides a method and system for detecting illegal buildings in urban and rural areas. Attention modules are added to the Stage 1 and Stage 2 stages of the ResNet50 network to enhance the algorithm's perception of small target features; a parallel hole convolution module is added to the Stage 3 stage to obtain multi-scale fusion features; the activation function of the ResNet50 network is replaced with Gelu to accelerate the convergence of the model and improve the model gradient explosion problem during training. The average accuracy of the improved RetinaNet algorithm in detecting illegal buildings in urban and rural areas reached 93.28%, which is 2.19% higher than the average accuracy of the original model. At the same time, the number of parameters of the algorithm is reduced by 16247552, which reduces the algorithm's missed detection rate of small targets, and verifies the effectiveness of the model improvement.

[0121] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A method for detecting illegal buildings in urban and rural areas, characterized in that: Includes steps: S1. Improve the RetinaNet model to build an illegal building detection model; The illegal building detection model includes a backbone network and a classification regression sub-network, wherein the backbone network includes a ResNet feature extraction network and a feature fusion network; the ResNet feature extraction network includes five modules of Stage0, Stage1, Stage2, Stage3, and Stage4 connected in sequence, and the output features of the modules of Stage2, Stage3, and Stage4 are input into the feature fusion network for multi-scale feature fusion, and the obtained fusion feature map is input into the classification regression sub-network for category judgment and position regression; The Stage0 module preprocesses the input image and then inputs it into the Stage1 module after passing through the maximum pooling layer; the Stage1 module includes 1 first BlockA module, N1 BlockB modules and 1 attention module, N1≥2; the Stage2 module includes 1 second BlockA module, N2 BlockB modules and 1 attention module, N2≥2; the Stage3 module includes 1 second BlockA module, N3 BlockB modules and 1 parallel void convolution module, N3≥2; the Stage4 module includes 1 second BlockA module and N4 BlockB modules, N4≥2; The first BlockA module and the second BlockA module adopt the structure of BlockA modules with different convolution step sizes, and the BlockA module downsamples the input feature map according to the convolution step size to achieve feature map scale transformation; the convolution step size of the BlockB module is 1, and the width and height of the input feature map are not changed, only the number of channels is changed; The attention module encodes the position information of the retained features in the horizontal direction and the vertical direction respectively; the operation performed by the attention module is: First, the C×H×W input features are averagely pooled in the horizontal and vertical directions to obtain C×H×1 and C×1×W output features, respectively. C, H, and W represent the number of channels, height, and width, respectively. Then, the output features of the horizontal direction C×H×1 are transformed in dimension and concat-operated with the output features of the vertical direction C×1×W to obtain the merged features of C×1×(W+H); Then, the merged features of C×1×(W+H) are convolved, normalized by the BN layer, and subjected to a nonlinear activation function to obtain the output features of C / r×1×(W+H), where r is the reduction rate. Then, convolution is used along the spatial dimension to transform the output features of C / r×1×(W+H) into C×H×1 and C×1×W, and then the sigmoid activation function is used to obtain the corresponding attention weight g h , g w ; Finally, the C×H×W input feature Input and the attention weight g h , g w Multiply them to get the output feature Output of C×H×W; The parallel dilated convolution module uses multiple parallel dilated convolution modules to perform multi-scale feature extraction; The operations performed by the parallel dilated convolution module are: First, the C×H×W input feature Input is subjected to a 1×1 convolution to change the number of input feature channels, and then normalized by the BN layer to obtain feature I. At the same time, the first-scale feature A is obtained by normalizing by the BN layer and adding a nonlinear activation function. At the same time, the second-scale feature B is obtained by normalizing by the BN layer and adding a nonlinear activation function. At the same time, the third-scale feature C is obtained by normalizing by the BN layer and adding a nonlinear activation function. Then, the first dilated convolution module is used to perform dilated convolution on feature A, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature D. The second dilated convolution module is used to perform dilated convolution on feature B, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature E. The third dilated convolution module is used to perform dilated convolution on feature C, and then normalized by the BN layer and a nonlinear activation function is added to obtain feature F. Then, the multi-scale features D, E, and F are concat-operated in the depth direction to obtain the multi-scale fusion feature G; Finally, the multi-scale fusion feature G is added to the feature I, and then the nonlinear activation function is passed to obtain the output feature Output of C×H×W; S2, build a data set; S3, using the data set to train and verify the illegal building detection model; S4. Deploy the trained illegal building detection model.

2. A method for detecting illegal buildings in urban-rural fringe areas according to claim 1, characterized in that: The convolution kernel sizes of the first atrous convolution module, the second atrous convolution module, and the third atrous convolution module are all 3×3, the step sizes are all 1, and the padding values ​​are 1, 2, and 5, respectively.

3. A method for detecting illegal buildings in urban-rural fringe areas according to claim 1, characterized in that: The operations performed by the BlockA module are: First, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer and a nonlinear activation function is added. Then, the convolution kernel is 3×3 and a step size of 2, and then normalized by a BN layer to obtain the first intermediate feature. At the same time, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of S1, and then normalized by a BN layer and a nonlinear activation function is added to obtain the second intermediate feature. Then, the first intermediate feature and the second intermediate feature are added together, and then passed through a nonlinear activation function to obtain the output feature Output.

4. A method for detecting illegal buildings in urban-rural fringe areas according to claim 3, characterized in that: In the first BlockA module, the step length S1 is set to 1; in the second BlockA module, the step length S2 is set to 2.

5. A method for detecting illegal buildings in urban-rural fringe areas according to claim 1, characterized in that: The operations performed by the BlockB module are: First, the input feature Input is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 3×3 and a step size of 1, then normalized by a BN layer and a nonlinear activation function is added. Then, it is convolved with a convolution kernel of 1×1 and a step size of 1, then normalized by a BN layer to obtain the first intermediate feature. Then, the first intermediate feature is added to the input feature Input, and then passed through a nonlinear activation function to obtain the output feature Output.

6. A method for detecting illegal buildings in urban-rural fringe areas according to any one of claims 1 to 5, characterized in that: The nonlinear activation functions used in the ResNet feature extraction network are all Gelu activation functions; N1=2, N2=3, N3=5, N4=2.

7. A method for detecting illegal buildings in urban-rural fringe areas according to claim 1, characterized in that: Step S2 specifically includes the following steps: S21, obtain the real-time images of urban and rural illegal buildings taken by high-definition surveillance cameras, and crop each real-time image into multiple images of the same size according to a fixed cropping position, and remove the images that do not contain the detection target information to construct an urban and rural illegal building image dataset; S22, resizing the image downloaded from the network to be consistent with the image cropped in step S1 and adding it to the urban and rural illegal building image dataset to obtain the original dataset; S23. Expand and annotate the original data set to obtain a data set containing 9 types of features: bricks, steel bars, people, color steel buildings, house frames, brick structures, breeding farms, adobe houses, and abandoned houses.

8. A system for detecting illegal buildings in urban and rural areas, characterized by: It includes an illegal building detection model construction unit, a data set construction unit, an illegal building detection model training unit, and an illegal building detection model application unit, which are respectively used to execute steps S1, S2, S3, and S4 of a method for detecting illegal buildings in urban and rural fringe areas as described in any one of claims 1 to 7.