Complex Texture Contour Feature Extraction of Cracks in Timber Structures of Ancient Architecture Based on YOLO Algorithm

Deep learning has achieved good results in the crack detection of roads and bridges. However, the timber structures of ancient architecture have strong orthotropic anisotropy and complex microscopic structures, and the law of cracks development is extremely complex. e image data has a large proportion of pixels, which is obviously dierent from the background gray value, and there is timber grain noise, thus the existing methods cannot accurately extract the complex texture contour feature of cracks. In previous studies, we have veried that YOLO v5s is eective in crack detection in timber structures of ancient architecture. However, there are many dierent versions of YOLO series models. In order to nd a better algorithm, this paper mainly adopts three models including YOLO v3, YOLO v4s-mish, and YOLO v5s to detect cracks in the timber structures of ancient architecture, and compares and analyzes the advantages and disadvantages of the three models. In the comparing process, we mainly have discussed the index performance of the three models in terms of training time, loss function, recall rate, and mAP value. We have summarized and analyzed the advantages and disadvantages of the three models in cracks detection of the timber structures of ancient architecture, and concluded the comparing results of the three models in cracks detection based on experiments. We published the rst picture data set of cracks in timber structures of ancient architecture, and applied YOLO model in the intelligent identication eld of cracks in timber structures of ancient architecture for the rst time, which opened up a new idea for the intelligent operation and maintenance of the timber structures of ancient architecture.


Introduction
ere are 5,058 key national preservation units of cultural relics in China.2,162 of them are ancient architecture and historical memorial architecture, which account for 42.74% (see Table 1 for details). Type one means revolutionary sites and revolutionary memorial architecture, type two means important historical sites and representative architecture in neoteric and modern times, type three means cave temples, stone carvings, and others, type four means ancient architecture and historical monuments, type ve means ancient sites, and type six means ancient burials. At the same time, timber structures account for a large proportion of existing ancient architecture in our country. Taking Beijing as an example, there are more than 1,700 cultural relics at the national, municipal, and district levels, among which there is more than 1,200 ancient timber architecture, accounting for about 71% [1]. e timber structures of ancient Chinese architecture have been constructed for a long time and have extremely high historical and cultural value. During its long service cycle, various forms of damage have appeared due to the in uence of the natural environment, climate temperature, and human factors. rough our research and investigation, we have found that cracks are the most common form of damage due to the characteristics of biological materials in ancient timber architecture. Almost all structural components such as columns, beams, purlins, and fang will crack to a certain extent [2] (see Figure 1 for details).
e timber structures of ancient Chinese architecture adopt mortise and tenon joints, and the cracks are characterized by large numbers, complicated causes, and great harm. e strong orthotropic anisotropy and complex microstructure of timber lead to extremely complicated development laws of cracks. General cracks will not a ect the safety of the structure, but under the effect of load and environment, after the general cracks further expand into dangerous cracks, they will cause local structural fractures, resulting in the continuous collapse of the overall structure [2]. According to "Technical code for maintenance and strengthening of ancient timber architecture" and "Code for construction and acceptance of in traditional Chinese ancient architecture", the criteria for identifying dangerous cracks are shown in Table 2.
erefore, how to use new theories and new methods to accurately detect and dynamically monitor cracks in timber structures of ancient architecture that is about to reach dangerous crack indicators is a new problem and challenge in the field of timber structure protection of ancient architecture.
Most ancient timber structures in China only use manual inspection to identify and record cracks, and a small number of ancient timber structures have introduced nondestructive testing instruments such as ultrasonic, stress wave, and Provis. e above-mentioned crack detection methods have the following disadvantages: the first is the huge consumption of manpower, material, and financial resources; the second is that there are blind areas that cannot be reached in the detection process; the third is that the error of the detection result is large and it is closely related to the professional level of the inspectors; the fourth is the long detection cycle, which makes it difficult to feed back the structural emergencies, and the detection lacks timeliness.
erefore, seeking a fast, convenient, and easy-to-operate method for detecting cracks in timber structures of ancient architecture, can reduce the risk of collapse of timber structures of ancient architecture and improve the level of the intellectualization, specialization, informatization, and refinement of preventive protection of timber structures of ancient architecture has very important scientific, cultural and social significance.
At present, there are few studies on the detection of cracks in ancient architecture, especially the studies on the detection of cracks in timber structures of ancient architecture. Perumal and Venkatachalam [3] proposed a method based on a multi-layer post feedback LSD (Linear Scale-Space Differentiation) model, to extract crack defects and suppress the noise of timber fiber ditching to the greatest extent. However, the accuracy of crack detection needs to be improved. Enrique García-Macías et al. [4] put forward a new seismic damage identification method for historical masonry structures, which was suitable for the use of computationally efficient metamodels for real-time system identification. Wang [5] proposed a new automatic damage detection technology that used the Faster R-CNN model based on the ResNet101 framework to detect two types of damage (weathering and spalling) to historic masonry structures. Dohyung Kwon [6] put forward a system that used deep learning technology to automatically detect and classify damaged cultural relics. M.Cabaleiro [7] proposed an automatic detection algorithm that used LiDAR to collect cracks in timber beams, which could identify, analyze and monitor cracks and their geometric characteristics. ese methods are difficult to directly apply to the detection of Table 1: Key national preservation units of cultural relics.

