Ancient city wall surface vegetation classification model establishment method, classification method and system

Through the Yolov8 segmentation model based on the attention mechanism and deformable convolution and the Swin Transformer classification model with double-layer routing attention, the problem of low accuracy in identifying and classifying vegetation on the surface of the ancient city wall is solved, and the classification of small and irregularly shaped vegetation is improved. Segmentation and classification capabilities enhance the model's attention and generalization capabilities.

CN118674971APending Publication Date: 2024-09-20XI'AN UNIVERSITY OF ARCHITECTURE AND TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410678834.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

In the existing technology, the accuracy of vegetation recognition and classification on the surface of ancient city walls is low. There are problems such as small vegetation targets, irregular shapes, large proportions of background information, many interference factors, and unbalanced data samples, resulting in low classification accuracy.

Method used

The Yolov8 segmentation model based on attention mechanism and deformable convolution is used for image segmentation to obtain vegetation category information, and the Swin Transformer classification model based on double-layer routing attention is used for fine classification, combined with data oversampling and mixup hybrid enhancement methods. Data differences enhance the generalization ability of the model.

Benefits of technology

It improves the segmentation ability of irregular-shaped vegetation, enhances attention to vegetation information, reduces model deviation and weak generalization ability, and improves the accuracy of identification and classification of vegetation on ancient city walls.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118674971A
    Figure CN118674971A
Patent Text Reader

Abstract

The invention discloses an ancient city wall surface vegetation classification model establishment method, classification method and system, and the method comprises the steps: obtaining an image data set of ancient city wall surface vegetation, and carrying out the preprocessing of the image data set; an SAM model is adopted to carry out auxiliary labeling on a preprocessed image data set, and for the problem that a vegetation target in a city wall image is small and irregular in shape, the adaptability of a convolutional neural network to an irregular-shaped target is improved, and the receptive field of the target is expanded; according to the method, a Yov8 segmentation model based on an attention mechanism and deformable convolution is trained and tested, an ancient city wall surface vegetation image is segmented, the ancient city wall surface vegetation image and category information thereof are acquired, a Swin Transform classification model based on double-layer routing attention is trained and constructed by adopting a public data set, and the classification of the ancient city wall surface vegetation image and the category information of the ancient city wall surface vegetation image is realized. And then a Swin Transform classification model based on double-layer routing attention is adopted to classify the segmented ancient city wall vegetation image data set. The technical problem of low accuracy of ancient city wall vegetation identification and classification in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of digital image processing and relates to a classification method, in particular to an ancient city wall surface vegetation classification model establishment method, a classification method and a system. Background Art

[0002] At present, the vegetation on the surface of the ancient city wall covers a wide area. The artificial method of identifying vegetation requires botanists with professional knowledge to identify them one by one. When sampling and testing, it is necessary to reduce the damage to the ancient city wall while ensuring the integrity of the vegetation. The process is time-consuming and laborious and increases the cost. In addition, there are problems such as small vegetation targets to be segmented on the surface of the ancient city wall, irregular shapes, large proportion of background information in the ancient city wall image, many interference factors, and model deviation caused by large differences in the number and distribution of vegetation samples. In addition, the vegetation data samples on the surface of the ancient city wall are unbalanced, the differences between different vegetation classes of the same genus are small, and the discriminative regional similarity is high, resulting in low classification accuracy. To address this problem, it is necessary to design a classification model establishment method, classification method and system for the vegetation on the surface of the ancient city wall. The segmentation model is trained using the image data of the ancient city wall to obtain the vegetation image and its category information on the surface of the ancient city wall, provide prior knowledge for the subsequent vegetation fine classification prediction samples, and further classify the different vegetation of the same genus through the segmentation model. Summary of the invention

[0003] In view of the shortcomings of the prior art, the purpose of the present invention is to provide a method for establishing a classification model of vegetation on the surface of an ancient city wall, a classification method and a system, so as to solve the technical problem of low accuracy in the identification and classification of vegetation on ancient city walls in the prior art.

[0004] In order to solve the above technical problems, the present invention adopts the following technical solutions to achieve the above problems:

[0005] A method for constructing a vegetation classification model on the surface of an ancient city wall, specifically comprising the following steps:

[0006] Step 1: obtain an image dataset of vegetation on the surface of the ancient city wall and preprocess it;

[0007] Step 2: Use the SAM model to assist in labeling the preprocessed image dataset, and randomly divide the labeled image dataset into a training set and a test set according to proportion;

[0008] The image dataset includes meat, apetalum, moss, algae, biological residues and other categories;

[0009] Step 3: Build a Yolov8 segmentation model based on attention mechanism and deformable convolution;

[0010] Step 4: Take the training set obtained in step 2 as input, take the category information of vegetation on the surface of the ancient city wall as output, and train the Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 3 to obtain a trained Yolov8 segmentation model based on attention mechanism and deformable convolution;

[0011] Step 5: Input the test set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 for segmentation to obtain the test set after segmentation;

[0012] The segmented test set is the plant category of vegetation on the surface of the ancient city wall;

[0013] Step 6, obtaining the corresponding public plant dataset according to the segmented test set obtained in step 5;

[0014] Step 7: Build a Swin Transformer classification model based on double-layer routing attention;

