{'fraction_non_alphanumeric': 0.03358270441287941, 'fraction_numerical': 0.014402003757044458, 'mean_word_length': 5.173753814852493, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Construction material classification on imbalanced datasets for construction monitoring automation using Vision Transformer (ViT) architecture

Nowadays, automation is a critical topic due to its significant impacts on the productivity of construction projects. Utilizing automation in this industry brings about great results, such as remarkable improvements in the efficiency, quality, and safety of construction activities. The scope of automation in construction includes a wide range of stages, and monitoring construction projects is no exception. Additionally, it is of great importance in project management since an accurate and timely assessment of project progress enables managers to quickly identify deviations from the schedule and take the required actions at the right time. In this stage, one of the most important tasks is to daily keep track of the project progress, which is very time-consuming and labor-intensive, but automation has facilitated and accelerated this task. It also eliminated or at least decreased the risk of many dangerous tasks. In this way, the first step of construction automation is to detect used materials in a project site automatically. In this paper, a novel deep learning architecture is utilized, called Vision Transformer (ViT), for detecting and classifying construction materials. To evaluate the applicability and performance of the proposed method, it is trained and tested on three large imbalanced datasets, namely Construction Material Library (CML) and Building Material Dataset (BMD), used in the previous papers, as well as a new dataset created by combining them. The achieved results revealed an accuracy of 100 percent in all parameters and also in each material category. It is believed that the proposed method provides a novel and robust tool for detecting and classifying different material types.


Introduction
Efficient and effective progress monitoring practices provide information regarding performance deviations to the execution plan , which help the project management office (PMO) towards timely implementation of control actions to minimize the negative impacts [1,2]. Therefore, project progress monitoring and controlling is one of the most important tasks of construction project management [3,4]. Construction progress monitoring is currently performed mostly manually, in a labor-intensive and error-prone non-automated process [5]. Accurate and efficient tracking, analysis, and visualization of the as-built (actual) status of buildings under construction are critical components of successful project monitoring [6]. The majority of construction management and monitoring processes are still conducted traditionally with the use of 2D drawings, reports, schedules, and photo logs, making the process complicated and inefficient [7]. Automation of construction progress monitoring aids to improve the accuracy of progress monitoring and controlling. For this purpose, different approaches and systems have been used on construction sites including web-based technologies, cloud computing, Building Information Modelling (BIM), photogrammetry, videogrammetry, laser scanner, and material recognition [4,[7][8][9][10][11][12][13].
In the last two decades, advancements in computer processes and digital camera technologies have allowed the construction sector to effectively process and retrieve valuable information from video clips and digital images [1,14]. In the contemporary era, applications of image processing and computer vision techniques like machine learning and deep learning are considered as an intensive area of research with steady growth in the Architecture, Engineering, Construction, and Facilities Management (AEC/FM) industry [14,15]. The core technique of image-based methods focuses on using the visual features of building materials such as color, texture, roughness, and projection [3,[6][7][8] for automatic classification [15][16][17][18][19]. In recent years, advancement in deep learning has enabled researchers to develop robust tools for analyzing images at remarkable accuracies [20]. But, Image classification is still a wellknown machine vision problem [11,[21][22][23][24].
In the current study, we have utilized Vision Transformer (ViT) architecture as a reliable classifier to maximize the accuracy of construction material detection. It must be noted that the variety, quality, and quantity of the employed data for training models have always been the key factors to evaluate the robustness of the implemented architecture, which were fulfilled effectively in this research since all of them were considered though using different imbalanced datasets. In the end, the best result, a 100% accuracy rate, was achieved, which has been unprecedented to get such a result for all of the parameters and also all material classes. As such, Vision Transformer classifier provides a new and promising perspective for automatic building material classification, in support of automated progress monitoring.
In the following, prior studies on material recognition and classification are briefly reviewed. The datasets are introduced in Section 3. Then, the methodology and implementation details are described in Section 4. Section 5 is allocated to the results and discussion representing validation experiments on three building material datasets to validate the accuracy and robustness of the introduced method. Lastly, the conclusion and suggestions for future work are presented (Section 6, 7 respectively).

Background and related work
Currently, there are growing interests and trends in modeling the digital 3D world [25]. In addition, in recent decades, building information modeling (BIM) has become a very popular technology in the civil engineering and asset management industries [26,27]. In the context of project management automation, there have been several attempts to improve the process of scan-to-BIM. Computer vision techniques have been widely applied in construction, from fundamental tasks to high-level applications, promoting automation in construction and yield continuous improvements in safety, quality, and productivity [28]. In terms of an applicationoriented framework for scan-to-BIM, which is proposed by Wang et al., identification of information requirements is the first major step of a scan-to-BIM process since the elements need their respective material information to be recognized [29]. Therefore, automatically identifying construction materials with images from construction sites has attracted a lot of interest in the last two decades. This rising interest is expected from the importance and utility of automation for a wide range of construction applications, from the generation of a 3D as-built model, such as scan-to-BIM process, to automated project monitor and control [17]. In this regard, the related research is reviewed and the results are briefly mentioned. Furthermore, the summary is presented in Table 1.
Building material detection was first proposed by Brilakis et al. (2005) to recover images and identify building elements from two-dimensional images [30,31]. Then, Zhu and Brilakis presented a method of identifying concrete material regions using machine learning techniques [32]. Araújo et al. described a methodology that uses functional machine learning techniques to automatically classify granite at various processing stages based on spectral information captured by a spectrophotometer [33]. Kim et al. proposed an automated color model-based concrete detection method via analyzing the performance of three machine learning algorithms (Gaussian Mixture Modelling (GMM), Artificial Neural Network (ANN) model, and Support Vector Machine (SVM)) [34]. Son et al. introduced the use of a heterogeneous ensemble classifier to improve the detection accuracy of major construction materials such as concrete, steel, and wood on construction sites [17]. Yazdi and Sarafrazi proposed an automated system for the segmentation of concrete images into microstructures using texture analysis via an ANN classifier [35].
Han and Golparvar-Fard presented two methods for sampling and recognizing construction material from image-based point cloud data and inferring progress using a statistical representation from the material classification [30]. Dimitrov and Golparvar-Fard presented a robust material classification method (a multiple one-vs.-all x 2 kernel SVM classifier) for semantically-rich as-built 3D modeling and construction monitoring purposes [18]. Han and Golparvar-Fard presented a new appearance-based material classification method for operation-level monitoring of construction progress using BIM and daily construction photologs [16]. Han et al. introduced an improved appearance-based progress monitoring method by removing occlusion; then, they have used the SVM algorithm to classify materials [36]. Yang et al. proposed an image-based 3D modeling and recognizing its surface materials from images taken from various points of view; in this research, SVM algorithm has been used [37]. Rashidi et al. conducted a comparison study to evaluate the performance of different machine learning techniques (Multilayer Perceptron (MLP), Radial Basis Function (RBF), and SVM) for detection of three common categorists of building materials: Concrete, red brick, and OSB boards [14]. Degol et al. employed 3D geometry features with state-of-the-art material classification 2D features and find that both jointly and independently modeling 3D geometry improve mean classification accuracy [38]. Jiang et al. explored the application of a convolutional neural network (CNN) in classifying and identifying asphalt mixtures using the sectional images obtained from the X-ray computed tomography (CT) method [39]. Lee and Park designed and implemented a system that exhibited improved performance on the detection of reinforcing bars [40]. Bunrit et al. proposed an automatic feature extraction method by a novel CNN in transfer learning technique for construction material image classification task [41]. In another study, Bunrit et al. investigated the transfer learning of GoogleNet and ResNet101 that pre-trained on the ImageNet dataset (source task) with a task specific on construction material images classification [42]. Yuan et al. introduced a terrestrial laser scanner (TLS) data-based method for classifying common building materials in which material reflectance, HSV colors(Hue, Saturation, Value), and surface roughness are used as classification features [15]. Mahami et al. employed a new deep learning technique (VGG16) to detect the type of different construction materials accurately [11].
Utilizing only proprioceptive force data acquired from an autonomous digging system and three machine learning algorithms (KNN(K Nearest Neighbor), ANN, k-means), Fernando and Marshal presented a classification methodology for excavation material identification [43]. Davis et al. designed and described a deep CNN to identify seven typical Construction and Demolition Waste (C&DW) classifications (both single and mixed disposal) using digital images of waste deposited in a construction site bin [44]. Alaloul and Qureshi used an ANN model to classify some construction materials [1]. The literature review indicated that material recognition had been regarded in many studies, but some shortcomings still need to be addressed. Some of the previous studies were restricted to just one specific material [32-35, 39, 40, 43] or at least a limited number of material categories [1,14,17,37,41,42]. Furthermore, some studies employed tiny datasets, that is to say, a few images and sometimes containing just one material category [35]. It must be noted that tiny datasets could lead to biased training since the performance of the trained model can vary for new material from the same class but with a different color or shape [44]. And, results may be affected due to the lack of a sufficient variety of light conditions in the images of the dataset too [14].
Additionally, the accuracy rates resulted from other studies whose datasets were more acceptable, in terms of the number of images and classes of materials, were 90.8% to 97.35% [11,15,16,18,30,36,38]. The biggest challenge of these studies is related to some materials with similar shape and texture. For instance, in an experiment, grass, form work, and brick have been detected with the most accuracy rate due to their unique pattern or texture; nevertheless, soil, cement, and concrete are recognized with much error owing to their similar shapes and textures [18]. In another study, gravel, sand, cement-granular, and asphalt have been problematic in achieving a 100% accuracy rate [11]. Consequently in this research, some of the acceptable datasets of prior studies are utilized to train, test, and validate ViT model as a reliable classifier to maximize the accuracy rate of material recognition; and finally, the comparison among results is presented.

Dataset
In this study, first, two specific datasets, used be previous studies, were utilized for training and evaluating Vision transformer (ViT) model.
The first is the dataset of [11] created by Mahami et al. (henceforth referred to as Building Material Dataset abbreviated to BMD) consisting of 1231 images of various resolutions, captured from different distances, viewpoints, and light conditions. The dataset deals with 11 classes, applied to identify different materials such as asphalt, brick, wood, etc. that can be seen in Table 2. Furthermore, the distribution of data in each class was imbalanced, shown better in Figure 1. The second dataset is the Construction Materials Library (CML) including a wide range of materials and intra-class variability, which was created by Dimitrov and Golparvar-Fard (2014) and improved by Han and Golparvar-Fard (2015), used in [16,18,30,36] for material recognition purposes. The total number of images in the CML is 3266 which have a fixed resolution of 200200 pixels, consisting of 20 classes presented in Table 3. Also, the class distribution is depicted in Figure 2. Moreover, [41,42] employed some parts of the CML too.  In addition, from the combination of these datasets, a new composite dataset is created, including 4497 images and 24 classes of materials, as it is shown in Table 4 and Figure 3. The important characteristic of this dataset is the variety in size and quality of images and also the various class distribution which is interpreted as imbalanced data and leads to a more challenging project as learning from such data is a common problem in classification. In fact, the classification of data with imbalanced class distribution has encountered a significant drawback of the attainable performance by most standard classifier learning algorithms [45]. Moreover, highly imbalanced data poses added difficulty, as most learners will exhibit bias towards the majority class, and in extreme cases, may ignore the minority class altogether [46].
There are samples of images in material classes of BMD and CML datasets represented in Figure 4 and Figure 5, respectively. As can be seen, some materials have a unique pattern, such as brick and form work that makes classification less challenging. While others are of similar appearance properties, like sandstorm, gravel, asphalt, cement-granular, and stone-granular, which leads to a more problematic classification. However, we overcame this challenge.

An important part of deep learning is the use of convolutional neural networks (CNNs).
Many studies in recent years have used famous network architectures like VGG-16 [47], DenseNet [48], GoogleNet [49,50], and EfficientNet [51]. Typically, these networks are composed of convolutional layers and pooling layers, followed by a few fully connected layers. Several studies have suggested that more accuracy can be achieved by using a deeper network. The spatial stream ConvNet was designed taking into account how to balance performance and computation efficiency [52], and was based on the network configuration of the VGG-16 [47] , which worked for the classification of the images and was proven to extract the features of images layer by layer. Although the configuration of the VGG-16 is simple and effective, the large number of parameters (140 million) on fully connected layers is the main problem [47]. However, CNNs come with shortcomings. This is because convolution operates on a fixed-size window. Therefore the model cannot recognize long-range spatial relationships between different parts of the images or between individual images. In addition to using CNNs as a training tool, there are other challenges such as layer pooling which leads to information loss, as well as translation invariance which prevents models from dynamically adapting to changes in the input.
Attention-based architectures like Transformers [53] have been developed into the Natural Language Processing (NLP) domain to optimize various language-related tasks more effectively, such as translations and text classification. Transformers have resulted in significant performance gains, which have caused a great deal of interest in the computer vision community to apply similar self-attentional models to vision tasks. Several computer vision studies have been inspired by the success of self-attention in NLP that incorporate self-attention in CNN-like architectures [54,55]. A few works has used the self-attention mechanism [56,57] as an alternative to the convolution mechanism. Despite their efficiency, these models haven't been able to scale on modern hardware accelerators because they require specialized attention patterns.
The Vision Transformer (ViT) architecture was introduced by Dosovitskiy et al. (2020) [58] for the first time. An attempt is made to design a deep neural network algorithm that does not use convolution operations over large datasets. For this purpose, ViT employs the original transformer which was developed in [53] for NLP tasks with a few changes. The general concept of Vit is to divide the image into patches, then flatten and project them into a Ddimensional embedding space obtaining the so-called patch embedding. In the viewpoint of NLP, a new network will be trained in a supervised learning manner by first treating image patches as tokens (words) and then using them as inputs. Next, it adds positional embedding (a set of learnable vectors allowing the model to retain positional information) and concatenate a (learnable) class token, then let the Transformer encoder do its magic. As opposed to CNNs which function on spatial domain-specific information, transformers work on vectors and require much more and larger datasets to discover knowledge. Finally, a classification head is applied to the class token to obtain the model's logits. The model's performance was acceptable when trained on ImageNet (1M images), great when pre-trained on ImageNet-21k (14M images), and state-of-the-art when pre-trained on Google's internal JFT-300M dataset (300M images) [58].   [53] The main architecture of the transformer encoder comes from [53]. A multiheaded selfattention mechanism is layered on top of different encoder blocks for each block. Prior to being fed into the multi-head self-attention, and also prior to the MLP blocks, layer normalization is applied to the embedded patches. An encoder's general mechanism is illustrated in Figure 6, and Figure 7 provides a general explanation of how encoders, multi-head attention, and scaleddot product attention work.
An important part of deep learning is the use of convolutional neural networks (CNNs). Many studies in recent years have used famous network architectures like VGG-16 [47], DenseNet [48], GoogleNet [49,50], and EfficientNet [51]. Typically, these networks are composed of convolutional layers and pooling layers, followed by a few fully connected layers. Several studies have suggested that more accuracy can be achieved by using a deeper network. The spatial stream ConvNet was designed taking into account how to balance performance and computation efficiency [52], and was based on the network configuration of the VGG-16 [47] , which worked for the classification of the images and was proven to extract the features of images layer by layer. Although the configuration of the VGG-16 is simple and effective, the large number of parameters (140 million) on fully connected layers is the main problem [47]. However, CNNs come with shortcomings. This is because convolution operates on a fixed-size window. Therefore the model cannot recognize long-range spatial relationships between different parts of the images or between individual images. In addition to using CNNs as a training tool, there are other challenges such as layer pooling which leads to information loss, as well as translation invariance which prevents models from dynamically adapting to changes in the input.
Having pre-trained on large amounts of data and transferred to numerous mid-sized or small image recognition benchmarks, ViT achieves great results in comparison with state-of-the-art CNNs while it needs considerably fewer computational resources to train [58].
All in all, how CNNs have been applied to computer vision tasks has been largely driven by advances in GPU technology and modern computational power. In a wide range of applications, consisting of challenging image detection tasks on ImageNet, several architectures have achieved state-of-the-art performance. Although CNNs have many advantages, they have some limitations, namely locality, translation invariance, and max pooling. Vision transformers are able to resolve CNN challenges by addressing an image first as a sequence of patches, and then decoding them as a standard Transformer encoding, in contrast to many earlier tools inspired by NLP based on image analysis. This strategy is confirmed that can perform as well as CNN on natural image classification tasks when it is trained on large datasets.

Pre-processing and data augmentation
Due to the different resolutions of the images, the only pre-processing done is to resize the images to 224224 pixels. However, the data augmentation utilized includes Flip-Left-to-Right (FlipLR), Flip-UP-to-DOWN (FlipUD), translate, random crop, and Randaug [59], which are done during training, then the images are normalized.

Training
We used the basic Vision Transformer model with a size of 1616 patches to extract the features and the weights of the pre-trained model used on the original images. The model is 25 epochs with a learning rate of 0.0003, the Adam [60] optimization function, batch size 8, and the cross-entropy loss function, which have been employed for training. We also took advantage of Google Colab Graphics processing Tesla K8 Unit for training.

Network evaluation
We used four standard performance metrics, described in equation (1)  (1)

Results and Discussion
In this section, we first evaluate the model separately on the datasets used by the various partitions that are intended for the data, and finally we examine the reliability of these partitions by the 5-fold cross-validation method. In the following, we create a new and more challenging situation for the model by combining two datasets, and in this case, the model is evaluated by different data divisions.

Evaluating the BMD and the CML datasets
In order to evaluate the model more accurately, we evaluated the datasets in the most different divisions of the validation test as well as the 5-fold cross-validation mode, which is shown in Table 5 and Figure 9. Fusion matrix on the BMD dataset for: (a) data division (b) 5-fold cross-validation. Table 6. In all these cases, except for one case on two datasets, we obtained an accuracy of 100%. The imbalance in the number of data of datasets, in test phase, can be seen in fusion matrixes in Figure 9 and Figure 10. Finally, the performance of the proposed method has been compared with the existing state-of-the-art methods listed in Figure 10. Fusion matrix on the CML dataset for: (a) data division (b) 5-fold cross-validation. Table 7.     Due to the fact that both datasets used do not have a default partition to evaluate the model used, in order to make a fairer comparison with related work, in Table 5 and Figure 9. Fusion matrix on the BMD dataset for: (a) data division (b) 5-fold cross-validation. Table 6, we evaluated both datasets in different modes of data segmentation. According to the results obtained, our model was able to achieve 100% accuracy in all but one case. Also, for better evaluation, we used the 5-fold cross-validation method in Table 8 to be able to have a more accurate assessment of the model's behavior relative to different parts of the data. By doing this, we can evaluate the generalizability of the model for different partitions of data and in different conditions.

Combining Two Datasets
In this section, in order to evaluate the model in a new way, the two datasets are combined to test the model's performance in a more complex way than a separate evaluation for both data. In this case, the number of classes for material detection increased to 24, and also due to the difference in resolution of the two datasets, the way of photography, and the type of texture of different materials, the model has more challenges to achieve 100% accuracy, which are overcome efficiently. In this case, similarly, the model is evaluated in different modes of dataset segmentation, and also to better evaluate and measure the generalizability of the model performance on different parts of the dataset, the 5-fold cross-validation method is used.
According to the results shown in Table 9, it can be seen that the model has no over-fit on the test dataset, and the model can generalize to the test and validation dataset for different modes. In addition, the model has reached 100% accuracy on the validation and testing data in the case where 80% of the data is for training, 10% for validation, and 10% for testing, which is the best possible result.
However, in other cases where the model could not reach 100% accuracy on the test dataset, we can point to the imbalance in the number of data in each class of two datasets. Therefore, this imbalance can also be seen in the combined dataset too. As such, data division will be a more complex situation. It creates a combination for the distribution of each material and the texture difference in the dataset, making the model unable to achieve 100% accuracy. As a result, we evaluated the model with a Test Time Augment (TTA) method. In this algorithm, the original image and images augmented by training augment are separately given to the model and the max vote is selected as the final result. Consequently, the accuracy of the model increased in all used divisions.
The 5-fold cross-validation method has also been used to evaluate the model in the combination of two datasets. The model achieved 100% accuracy on folds one and two and 97.32%, 99.10%, and 99.10% on folds 3 to 5. However, according to the results of the 5-fold cross-validation method, it can be concluded that the obtained result represented in Table 9 is reliable and is not affected by the random division of data.

Conclusion
Monitoring construction projects according to the as-planned model is one of the most important activities for project managers. IN fact, accurate and timely assessment of project progress enables managers to make the right and immediate decision, when they encounter deviations. In this way, automated progress monitoring helps them a lot to improve the efficiency and accuracy of this process. One of the controversial and essential issues in automated construction management is material recognition and classification. Advancements in artificial intelligence have revolutionized many fields especially construction management through providing state-of-the-art methods.
Regarding the limitations of prior studies, this paper aims to introduce a method for maximizing the accuracy of material detection. In recent years, deep learning has aided material recognition a lot. The recent state-of-the-art Deep Learning Vision Transformer model is employed in this paper as a solution to achieve the highest accuracy rate in material recognition. It is applied on three imbalanced datasets of various material classes with different numbers, sizes, and qualities of images in each class, in order to validate the proposed model. Indeed, we utilized CML and BMD datasets as well as a compound dataset of them, in different data segmentation modes, to evaluate the model. Moreover, various data augmentation including Flip-Left-to-Right (FlipLR), Flip-UP-to-DOWN (FlipUD), translate, random crop, and Randaug were employed in order to solve the problems of data shortage, overfitting, and imbalanced classes so that we could keep the model's generalizability high, in the section of testing data. Taking advantage of evaluation metrics such as accuracy, precision, recall, and f1score revealed that ViT model outperforms the other presented state-of-the-art works with different data segmentation modes. Not only did the ViT model achieve a rate of 100% in all four parameters but it accomplished this accuracy rate in all material categories in three different datasets, which is really unprecedented, since identifying materials with similar shape and texture (such as soil, cement, gravel, sand, concrete, and asphalt) in prior studies has been problematic and challenging.

Future works
The effectiveness of the proposed model should be tested on other material classes which are more challenging, such as glass whose appearance features like reflection and transparency are very different from other construction materials. Future work may also seek to make up a method to be utilized on a broader scope of material detection. For instance, datasets made up of images that represent more than a single material could be considered to introduce a combined material recognition model. As the next step or to do more complementary work, it could also yield the amount of each material in the image. That would greatly help the automation of construction progress monitoring through presenting more detailed functional information.