Date
Batch number  Type one  Type two  Type three  Type four  Type five  Type six  Total  1961.03.04  One  33  -25  77  26  19  180  1982.02.23  Two  10  -7  28  10  7  62  1988.01.13  ree  41  -28  111  49  29  258  1996.11.20  Four  -50  12  110  56  22  250  2001.06.25  Five  -40  36  248  144  50  518  2006.05.25  Six  -206  64  513  220  77  1080  2013.05.03  Seven  -329  117  795  516  186  1943  2019.10.16  Eight  -234  51  280  167  30  762  Sum  84  859  340  2162 1188 420 5058 timber structure cracks in ancient architecture. e main reason is that the existing research objects are mostly nontimber materials such as concrete, masonry, and steel. e pixels of these structural crack images are relatively small and overlap with the background gray value, but it is different from the background and the shape of the noise. e cracks in the timber structure of the ancient architecture have a large percentage of pixels, the gray value of the background is obviously different, and the timber grain noise exists. erefore, these methods cannot be directly used in the crack detection of ancient timber architecture.
In recent years, deep learning theory, as the latest research result in the field of pattern recognition and machine learning, with its powerful modeling and representation capabilities, is gradually sweeping across the entire graphics research field, especially in tunnels, bridges, pavements, and concrete structures in our country. Phased results have been achieved in crack detection. Armi [8] elaborated on texture image analysis and texture classification, laying a foundation for this study. Pourkaramdel [9] have achieved good results in visual defect detection by using completed local quartet patterns and a majority decision algorithm.
In terms of tunnel and bridge crack detection: Aslam Y [10] proposed a new crack extraction algorithm, which used multi-layer features extracted from a full convolutional network and a naive Bayesian data fusion (NB-FCN) model to automatically split cracks and noise. Belloni et al. [11] combined advanced deep learning technology and innovative photogrammetric algorithms to develop a monitoring system that could effectively detect cracks in invisible images. Based on concrete crack image processing technology, Wang [12] put forward an image preprocessing scheme combining multiple adaptive filtering and contrast enhancement, which could improve the effect of removing background noise and obtaining information on the characteristics of veins and microcracks.
In terms of pavement crack detection: Ji [13] proposed an integrated method for crack detection based on Convolutional Neural Network DeepLabv3+, which was more effective and accurate in crack detection and quantification. Peng [14] proposed a three-threshold pavement crack detection method using random structure forest, which used channel features and paired difference features to enrich the patch information that constituted the crack image. Song [15] put forward a crack detection network, which could effectively detect crack information in complex environments. Based on a deep learning method, I A Kanaeva [16] used the generated training data to segment the cracks in the driver's view image. Zhang [17,18] optimized and improved the CrackNet crack monitoring software, and the results showed that the accuracy, recall rate, and F-measure were superior to traditional detection methods.
In the aspect of concrete structure crack detection: Wang et al. [19] proposed a method for quantitative classification of cracks of different severity based on deep convolutional neural networks, which used the orthogonal projection method to pre-process the training data, which had good robustness and adaptability to noise and light intensity. Zhao [20] put forward a detection system to investigate possible crack development problems under different construction conditions, which could evaluate the crack behavior in largescale concrete infrastructure. Qiao [21] proposed a concrete structure crack identification method based on an improved U-Net convolutional neural network to improve the accuracy of crack identification. Song Ee Park [22] used deep learning technology and structured light technology composed of vision and two laser sensors to detect and quantify cracks on the surface of concrete structures. Diana Andrushia [23] proposed a method to detect thermal cracks using ripple transformation, and the main components were noise removal, image enhancement, crack detection and crack geometric parameter detection. Zheng [24] established a fully convolutional network crack detection model, which provided strong theoretical support and practical value for the detection and research of concrete surface cracks. Wu [25] was based on Rayleigh's distributed optical fiber sensing technology to measure the evolution of the strain field related to the initiation and propagation of cracks in concrete structures. Gökhan Bayar [26] used the machine learning algorithm of Tyson polygons to study the crack pattern and propagation of random concrete surfaces. F. Panella [27] combined deep learning and traditional image processing to establish a tool that could detect, locate and measure structural defects. Hyunjun Kim [28] proposed a crack recognition strategy that combined hybrid image processing with UAV technology. Yu [29] proposed a novel method Greater than or equal to 1/3 of the beam length Greater than 10mm Beam crack 2 Greater than or equal to 1/3 of beam height Greater than 10mm Column crack Greater than or equal to 1/3 the column length Greater than 10mm Advances in Civil Engineering 3 based on deep convolutional neural networks to identify and localize damages of building structures equipped with smart control devices, this method is capable of automatically extracting high-level features from raw signals or low-level features and optimally selecting the combination of extracted features via a multi-layer fusion to satisfy any damage identification objective. After that, Yu et al. [30] achieved good results in the crack detection of concrete structures by using deep convolutional neural networks optimized by an enhanced chicken swarm algorithm. It can be inferred from this that the exploration and application of deep learning in the crack detection in timber structures of ancient architecture is an important development trend in solving the difficulties. YOLO (You Only Look Once) is the first single-stage target detection algorithm that has achieved good results in detection accuracy and detection speed. It has been successfully applied in agriculture [31,32], geology [33], remote sensing [34,35] and medicine [36], and other fields. In addition, it is also widely used in the field of transportation, such as traffic sign detection [37], traffic flow detection [38], pavement pit detection [39], and visual crack detection [40]. At the same time, in our published paper "Research on Crack Detection Method of Wooden Ancient Building Based on YOLO v5" [41], we verified that YOLO v5s was feasible for crack detection in ancient architecture.
Currently, YOLO v3 is one of the most popular singlestage detection methods, achieving a huge balance between detection speed and detection accuracy. Recently, the YOLO series has been updated, including three new versions, namely YOLO v4, YOLO v5, and YOLO X. Among them, YOLO v3, YOLO v4, and YOLO v5 are widely used and have good effects in various fields. erefore, this article will use these three models to study the crack detection effect of ancient architecture timber structures, and from the loss function (Box), loss average (Obj), precision (P), recall rate (R), F1 score, average precision (MAP), frames per second (FPS), inference time (Inference time) and weight (Weight) and other quantitative indicators for performance comparison and analysis. e conclusion of this paper will provide a reference for the selection of cracks detection methods for timber structures of ancient architecture.