[0015] Step 8: Take the public plant dataset obtained in step 6 as input, and take the species category of each plant in the public plant dataset as output, and train the Swin Transformer classification model based on double-layer routing attention constructed in step 7 to obtain a trained Swin Transformer classification model based on double-layer routing attention.

[0016] The Yolov8 segmentation model based on attention mechanism and deformable convolution includes Backone, Neck and Head connected in sequence;

[0017] Backbone is used to extract multi-scale feature information of the image of vegetation on the surface of the ancient city wall, enhance the features through multiple convolutional layers and attention mechanism modules, and output feature maps;

[0018] Neck is used to fuse and enhance the feature maps output by Backbone through a pyramid structure or feature fusion network;

[0019] Head is used to segment the feature map after Neck processing using a fully connected layer or a convolutional layer and output the segmentation result.

[0020] The Backbone includes a CBS module, a CBS module, a first C2f module, a CBS module, a second C2f module, a CBS module, a first C2f_DCN module, a CBS module, a second C2f_DCN module and an SPPF module connected in sequence;

[0021] The Neck includes a first CBAM module, a first Upsample module, a first Concat module, a third C2f module, a second CBAM module, a second Upsample module, a second Concat module, a fourth C2f module, a third CBAM module, a CBS module, a third Concat module, a fifth C2f module, a fourth CBAM module, a CBS module, a fourth Concat module and a sixth C2f module connected in sequence;

[0022] The first CBAM module and the fourth Concat module are connected to the SPPF module; the first Concat module is connected to the first C2f_DCN module; the second Concat module is connected to the second C2f module; the third Concat module is connected to the third C2f module;

[0023] The Head includes a first Detect module, a second Detect module, a third Detect module, a Segment module and an EIoU-Focal loss function; the first Detect module is connected to the fourth C2f module; the second Detect module is connected to the fifth C2f module; the third Detect module is connected to the sixth C2f module; the Segment module is connected to the first Detect module, the second Detect module and the third Detect module.

[0024] The Swin Transformer classification model based on double-layer routing attention includes a mixup data oversampling module, a mixup module, a PatchSets module, a Backbone, a Layer Norm module, an Avg Pooling module, a Softmax module, a Fully Connected module and a Classification module which are connected in sequence.

[0025] The Backbone includes four stages connected in sequence, the first stage includes a connected LinearEbedding module and two Swin Routiformer modules, the second stage includes a connected Patch Merging module and two Swin Routiformer modules; the third stage includes a connected Patch Merging module and six Swin Routiformer modules, and the fourth stage includes a connected Patch Merging module and two Swin Routiformer modules.

[0026] The Swin Routiformer module includes a first Layer Norm module, a W-MSA module, a first residual link module, a second Layer Norm module, a first MLP module, a second residual link module, a DWConv module, a third residual link module, a third Layer Norm module, a BRA module, a fourth residual link module, a fourth Layer Norm module, a second MLP module and a fifth residual link module, which are sequentially connected;

[0027] The input end of the first Layer Norm module is connected to the first residual link module; the output end of the first residual link module is connected to the second residual link module; the output end of the second residual link module is connected to the input end of the DWConv module; the output end of the third residual link module is connected to the fourth residual link module; the output end of the fourth residual link module is connected to the fifth residual link module.

[0028] In step 2, the ratio is 9:1.

[0029] The preprocessing is data enhancement processing using the MedAugument method.

[0030] A method for classifying vegetation on the surface of an ancient city wall, specifically comprising the following steps:

[0031] Step 1: Collect vegetation images on the surface of the ancient city wall, perform preprocessing and SAM model-assisted annotation on them in turn, and use them as a validation set;

[0032] Step 2, inputting the verification set collected in step 1 into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 of the ancient city wall surface vegetation classification model construction method to obtain a segmented verification set;

[0033] The segmented validation set is the plant categories of vegetation on the surface of the ancient city wall;

[0034] Step 3, input the segmented verification set obtained in step 2 into the trained Swin Transformer classification model based on double-layer routing attention obtained in step 8 of the ancient city wall surface vegetation classification model construction method for classification, and obtain the species category of each plant in each plant category.

[0035] A vegetation recognition and classification system for the surface of an ancient city wall, comprising a first data acquisition module, a model building module, a first model training module, a first processing module, a second data acquisition module, a second model training module, and a second processing module;

[0036] The first data acquisition module is used to obtain an image dataset of vegetation on the surface of the ancient city wall, preprocess it, and use the SAM model to assist in annotating the preprocessed image dataset, and randomly divide the annotated image dataset into a training set and a test set in proportion; and collect vegetation images on the surface of the ancient city wall, preprocess them and annotate them with the SAM model in turn, and use them as a verification set;

[0037] The model building module is used to build a Yolov8 segmentation model based on attention mechanism and deformable convolution and a Swin Transformer classification model based on double-layer routing attention;

[0038] The first model training module is used to input the training set into the Yolov8 segmentation model based on the attention mechanism and deformable convolution for training, so as to obtain the trained Yolov8 segmentation model based on the attention mechanism and deformable convolution;

[0039] The first processing module is used to input the test set into the trained Yolov8 segmentation model based on the attention mechanism and deformable convolution obtained in step 4 to segment it, so as to obtain the segmented test set; and, input the collected verification set into the trained Yolov8 segmentation model based on the attention mechanism and deformable convolution obtained in step 4 of the ancient city wall surface vegetation classification model construction method, so as to obtain the segmented verification set;

