# A Defect Detection Method Based on YOLOv7 for Automated Remanufacturing
## 2 YOLOv7 Architecture  
YOLOv7 is the latest improved model of the YOLO series. YOLO models, including YOLOv7, are a type of single-stage framework that contains three main components, named backbone, neck, and head [38; 39; 40; 41; 42; 43; 44], as shown in Figure 1. The backbone extracts feature maps of an image and transfers them to the neck layers. Those maps are combined, fused, and passed to the next layers. Then, the head network predicts the objects' bounding boxesand their classes. Unlike the two-stage models, the YOLO series, a single-stage model, reconsidered the object detection task as a regression problem instead of a classification problem, which is the main feature of real-time detection algorithms [45]. The efficiency of the CNNs in the backbone network is important to enhance the inference process. Thus, the author of YOLOv7 proposed an enhanced method based on an efficient layer aggregation (ELAN) network named Extended-ELAN (E-ELAN). This method improves the ELAN architecture to boost the learning ability of a scaled network without disturbing or changing the original gradient propagation path. E-ELAN has a stronger learning ability for various features. Furthermore, YOLOv7 comes with a new method of scaling for concatenation-based models. The proposed method, named corresponding compound model scaling, addresses the issue of a larger width output of the computational block when depth scaling is performed on the architecture. With the proposed method, the depth of the concatenation-based model is scaled directly; however, the width of transition layers is scaled with a corresponding factor calculated from the change of the output width of the block. Moreover, several techniques have been introduced in the YOLOv7 to improve the model inference accuracy while maintaining a low training cost. Those strategies are called bags of freebies (BoF), including planned re-parameterization and dynamic label assignment. After a deep investigation of the re-parametrized convolution behavior when combined with various networks, the author showed an increase in the model's accuracy when using the RepConv without identity connection (RepConvN). Further, in supervised deep learning techniques, the head that represents the final prediction of the model is called the lead head, whereas the auxiliary head is the head that is used to assist the lead head. Previously, both heads were independent of each other, and their prediction and the ground truth were used as soft labels for label assignment. However, YOLOv7 proposed a new method for lead-dependent label assignment. Two types of label assigners were developed with the YOLOv7. One is lead head guided, where the soft label is mainly generated from the leader's head and ground truth. Another is coarse-to-fine lead head-guided, where two different soft labels are produced, including fine and coarse labels. The fine label is the same as the one generated in the lead head guided assigner; however, the coarse label is generated with relaxed rules on the positive sample assignment process. Figure 1: YOLOv7 architecture design. Other BoF techniques are also adopted and used in YOLOv7, such as batch normalization, implicit knowledge, and the exponential moving average (EMA) model. Normalization of the training batch, by integrating the mean and variance of the data to the bias and weight of the convolutional layer, is proved to directly affect the training process by utilizing a higher training rate and faster convergence [46]. Another technique is the implicit knowledge, adopted from the YOLOR [44], computed as a vector in the inference stage of YOLOv7, improving the prediction accuracy in previous versions. Lastly, adopting the EMA model as the final inference model in YOLOv7 has improved the inference accuracy. YOLOv7 outperforms all existing models in the object detection task in terms of both speed and accuracy [37].