Method for detecting surface defects of defective prefabricated French fries

CN118537318APending Publication Date: 2024-08-23TIANJIN UNIV OF SCI & TECH +1

Patent Information

Application Number
CN202410676049.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

In the existing technology, appearance defect detection on the prefabricated French fries production line mainly relies on manual labor, which is highly subjective, high cost, low detection efficiency, and low accuracy. It is easy to miss detection and misdetection, affecting product quality and production efficiency.

Method used

Using the improved YOLOv8n model, by introducing the EMCA lightweight and efficient channel attention mechanism and AKConv variable kernel convolution, combined with the WIOU loss function, the EAW-YOLOv8n model is constructed to automatically detect defective premade French fries.

Benefits of technology

It improves the detection accuracy and recall rate, reduces the problems of missed detection and false detection caused by manual factors, reduces the cost, improves the detection efficiency and automation level, and ensures the safety of food.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118537318A
    Figure CN118537318A
Patent Text Reader

Abstract

The invention belongs to the technical field of visual inspection, and particularly relates to a prefabricated French fries defective product surface defect detection method, which comprises the following steps: shooting an image in a built image acquisition environment; and carrying out data annotation on the shot image. Then the data sets are distributed according to the proportion of 8: 1: 1, and a training set, a verification set and a test set are divided; the method comprises the following steps of: firstly, carrying out a Yov8n model improvement, running the system to carry out model training, and finally, carrying out performance evaluation on the trained model, embedding the model into prefabricated potato chip defective product defect detection software to start detection after the evaluation is completed, and displaying the types and the quantity of potato chip defective product defects on a detection interface. According to the method, the accuracy and speed of defect detection of the defective prefabricated chips are improved, and the problems of missing detection and false detection caused by human factors are greatly avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of visual inspection, and in particular relates to a method for detecting surface defects of defective prefabricated French fries. Background Art

[0002] Prefabricated French fries are a kind of prefabricated food that is frozen after being pre-fried. The annual demand is large and the social demand is high. Its production goes through the processes of washing, peeling, cutting, blanching, draining, frying, freezing and bagging potatoes. During the production process, due to the quality problems of the potato raw materials themselves and the process problems during the processing, prefabricated French fries will have various types of appearance defects such as brown spots, mildew, black spots, green spots, etc. Prefabricated French fries with these defects will not only affect the product quality but also affect the health of consumers. At present, the inspection of products with appearance defects on the production line of prefabricated French fries is mainly based on manual screening. Manual inspection is highly subjective and will be affected by personal emotions, fatigue, light and other conditions. It has high cost, low inspection efficiency, inconsistent inspection standards, low degree of automation, low accuracy of inspection results, and is prone to missed inspections and false inspections, which reduces the quality of the product and restricts the efficiency of production. Summary of the invention

[0003] The purpose of the present invention is to provide a method for detecting surface defects of defective prefabricated French fries to solve the problems existing in the prior art.

[0004] To achieve the above object, the present invention provides the following technical solution: a method for detecting surface defects of defective prefabricated French fries, comprising the following steps:

[0005] S01, photographing images of appearance defects of defective prefabricated French fries;

[0006] S02, self-made data set, using the image annotation software labelimg to annotate the acquired images with defects, the annotation information includes defect category and coordinates, and the annotated label files and images are processed, and divided into training set, validation set and test set according to the proportion;

[0007] S03. Based on the YOLOv8n original network, the EMCA lightweight and efficient channel attention mechanism is introduced into the SPPF module in the Backbone network to build the SPPF-EMCA module;

[0008] S04, introduce AKConv variable kernel convolution into the fifteenth layer C2f module of Neck network to construct C2f_AKConv module;

[0009] S05, replace the WIOU loss function with the original CIOU loss function to perform back propagation to update the parameters of the model and improve the loss function;

[0010] S06. Use the training set to train the improved Yolov8n model EAW-Yolov8n based on S03, S04, and S05 to obtain the training loss results and model training weights;