[0040] The second data acquisition module is used to obtain the corresponding public plant data set according to the obtained segmented test set;

[0041] The second model training module is used to input the obtained public plant data set into the constructed Swin Transformer classification model based on double-layer routing attention for training, so as to obtain a trained Swin Transformer classification model based on double-layer routing attention;

[0042] The second processing module is used to input the obtained segmented verification set into the obtained trained Swin Transformer classification model based on double-layer routing attention for classification, so as to obtain the species category of each plant in each plant category.

[0043] Compared with the prior art, the present invention has the following beneficial technical effects:

[0044] (I) The present invention targets the image dataset of vegetation on the surface of the ancient city wall, studies the instance segmentation task applicable to the vegetation on the surface of the ancient city wall, and constructs the Yolov8 segmentation model based on the attention mechanism and deformable convolution: irrelevant features are suppressed, and the degree of attention of the convolutional neural network to vegetation information is enhanced. Aiming at the problem that the vegetation targets in the city wall image are small and irregular in shape, the adaptability of the convolutional neural network to irregularly shaped targets is improved, and its receptive field is expanded; the Yolov8 segmentation model based on the attention mechanism and deformable convolution is trained and tested, the vegetation image on the surface of the ancient city wall is segmented, and the vegetation image on the surface of the ancient city wall and its category information are obtained, providing prior knowledge for the subsequent vegetation fine classification prediction samples; the Swin Transformer classification model based on double-layer routing attention constructed by training the public data set is used, and then the Swin Transformer classification model based on double-layer routing attention is used to classify the segmented ancient city wall vegetation image dataset, and finely classify the same genus and different vegetation, solving the technical problem of low accuracy of ancient city wall vegetation recognition and classification in the prior art.

[0045] (II) In this invention, a Yolov8 segmentation model based on attention mechanism and deformable convolution is constructed. Aiming at the problem that the vegetation targets to be segmented on the surface of the ancient city wall are small and irregular in shape, deformable convolution is introduced in Backone, and the C2f_DCN module is designed to give the convolution acquisition point offset, so that the model can adaptively adjust the size and shape of the convolution kernel, thereby improving its ability to segment small and irregularly shaped vegetation; Aiming at the problem that the background information of the ancient city wall image accounts for a large proportion and there are many interference factors, the CBAM attention mechanism is embedded in Neck, and the detection results are used to reversely guide the weight update of the feature map, thereby strengthening the model's ability to pay attention to the vegetation information on the surface of the ancient city wall; In order to solve the model bias problem caused by the large differences in the number and distribution of vegetation samples, the EIoU-Focal loss function is introduced in the Head to replace the CIou loss function, thereby reducing the loss weight of easy-to-classify vegetation samples.

[0046] (III) In the present invention, a Swin Transformer classification model based on double-layer routing attention is constructed. First, data oversampling and mixup hybrid enhancement methods are used to process the segmented test set, thereby reducing the problem of weak generalization ability of the Swin Transformer classification model based on double-layer routing attention due to vegetation data differences; the SwinRoutiformer module based on BRA enables the Swin Transformer classification model based on double-layer routing attention to filter out irrelevant feature information at the coarse area level and focus on the discrimination areas that are important for vegetation classification. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1It is a schematic diagram of the overall structure of the present invention;

[0048] Figure 2 It is a sample of vegetation on the surface of the ancient city wall;

[0049] Figure 3 This is a schematic diagram of the structure of the Yolov8 segmentation model that introduces the attention mechanism and deformable convolution;

[0050] Figure 4 This is a schematic diagram of the structure of the Swin Transformer classification model based on double-layer routing attention;

[0051] Figure 5 It is a schematic diagram of the structure of the Swin Routiformer module;

[0052] Figure 6 The schematic diagram of the segmentation results of some vegetation on the surface of the ancient city wall is shown;

[0053] Figure 7 The classification results of part of the vegetation on the surface of the ancient city wall are shown.

[0054] The specific contents of the present invention are further explained in detail below in conjunction with embodiments. DETAILED DESCRIPTION

[0055] It should be noted that, unless otherwise specified, all components in the present invention are components known in the art.

[0056] Specific embodiments of the present invention are given below. It should be noted that the present invention is not limited to the following specific embodiments, and all equivalent changes made on the basis of the technical solution of this application fall within the protection scope of the present invention.

[0057] The present invention provides a method for constructing a vegetation classification model on the surface of an ancient city wall, which specifically comprises the following steps:

[0058] Step 1: Obtain an image dataset of vegetation on the surface of the ancient city wall and preprocess it;

[0059] Step 2: Use the SAM model to assist in labeling the preprocessed image dataset, and randomly divide the labeled image dataset into a training set and a test set according to proportion;

[0060] Step 3: Build a Yolov8 segmentation model based on attention mechanism and deformable convolution;

[0061] Step 4, input the training set into the Yolov8 segmentation model based on attention mechanism and deformable convolution for training, and obtain the trained Yolov8 segmentation model based on attention mechanism and deformable convolution;

[0062] Step 5: Input the test set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 for segmentation to obtain the test set after segmentation;

[0063] The segmented test set is the plant category of vegetation on the surface of the ancient city wall;

[0064] Step 6, obtaining the corresponding public plant dataset according to the segmented test set obtained in step 5;