Data Collection and Processing
Since there is currently no publicly published dataset of cracks in timber structures of ancient architecture in domestic research, to achieve the goal of the research, this paper has taken the Bawang Academy (founded in 1415) on the campus of Shen-yang Jianzhu University as the research object, collected 474 pictures, and established a dataset of cracks in timber structures of ancient architecture. We have published this dataset publicly at https://github.com/WangMissYou/MaDataSet, called MaDataSet, which contains both original and annotated images. Some selected samples are shown in Figure 2.

Subsection.
e selection, labeling, and data information generation of the pictures have continued to follow the author's thoughts and practices in the previous academic paper "Research on Crack Detection Method of Wooden Ancient Building Based on YOLO v5" [38] and selected the same batch of pictures of ancient architecture timber structure cracks. To show the forms of being of different types of cracks, a labeling information table of the same crack is generated.
(1) Picture Selection and Crack Marking. In this section, we select data with certain characteristics to illustrate the characteristics of cracks. is part has been published in the paper "Research on Crack Detection Method of Wooden Ancient Building Based on YOLO v5" [38]. On account of the same pictures being used, we have quoted the description of the picture in that paper accordingly. It can be seen from Figure 3(a) that the surface of the ancient architecture's timber structure is rough, there is bark interference, and the cracks are not obvious. Such cracks need to show more obvious characteristics when marking, and the cracks interfered with by bark are not marked; Figure 3(b) shows that the surface of the timber structure of ancient architecture is relatively smooth, and there is local weathering, and the characteristics of cracks are obvious. At the same time, the spacing of some cracks is small. When such cracks are marked, the cracks with smaller spacing can be combined and marked separately. Separate cracks are marked separately; as can be seen from Figure 3(c), the surface of the timber structure of ancient architecture with paint is relatively smooth, with obvious crack features, a large number of cracks, and a short length. Such visible cracks need to be marked clearly all one by one; as can be seen from Figure 3(d), the surface of the timber structure of the ancient architecture is relatively smooth, and the characteristics of the cracks are obvious. After manual identification, it is found that there is wood grain, only cracks are marked, and wood grain is not marked; as can be seen from Figure 3(e), the surface of the timber structure of ancient architecture is relatively rough, with peeling and different colors, and there are also small cracks in the peeling part. After manual identification, it is sure that it is not a timber structure crack. When such cracks are marked, you can select the representative cracks with obvious characteristics from the clear and fuzzy cracks to mark, and the cracks caused by the peeling are not marked; from Figure 3(f ), it can be seen that the paint on the surface of the ancient architecture's timber structure has peeled off, and the cracks are clearly distributed. e length of the cracks is different, all such cracks can be marked when marking; from Figure 3(g), it can be seen that the surface of the ancient architecture timber structure is smooth, the cracks contrast sharply, and there are particularly obvious and regular wide and narrow cracks. Similar cracks can be marked directly when marking; as can be seen from Figure 3(h), the surface of the ancient architecture timber structure is smooth, the number of cracks is small, and the characteristics of the length of the cracks are obvious. Such cracks can be marked with one long crack and one short crack respectively. In the case of a large number of cracks, you can mark a few more as appropriate. As can be seen from Figure 3(i), the surface of the timber structure of the ancient architecture is rough, the timber structure is weathered and corroded, the log body is clearly visible, and the number of cracks is large. e spacing is small and such cracks can be combined and marked according to the concentrated area of the crack density when marking, and the timber grain of the log itself is not processed.
(2) Generate Data Information. File After the crack pictures are marked, save it, and use the label software LabelImg system to generate a txt file of the crack pictures marking information, including the number and location of the crack marks, and name it "crack", as shown in Table 3.