[0011] S07. Use the test set to evaluate the performance of the improved defect detection model. The performance of the model is evaluated by precision (P), recall (R), mAP50, and inference time of each image. The evaluated model is applied to defect detection of defective prefabricated French fries.

[0012] Preferably, in S3, the EMCA attention mechanism is specifically implemented as follows:

[0013] First, the dimension is compressed from H×W×C to 1×1×C by performing global average pooling and global maximum pooling operations on the input feature map, and then the global average pooling result and the global maximum pooling result are added together;

[0014] Then the adaptive one-dimensional convolution kernel size k is calculated. Given the channel dimension C, the convolution kernel size k can be adaptively calculated as:

[0015]

[0016] Where |t|odd represents the odd number closest to t; set γ = 2 and b = 1; it can be seen from the formula that the value of k is adaptively determined by the nonlinear mapping of the channel size, and the higher the dimension, the longer the range of interaction;

[0017] Then, the k value obtained by adaptive calculation is used in the one-dimensional convolution kernel, the feature map obtained by adding the above is subjected to a one-dimensional convolution operation with a convolution kernel size of k, and the weight ω for each channel of the feature map is obtained through the Sigmoid activation function. The calculation formula of ω is as follows

[0018] ω=Sigmoid(C1D k (x))

[0019] Where C1D represents one-dimensional convolution, and x represents the input channel;

[0020] Finally, the normalized weights and the initial input feature map are multiplied channel by channel to generate a weighted feature map.

[0021] Preferably, in S4, AKConv can efficiently extract features from convolution kernels of irregular and arbitrary sampling shapes, and can adapt to defect targets of different shapes in the data set;

[0022] The specific implementation steps of AKConv are as follows:

[0023] First, the initial sampling shape of the convolution kernel is given according to the input feature map. For convolution kernels of different sizes and shapes, the coordinate generation algorithm dynamically generates the initial sampling coordinates. Then, Conv2d is used to perform the convolution operation on the input feature map. After the convolution operation, AKConv will learn the most effective offset for specific feature maps and defect targets through the network according to the characteristics of the defects to dynamically adjust the sampling position of the irregular convolution kernel, more accurately align and extract the key features in the feature map, and dynamically adjust the initial sampling convolution kernel shape when processing different defects, so that the convolution kernel can more accurately cover and extract different defect targets in the feature map, thereby improving the accuracy of feature extraction. Then, the feature map is resampled according to the adjusted sampling shape. The resampled feature map is reshaped, convolved again, and standardized, and then the final result is output through the activation function SiLU.

[0024] Preferably, in S5, WIOUv1 constructs distance attention based on the distance metric, with two layers of attention:

[0025] L WIOUv1 =R WIoU L IOU

[0026]

[0027] Where R WIoU ∈[1, e) represents the high-quality anchor box loss, L IOU ∈[0, 1] represents the IoU loss. These two parameters will weaken the loss of high-quality anchor boxes while increasing the loss of ordinary-quality anchor boxes, and increase the attention paid to the distance between the center points of the anchor boxes and the real boxes when they overlap well. In order to prevent R WIoU Produce gradients that hinder convergence. The superscript * indicates that W g and H g Separating it from the calculation can effectively prevent the model from not converging.

[0028] In order to make the model more focused on difficult samples on the basis of WIOUv1, the contribution of simple examples to the loss value is effectively reduced, thereby improving the classification performance. and L IOU The mean of the loss constructs WIOUv2, and the formula is defined as follows:

[0029]

[0030] Among them is the sliding average of momentum m, and the normalization factor is dynamically updated to make the gradient gain The overall level is maintained at a high level, which helps the model converge faster in the later stages of training.

[0031] Preferably, it is characterized in that: in S6, EAW-Yolov8n is mainly composed of four parts: input end (Input), backbone network (Backbone), neck network (Neck), and head network (Head).

[0032] Preferably, in S7, the performance of the model is measured by precision (P), recall (R), mAP, and inference time per image to measure the accuracy and detection speed of the model, and the calculation formula is as follows:

[0033]

[0034]

[0035]