[0065] Step 7: Build a Swin Transformer classification model based on double-layer routing attention;

[0066] Step 8: Input the public plant dataset obtained in step 6 into the Swin Transformer classification model based on double-layer routing attention constructed in step 7 for training, and obtain a trained Swin Transformer classification model based on double-layer routing attention.

[0067] In the above technical scheme, for the image dataset of vegetation on the surface of the ancient city wall, the instance segmentation task suitable for the vegetation on the surface of the ancient city wall is studied, and the Yolov8 segmentation model based on the attention mechanism and deformable convolution is constructed: irrelevant features are suppressed and the attention of the convolutional neural network to vegetation information is enhanced. In view of the problem that the vegetation targets in the city wall image are small and irregular in shape, the adaptability of the convolutional neural network to irregularly shaped targets is improved and its receptive field is expanded; the Yolov8 segmentation model based on the attention mechanism and deformable convolution is trained and tested, the vegetation image on the surface of the ancient city wall is segmented, and the vegetation image on the surface of the ancient city wall and its category information are obtained, providing prior knowledge for the subsequent vegetation fine classification prediction samples; the Swin Transformer classification model based on double-layer routing attention constructed by training the public data set is used, and then the Swin Transformer classification model based on double-layer routing attention is used to classify the segmented ancient city wall vegetation image dataset, and finely classify the same genus and different vegetation, solving the technical problem of low accuracy of ancient city wall vegetation recognition and classification in the prior art.

[0068] Specifically, the Yolov8 segmentation model based on attention mechanism and deformable convolution includes Backone, Neck and Head connected in sequence;

[0069] Backbone is used to extract multi-scale feature information of the image of vegetation on the surface of the ancient city wall, enhance the features through multiple convolutional layers and attention mechanism modules, and output feature maps;

[0070] Neck is used to fuse and enhance the feature maps output by Backbone through a pyramid structure or feature fusion network;

[0071] Head is used to segment the feature map after Neck processing using a fully connected layer or a convolutional layer and output the segmentation result.

[0072] Specifically, Backbone includes a CBS module, a CBS module, a first C2f module, a CBS module, a second C2f module, a CBS module, a first C2f_DCN module, a CBS module, a second C2f_DCN module and an SPPF module connected in sequence;

[0073] Neck includes a first CBAM module, a first Upsample module, a first Concat module, a third C2f module, a second CBAM module, a second Upsample module, a second Concat module, a fourth C2f module, a third CBAM module, a CBS module, a third Concat module, a fifth C2f module, a fourth CBAM module, a CBS module, a fourth Concat module and a sixth C2f module, which are connected in sequence;

[0074] The first CBAM module and the fourth Concat module are connected to the SPPF module; the first Concat module is connected to the first C2f_DCN module; the second Concat module is connected to the second C2f module; the third Concat module is connected to the third C2f module;

[0075] Head includes a first Detect module, a second Detect module, a third Detect module, a Segment module and an EIoU-Focal loss function; the first Detect module is connected to the fourth C2f module; the second Detect module is connected to the fifth C2f module; the third Detect module is connected to the sixth C2f module; the Segment module is connected to the first Detect module, the second Detect module and the third Detect module.

[0076] like Figure 3As shown in the figure, a Yolov8 segmentation model based on attention mechanism and deformable convolution is built. Aiming at the problem that the vegetation targets to be segmented on the surface of the ancient city wall are small and irregular in shape, deformable convolution is introduced in Backone, and the C2f_DCN module is designed. The convolution acquisition point offset is given to enable the model to adaptively adjust the size and shape of the convolution kernel, thereby improving its ability to segment small and irregularly shaped vegetation. Aiming at the problem that the background information of the ancient city wall image accounts for a large proportion and there are many interference factors, the CBAM attention mechanism is embedded in Neck, and the detection results are used to reversely guide the weight update of the feature map, so as to enhance the model's ability to pay attention to the vegetation information on the surface of the ancient city wall. In order to solve the model bias problem caused by the large differences in the number and distribution of vegetation samples, the EIoU-Focal loss function is introduced in the Head to replace the CIou loss function, so as to reduce the loss weight of easy-to-classify vegetation samples.

[0077] Among them, in Backbone, the first CBS module is used for preliminary feature extraction; the second CBS module is used for further feature enhancement; the first C2f module is responsible for multi-scale feature fusion; the third CBS module continues feature extraction; the second C2f module performs multi-scale feature fusion again; the fourth CBS module further extracts features; the first C2f_DCN module is used to fuse dynamic convolution features; the fifth CBS module continues feature extraction; the second C2f_DCN module further fuses dynamic convolution features; the SPPF module performs spatial pyramid pooling to enhance feature representation.

[0078] In Neck, the first CBAM module is used for feature enhancement of the attention mechanism; the first Upsample module realizes feature upsampling; the first Concat module fuses the upsampled features with the previous-level features; the third C2f module is used for multi-scale feature fusion; the second CBAM module further enhances the features; the second Upsample module performs feature upsampling; the second Concat module fuses the upsampled features with the previous-level features; the fourth C2f module performs multi-scale feature fusion; the third CBAM module continues to enhance the features; the fifth CBS module performs feature extraction; the third Concat module fuses the extracted features with the previous-level features; the fifth C2f module performs multi-scale feature fusion; the fourth CBAM module continues to enhance the features; the sixth CBS module performs feature extraction; the fourth Concat module fuses the extracted features with the previous-level features; the sixth C2f module performs the final multi-scale feature fusion.