Model Validation.
YOLO is a new target detection method, which is characterized by fast detection and high accuracy. Base YOLO model processes images in real-time at 45 frames per second. e YOLO networks have 24 convolutional layers followed by 2 fully connected layers. Alternating 1x1 convolutional layers reduce the feature space from preceding layers. YOLO can pretrain the convolutional layers on the ImageNet classification task at half the resolution (224 × 224 input image ) and then double the resolution for detection. e basic network structure is shown in Figure 4 [42].
Many YOLO versions have been produced after years of research. YOLO v3 algorithm includes three models: YOLO v3, YOLO v3-tiny, and YOLO v3-SPP; YOLO v4 algorithm includes four models: YOLO v4s-mish, YOLO v4m-mish, YOLO v4l-mish, and YOLO v4x-mish; YOLO v5 algorithm includes four models: YOLO v5n, YOLO v5s, YOLO v5l, and YOLO v5x. is paper selects the YOLO v3, YOLO v4s-mish, and YOLO v5s models for research. e main reasons are: first, the three models can generate test results graphs with the same indicators, which is convenient for comparison and analysis; second, the three models are lightweight, suitable for target detection in small scenes and small and medium data sets; third, the three models are based on the PyTorch deep learning framework developed by Facebook, and have good results in simple target detection.