[0036] Where TP represents the number of correctly detected positive samples, FP represents the number of incorrectly detected positive samples, FN represents the number of incorrectly detected negative samples, nc is the number of detection categories, and k = 1, 2, …, nc.

[0037] The beneficial effects of the present invention are as follows: the present invention improves the original YOLOv8n model, introduces the EMCA efficient and lightweight channel attention mechanism into the original SPPE module in the YOLOv8n model structure, enhances the global perspective information of the features and features of different scales, adjusts the weights of the channel features, suppresses unimportant channel features, and enables the model to better focus on important channel features, improves the performance and generalization ability of the network, and improves the detection accuracy and recall rate of the model. The AKConv variable kernel convolution is introduced into the C2f module in the fifteenth layer of the small eye detection layer in the neck network, so that the convolution operation can achieve more accurate feature extraction for defects of various shapes and sizes and defects in different positions in the image, thereby improving the accuracy and efficiency of feature extraction. The CIOU loss function in the original Yolov8n is replaced by the WIOU loss function, which better solves the problem of sample imbalance and improves the convergence speed and accuracy of the model.

[0038] The present invention uses the improved EAW-YOLOv8n model to detect the defects of prefabricated French fries, which greatly improves the detection accuracy while ensuring the inference speed. The model inference time is 1.8ms, the mAP value is 94.0%, and the defective product detection accuracy is 99.5%. This method improves the accuracy and speed of defect detection for prefabricated French fries, greatly avoids the problems of missed detection and false detection caused by human factors, greatly reduces labor costs, improves product detection efficiency and automation, improves food safety, and protects the health of consumers. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1is a flow chart of the present invention;

[0040] Figure 2 It is a visualization diagram of the loss function in the present invention;

[0041] Figure 3 This is the EAW-YOLOv8n network architecture diagram in the present invention;

[0042] Figure 4 It is a rendering of the detection part of the present invention. DETAILED DESCRIPTION

[0043] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0044] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. In addition, the terms "first", "second", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0045] In the description of the invention, it should be noted that, unless otherwise clearly specified and limited, the terms "install", "connect", "connect", "fixed connection" and "fixed connection" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the invention can be understood according to specific circumstances.

[0046] The specific implementation of the present invention is described in detail below with reference to the accompanying drawings and preferred embodiments.

[0047] like Figure 1 As shown, a method for detecting surface defects of defective prefabricated French fries comprises the following steps:

[0048] S01. Capture images of appearance defects of defective pre-made French fries. The main idea is to build a detection environment, such as setting the shooting background, lighting conditions, etc., and capture images.

[0049] S02, self-made data set, the acquired images are annotated with defects using the image annotation software labelimg. The annotation information contained includes defect category and coordinates. The annotated label files and images are processed and divided into training set, validation set and test set in the ratio of 8:1:1.

[0050] S03. Based on the YOLOv8n original network, the EMCA lightweight and efficient channel attention mechanism is introduced into the SPPF module in the Backbone network to build the SPPF-EMCA module;

[0051] S04, introduce AKConv variable kernel convolution into the fifteenth layer C2f module of Neck network to construct C2f_AKConv module;

[0052] S05. Replace the original CIOU loss function with the WIOU loss function to improve the network.

[0053] S06. Use the training set to train the improved Yolov8n model EAW-Yolov8n based on S03, S04, and S05 to obtain the training loss results and model training weights;

[0054] S07. Use the test set to evaluate the performance of the improved defect detection model. The performance of the model is evaluated by precision (P), recall (R), mAP50, and reasoning time per image. The evaluated model is applied to defect detection of frozen pre-made French fries.

[0055] For further optimization, the step S03 is specifically as follows:

[0056] During target detection, as the number of layers of the model becomes deeper, the resolution of the feature image will become smaller and the number of channels will increase. Low-resolution feature maps have a large amount of channel information. At this time, it is difficult for the model to distinguish which channel information is important from a large amount of channel information. The channel attention mechanism can enable the model to pay more attention to the feature information of important channels, thereby improving the performance of the model. Efficient Channel Attention (ECA) is a typical representative of the channel attention mechanism. The present invention adds a lightweight and efficient channel attention mechanism EMCA to the SPPF module in the Backbone network of YOLOv8n to construct an SPPF-EMCA module.