[0079] In the Head, the first Detect module is connected to the fourth C2f module for preliminary detection; the second Detect module is connected to the fifth C2f module for intermediate detection; the third Detect module is connected to the sixth C2f module for final detection; the Segment module is connected to the first Detect module, the second Detect module and the third Detect module for final segmentation processing; the EIoU-Focal loss function is used to optimize the detection and segmentation results of the model.

[0080] Specifically, the Swin Transformer classification model based on double-layer routing attention includes a mixup data oversampling module, a mixup module, a PatchSets module, a Backbone, a Layer Norm module, an AvgPooling module, a Softmax module, a Fully Connected module and a Classification module, which are connected in sequence.

[0081] like Figure 4 As shown in the figure, a Swin Transformer classification model based on double-layer routing attention is constructed. Firstly, data oversampling and mixup hybrid enhancement methods are used to process the segmented test set, which reduces the problem of weak generalization ability of the Swin Transformer classification model based on double-layer routing attention due to vegetation data differences; based on the SwinRoutiformer module of BRA, the Swin Transformer classification model based on double-layer routing attention filters out irrelevant feature information at the coarse area level and focuses on the discriminant areas that are important for vegetation classification.

[0082] Specifically, Backbone includes four stages connected in sequence. The first stage includes a connected LinearEbedding module and two Swin Routiformer modules, the second stage includes a connected Patch Merging module and two Swin Routiformer modules; the third stage includes a connected Patch Merging module and six Swin Routiformer modules, and the fourth stage includes a connected Patch Merging module and two Swin Routiformer modules.

[0083] In the above technical solution, the Swin Transformer classification model based on double-layer routing attention has an input image size of H×W and an input image with a feature dimension of 3. After mixup and PatchSets, the image size becomes The feature dimension becomes 48; in Stage 1, the Linear Embedding module changes the feature dimension from 48 to 96. In Stage 2 to Stage 4, the image block size is halved and the feature dimension is doubled.

[0084] Specifically, the Swin Routiformer module includes a first Layer Norm module, a W-MSA module, a first residual link module, a second Layer Norm module, a first MLP module, a second residual link module, a DWConv module, a third residual link module, a third Layer Norm module, a BRA module, a fourth residual link module, a fourth LayerNorm module, a second MLP module, and a fifth residual link module, which are sequentially connected;

[0085] The input end of the first Layer Norm module is connected to the first residual link module; the output end of the first residual link module is connected to the second residual link module; the output end of the second residual link module is connected to the input end of the DWConv module; the output end of the third residual link module is connected to the fourth residual link module; the output end of the fourth residual link module is connected to the fifth residual link module.

[0086] like Figure 5 As shown in the figure, the Swin Routiformer module consists of a BRA mechanism, an LN layer, a W-MSA module, a residual connection, and an MLP layer, and uses a 3×3 depth convolution to implicitly encode relative position information, thereby enhancing the scalability and adaptability of the model.

[0087] In step 2, the ratio is 9:1.

[0088] The preprocessing method is MedAugument method for data enhancement.

[0089] The present invention provides a method for classifying vegetation on the surface of an ancient city wall, which is based on a method for constructing a classification model of vegetation on the surface of an ancient city wall, and specifically comprises the following steps:

[0090] Step 1: Collect vegetation images on the surface of the ancient city wall, perform preprocessing and SAM model-assisted annotation on them in turn, and use them as a validation set;

[0091] Step 2, input the validation set collected in step 1 into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 of the ancient city wall surface vegetation classification model construction method to obtain the segmented validation set;

[0092] The segmented validation set is the plant categories of vegetation on the surface of the ancient city wall;

[0093] Step 3, input the segmented validation set obtained in step 2 into the trained Swin Transformer classification model based on double-layer routing attention obtained in step 8 of the ancient city wall surface vegetation classification model construction method for classification, and obtain the species category of each plant in each plant category.

[0094] The present invention also provides a system for identifying and classifying vegetation on the surface of an ancient city wall, which is based on a method for building a classification model of vegetation on the surface of an ancient city wall and a method for classifying vegetation on the surface of an ancient city wall, and comprises a first data acquisition module, a model building module, a first model training module, a first processing module, a second data acquisition module, a second model training module, and a second processing module;

[0095] The first data acquisition module is used to obtain an image dataset of vegetation on the surface of the ancient city wall, preprocess it, and use the SAM model to assist in annotating the preprocessed image dataset, and randomly divide the annotated image dataset into a training set and a test set in proportion; and collect vegetation images on the surface of the ancient city wall, preprocess them and annotate them with the SAM model in turn, and use them as a verification set;

[0096] The model building module is used to build the Yolov8 segmentation model based on attention mechanism and deformable convolution and the Swin Transformer classification model based on double-layer routing attention;

[0097] The first model training module is used to input the training set into the Yolov8 segmentation model based on the attention mechanism and deformable convolution for training, so as to obtain the trained Yolov8 segmentation model based on the attention mechanism and deformable convolution;

[0098] The first processing module is used to input the test set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 to segment, so as to obtain the segmented test set; and, input the collected verification set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 of the ancient city wall surface vegetation classification model construction method, so as to obtain the segmented verification set;

