Plastic bottle surface defect detection method, device, equipment and medium
The proposed method leverages image processing and a pre-trained model with optimized structures to enhance defect detection on plastic bottles, addressing inefficiencies in traditional human inspection methods by improving detection speed and accuracy.
Patent Information
- Application Number
- CN202411762328.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-25
AI Technical Summary
Traditional human-based inspection methods for detecting defects on plastic bottles are inefficient and lack accuracy, leading to high labor costs and suboptimal detection speed in modern automated production lines.
A method and apparatus for detecting defects on plastic bottles using image processing techniques, involving data enhancement strategies and a pre-trained model with optimized feature extraction and loss modules to improve detection accuracy and speed.
The solution enables rapid and accurate detection of defects on plastic bottles, reducing computational load and enhancing feature extraction speed while increasing detection accuracy.
Smart Images

Figure CN119693326A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent detection technology, and in particular to a method, device, equipment and medium for detecting surface defects of plastic bottles. Background Art
[0002] During the production process of plastic packaging bottles, surface defects such as scratches, holes, dirt, and incomplete injection molding may occur. These defects not only affect the appearance of the product, but also damage the sealing and durability of the product, thereby affecting the consumer experience and brand reputation. Therefore, it is very necessary to perform surface defect detection on plastic packaging bottles.
[0003] With the development of industrial automation technology, the cycle time of plastic packaging bottle production lines has been gradually shortened. The speed of inspection has also been required to be improved. Traditional manual inspection methods require manual inspection of multiple sides of plastic packaging bottles, and some inconspicuous defects need to be inspected by shining light on the back. The cycle time of a single product is about 0.5 seconds, and manual inspection is labor-intensive, labor-intensive, and labor-intensive. The inspection efficiency is low and the inspection accuracy cannot be guaranteed. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, equipment and medium for detecting surface defects of plastic bottles, aiming to solve the problems of low manual detection efficiency and low detection accuracy in the prior art.
[0005] In a first aspect, an embodiment of the present invention provides a method for detecting surface defects of a plastic bottle, the method comprising:
[0006] In response to an image acquisition instruction, acquiring an image to be detected corresponding to the image acquisition instruction;
[0007] Performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected;
[0008] The enhanced image is input into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
[0009] In a second aspect, an embodiment of the present invention provides a plastic bottle surface defect detection device, the device comprising:
[0010] An image acquisition unit to be detected, used for acquiring an image to be detected corresponding to the image acquisition instruction in response to the image acquisition instruction;
[0011] A data enhancement unit, configured to perform data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected;
[0012] The defect detection result acquisition unit is used to input the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
[0013] In a third aspect, an embodiment of the present application further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for detecting surface defects of plastic bottles as described in the first aspect is implemented.
[0014] In a fourth aspect, an embodiment of the present application further provides a storage medium, wherein the storage medium stores a computer program, the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the plastic bottle surface defect detection method described in the first aspect above.
[0015] The embodiment of the present invention discloses a plastic bottle surface defect detection method, device, equipment and medium, including obtaining an image to be detected corresponding to an image acquisition instruction; performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected; inputting the enhanced image into a pre-trained plastic surface defect detection model to perform defect detection to obtain a defect detection result of the plastic bottle surface; the plastic surface defect detection model includes a feature extraction optimization structure arranged before a pooling fusion module of a backbone network and a loss module arranged on an output layer, thereby reducing the model calculation amount and improving the feature extraction speed and accuracy through the added feature extraction optimization structure, and at the same time improving the accuracy of target detection through the added loss module. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0017] Figure 1 A schematic diagram of a process for detecting surface defects of plastic bottles provided by an embodiment of the present invention;
[0018] Figure 2is a training result diagram of a plastic surface defect detection model to be trained in the plastic bottle surface defect detection method provided by an embodiment of the present invention;
[0019] Figure 3 is a network structure diagram of a plastic surface defect detection model in a plastic bottle surface defect detection method provided by an embodiment of the present invention;
[0020] Figure 4 A schematic block diagram of a plastic bottle surface defect detection device provided by an embodiment of the present invention;
[0021] Figure 5 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0022] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0024] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0025] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0026] See also Figures 1 to 3 The plastic bottle surface defect detection method is applied to a plastic bottle surface defect detection device, such as Figure 1-3 As shown, the method includes the following steps S110-S130.
[0027] S110. In response to an image acquisition instruction, acquire an image to be detected corresponding to the image acquisition instruction.
[0028] In this embodiment, the technical solution is described with the server as the execution subject, and is aimed at the detection of surface defects of plastic packaging bottles in the production process of plastic packaging bottles, wherein the surface defects of plastic packaging bottles mainly include stains, scratches, holes, surface pits and black line defects. Specifically, by installing four groups of photoelectric sensors and industrial cameras on the production line, when each plastic packaging bottle reaches a predetermined position, it responds to the image acquisition instruction to obtain the image to be detected corresponding to the image acquisition instruction. Among them, the image acquisition instruction can be triggered by relevant staff, or it can be set to be triggered at a time.
[0029] In one embodiment, before the step of acquiring the image to be detected corresponding to the image acquisition instruction in response to the image acquisition instruction, the step further includes:
[0030] Acquire a pre-stored enhanced training set from a local database, perform data preprocessing on the enhanced training set based on a preprocessing strategy to obtain an updated enhanced training set, and use the updated enhanced training set as a target enhanced training set;
[0031] The target enhanced training set is used to perform model training on the plastic surface defect detection model to be trained until the loss function in the plastic surface defect detection model to be trained meets a preset training stop condition, then the model training is stopped and the plastic surface defect detection model is obtained; wherein the loss function in the plastic surface defect detection model to be trained is calculated by the loss module.
[0032] In this embodiment, by obtaining the image annotation strategy, mosaic data enhancement and adaptive anchor frame in the preprocessing strategy, each image in the enhanced training set is annotated with defects through the image annotation strategy, the image is data enhanced through mosaic data enhancement, and then the optimal anchor frame value is calculated through the adaptive anchor frame to obtain an updated enhanced training set, and the updated enhanced training set is used as the target enhanced training set; wherein the defect annotation includes the defect type and defect location, and the defect location is the coordinates (x, y) of the center point of the rectangular box of the defect target, the width w of the rectangular box size, and the height h.
[0033] Moreover, in the process of training the plastic surface defect detection model to be trained using the target enhanced training set, the Windows 10 operating system is used, the graphics card is 12G NVIDIA GeForce RTX3060, the experimental platform is Anaconda+Pycharm, the environment configuration is CUDA12.1, Python3.8, Pytorch1.10.1, wherein the initial learning rate is 0.001, the descent method is the cosine annealing strategy, the learning rate momentum is 0.937, the weight decay coefficient is 5e-4, 24 Batchsize, and the SGD optimizer is used for 1000 iterations of training. After nearly 100 rounds of iterative training, if the loss function in the plastic surface defect detection model to be trained is less than the set value, the training will be terminated in advance to generate a plastic surface defect detection model. Among them, the training results of the plastic surface defect detection model to be trained are as follows: Figure 2 As shown, the loss function in the plastic surface defect detection model to be trained is calculated by the loss module; the loss module includes an angle cost loss function, a distance cost loss function, a shape cost loss function and an IoU cost loss function, wherein the calculation formula of the loss module is as follows:
[0034]
[0035] Among them, Λ represents the angle cost loss function between the predicted box and the real box, Δ represents the distance cost loss function of the horizontal and vertical distances between the center points of the predicted box and the real box, Ω represents the shape cost loss function of the relative difference in width and height between the predicted box and the real box, and IoU represents the degree of overlap between the predicted box and the real box.
[0036] In addition, the target enhancement training set is used to train the YOLOV5S network structure model to obtain the weight file of the trained YOLOV5S network structure model and the accuracy, recall rate and mAP value on the target enhancement training set; the target enhancement training set is used to train the improved YOLOV5S network structure model (i.e., the plastic surface defect detection model to be trained) to obtain the weight file of the trained YOLOV5S+IR+CE+SIOU network structure model (i.e., the plastic surface defect detection model) and the accuracy, recall rate and mAP value on the target enhancement training set, IR represents the inverted residual module, CE represents the attention mechanism module, and SIOU represents the loss module. As shown in Table 1:
[0037] Table 1: Training results comparison table
[0038]
[0039] Among them, Precision is the accuracy; Recall is the recall rate, mAP is the average of all AP categories, mAP@0.5 means the mAP value calculated by IoU when the threshold is set to 0.5, and mAP@0.5:0.95 means the average mAP value calculated by IoU when the step size is 0.05 and the threshold is set to 0.5 to 0.95.
[0040] Therefore, compared with the YOLOV5S network structure model, the YOLOV5S+IR+CE+SIOU network structure model (i.e., plastic surface defect detection model) reduces the amount of calculation, and the single-round iteration speed is reduced from 154 seconds to 142 seconds, an increase of 7.79%, the accuracy is increased from 93.8% to 99.7%, and the overall recall rate is increased from 93.5% to 99.0%. Therefore, it can be seen that it optimizes the feature extraction capability and has a faster convergence speed and higher accuracy.
[0041] S120: Perform data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected.
[0042] In this embodiment, the data enhancement processing is performed on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected, including:
[0043] Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy;
[0044] The image to be detected is subjected to data enhancement processing through any one of the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
[0045] In addition, the performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected also includes:
[0046] Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy;
[0047] The image to be detected is subjected to data enhancement processing in sequence through the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
[0048] Specifically, data enhancement processing is performed based on the image to be detected, and each image is randomly amplified to generate a new image by simulating the changes that may occur on the scene; wherein, the method of data enhancement processing for the image to be detected is not limited to the above two methods, and data enhancement processing can also be performed by a combination of any two sub-strategies or any three sub-strategies among the image flip sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy, which are not specifically limited here. In addition, the image translation sub-strategy is to randomly move the center of the image to any angle by 0 to 10% of the long side of the width or height of the image size; the image scaling sub-strategy is to randomly reduce or enlarge the image along the center point by 85% to 115% of the original image. Moreover, after the image to be detected is subjected to data enhancement processing, the part exceeding the original size of the image is cropped, and the missing part is filled with black; in addition, if the defective target in the image is cropped by the data enhancement processing, the image is discarded and regenerated to enrich the first data set and improve the training effect.
[0049] S130. Input the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
[0050] In this embodiment, the plastic surface defect detection model (such as Figure 3As shown in the figure, in addition to a backbone network and an output layer, the system also includes an input layer, a neck network and a head network, wherein the input layer, the backbone network, the neck network, the head network and the output layer are connected in sequence. In addition, the backbone network includes, in addition to the newly added feature extraction optimization structure, a first CBS module, a second CBS module, a first C3 module, a third CBS module, a second C3 module, a fourth CBS module and a third C3 module, wherein the first CBS module is connected in sequence to the second CBS module, the first C3 module, the third CBS module, the second C3 module, the fourth CBS module, the third C3 module, the feature extraction optimization structure and the pooling fusion module; the neck network includes a fifth CBS module connected to the pooling fusion module, a first upsampling module, a first Concat module connected to the third C3 module, a fourth C3 module, a sixth CBS module, a second upsampling module, a second Concat module connected to the second C3 module, a fifth C3 module, a seventh CBS module, a third Concat module connected to the sixth CBS module, a sixth C3 module, an eighth CBS module, a fourth Concat module connected to the first upsampling module, and a seventh C3 module. module, the fifth CBS module is also connected to the first up-sampling module, the first Concat module, the fourth C3 module, the sixth CBS module, the second up-sampling module, the second Concat module, the fifth C3 module, the seventh CBS module, the third Concat module, the sixth C3 module, the eighth CBS module, the fourth Concat module and the seventh C3 module in sequence; the head network includes a first convolution head structure connected to the fifth C3 module, a second convolution head structure connected to the sixth C3 module, and a third convolution head structure connected to the seventh C3 module; wherein the first convolution head structure includes a first Conv module and a first Head module connected to the first Conv module; the second convolution head structure includes a second Conv module and a second Head module connected to the second Conv module; the third convolution head structure includes a third Conv module and a third Head module connected to the third Conv module.
[0051] Furthermore, the step of inputting the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain the defect detection result of the plastic bottle surface specifically includes: performing a pre-processing operation on the enhanced image at the input layer to obtain a pixel matrix corresponding to the enhanced image, after the enhanced image is pre-processed at the input layer, the enhanced image will first be converted into a pixel matrix that can be processed by the neural network to ensure that the data of the enhanced image can be correctly processed later; wherein the pixel matrix is composed of the pixel value of each pixel of the image. For example, each pixel value of a grayscale image ranges from 0 to 255, representing a color intensity from pure black to pure white; an RGB image has three channels, and the pixel value of each channel also ranges from 0 to 255, corresponding to red, green, and blue, respectively. Furthermore, the pixel matrix is input into the first CBS module, the second CBS module, the first C3 module, the third CBS module and the second C3 module for feature extraction to obtain the first feature; the first feature is then input into the fourth CBS module and the third C3 module for further feature extraction to obtain the second feature; in addition, the second feature is input into the feature extraction optimization structure and the pooling fusion module for further feature extraction and feature integration to obtain the third feature. Among them, the first CBS module, the second CBS module, the third CBS module and the fourth CBS module all encapsulate the combined operation of convolution, batch normalization and activation function, which is used to perform convolution operations on each input image to improve the efficiency and effect of feature extraction; the first C3 module, the second C3 module and the third C3 module are used for deep feature extraction, aiming to improve the feature extraction capability of the network model; the feature extraction optimization structure can be used to reduce the number of parameters in the convolution layer; the pooling fusion module is used to integrate multi-scale features to keep the size of the feature map unchanged.Then, the obtained third feature is input into the fifth CBS module and the first upsampling module for feature extraction and feature adjustment to obtain a fourth feature, and the fourth feature and the second feature are further fused in the first Concat module to obtain a first fused feature; the first fused feature is input into the fourth C3 module and the sixth CBS module for feature extraction to obtain a fifth feature, and the fifth feature is fused with the first feature in the second Concat module through the second upsampling module to obtain a second fused feature; and the second fused feature is input into the fifth C3 module to obtain a sixth feature, and the sixth feature is fused with the fifth feature through the seventh CBS module in The third Concat module is fused to obtain the third fused feature; and the third fused feature is input into the sixth C3 module to obtain the seventh feature, and the seventh feature is fused with the fourth feature in the fourth Concat module through the eighth CBS module to obtain the fourth fused feature; finally, the fourth fused feature is input into the seventh C3 module for further feature extraction to obtain the eighth feature; in addition, the sixth feature, the seventh feature and the eighth feature are respectively input into the first convolution head structure, the second convolution head structure and the third convolution head structure to obtain three feature maps of different scales, so as to enhance the detection ability of the model for targets of different scales through the feature maps of three different scales. Further, the feature maps of three different scales are input into the output layer for target detection to obtain the defect detection result; specifically, the output layer will classify each position on each feature map of the three different scales to determine whether there is a target object, and perform regression adjustment of the bounding box to obtain a more accurate target position, thereby outputting the final defect detection result; wherein, the defect detection result includes the category and position information of the detected target.
[0052] Therefore, through the above steps, this embodiment can quickly and accurately detect the target defect in the enhanced image and output the defect detection result corresponding to the enhanced image.
[0053] In one embodiment, the feature extraction optimization structure includes an inverted residual module and an attention mechanism module, and the inverted residual module is connected to the attention mechanism module; the second feature is input into the feature extraction optimization structure and the pooling fusion module to obtain the third feature, including:
[0054] Inputting the second feature into the inverted residual module for a first feature optimization to obtain a first sub-feature;
[0055] Inputting the first sub-feature into the attention mechanism module for a second feature optimization to obtain a second sub-feature;
[0056] The second sub-feature is input into the pooling fusion module for pooling processing to obtain the third feature.
[0057] In this embodiment, since the YOLOv5 detection model has insufficient ability to extract surface defects of plastic bottles and insufficient feature fusion, this embodiment specifically sequentially passes the second feature through the linear bottleneck, depthwise separable convolution, point-by-point convolution, residual connection and activation function in the inverted residual module, and finally outputs the first sub-feature;
[0058] Moreover, the linear bottleneck is a 1x1 point-by-point convolution, which is used to reduce the number of channels of the feature map before entering the depth-wise separable convolution to reduce the amount of computation; its formula is as follows:
[0059] Linear(x,W lin )=W lin *x;
[0060] Among them, x represents the feature map, W lin Represents the weight matrix of the linear bottleneck layer, which is used to reduce the number of channels of the input feature map x from C to D, where C is greater than D and C and D are positive integers.
[0061] Depthwise separable convolution: Each input channel is independently convolved with a spatial convolution kernel, and the input feature map x is subjected to depthwise convolution processing; wherein each input channel is independently applied with a spatial convolution kernel; its formula is expressed as follows:
[0062]
[0063] Where D represents the number of input channels, x d represents the feature map of the dth channel, K d Represents the d-th depth convolution kernel, where d is a positive integer.
[0064] Point-wise convolution (1x1) is used again to further combine features, realize cross-channel fusion features, and increase nonlinearity; its formula is as follows:
[0065] PWConv(DWConv(Linear(x)), W pw )=W pw *(DWConv(x));
[0066] Among them, W pw Represents the point-by-point convolution weight matrix, which is used to expand the number of feature channels D back to C, where C is greater than D, and C and D are positive integers.
[0067] Furthermore, residual connection: add the input feature map x to the output of the depthwise separable convolution and point-by-point convolution to realize the flow of gradients in the network model and reduce the gradient vanishing problem during training; its formula is as follows:
[0068] IR-LB(x)=PWConv(DWConv(Linear(x)))+Linear(x);
[0069] The output of the residual connection is passed through an activation function ReLU6 to introduce nonlinearity and enhance the expressiveness of the model.
[0070] RELU6(x)=min(max(0,x),6);
[0071] OutPut=ReLU6(PWConv(DWConv(Linear(x)))+x);
[0072] Among them, Output is the final result of the inverted residual module, which contains the spatial and channel information of the extracted features.
[0073] In addition, the first sub-feature is sequentially passed through the Squeeze operation, the Excitation operation and the Reweight operation in the attention mechanism module to obtain the second sub-feature.
[0074] Specifically, the Squeeze operation: use global average pooling to aggregate the spatial information of each feature map and generate a global feature vector with a length equal to the number of channels; its formula is as follows:
[0075]
[0076] Among them, x c represents the c-th channel of the input feature map x, H and W represent the height and width of the feature map respectively, i represents the i-th position in the height direction of the feature map; j represents the j-th position in the width direction of the feature map.
[0077] Excitation operation: learn the relationship between channels through two fully connected layers. The first layer uses the ReLU activation function and the second layer uses the sigmoid activation function. The formula is as follows: C =σ(g(Z C )) = σ(W2×ReLU(W1×Z));
[0078] Among them, g represents the ReLU activation function, σ represents the sigmoid activation function, W1 and W2 represent the weight matrices of the fully connected layer, Z represents the channel-level features of the input feature map, and Z CRepresents the feature of the cth channel of the input feature map Z, and Sc represents the weight of the cth channel of the input feature map Z.
[0079] Reweight operation: Reweight the feature vector S of length C C Reshape into a 1×1×C shape to align with the channel dimension of the original feature map x, and then S C Multiply the original feature map x channel by channel to achieve adaptive recalibration of the channel; the formula is as follows:
[0080] x SE = x × Resharp (S C );
[0081] Then, through a residual connection and ReLU activation function, the output feature map after adding the attention mechanism is obtained. The formula is as follows:
[0082] output = ReLU(x+x SE );
[0083] Among them, x SE Represents the adaptively recalibrated feature map of the channel.
[0084] Therefore, through the combination of the above-mentioned inverted residual module and the attention mechanism module, the amount of calculation is reduced while retaining the main features, thereby improving the speed and accuracy of feature extraction.
[0085] Finally, the second sub-feature is input into the pooling fusion module for pooling processing to integrate multi-scale features, thereby obtaining the third feature, thereby improving the recognition ability of objects of different scales.
[0086] It can be seen from the above technical solutions that the present invention reduces the amount of model calculation and improves the feature extraction speed and accuracy by adding a feature extraction optimization structure, and at the same time improves the accuracy of target detection by adding a loss module.
[0087] Figure 4 A schematic block diagram of a plastic bottle surface defect detection device provided by an embodiment of the present invention. Figure 4 As shown, the present invention also provides a plastic bottle surface defect detection device, the plastic bottle surface defect detection device includes a unit for executing the above-mentioned plastic bottle surface defect detection method, specifically, refer to Figure 4 The plastic bottle surface defect detection device 10 includes a to-be-detected image acquisition unit 110 , a data enhancement unit 120 and a defect detection result acquisition unit 130 .
[0088] The image to be detected acquiring unit 110 is used to acquire the image to be detected corresponding to the image acquisition instruction in response to the image acquisition instruction.
[0089] In this embodiment, the technical solution is described with the server as the execution subject, and is aimed at the detection of surface defects of plastic packaging bottles in the production process of plastic packaging bottles, wherein the surface defects of plastic packaging bottles mainly include stains, scratches, holes, surface pits and black line defects. Specifically, by installing four groups of photoelectric sensors and industrial cameras on the production line, when each plastic packaging bottle reaches a predetermined position, it responds to the image acquisition instruction to obtain the image to be detected corresponding to the image acquisition instruction. Among them, the image acquisition instruction can be triggered by relevant staff, or it can be set to be triggered at a time.
[0090] In one embodiment, before the to-be-detected image acquisition unit 110, the following further comprises:
[0091] Acquire a pre-stored enhanced training set from a local database, perform data preprocessing on the enhanced training set based on a preprocessing strategy to obtain an updated enhanced training set, and use the updated enhanced training set as a target enhanced training set;
[0092] The target enhanced training set is used to perform model training on the plastic surface defect detection model to be trained until the loss function in the plastic surface defect detection model to be trained meets a preset training stop condition, then the model training is stopped and the plastic surface defect detection model is obtained; wherein the loss function in the plastic surface defect detection model to be trained is calculated by the loss module.
[0093] In this embodiment, by obtaining the image annotation strategy, mosaic data enhancement and adaptive anchor frame in the preprocessing strategy, each image in the enhanced training set is annotated with defects through the image annotation strategy, the image is data enhanced through mosaic data enhancement, and then the optimal anchor frame value is calculated through the adaptive anchor frame to obtain an updated enhanced training set, and the updated enhanced training set is used as the target enhanced training set; wherein the defect annotation includes the defect type and defect location, and the defect location is the coordinates (x, y) of the center point of the rectangular box of the defect target, the width w of the rectangular box size, and the height h.
[0094] Moreover, in the process of training the plastic surface defect detection model to be trained using the target enhanced training set, the Windows 10 operating system is used, the graphics card is 12G NVIDIA GeForce RTX3060, the experimental platform is Anaconda+Pycharm, the environment configuration is CUDA12.1, Python3.8, Pytorch1.10.1, wherein the initial learning rate is 0.001, the descent method is the cosine annealing strategy, the learning rate momentum is 0.937, the weight decay coefficient is 5e-4, 24 Batchsize, and the SGD optimizer is used for 1000 iterations of training. After nearly 100 rounds of iterative training, if the loss function in the plastic surface defect detection model to be trained is less than the set value, the training will be terminated in advance to generate a plastic surface defect detection model. Among them, the training results of the plastic surface defect detection model to be trained are as follows: Figure 2 As shown, the loss function in the plastic surface defect detection model to be trained is calculated by the loss module; the loss module includes an angle cost loss function, a distance cost loss function, a shape cost loss function and an IoU cost loss function, wherein the calculation formula of the loss module is as follows:
[0095]
[0096] Among them, Λ represents the angle cost loss function between the predicted box and the real box, Δ represents the distance cost loss function of the horizontal and vertical distances between the center points of the predicted box and the real box, Ω represents the shape cost loss function of the relative difference in width and height between the predicted box and the real box, and IoU represents the degree of overlap between the predicted box and the real box.
[0097] In addition, the target enhancement training set is used to train the YOLOV5S network structure model to obtain the weight file of the trained YOLOV5S network structure model and the accuracy, recall rate and mAP value on the target enhancement training set; the target enhancement training set is used to train the improved YOLOV5S network structure model (i.e., the plastic surface defect detection model to be trained) to obtain the weight file of the trained YOLOV5S+IR+CE+SIOU network structure model (i.e., the plastic surface defect detection model) and the accuracy, recall rate and mAP value on the target enhancement training set, IR represents the inverted residual module, CE represents the attention mechanism module, and SIOU represents the loss module. As shown in Table 1:
[0098] Table 1: Training results comparison table
[0099]
[0100]
[0101] Among them, Precision is the accuracy; Recall is the recall rate, mAP is the average of all AP categories, mAP@0.5 means the mAP value calculated by IoU when the threshold is set to 0.5, and mAP@0.5:0.95 means the average mAP value calculated by IoU when the step size is 0.05 and the threshold is set to 0.5 to 0.95.
[0102] Therefore, compared with the YOLOV5S network structure model, the YOLOV5S+IR+CE+SIOU network structure model (i.e., plastic surface defect detection model) reduces the amount of calculation, and the single-round iteration speed is reduced from 154 seconds to 142 seconds, an increase of 7.79%, the accuracy is increased from 93.8% to 99.7%, and the overall recall rate is increased from 93.5% to 99.0%. Therefore, it can be seen that it optimizes the feature extraction capability and has a faster convergence speed and higher accuracy.
[0103] The data enhancement unit 120 is used to perform data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected.
[0104] In this embodiment, the data enhancement unit 120 is specifically used for:
[0105] Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy;
[0106] The image to be detected is subjected to data enhancement processing through any one of the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
[0107] In addition, the data enhancement unit 120 is further specifically configured to:
[0108] Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy;
[0109] The image to be detected is subjected to data enhancement processing in sequence through the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
[0110] Based on the image to be detected, data enhancement processing is performed, and each image is randomly amplified to generate a new image by simulating the changes that may occur on the scene; wherein, the method of data enhancement processing for the image to be detected is not limited to the above two methods, and data enhancement processing can also be performed by a combination of any two sub-strategies or any three sub-strategies among the image flip sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy, which are not specifically limited here. In addition, the image translation sub-strategy is to randomly move the center of the image to any angle by 0 to 10% of the long side of the width or height of the image size; the image scaling sub-strategy is to randomly reduce or enlarge the image along the center point by 85% to 115% of the original image. In addition, after the image to be detected is subjected to data enhancement processing, the part exceeding the original size of the image is cropped, and the missing part is filled with black; in addition, if the defective target in the image is cropped by the data enhancement processing, the image is discarded and regenerated to enrich the first data set and improve the training effect.
[0111] The defect detection result acquisition unit 130 is used to input the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
[0112] In this embodiment, the plastic surface defect detection model (such as Figure 3As shown in the figure, in addition to a backbone network and an output layer, the system also includes an input layer, a neck network and a head network, wherein the input layer, the backbone network, the neck network, the head network and the output layer are connected in sequence. In addition, the backbone network includes, in addition to the newly added feature extraction optimization structure, a first CBS module, a second CBS module, a first C3 module, a third CBS module, a second C3 module, a fourth CBS module and a third C3 module, wherein the first CBS module is connected in sequence to the second CBS module, the first C3 module, the third CBS module, the second C3 module, the fourth CBS module, the third C3 module, the feature extraction optimization structure and the pooling fusion module; the neck network includes a fifth CBS module connected to the pooling fusion module, a first upsampling module, a first Concat module connected to the third C3 module, a fourth C3 module, a sixth CBS module, a second upsampling module, a second Concat module connected to the second C3 module, a fifth C3 module, a seventh CBS module, a third Concat module connected to the sixth CBS module, a sixth C3 module, an eighth CBS module, a fourth Concat module connected to the first upsampling module, and a seventh C3 module. module, the fifth CBS module is also connected to the first up-sampling module, the first Concat module, the fourth C3 module, the sixth CBS module, the second up-sampling module, the second Concat module, the fifth C3 module, the seventh CBS module, the third Concat module, the sixth C3 module, the eighth CBS module, the fourth Concat module and the seventh C3 module in sequence; the head network includes a first convolution head structure connected to the fifth C3 module, a second convolution head structure connected to the sixth C3 module, and a third convolution head structure connected to the seventh C3 module; wherein the first convolution head structure includes a first Conv module and a first Head module connected to the first Conv module; the second convolution head structure includes a second Conv module and a second Head module connected to the second Conv module; the third convolution head structure includes a third Conv module and a third Head module connected to the third Conv module.
[0113] Furthermore, the step of inputting the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain the defect detection result of the plastic bottle surface specifically includes: performing a pre-processing operation on the enhanced image at the input layer to obtain a pixel matrix corresponding to the enhanced image, after the enhanced image is pre-processed at the input layer, the enhanced image will first be converted into a pixel matrix that can be processed by the neural network to ensure that the data of the enhanced image can be correctly processed later; wherein the pixel matrix is composed of the pixel value of each pixel of the image. For example, each pixel value of a grayscale image ranges from 0 to 255, representing a color intensity from pure black to pure white; an RGB image has three channels, and the pixel value of each channel also ranges from 0 to 255, corresponding to red, green, and blue, respectively. Furthermore, the pixel matrix is input into the first CBS module, the second CBS module, the first C3 module, the third CBS module and the second C3 module for feature extraction to obtain the first feature; the first feature is then input into the fourth CBS module and the third C3 module for further feature extraction to obtain the second feature; in addition, the second feature is input into the feature extraction optimization structure and the pooling fusion module for further feature extraction and feature integration to obtain the third feature. Among them, the first CBS module, the second CBS module, the third CBS module and the fourth CBS module all encapsulate the combined operation of convolution, batch normalization and activation function, which is used to perform convolution operations on each input image to improve the efficiency and effect of feature extraction; the first C3 module, the second C3 module and the third C3 module are used for deep feature extraction, aiming to improve the feature extraction ability of the network model; the feature extraction optimization structure can be used to reduce the number of parameters in the convolution layer; and the pooling fusion module is used to integrate multi-scale features to keep the size of the feature map unchanged.Then, the obtained third feature is input into the fifth CBS module and the first upsampling module for feature extraction and feature adjustment to obtain a fourth feature, and the fourth feature and the second feature are further fused in the first Concat module to obtain a first fused feature; the first fused feature is input into the fourth C3 module and the sixth CBS module for feature extraction to obtain a fifth feature, and the fifth feature is fused with the first feature in the second Concat module through the second upsampling module to obtain a second fused feature; and the second fused feature is input into the fifth C3 module to obtain a sixth feature, and the sixth feature is fused with the fifth feature through the seventh CBS module in The third Concat module is fused to obtain the third fused feature; and the third fused feature is input into the sixth C3 module to obtain the seventh feature, and the seventh feature is fused with the fourth feature in the fourth Concat module through the eighth CBS module to obtain the fourth fused feature; finally, the fourth fused feature is input into the seventh C3 module for further feature extraction to obtain the eighth feature; in addition, the sixth feature, the seventh feature and the eighth feature are respectively input into the first convolution head structure, the second convolution head structure and the third convolution head structure to obtain three feature maps of different scales, so as to enhance the detection ability of the model for targets of different scales through the feature maps of three different scales. Further, the feature maps of three different scales are input into the output layer for target detection to obtain the defect detection result; specifically, the output layer will classify each position on each feature map of the three different scales to determine whether there is a target object, and perform regression adjustment of the bounding box to obtain a more accurate target position, thereby outputting the final defect detection result; wherein, the defect detection result includes the category and position information of the detected target.
[0114] Therefore, through the above steps, this embodiment can quickly and accurately detect the target defect in the enhanced image and output the defect detection result corresponding to the enhanced image.
[0115] In one embodiment, the feature extraction optimization structure includes an inverted residual module and an attention mechanism module, and the inverted residual module is connected to the attention mechanism module; the second feature is input into the feature extraction optimization structure and the pooling fusion module to obtain the third feature, including:
[0116] Inputting the second feature into the inverted residual module for a first feature optimization to obtain a first sub-feature;
[0117] Inputting the first sub-feature into the attention mechanism module for a second feature optimization to obtain a second sub-feature;
[0118] The second sub-feature is input into the pooling fusion module for pooling processing to obtain the third feature.
[0119] In this embodiment, since the YOLOv5 detection model has insufficient ability to extract surface defects of plastic bottles and insufficient feature fusion, this embodiment specifically sequentially passes the second feature through the linear bottleneck, depthwise separable convolution, point-by-point convolution, residual connection and activation function in the inverted residual module, and finally outputs the first sub-feature;
[0120] Moreover, the linear bottleneck is a 1x1 point-by-point convolution, which is used to reduce the number of channels of the feature map before entering the depth-wise separable convolution to reduce the amount of computation; its formula is as follows:
[0121] Linear(x,W lin )=W lin *x;
[0122] Among them, x represents the feature map, W lin Represents the weight matrix of the linear bottleneck layer, which is used to reduce the number of channels of the input feature map x from C to D, where C is greater than D and C and D are positive integers.
[0123] Depthwise separable convolution: Each input channel is independently convolved with a spatial convolution kernel, and the input feature map x is subjected to depthwise convolution processing; wherein each input channel is independently applied with a spatial convolution kernel; its formula is expressed as follows:
[0124]
[0125] Where D represents the number of input channels, x d represents the feature map of the dth channel, K d Represents the d-th depth convolution kernel, where d is a positive integer.
[0126] Point-wise convolution (1x1) is used again to further combine features, realize cross-channel fusion features, and increase nonlinearity; its formula is as follows:
[0127] PWConv(DWConv(Linear(x)), W pw )=W pw *(DWConv(x));
[0128] Among them, W pw Represents the point-by-point convolution weight matrix, which is used to expand the number of feature channels D back to C, where C is greater than D, and C and D are positive integers.
[0129] Furthermore, residual connection: add the input feature map x to the output of the depthwise separable convolution and point-by-point convolution to realize the flow of gradients in the network model and reduce the gradient vanishing problem during training; its formula is as follows:
[0130] IR-LB(x)=PWConv(DWConv(Linear(x)))+Linear(x);
[0131] The output of the residual connection is passed through an activation function ReLU6 to introduce nonlinearity and enhance the expressiveness of the model.
[0132] RELU6(x)=min(max(0,x),6);
[0133] OutPut=ReLU6(PWConv(DWConv(Linear(x)))+x);
[0134] Among them, Output is the final result of the inverted residual module, which contains the spatial and channel information of the extracted features.
[0135] In addition, the first sub-feature is sequentially passed through the Squeeze operation, the Excitation operation and the Reweight operation in the attention mechanism module to obtain the second sub-feature.
[0136] Specifically, the Squeeze operation: use global average pooling to aggregate the spatial information of each feature map and generate a global feature vector with a length equal to the number of channels; its formula is as follows:
[0137]
[0138] Among them, x c represents the c-th channel of the input feature map x, H and W represent the height and width of the feature map respectively, i represents the i-th position in the height direction of the feature map; j represents the j-th position in the width direction of the feature map.
[0139] Excitation operation: learn the relationship between channels through two fully connected layers. The first layer uses the ReLU activation function and the second layer uses the sigmoid activation function. The formula is as follows: C =σ(g(Z C )) = σ(W2×ReLU(W1×Z));
[0140] Among them, g represents the ReLU activation function, σ represents the sigmoid activation function, W1 and W2 represent the weight matrices of the fully connected layer, Z represents the channel-level features of the input feature map, and Z CRepresents the feature of the cth channel of the input feature map Z, and Sc represents the weight of the cth channel of the input feature map Z.
[0141] Reweight operation: Reweight the feature vector S of length C C Reshape into a 1×1×C shape to align with the channel dimension of the original feature map x, and then S C Multiply the original feature map x channel by channel to achieve adaptive recalibration of the channel; the formula is as follows:
[0142] x SE = x × Resharp (S C );
[0143] Among them, x SE Represents the adaptively recalibrated feature map of the channel.
[0144] Then, through a residual connection and ReLU activation function, the output feature map after adding the attention mechanism is obtained. The formula is as follows:
[0145] output = ReLU(x+x SE );
[0146] Therefore, through the combination of the above-mentioned inverted residual module and the attention mechanism module, the amount of calculation is reduced while retaining the main features, thereby improving the speed and accuracy of feature extraction.
[0147] Finally, the second sub-feature is input into the pooling fusion module for pooling processing to integrate multi-scale features, thereby obtaining the third feature, thereby improving the recognition ability of objects of different scales.
[0148] It can be seen from the above technical solutions that the present invention reduces the amount of model calculation and improves the feature extraction speed and accuracy by adding a feature extraction optimization structure, and at the same time improves the accuracy of target detection by adding a loss module.
[0149] The above-mentioned plastic bottle surface defect detection device can be implemented in the form of a computer program, which can be used in Figure 5 Runs on the computer device shown.
[0150] See also Figure 5 , Figure 5 A schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 500 is a server, which may be an independent server or a server cluster composed of multiple servers. The computer device 500 may also be a sending end, which may be an electronic device with communication functions such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant, and a wearable device.
[0151] See also Figure 5 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a storage medium 503 and an internal memory 504 .
[0152] The storage medium 503 can store an operating system 5031 and a computer program 5032. When the computer program 5032 is executed, the processor 502 can execute a method for detecting surface defects of a plastic bottle.
[0153] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .
[0154] The internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute the plastic bottle surface defect detection method.
[0155] The network interface 505 is used for network communication, such as providing data information transmission, etc. Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device 500 to which the solution of the present invention is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0156] The processor 502 is used to run the computer program 5032 stored in the memory to implement the plastic bottle surface defect detection method disclosed in the embodiment of the present invention.
[0157] Those skilled in the art will understand that Figure 5 The embodiments of the computer device shown in the figure do not constitute a limitation on the specific composition of the computer device. In other embodiments, the computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, in some embodiments, the computer device may only include a memory and a processor. In such embodiments, the structure and function of the memory and the processor are the same as those of the embodiment of the present invention. Figure 5 The embodiments shown are consistent and will not be described again here.
[0158] It should be understood that in the embodiment of the present invention, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0159] In another embodiment of the present invention, a computer-readable storage medium is provided. The computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the plastic bottle surface defect detection method disclosed in the embodiment of the present invention is implemented.
[0160] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the above-described equipment, system and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. Those of ordinary skill in the art can appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0161] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, systems and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. Units with the same function may also be combined into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, systems or units, or may be electrical, mechanical or other forms of connection.
[0162] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.
[0163] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0164] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), disk or optical disk and other media that can store program codes.
[0165] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A method for detecting surface defects of plastic bottles, characterized in that: The method comprises: In response to an image acquisition instruction, acquiring an image to be detected corresponding to the image acquisition instruction; Performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected; The enhanced image is input into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
2. The method for detecting surface defects of plastic bottles according to claim 1, characterized in that: Before the step of acquiring the image to be detected corresponding to the image acquisition instruction in response to the image acquisition instruction, the method further comprises: Acquire a pre-stored enhanced training set from a local database, perform data preprocessing on the enhanced training set based on a preprocessing strategy to obtain an updated enhanced training set, and use the updated enhanced training set as a target enhanced training set; The target enhanced training set is used to perform model training on the plastic surface defect detection model to be trained until the loss function in the plastic surface defect detection model to be trained meets a preset training stop condition, then the model training is stopped and the plastic surface defect detection model is obtained; wherein the loss function in the plastic surface defect detection model to be trained is calculated by the loss module.
3. The method for detecting surface defects of plastic bottles according to claim 1, characterized in that: The plastic surface defect detection model also includes an input layer, a neck network and a head network, wherein the input layer, the backbone network, the neck network, the head network and the output layer are connected in sequence; The backbone network further includes a first CBS module, a second CBS module, a first C3 module, a third CBS module, a second C3 module, a fourth CBS module and a third C3 module, and the first CBS module is connected with the second CBS module, the first C3 module, the third CBS module, the second C3 module, the fourth CBS module, the third C3 module, the feature extraction optimization structure and the pooling fusion module in sequence; The neck network includes a fifth CBS module connected to the pooling fusion module, a first upsampling module, a first Concat module connected to the third C3 module, a fourth C3 module, a sixth CBS module, a second upsampling module, a second Concat module connected to the second C3 module, a fifth C3 module, a seventh CBS module, a third Concat module connected to the sixth CBS module, a sixth C3 module, an eighth CBS module, a fourth Concat module connected to the first upsampling module, and a seventh C3 module, and the fifth CBS module is also connected to the first upsampling module, the first Concat module, the fourth C3 module, the sixth CBS module, the second upsampling module, the second Concat module, the fifth C3 module, the seventh CBS module, the third Concat module, the sixth C3 module, the eighth CBS module, the fourth Concat module and the seventh C3 module in sequence; The head network includes a first convolution head structure connected to the fifth C3 module, a second convolution head structure connected to the sixth C3 module, and a third convolution head structure connected to the seventh C3 module.
4. The method for detecting surface defects of plastic bottles according to claim 3, characterized in that: The step of inputting the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result on the surface of the plastic bottle includes: Performing a preprocessing operation on the enhanced image at an input layer to obtain a pixel matrix corresponding to the enhanced image; Inputting the pixel matrix into the first CBS module, the second CBS module, the first C3 module, the third CBS module and the second C3 module to obtain a first feature; Inputting the first feature into the fourth CBS module and the third C3 module to obtain a second feature; Inputting the second feature into the feature extraction optimization structure and the pooling fusion module to obtain a third feature; Inputting the third feature into the fifth CBS module and the first upsampling module to obtain a fourth feature, and fusing the fourth feature with the second feature in the first Concat module to obtain a first fused feature; Inputting the first fused feature into the fourth C3 module and the sixth CBS module to obtain a fifth feature, and the fifth feature is fused with the first feature in the second Concat module through the second upsampling module to obtain a second fused feature; Inputting the second fused feature into the fifth C3 module to obtain a sixth feature, and the sixth feature is fused with the fifth feature in the third Concat module through the seventh CBS module to obtain a third fused feature; Input the third fused feature into the sixth C3 module to obtain a seventh feature, and the seventh feature is fused with the fourth feature in the fourth Concat module through the eighth CBS module to obtain a fourth fused feature; Inputting the fourth fusion feature into the seventh C3 module to obtain an eighth feature; Inputting the sixth feature, the seventh feature, and the eighth feature into the first convolution head structure, the second convolution head structure, and the third convolution head structure, respectively, to obtain feature maps of three different scales; The feature maps of three different scales are input into the output layer for target detection to obtain the defect detection result.
5. The method for detecting surface defects of plastic bottles according to claim 4, characterized in that: The feature extraction optimization structure includes an inverted residual module and an attention mechanism module, and the inverted residual module is connected to the attention mechanism module; the second feature is input into the feature extraction optimization structure and the pooling fusion module to obtain a third feature, including: Inputting the second feature into the inverted residual module for a first feature optimization to obtain a first sub-feature; Inputting the first sub-feature into the attention mechanism module for a second feature optimization to obtain a second sub-feature; The second sub-feature is input into the pooling fusion module for pooling processing to obtain the third feature.
6. The method for detecting surface defects of plastic bottles according to claim 1, characterized in that: The step of performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected includes: Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy; The image to be detected is subjected to data enhancement processing through any one of the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
7. The method for detecting surface defects of plastic bottles according to claim 1, characterized in that: The step of performing data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected further includes: Obtaining an image flip sub-strategy, an image translation sub-strategy, an image scaling sub-strategy, and an image contrast sub-strategy included in the preset enhancement strategy; The image to be detected is subjected to data enhancement processing in sequence through the image flipping sub-strategy, the image translation sub-strategy, the image scaling sub-strategy and the image contrast sub-strategy to obtain the enhanced image.
8. A plastic bottle surface defect detection device, characterized in that: The device comprises: An image acquisition unit to be detected, used for acquiring an image to be detected corresponding to the image acquisition instruction in response to the image acquisition instruction; A data enhancement unit, configured to perform data enhancement processing on the image to be detected based on a preset image enhancement strategy to obtain an enhanced image corresponding to the image to be detected; The defect detection result acquisition unit is used to input the enhanced image into a pre-trained plastic surface defect detection model for defect detection to obtain a defect detection result of the plastic bottle surface; wherein the plastic surface defect detection model includes a feature extraction optimization structure and a loss module, the feature extraction optimization structure is arranged before the pooling fusion module of the backbone network, and the loss module is arranged on the output layer.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for detecting surface defects of plastic bottles according to any one of claims 1 to 7 is implemented.
10. A storage medium, characterized in that: The storage medium stores a computer program, which includes program instructions. When the program instructions are executed by a processor, the processor executes the plastic bottle surface defect detection method according to any one of claims 1 to 7.