[0057] The EMCA attention mechanism is modified from the ECA attention mechanism. At the channel input end of the ECA structure, the input is subjected to global average pooling (AdaptiveAvgPool2d) and global maximum pooling (AdaptiveMaxPool2d), and then the addition operation is performed to enhance the global perspective information of the features and features of different scales. The improved ECA attention mechanism is called the EMCA attention mechanism.

[0058] The EMCA attention mechanism uses a 1×1 convolutional layer directly after the global average pooling layer and the global maximum pooling layer, removing the fully connected layer. With very little additional computational cost, it efficiently implements local cross-channel interactions and extracts the dependencies between channels. The size of the convolution kernel k of the 1×1 convolutional layer is adaptively determined by a function, and the kernel size k represents the coverage of local cross-channel interactions, that is, how many neighbors participate in the attention prediction of a channel.

[0059] The specific implementation of the EMCA attention mechanism is as follows:

[0060] First, the dimension is compressed from H×W×C to 1×1×C by performing global average pooling and global maximum pooling operations on the input feature map, and then the global average pooling results and the global maximum pooling results are added.

[0061] Then the adaptive one-dimensional convolution kernel size k is calculated. Given the channel dimension C, the convolution kernel size k can be adaptively calculated as:

[0062]

[0063] where |t| odd Represents the odd number closest to t; set γ = 2 and b = 1; it can be seen from the formula that the size of the k value is adaptively determined by the nonlinear mapping of the channel size, and the higher the dimension, the longer the range of interaction.

[0064] Then, the k value obtained by adaptive calculation is used in the one-dimensional convolution kernel, the feature map obtained by adding the above is subjected to a one-dimensional convolution operation with a convolution kernel size of k, and the weight ω for each channel of the feature map is obtained through the Sigmoid activation function. The calculation formula of ω is as follows