[0099] The second data acquisition module is used to obtain the corresponding public plant data set according to the obtained segmented test set;

[0100] The second model training module is used to input the obtained public plant data set into the constructed Swin Transformer classification model based on double-layer routing attention for training, so as to obtain a trained Swin Transformer classification model based on double-layer routing attention;

[0101] The second processing module is used to input the obtained segmented verification set into the obtained trained Swin Transformer classification model based on double-layer routing attention for classification, so as to obtain the species category of each plant in each plant category.

[0102] Simulation experiment:

[0103] In order to verify the application effect of the present invention in actual situations, an application effect test was conducted on the vegetation dataset on the surface of the ancient city wall. First, a dataset of vegetation images on the surface of the ancient city wall was constructed to provide support for the segmentation algorithm. Subsequently, a dataset of plants of different categories after segmentation was created to subdivide the specific names of the plants. The two datasets will be described in detail below.

[0104] The vegetation data on the surface of the ancient city wall was collected from the ancient city wall of Xi'an from April 15 to September 20, 2023. The image data acquisition device is iPhone12, and the shooting distance is 1 to 3 meters. The resolution of the collected image is 4032 pixels × 3024 pixels, and the storage format is .jpg.

[0105] A total of 669 images of vegetation on the surface of the ancient city wall were collected in this experiment. After evaluation by experts, these images were confirmed to contain a variety of vegetation types, including succulents, apetals, mosses, algae, biological residues and other types. Biological residues refer to the remains of vegetation and a combination of various microorganisms after the wall maintenance staff sprayed drugs to kill or inhibit growth, while other types include rare vegetation types that appear less than 5 times in the data set.

[0106] Table 1 Types and quantities of vegetation on the surface of ancient city walls

[0107]

[0108] In order to make the data suitable for segmentation algorithms, these images were annotated. The sample size after annotation was small and the distribution of samples in each category was uneven, so the data set was expanded using the MedAugument data enhancement method. After enhancement, a total of 64,646 vegetation samples on the surface of the ancient city wall were marked. The training set, validation set, and test set of each type of sample were divided into 9:1. The vegetation and its number in each category are detailed in Table 1.

[0109] For succulent plants, we use the original succulent dataset from Yangtze University. This dataset collects images of 190 succulent plants. For apetalum, we use a public dataset from the Chinese Biological Species List. There is no public dataset for mosses, so we integrate and expand multiple public moss image datasets, including 110 species of mosses that are most widely distributed in China, with the number of images of each species ranging from 90 to 200. Biological residues and algae are not included in the classification category due to their microscopic characteristics.

[0110] To ensure the rigor of the experimental results, the simulation experiment uses a unified device for network model training. The deep learning framework used in the experiment is Pytorch, the experimental environment is based on Anaconda3 and Python3.8, the CUDA version is 10.2.89, and all network model training and testing are performed on the Windows 10 operating system. The device configuration is i7-9750H@2.60GHz CPU and GeForce RTX 2060 GPU.

[0111] In the image segmentation model, the model performance test indicators used in this simulation experiment include accuracy, intersection over union (Iou), mean intersection over union (MIoU), and mean pixel accuracy (mPA). In the classification model, the performance evaluation indicators used include Top-1 Accuracy (TA), F1-Score (F1-Score) and Authentic Accuracy (AA). The Authentic Accuracy evaluates the generalization performance of the model for the task of classifying real vegetation on the surface of the ancient city wall. The calculation formula is as follows:

[0112]

[0113] In order to comprehensively evaluate the Yolov8 segmentation model based on attention mechanism and deformable convolution, it was compared with the three mainstream semantic segmentation models, U-Net, DeepLabv3+, and Mask R-CNN, all of which were pre-trained using the COCO dataset. Then, the feature extraction layer was frozen and the ancient city wall surface vegetation dataset was trained for 40 epochs.

[0114] Table 2 shows the performance of five different image segmentation models when processing images of vegetation on the surface of the city wall. The performance of each model is measured by the intersection over union ratio. In comparison, the Yolov8 segmentation model (Ours) based on the attention mechanism and deformable convolution proposed in this paper outperforms the other three models in overall performance, with an average IoU of 89.39%. Although Mask R-CNN achieved an IoU of 94.51% on meat and U-Net achieved 98.53% in other categories, they were inferior to the model proposed in this paper in other categories.

[0115] Table 2 IoU comparison of various models for the ancient city wall surface vegetation segmentation task

[0116] Table 2IoU comparison of various models of vegetation segmentationtask on the surface of

[0117] ancient city walls

[0118]

[0119] Table 3 shows the comprehensive performance of several models in the task of vegetation segmentation on the surface of the ancient city wall through mIoU, mPA and Accuracy. In terms of the mIoU indicator, the Yolov8 segmentation model based on the attention mechanism and deformable convolution performs best, reaching 90.38%, which is significantly higher than other models; in the mPA indicator, the Yolov8 segmentation model based on the attention mechanism and deformable convolution also ranks first, reaching 83.69%, showing a high pixel-level prediction accuracy, while the mPA of DeepLabv3+ and U-Net are 78.05% and 76.94% respectively, which are relatively low. Overall, the Yolov8 segmentation model based on the attention mechanism and deformable convolution of the present invention surpasses several other commonly used models in three key performance indicators, showing its superiority in the segmentation of vegetation on the surface of the ancient city wall.