Figures, Tables, and Schemes.
is test uses a Dell laptop, the model is G15 5511-R1866B2021, the system configuration is GeForce RTX3060, the CPU model is 17-11800H, and the internal memory is 16G, the operating system is Win-dows10, the development platform uses pycharm, and the programming language is Python. Based on the PyTorch deep learning framework developed by Facebook, a series of models of the YOLO algorithm are trained using the established COCO data set.  Advances in Civil Engineering

Training Program.
is test has selected 6608 cracks from 474 pictures of "Wang Ba Academy" as training samples and uses YOLO v3, YOLO v4s-mish, and YOLO v5s models for training to detect the cracks in the pictures, the total number of training rounds for each model is 450 rounds. Hyperparameters setting refers to the research results of Al-qudah and Suen [43], this work involves four steps: training, testing, model selection, and deployment. For the first step, the training phase is paired with a "models generator" component that can generate n-different models by optimizing the network hyperparameters based on various factors such as available processing power, batch size, and available images in the dataset. erefore, this step will yield n-trained models instead of just one trained model. To test the robustness of each trained model, the testing phase is associated with a "testing configurator" that generates all possible testing configurations based on the optimized hyperparameters from the training phase. Each trained model is tested against all possible configurations. e model selector then selects the best model based on the recall ratio. Finally, the system is deployed for usage in real applications. For the deployment of the real application, the system can employ an estimation component that can match the system with the best model that best fits the system's requirements which might not be the one with the highest recall ratio. According to the actual needs of the test, this paper defines the data set file as a "crack. yaml" and uses a single GPU to accelerate training.

Precision and Recall.
In target detection, accuracy and recall are typical and important evaluation indicators. Accuracy represents the ratio of the number of pairs found to all the numbers found, and it measures the probability of a positive class classified by a classifier. e recall rate represents the ratio of the positive class that should be found to all the positive classes that should have been found, and it measures the ability of a class to find all the positive classes. e calculation formulas of precision and recall rate are shown in formula 1 and formula 2: In the formula: P is the precision; R is the recall rate; TP is the number of positive samples that are identified as containing cracks; FP is the number of negative samples that are identified without cracks; FN is the number of positive samples that are not identified as containing cracks number of samples.

AP Value and F1
Score. When the detection target is identified, the index of inspection accuracy is represented by mAP, which represents the average value of multiple categories of AP. Because the test sample has only one type of cracks in the timber structure of ancient architecture, AP can be directly used as an evaluation index for crack detection. AP represents the pros and cons of the model's detection effect. e larger the value is, the better the detection result is. According to recall and precision to make a curve, the area under the curve is AP, and the AP value is the integration of the area. e specific formula is shown in the following formula: F1 score is generally used to evaluate the comprehensive performance of the model, and its calculation formula is shown in the following formula:

Box, Objectness, and Classification.
Box represents the loss of using GIoU Loss as the bounding box. e box is inferred to be the mean value of the GIoU loss function. e smaller the value is, the more accurate the detected box is. Val Box represents the bounding box loss of the validation set.
Object-ness means that it is presumed to be the average value of target detection loss. e smaller the value is, the more accurate the target detection is. Val Objectness represents the average value of the target detection loss in the validation set. Classification indicates that it is estimated to be the average value of the classification loss. e smaller the value is, the more accurate the classification is. Val Classification represents the mean value of the classification loss of the validation set.

FPS and Training
Time. FPS is a related concept in the image field, which represents the number of image frames transmitted per second during the training process. When the FPS value of the model exceeds 30, it is proved that the model can realize real-time image processing. e training time is the total time used to complete the picture training. Both of these indicators are evaluation indicators that consider the speed of model training images.

Model Training Results.
In this paper, three models including YOLO v3, YOLO v4s-mish, and YOLO v5s are used to train the cracks in the timber structure of ancient architecture, and the numerical results of related indicators are obtained. Among them, the loss function of the YOLO v3 model is 0.026, the recall rate is 91.64%, and the mAP value is 0.955, which is better than the YOLO v4smish and YOLO v5s models. e minimum accuracy of the YOLO v4s-mish model is 60%, the maximum loss function is 0.042, and the minimum F1 value is 0.717, indicating that its comprehensive performance is relatively poor. e loss function of the YOLO v5s model is 0.037, the F1 value is 0.914, which is between YOLO v3 and Advances in Civil Engineering YOLO v4s-mish, the accuracy is up to 92.91%, and the mAP value is 0.929, showing a good overall performance. e training results of the three models are shown in Table 4