[0065] ω=Sigmoid(C1D k (x)

[0066] Where C1D represents one-dimensional convolution, and x represents the input channel;

[0067] Finally, the normalized weights and the initial input feature map are multiplied channel by channel to generate a weighted feature map.

[0068] By introducing the EMCA attention machine, the weights of channel features can be adaptively adjusted to suppress unimportant channel features, so that the network can better focus on important channel features and improve the performance and generalization ability of the network. Therefore, the EMCA attention mechanism effectively enhances the representation ability of the network without increasing too many parameters and computational costs, thereby improving detection accuracy and recall rate.

[0069] For further optimization, the step S04 is specifically as follows:

[0070] Since small target defects account for a high proportion of defect targets in the detection samples, and the defects have irregular shapes and non-fixed sizes, the present invention introduces AKConv variable kernel convolution in the C2f module in the fifteenth layer of the Neck network of YOLOv8n to construct the C2f_AKConv module. AKConv can give the convolution kernel any number of parameters (such as 1, 2, 3, 4, 5, 6, 7, etc.) and any sampling shape to efficiently extract features from convolution kernels of irregular and arbitrary sampling shapes, breaking through the limitations of traditional square convolutions that are limited to fixed local windows and cannot capture information at other locations, and that convolution kernels with fixed sampling shapes cannot adapt well to the constantly changing defect targets, so that the convolution operation can achieve more accurate feature extraction for defects of various shapes and sizes and defects at different locations, thereby improving the accuracy and efficiency of feature extraction.

[0071] The specific implementation steps of AKConv are as follows:

[0072] First, the initial sampling shape of the convolution kernel is given according to the input feature map. For convolution kernels of different sizes and shapes, the coordinate generation algorithm dynamically generates the initial sampling coordinates. Then, Conv2d is used to perform the convolution operation on the input feature map. After the convolution operation, AKConv will learn the most effective offset for specific feature maps and defect targets through the network according to the characteristics of the defects to dynamically adjust the sampling position of the irregular convolution kernel, more accurately align and extract the key features in the feature map, and dynamically adjust the initial sampling convolution kernel shape when processing different defects, so that the convolution kernel can more accurately cover and extract different defect targets in the feature map, thereby improving the accuracy of feature extraction. Then, the feature map is resampled according to the adjusted sampling shape. The resampled feature map is reshaped, convolved again, and standardized, and then the final result is output through the activation function SiLU.

[0073] Specifically, AKConv supports linear increase or decrease in the number of convolution parameters, and can flexibly increase or decrease the complexity of the model according to task requirements and hardware capabilities. While maintaining high performance, the number of parameters is reduced as much as possible, which helps to optimize in the hardware environment.

[0074] Through the AKConv variable kernel convolution design, the size and shape of the convolution kernel can be flexibly adjusted according to defects of different sizes, shapes, and positions in the data set, thereby achieving more efficient feature extraction.

[0075] For further optimization, the step S05 is specifically as follows:

[0076] The loss function is used to evaluate the deviation between the model's prediction results and the true target. The closer the prediction results are to the true target, the smaller the loss function value. The IOU loss function is the most commonly used loss function for target detection. It measures the overlap between the predicted box and the true box. It represents the intersection-over-union ratio of the true box to the predicted box, and determines the positioning performance of the model. Figure 2 As shown, the relationship between the true box, the predicted box and the intersection-over-union ratio is intuitively expressed.

[0077] In the figure: (A) the true bounding box and (B) the predicted bounding box, (C) the intersection of the true bounding box and the predicted bounding box.

[0078]

[0079] IOU is used to calculate the overlap of the detection box. IOU loss can ensure that the overlap between the predicted detection box and the true target box is maximized, thereby improving the accuracy of detection. Its expression is as follows:

[0080] L IOU =1-IOU

[0081] The loss function of the YOLOv8n target detection task mainly includes two aspects: classification loss (BCE Loss) and regression loss (CIOU Loss+DFL Loss). That is, the loss function of the YOLOv8n network target detection task is:

[0082] Loss=a*BCE Loss j+b*CIOU Loss+c*DFL Loss

[0083] Among them, a, b, and c correspond to the weight coefficients of the three losses, a=0.5, b=7.5, and c=0.3.

[0084] The border loss function used in the original Yolov8 network is CIOU. In the CIOU loss function, when the aspect ratio of the predicted box and the true box is the same, the penalty term of the aspect ratio is always 0, which is unreasonable. At the same time, the gradients of w and h relative to v in CIoU are a pair of opposite numbers. The two cannot increase or decrease at the same time, which will hinder the effective optimization of the model.

[0085] The traditional IoU loss function only considers the overlap between the predicted box and the true box, and is committed to strengthening the fitting ability of the bounding box loss. However, there are not only high-quality examples in the training data, but also low-quality examples. Emphasizing the regression of the bounding box to low-quality examples will harm the improvement of the model detection performance. To solve the above problems, the Wise-IoU (WIOU) loss function is proposed.

[0086] Because there are inevitably low-quality examples in the training data, geometric metrics such as distance and aspect ratio will increase the penalty for low-quality examples, thereby reducing the generalization ability of the model. WIOUv1 constructs distance attention based on distance metrics, with two layers of attention:

[0087] L WIOU v1 -R WIoU L IOU

[0088]

[0089] Where R WIoU ∈[1, e) represents the high-quality anchor box loss, L IOU ∈[0, 1] represents the IoU loss. These two parameters will weaken the loss of high-quality anchor boxes while increasing the loss of ordinary-quality anchor boxes, and increase the attention paid to the distance between the center points of the anchor boxes and the real boxes when they overlap well. In order to prevent R WIoU Produce gradients that hinder convergence. The superscript * indicates that W g and H g Separating it from the calculation can effectively prevent the model from not converging.

[0090] In order to make the model more focused on difficult samples on the basis of WIOUv1, the contribution of simple examples to the loss value is effectively reduced, thereby improving the classification performance. and L IOU The mean of the loss constructs WIOUv2, and the formula is defined as follows:

[0091]

[0092] Among them is the sliding average of momentum m, and the normalization factor is dynamically updated to make the gradient gain The overall level is maintained at a high level, which helps the model converge faster in the later stages of training.

[0093] The present invention uses the WIOU loss function instead of the CIOU loss function to balance the penalty between low-quality anchor boxes and high-quality anchor boxes, reduce the impact of low-quality examples, better solve the sample imbalance problem, and improve the convergence speed and accuracy of the model. For further optimization, the step S06 is specifically as follows:

[0094] After steps S03, S04, and S05, the improved detection model EAW-Yolov8n is obtained. EAW-Yolov8n is mainly composed of four parts: input, backbone network, neck network, and head network. Before entering the model training, the images of the training set are first enhanced by the mosaic method of Yolov8, and then adaptively scaled to a size of 640px×640px×3. Then they are input into the Backbone network, and feature information is extracted through the zero-layer Conv module, the first-layer Conv module, the second-layer C2f module, the third-layer Conv module, the fourth-layer C2f module, the fifth-layer Conv module, the sixth-layer C2f module, the seventh-layer Conv module, the eighth-layer C2f module, and the ninth-layer SPPF-EMCA module. The function of the Conv module is to extract features by performing convolution operations on the input image; the function of the C2f module is to fuse feature maps of different scales; the function of the SPPF-EMCA module is to extract features at different scales through spatial pyramid operations, and adjust the channel weights through the EMCA channel attention mechanism to suppress unimportant channel feature information and make the model focus on important channel feature information.

[0095] The feature information extracted from the backbone network enters the Neck network, and passes through the tenth-layer Upsample module, the eleventh-layer Concat module, the twelfth-layer C2f module, the thirteenth-layer Upsample module, the fourteenth-layer Concat module, the fifteenth-layer C2f_AKConv module, the sixteenth-layer Conv module, the seventeenth-layer Concat module, the eighteenth-layer C2f module, the nineteenth-layer Conv module, the twentieth-layer Concat module, and the twenty-first-layer C2f module in sequence for feature fusion and enhancement. The function of the Upsample module is to perform upsampling and double the resolution of the feature map; the function of the eleventh-layer Concat module is to connect the P4 feature map of the backbone network with the feature map upsampled by the tenth-layer Upsample module; the function of the fourteenth-layer Concat module is to connect the P3 feature map of the backbone network with the feature map upsampled by the thirteenth-layer Upsample module; the function of the seventeenth-layer Concat module is to connect the P4 feature map of the neck network with the feature map proposed by the sixteenth-layer Conv module; the function of the twentieth-layer Concat module is to connect the P5 feature map of the neck network with the feature map proposed by the ninth-layer SPPF-EMCA module; the function of the fifteenth-layer C2f_AKConv module is to introduce AKConv variable kernel convolution. In view of the characteristics of the data set with many small targets, irregular shapes and non-fixed sizes of defects, AKConv flexibly adjusts the size and shape of the convolution kernel to improve the accuracy and efficiency of feature extraction.

[0096] After the feature maps in the fifteenth layer C2f_AKConv module, the eighteenth layer C2f module, and the twenty-first layer C2f module in the Neck network are fused, they enter the Head network respectively, and the Detect module performs target detection to generate the final detection results. The Detect module contains two branches, namely the defect classification branch and the defect location branch. The defect classification branch is composed of the first Conv module, the first Conv2d module, and the first Bbox.Loss module connected in sequence. The input end of the first Conv module is used as the input of the Detect module, and the output end of the first Bbox.Loss module is used as the output of the Detect module for the location information of the defect detection. The defect location branch is composed of the second Conv module, the second Conv2d module, and the first Cls.Loss module connected in sequence. The input end of the second Conv module is used as the input of the Detect module, and the output end of the first Cls.Loss module is used as the output of the Detect module for the classification information of the defect detection.

[0097] For further optimization, the step S07 is specifically as follows:

[0098] The performance of the model is evaluated by precision (P), recall (R), mAP, and inference time per image to measure the accuracy and detection speed of the model. The calculation formula is as follows:

[0099]

[0100]

[0101]

[0102] Where TP represents the number of correctly detected positive samples, FP represents the number of incorrectly detected positive samples, FN represents the number of incorrectly detected negative samples, nc is the number of detection categories, and k = 1, 2, …, nc.

[0103] The detection accuracy, recall, mAP50, mAP50-95 and inference time of each image of the improved EAW-Yolov8n model proposed in the present invention reached 0.92, 0.89, 0.94, 0.737 and 1.8 ms respectively.

[0104] In summary, the present invention successfully applies the EAW-YOLOv8n algorithm in the defect detection of pre-made French fries. The architecture of the EAW-YOLOv8n network is as follows: Figure 3 shown.

[0105] This method is used to detect some effects such as Figure 4 shown.

[0106] The present invention improves the original YOLOv8n model, introduces the EMCA efficient and lightweight channel attention mechanism into the original SPPF module in the YOLOv8n model structure, enhances the global perspective information of the features and features of different scales, adjusts the weights of the channel features, suppresses unimportant channel features, and enables the model to better focus on important channel features, improves the performance and generalization ability of the network, and improves the detection accuracy and recall rate of the model. The AKConv variable kernel convolution is introduced into the C2f module in the fifteenth layer of the Neck network, so that the convolution operation can achieve more accurate feature extraction for defects of various shapes and sizes and defects in different positions in the image, thereby improving the accuracy and efficiency of feature extraction. The CIOU loss function in the original Yolov8n is replaced by the WIOU loss function, which better solves the problem of sample imbalance and improves the convergence speed and accuracy of the model.

[0107] The present invention uses the improved EAW-YOLOv8n model to detect the defects of prefabricated French fries, which greatly improves the detection accuracy while ensuring the inference speed. The inference time of each image of the model is 1.8ms, the mAP value is 94.0%, and the defective product detection accuracy is 99.5%. This method improves the accuracy and speed of defect detection of prefabricated French fries, greatly avoids the problems of missed detection and false detection caused by human factors, greatly reduces labor costs, improves product detection efficiency and automation, improves food safety, and protects the health of consumers.

[0108] It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications should also be regarded as within the scope of protection of the present invention.

Claims

1. A method for detecting surface defects of defective prefabricated French fries. Features: The steps include: S01, photographing images of appearance defects of defective prefabricated French fries; S02, self-made data set, the acquired images are annotated with defects using the image annotation software label img, the annotation information includes defect category and coordinates, and the annotated label files and images are processed, and divided into training set, validation set and test set in the ratio of 8:1:1; S03. Based on the YOLOv8n original network, the EMCA lightweight and efficient channel attention mechanism is introduced into the SPPF module in the Backbone network to build the SPPF-EMCA module; S04, introduce AKConv variable kernel convolution into the fifteenth layer C2f module of Neck network to construct C2f_AKConv module; S05, replace the WIOU loss function with the original CIOU loss function to perform back propagation to update the parameters of the model and improve the loss function; S06. Use the training set to train the improved Yolov8n model EAW-Yolov8n based on S03, S04, and S05 to obtain the training loss results and model training weights; S07. Use the test set to evaluate the performance of the improved defect detection model. The performance of the model is evaluated by precision (P), recall (R), mAP50, and frames per second (FPS). The evaluated model is applied to defect detection of defective prefabricated French fries.

2. A method for detecting surface defects of defective prefabricated French fries according to claim 1, Features: In S3, the EMCA attention mechanism is implemented as follows: First, the dimension is compressed from H×W×C to 1×1×C by performing global average pooling and global maximum pooling operations on the input feature map, and then the global average pooling result and the global maximum pooling result are added together; Then the adaptive one-dimensional convolution kernel size k is calculated. Given the channel dimension C, the convolution kernel size k can be adaptively calculated as: Where |t|odd represents the odd number closest to t; set γ = 2 and b = 1; it can be seen from the formula that the value of k is adaptively determined by the nonlinear mapping of the channel size, and the higher the dimension, the longer the range of interaction; Then, the k value obtained by adaptive calculation is used in the one-dimensional convolution kernel, the feature map obtained by adding the above is subjected to a one-dimensional convolution operation with a convolution kernel size of k, and the weight ω for each channel of the feature map is obtained through the Sigmoid activation function. The calculation formula of ω is as follows ω=Sigmoid(C1D k (x)) Where C1D represents one-dimensional convolution, and x represents the input channel; Finally, the normalized weights and the initial input feature map are multiplied channel by channel to generate a weighted feature map.

3. A method for detecting surface defects of defective prefabricated French fries according to claim 1, Features: In S4, AKConv can efficiently extract features from convolution kernels with irregular and arbitrary sampling shapes, and can adapt to defect targets of different shapes in the data set; The specific implementation steps of AKConv are as follows: First, the initial sampling shape of the convolution kernel is given according to the input feature map. For convolution kernels of different sizes and shapes, the coordinate generation algorithm dynamically generates the initial sampling coordinates. Then, Conv2d is used to perform the convolution operation on the input feature map. After the convolution operation, AKConv will learn the most effective offset for specific feature maps and defect targets through the network according to the characteristics of the defects to dynamically adjust the sampling position of the irregular convolution kernel, more accurately align and extract the key features in the feature map, and dynamically adjust the initial sampling convolution kernel shape when processing different defects, so that the convolution kernel can more accurately cover and extract different defect targets in the feature map, thereby improving the accuracy of feature extraction. Then, the feature map is resampled according to the adjusted sampling shape. The resampled feature map is reshaped, convolved again, and standardized, and then the final result is output through the activation function SiLU.

4. A method for detecting surface defects of defective prefabricated French fries according to claim 1, Features: In S5, WIOUv1 builds distance attention based on distance metric, with two layers of attention: L WIOUv1 =R WIoU L Iou Where R WIoU ∈[1, e) represents the high-quality anchor box loss, L IOU ∈[0, 1] represents the IoU loss. These two parameters will weaken the loss of high-quality anchor boxes while increasing the loss of ordinary-quality anchor boxes, and increase the attention paid to the distance between the center points of the anchor boxes and the real boxes when they overlap well. In order to prevent R WIoU Produce gradients that hinder convergence. The superscript * indicates that W g and H g Separating it from the calculation can effectively prevent the model from not converging. In order to make the model more focused on difficult samples on the basis of WIOUv1, the contribution of simple examples to the loss value is effectively reduced, thereby improving the classification performance. and L IOU The mean of the loss constructs WIOUv2, and the formula is defined as follows: Among them is the sliding average of momentum m, and the normalization factor is dynamically updated to make the gradient gain The overall level is maintained at a high level, which helps the model converge faster in the later stages of training.

5. A method for detecting surface defects of defective prefabricated French fries according to claim 1, Features: In S6, EAW-Yolov8n is mainly composed of four parts: input, backbone network, neck network, and head network.

6. A method for detecting surface defects of defective prefabricated French fries according to claim 1, Features: In S7, the performance of the model is measured by precision (P), recall (R), mAP, and inference time per image to measure the accuracy and detection speed of the model. The calculation formula is as follows: Where TP represents the number of correctly detected positive samples, FP represents the number of incorrectly detected positive samples, FN represents the number of incorrectly detected negative samples, nc is the number of detection categories, and k = 1, 2, …, nc.

Citation Information

Patent Citations

  • Cigarette appearance defect detection method and system

    CN114170161A

  • Improved YOLOv5s-based injection molding part surface defect detection method

    CN116542932A

  • PCB bare board surface defect detection method based on YOLOv8

    CN116823738A

  • Automobile brake disc surface defect detection method based on deep learning

    CN117541568A

  • Strip steel surface defect detection method based on improved YOLO model

    CN117611571A

Cited By

  • Composite material plate pit and dirt detection method based on machine vision

    CN119901747A

  • Gear end face defect detection method based on multi-scale target detection

    CN119904444A

  • Conveying line intelligent detection method and system based on machine vision

    CN120741483A