[0120] Table 3 Comparison of mIoU, mPA and Accuracy performance of each model

[0121]

[0122] exist Figure 6In the paper, some segmentation results of U-Net, DeepLabV3+, Mask R-CNN, original Yolov8 model and Yolov8 segmentation model based on attention mechanism and deformable convolution on the vegetation dataset of the ancient city wall surface are shown. The analysis shows that U-Net and DeepLabv3+ have a large missed detection problem when segmenting the moss category. In contrast, the segmentation effect of Mask R-CNN and original Yolov8 is relatively ideal. However, the Yolov8 segmentation model based on attention mechanism and deformable convolution of the present invention performs better and can accurately segment small areas of moss around large areas of moss. When dealing with succulent plants, U-Net and Yolov8 models often miss smaller succulents, and Mask R-CNN and DeepLabv3+ sometimes mistakenly classify succulent plants growing in moss as mosses. In contrast, the Yolov8 segmentation model based on attention mechanism and deformable convolution proposed in the present invention can accurately segment small succulent plants. For algae vegetation, although all models can perform segmentation well, the Yolov8 segmentation model based on attention mechanism and deformable convolution performs best, and can accurately identify the fallen leaves on the city wall as other categories of vegetation for segmentation.

[0123] Then, the Swin Transformer classification model based on double-layer routing attention was used for training and testing to obtain the species names of plants in each category. The performance analysis improvement effect of Swin Transformer (Swin-T) and Swin Transformer based on double-layer routing attention (Swin-R) was compared, and the accuracy of the two models on the test set is shown in Table 4. In the succulent category, the F1 score and top1 accuracy of Swin-R were 95.20% and 96.49%, respectively, which were 0.59% and 1.26% higher than Swin-T, respectively; in the apetal category, the F1 score and top1 accuracy of Swin-R were 91.41% and 92.36%, respectively, which were 0.87% and 2.25% higher than Swin-T, respectively; in the moss category, the F1 score and top1 accuracy of Swin-R were 67.34% and 68.26%, respectively, which were 5.21% and 2.26% higher than Swin-T, respectively. Experimental results show that Swin-R is superior to the original model in all indicators.

[0124] Table 4 The performance of the model on the vegetation

[0125]

[0126] The optimal model was used to predict the categories of succulents and apetalum on the surface of the ancient city wall, and the prediction results were compared with the identification results of experts. The AA index was used to measure the classification performance of the model under actual conditions. The experimental results showed that the consistency between the model prediction results and the expert identification results reached 93.51% for succulents, 91.80% for apetalum, and 79.74% for mosses, which were 2.14%, 1.84%, and 4.34% higher than Swin-T, respectively. Figure 7 The classification results of some vegetation on the surface of the ancient city wall are shown, among which (a) (b) are different types of Lepidium, (c) (d) are different types of succulents, and (e) (f) are different types of mosses. The above experiments further confirm the excellent performance of the Swin Transformer classification model based on double-layer routing attention in the task of vegetation classification on the surface of the ancient city wall.

Claims

1. A method for constructing a vegetation classification model on the surface of an ancient city wall, characterized in that: The specific steps include: Step 1: obtain an image dataset of vegetation on the surface of the ancient city wall and preprocess it; Step 2: Use the SAM model to assist in labeling the preprocessed image dataset, and randomly divide the labeled image dataset into a training set and a test set according to proportion; The image dataset includes meat, apetalum, moss, algae, biological residues and other categories; Step 3: Build a Yolov8 segmentation model based on attention mechanism and deformable convolution; Step 4: Take the training set obtained in step 2 as input, take the category information of vegetation on the surface of the ancient city wall as output, and train the Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 3 to obtain a trained Yolov8 segmentation model based on attention mechanism and deformable convolution; Step 5: Input the test set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 for segmentation to obtain the test set after segmentation; The segmented test set is the plant category of vegetation on the surface of the ancient city wall; Step 6, obtaining the corresponding public plant dataset according to the segmented test set obtained in step 5; Step 7: Build a Swin Transformer classification model based on double-layer routing attention; Step 8: Take the public plant dataset obtained in step 6 as input, and take the species category of each plant in the public plant dataset as output, and train the Swin Transformer classification model based on double-layer routing attention constructed in step 7 to obtain a trained Swin Transformer classification model based on double-layer routing attention.

2. The method for constructing a vegetation classification model on the surface of an ancient city wall as claimed in claim 1, characterized in that: The Yolov8 segmentation model based on attention mechanism and deformable convolution includes Backone, Neck and Head connected in sequence; Backbone is used to extract multi-scale feature information of the image of vegetation on the surface of the ancient city wall, enhance the features through multiple convolutional layers and attention mechanism modules, and output feature maps; Neck is used to fuse and enhance the feature maps output by Backbone through a pyramid structure or feature fusion network; Head is used to segment the feature map after Neck processing using a fully connected layer or a convolutional layer and output the segmentation result.