Analysis of Training Results.
e above chart information is refined and summarized, and evaluation indexes such as FPS, inference time, total runtime, and weight are added at the same time to form the evaluation index table       required for the performance comparison of the models in this paper, as shown in Table 7. Table 7 summarizes the training results of the three models including YOLO v3, YOLO v4s-mish, and YOLO v5s. It can be seen that most of the evaluation indicators of the YOLO v3 model are effective, but the maximum weight is 118MB, the minimum FPS value is 71.43, and the longest inference time is 21ms, indicating that the greater the weight of the model is, the better the effect of the related evaluation indicators is. However, due to the complex network structure, the inference time will be prolonged. e YOLO v4s-mish model is improved based on the original YOLO v4 model. Its weight is 18MB and the network structure is relatively simple. But from the evaluation index value, the overall performance is poor and there is no significant advantage in training speed. e minimum weight of the YOLO v5s model is only 14MB, which is the simplest network structure among the three models. e maximum FPS value is 166.67, and the minimum inference time is 8.1ms. is shows that the training speed of this model is the fastest compared to the other two models. of. It can be seen from the above analysis that the YOLO v5s model has a better overall performance considering the accuracy, training speed, and network structure complexity.

Research Conclusion.
Based on the author's previous research, this paper continues to explore the application performance of the YOLO series models in the detection of cracks in ancient architecture timber structures and compares the training and testing effects of YOLO v3, YOLO v4s-mish, and YOLO v5s. e results are obtained as follows: (1) e loss function of the YOLO v3 model is 0.026, the recall rate is 91.64%, and the mAP value is 0.955, which are better than the YOLO v4s-mish and YOLO v5s models, but the maximum weight is 118MB, the minimum FPS value is 71.43, and the maximum inference time is 21ms, indicating that the model has good overall performance, but the training speed is slow. (2) e YOLO v4s-mish model is improved based on the original YOLO v4 model, its weight is 18MB, and the network structure is relatively simple. However, the minimum accuracy of this model is 60%, the maximum loss function is 0.042, and the minimum F1 value is 0.717, indicating that its comprehensive performance is relatively poor. At the same time, there is no obvious advantage in detection speed. (3) e loss function of the YOLO v5s model is 0.037, the F1 value is 0.914, which are both between YOLO v3 and YOLO v4s-mish, the accuracy is up to 92.91%, and the mAP value is 0.929, showing a good comprehensive performance. At the same time, the minimum weight of this model is only 14MB, which is the simplest network structure among the three models. e maximum FPS value is 166.67, and the minimum inference time is 8.1ms, which shows that the training speed of this model is the fastest compared to the other two models. (4) e confidence of the YOLO v3 model is 0.82, the confidence of the YOLO v4s-mish model is 0.89, and the confidence of the YOLO v5s model is 0.85. e confidence of the three models is above 0.8, indicating that the three models have better test results.

Future Research Directions.
e author's research on the detection of cracks in the timber structures of ancient architecture is in its infancy, and the next step of the research work will continue to strengthen in the following aspects: (1) Use advanced technology such as drone tilt photogrammetry to obtain images of cracks in timber structures of ancient architecture, continuously expand data sets, strengthen image screening and processing, obtain more effective data sets, and improve crack detection accuracy. (2) Establish a deep learning-based detection, positioning, measurement, and analysis integrated ancient architecture timber structure crack monitoring system to realize dynamic monitoring of crack development trends. (3) U-Net, Mask R-CNN, and other models have also achieved good results in the field of image recognition. Comparing the training results of the YOLO series model with these two models will help to find out more suitable methods for the crack detection of ancient architecture timber structures.
Data Availability e data presented in this study are available on request from the corresponding author.
Disclosure e funders had no role in the design of the study; in the collection, analysis, or interpretation of data; in the writing of the manuscript, or in the decision to publish the results.

Conflicts of Interest
e authors declare no conflicts of interest.