3. The method for constructing a vegetation classification model on the surface of an ancient city wall as claimed in claim 2, characterized in that: The Backbone includes a CBS module, a CBS module, a first C2f module, a CBS module, a second C2f module, a CBS module, a first C2f_DCN module, a CBS module, a second C2f_DCN module and an SPPF module connected in sequence; The Neck includes a first CBAM module, a first Upsample module, a first Concat module, a third C2f module, a second CBAM module, a second Upsample module, a second Concat module, a fourth C2f module, a third CBAM module, a CBS module, a third Concat module, a fifth C2f module, a fourth CBAM module, a CBS module, a fourth Concat module and a sixth C2f module connected in sequence; The first CBAM module and the fourth Concat module are connected to the SPPF module; the first Concat module is connected to the first C2f_DCN module; the second Concat module is connected to the second C2f module; the third Concat module is connected to the third C2f module; The Head includes a first Detect module, a second Detect module, a third Detect module, a Segment module and an EIoU-Focal loss function; the first Detect module is connected to the fourth C2f module; the second Detect module is connected to the fifth C2f module; the third Detect module is connected to the sixth C2f module; the Segment module is connected to the first Detect module, the second Detect module and the third Detect module.

4. The method for constructing a vegetation classification model on the surface of an ancient city wall according to claim 1, characterized in that: The Swin Transformer classification model based on double-layer routing attention includes a mixup data oversampling module, a mixup module, a PatchSets module, a Backbone, a Layer Norm module, an Avg Pooling module, a Softmax module, a FullyConnected module and a Classification module which are connected in sequence.

5. The method for constructing a vegetation classification model on the surface of an ancient city wall as claimed in claim 4, characterized in that: The Backbone includes four stages connected in sequence, the first stage includes a connected Linear Ebedding module and two Swin Routiformer modules, the second stage includes a connected Patch Merging module and two Swin Routiformer modules; the third stage includes a connected Patch Merging module and six Swin Routiformer modules, and the fourth stage includes a connected Patch Merging module and two Swin Routiformer modules.

6. The method for constructing a vegetation classification model on the surface of an ancient city wall as claimed in claim 5, characterized in that: The SwinRoutiformer module includes a first Layer Norm module, a W-MSA module, a first residual link module, a second Layer Norm module, a first MLP module, a second residual link module, a DWConv module, a third residual link module, a third Layer Norm module, a BRA module, a fourth residual link module, a fourth Layer Norm module, a second MLP module and a fifth residual link module, which are sequentially connected; The input end of the first Layer Norm module is connected to the first residual link module; the output end of the first residual link module is connected to the second residual link module; the output end of the second residual link module is connected to the input end of the DWConv module; the output end of the third residual link module is connected to the fourth residual link module; the output end of the fourth residual link module is connected to the fifth residual link module.

7. The method for constructing a vegetation classification model on the surface of an ancient city wall according to claim 1, characterized in that: In step 2, the ratio is 9:

1.

8. The method for constructing a classification model of vegetation on the surface of an ancient city wall as claimed in claim 1, characterized in that: The preprocessing is data enhancement processing using the MedAugument method.

9. A method for classifying vegetation on the surface of an ancient city wall, characterized in that: The method for constructing a vegetation classification model on the surface of an ancient city wall according to any one of claims 1 to 8 specifically comprises the following steps: Step 1: Collect vegetation images on the surface of the ancient city wall, perform preprocessing and SAM model-assisted annotation on them in turn, and use them as a validation set; Step 2, inputting the verification set collected in step 1 into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 of the ancient city wall surface vegetation classification model construction method to obtain a segmented verification set; The segmented validation set is the plant categories of vegetation on the surface of the ancient city wall; Step 3: Input the segmented validation set obtained in step 2 into the trained Swin based on double-layer routing attention obtained in step 8 of the ancient city wall surface vegetation classification model construction method. Classification is performed in the Transformer classification model to obtain the species category of each plant in each plant category.

10. A vegetation identification and classification system for the surface of an ancient city wall, characterized in that: Based on the ancient city wall surface vegetation classification model construction method described in any one of claims 1 to 8 and the ancient city wall surface vegetation classification method described in claim 9, it includes a first data acquisition module, a model building module, a first model training module, a first processing module, a second data acquisition module, a second model training module and a second processing module; The first data acquisition module is used to obtain an image dataset of vegetation on the surface of the ancient city wall, preprocess the image dataset, and use the SAM model to assist in annotating the preprocessed image dataset, and randomly divide the annotated image dataset into a training set and a test set in proportion; And collect vegetation pictures on the surface of the ancient city wall, pre-process them and annotate them with the SAM model in turn, and use them as a validation set; The model building module is used to build a Yolov8 segmentation model based on attention mechanism and deformable convolution and a Swin Transformer classification model based on double-layer routing attention; The first model training module is used to input the training set into the Yolov8 segmentation model based on the attention mechanism and deformable convolution for training, so as to obtain the trained Yolov8 segmentation model based on the attention mechanism and deformable convolution; The first processing module is used to input the test set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 for segmentation, so as to obtain a test set after segmentation; And, inputting the collected validation set into the trained Yolov8 segmentation model based on attention mechanism and deformable convolution obtained in step 4 of the method for building the ancient city wall surface vegetation classification model, to obtain a segmented validation set; The second data acquisition module is used to obtain the corresponding public plant data set according to the obtained segmented test set; The second model training module is used to input the obtained public plant data set into the constructed Swin Transformer classification model based on double-layer routing attention for training, so as to obtain a trained Swin Transformer classification model based on double-layer routing attention; The second processing module is used to input the obtained segmented verification set into the obtained trained Swin Transformer classification model based on double-layer routing attention for classification, so as to obtain the species category of each plant in each plant category.