Multi-scale adaptive reconstruction barrel body defect detection method and device based on attention, equipment and storage medium

By constructing an encoder, decoder, and adaptive reconstruction network based on an attention-based multi-scale adaptive reconstruction method, the problems of low efficiency, high false negative rate, and insufficient real-time performance in barrel appearance defect detection are solved, and high-precision detection of minute defects is achieved.

CN121526982APending Publication Date: 2026-02-13CHANGCHUN BEIFANG INSTR EQUIP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511533501.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-24
Publication Date
2026-02-13

AI Technical Summary

Technical Problem

Existing methods for detecting defects in barrel appearance suffer from low efficiency, poor consistency, high missed detection rate, and insufficient real-time performance, especially in detecting reflective surfaces on barrel surfaces and minor defects.

Method used

A multi-scale adaptive reconstruction method based on attention is adopted. The detection model is constructed by an encoder, a decoder and an adaptive reconstruction network. The multi-scale feature extraction and fusion module is combined with a multi-head attention module to focus on the defect region and noise is removed by the adaptive reconstruction network to generate high-precision defect detection results.

Benefits of technology

It improves the accuracy and real-time performance of barrel defect detection, effectively identifies minute defects, adapts to barrel curvature and reduces false alarm rate, and meets the stringent requirements of industrial automated production lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121526982A_ABST
    Figure CN121526982A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to an attention-based multi-scale adaptive reconstruction barrel body defect detection method, device and equipment and a storage medium. Based on an encoder-decoder architecture, an attention-based multi-scale feature extraction module, a multi-scale feature fusion module and an adaptive reconstruction module are adopted; a multi-scale self-adaptive reconstruction barrel body defect detection model based on attention is provided, features output by an encoder are converted into a probability matrix, the defect probability of a corresponding pixel position is obtained, a defect image is reconstructed into a normal image through a self-adaptive reconstruction module, and the accuracy of small industrial defect detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, in particular to a barrel body defect detection method and device based on attention multi-scale adaptive reconstruction, equipment and storage medium. BACKGROUND

[0002] The existing barrel body appearance defect detection mainly adopts manual inspection or traditional machine vision scheme. The manual method is low in efficiency and poor in consistency; the traditional vision needs to manually design features and thresholds for different defects, which is difficult to change, and has a high missing detection rate for small defects such as scratches and pits. In recent years, deep learning algorithms based on unsupervised reconstruction have made progress in general industrial defect detection, but there are the following problems when directly applied to barrel body and barrel surface: (1) the barrel curved surface is reflective, and the weld texture is complex, which makes it difficult for the reconstruction network to restore the normal texture, resulting in a high false positive rate; (2) small defects (<1cm) account for a very small proportion in the collected images and are difficult to find; (3) on an industrial automation production line, the target recognition algorithm needs to meet strict real-time requirements, and its inference delay must be better than the production line beat time limit, in order to ensure reliable operation in a high-throughput continuous production environment. SUMMARY

[0003] Therefore, the purpose of the present application is to provide a barrel body defect detection method and device based on attention multi-scale adaptive reconstruction, which can adapt to the barrel curved surface and has small defect sensitivity, to solve the problems of missing detection, overkill and insufficient real-time in the prior art. The specific scheme is as follows:

[0004] In a first aspect, the present application provides a barrel body defect detection method based on attention multi-scale adaptive reconstruction, which comprises:

[0005] Constructing a barrel body defect detection model based on attention multi-scale adaptive reconstruction, wherein the barrel body defect detection model based on attention multi-scale adaptive reconstruction comprises an encoder, a decoder and an adaptive reconstruction network;

[0006] Making a packaging container image dataset and training the barrel body defect detection model based on attention multi-scale adaptive reconstruction using the packaging container image dataset;

[0007] Obtaining a packaging container image and inputting it into the barrel body defect detection model based on attention multi-scale adaptive reconstruction;

[0008] The barrel defect detection model based on attention multi-scale adaptive reconstruction infers the input packaging container image, specifically: first, the encoder converts the input packaging container image into high-dimensional features, then the decoder converts the features into a probability matrix, and then the adaptive reconstruction network adaptively reconstructs the probability matrix output by the decoder and the denoised input image into a normal image, finally, the reconstructed image and the original image are pixel by pixel, and the abnormal score is used to judge whether the input image has defects, and the mask is used to locate the defects, and the detection result is output.

[0009] Further, in the packaging container image dataset preparation stage, salt and pepper noise is added to the images in the packaging container image dataset to balance the number of normal images and defect images in the packaging container image dataset.

[0010] Further, the encoder adopts an EfficientNet network to extract multi-scale features of the input packaging container image through convolution kernels of different depths and sizes.

[0011] Further, the decoder includes an attention-based multi-scale feature extraction module and a multi-scale feature fusion module; the attention-based multi-scale feature extraction module extracts features of different receptive fields through multi-scale convolution, uses group normalization and average fusion to enhance feature stability, and combines a multi-head attention module to focus on defect areas to generate robust and generalizable defect features; the multi-scale feature fusion module extracts features through multi-scale convolution, adjusts the channel dimension and maintains the spatial resolution through upsampling and downsampling, and generates a probability matrix of the same size as the input packaging container image after batch normalization and GeLU activation function, for pixel-level prediction of defects.

[0012] Further, the process of removing noise in the probability matrix Z and generating a reconstructed image includes multiple iterations, and the image after denoising t times is calculated as where t represents the tth iteration, is a custom parameter that gradually decreases in a cosine annealing manner, and ∈ θ (x t , t) is the model predicted noise.

[0013] Further, in the denoising process of the adaptive reconstruction network, the difference β between the images before and after denoising is compared step by step, and when the difference β is less than the threshold value γ, the denoising is stopped, and the calculation formula is The probability matrix Z, the image after denoising t times and the original image x a are fused to obtain the feature The calculation is as formula The reconstructed image I is obtained through a generative adversarial network (GAN), and the calculation is as formula

[0014] In a second aspect, the present application also provides a barrel body defect detection device based on attention multi-scale adaptive reconstruction, the device comprising:

[0015] A model construction module is configured to construct a barrel body defect detection model based on attention multi-scale adaptive reconstruction, wherein the barrel body defect detection model based on attention multi-scale adaptive reconstruction comprises an encoder, a decoder, and an adaptive reconstruction network.

[0016] A data set production module is configured to produce a packaging container image data set and train the barrel body defect detection model based on attention multi-scale adaptive reconstruction using the packaging container image data set.

[0017] An image acquisition module is configured to acquire a packaging container image and input the packaging container image into the barrel body defect detection model based on attention multi-scale adaptive reconstruction.

[0018] A defect detection module is configured to perform inference on the input packaging container image by the barrel body defect detection model based on attention multi-scale adaptive reconstruction, specifically: the encoder converts the input packaging container image into high-dimensional features, the decoder converts the features into a probability matrix, the adaptive reconstruction network adaptively reconstructs the probability matrix output by the decoder and the input image after denoising into a normal image, the reconstructed image and the original image are pixel by pixel, and it is determined whether the input image has defects through an abnormal score, the defects are located according to the obtained mask, and a detection result is output.

[0019] Further, the model construction module further comprises a data enhancement module, which is configured to add pepper noise to simulate defects in the images in the packaging container image data set, and balance the number of normal images and defect images in the packaging container image data set.

[0020] In a third aspect, the present application also provides an electronic device, comprising: a memory configured to save a computer program; and a processor configured to execute the computer program to implement the barrel body defect detection method based on attention multi-scale adaptive reconstruction.

[0021] In a fourth aspect, the present application also provides a computer readable storage medium configured to save a computer program, wherein the computer program is executed by a processor to implement the barrel body defect detection method based on attention multi-scale adaptive reconstruction.

[0022] Compared with the prior art, the present application has the following beneficial effects:

[0023] The present application is based on an encoder-decoder architecture, adopts an attention-based multi-scale feature extraction module, a multi-scale feature fusion module and an adaptive reconstruction module, and provides an attention-based multi-scale adaptive reconstruction barrel body defect detection model, which converts the features output by the encoder into a probability matrix to obtain the defect probability of the corresponding pixel position, and then reconstructs the defect image into a normal image through the adaptive reconstruction module to improve the accuracy of small industrial defect detection.

[0024] The present application aims at the problems of data imbalance and small defect detection in industrial scenes. First, artificial salt and pepper noise is added to simulate industrial defects, increase the number of defect images, and improve the proportion of defect images in the training set to solve the problem of data imbalance. Then, the attention-based multi-scale feature extraction module is used to fuse the features of different receptive fields and enhance the understanding ability of the image. The multi-head attention module is used to add weights to the feature map to obtain an attention feature map, and the features of small defects at different scales are weighted to make the model focus on the small defect area in the image and improve the detection accuracy of small defects. The multi-scale feature fusion module is used to perform convolution operation on the attention feature map and the multi-scale convolution kernel, and then perform upsampling and downsampling in sequence to obtain a low-dimensional feature map, enlarge the feature difference between the normal area and the defect area, and improve the defect detection accuracy. Finally, the adaptive reconstruction module is used to remove the artificial noise in the image during the image reconstruction stage in the model training process, restore the defect area to the normal area as much as possible, make the model fully learn the features of the normal image, and improve the recognition ability of the model for unknown defects. BRIEF DESCRIPTION OF DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and those skilled in the art can also obtain other related drawings without creative labor based on these drawings.

[0026] Figure 1 A flow chart of an attention-based multi-scale adaptive reconstruction barrel body defect detection method according to an exemplary embodiment.

[0027] Figure 2 A structure diagram of an attention-based multi-scale adaptive reconstruction barrel body defect detection model according to an exemplary embodiment.

[0028] Figure 3A flowchart of defect detection of an input image by a barrel body defect detection model based on attention multi-scale adaptive reconstruction according to an exemplary embodiment.

[0029] Figure 4 A reasoning process diagram of an input packaging container image by a barrel body defect detection model based on attention multi-scale adaptive reconstruction according to an exemplary embodiment.

[0030] Figure 5 A structure diagram of a decoder according to an exemplary embodiment.

[0031] Figure 6 A denoising reconstruction flowchart of an adaptive reconstruction network according to an exemplary embodiment.

[0032] Figure 7 A business flowchart of a filling business using a barrel body defect detection method based on attention multi-scale adaptive reconstruction according to an exemplary embodiment.

[0033] Figure 8 A working flowchart of a filling machine using a barrel body defect detection method based on attention multi-scale adaptive reconstruction according to an exemplary embodiment.

[0034] Figure 9 A framework diagram of a barrel body defect detection model based on attention multi-scale adaptive reconstruction according to an exemplary embodiment.

[0035] In the above figures:

[0036] 100. Model construction module, 200. Dataset making module, 300. Image acquisition module, 400. Defect detection module, 500. Data enhancement module. DETAILED DESCRIPTION

[0037] In order to better explain the technical solutions in the present application, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the specification and specific implementation manners. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the scope of protection of the present application. In some examples, methods, means, elements and circuits familiar to those skilled in the art are not described in detail in order to highlight the main idea of the present application. Similarly, in order to be clear and concise, the description of well-known functions and structures is omitted in the following description.

[0038] Embodiment one

[0039] Reference Figure 1The embodiment provides a barrel body defect detection method based on attention and multi-scale adaptive reconstruction.

[0040] S10, a barrel body defect detection model based on attention and multi-scale adaptive reconstruction is constructed.

[0041] S20, a packaging container image dataset is made, and the barrel body defect detection model based on attention and multi-scale adaptive reconstruction is trained using the packaging container image dataset.

[0042] S30, a packaging container image is acquired and input into the barrel body defect detection model based on attention and multi-scale adaptive reconstruction.

[0043] S40, the barrel body defect detection model based on attention and multi-scale adaptive reconstruction performs inference on the input packaging container image and outputs a detection result.

[0044] Reference Figures 2 to 4 is made to detailed introduction of how to perform defect detection on the input packaging container image by using the barrel body defect detection model based on attention and multi-scale adaptive reconstruction.

[0045] The barrel body defect detection model based on attention and multi-scale adaptive reconstruction has a structure as shown in Figure 2 , and includes an encoder E, a decoder D and an adaptive reconstruction network AR.

[0046] The barrel body defect detection model based on attention and multi-scale adaptive reconstruction has a defect detection process on an input packaging container image as shown in Figure 3 , and specifically includes the following steps:

[0047] S41, the encoder E converts the input packaging container image into high-dimensional features.

[0048] S42, the decoder D converts the features into a probability matrix.

[0049] S43, the adaptive reconstruction network AR adaptively reconstructs the probability matrix output by the decoder D and the input image after denoising into a normal image.

[0050] S44, the reconstructed image and the original image are pixel by pixel, whether the input image has defects is judged through an abnormal score, defects are positioned according to a mask obtained, and a detection result is output, the detection result including a defect category, a position and a confidence, and the defect category, the position and the confidence are output.

[0051] The inference process of the barrel body defect detection model based on attention and multi-scale adaptive reconstruction on an input packaging container image is as shown in Figure 4As shown, in the packaging container image dataset making stage, a data enhancement step is further included, a salt and pepper noise is added to the images in the packaging container image dataset to simulate defects, the number of normal images and defect images in the packaging container image dataset is balanced, the mean square error of the added noise and the model predicted noise is calculated to make the model predicted noise close to the real defect, the image reconstruction effect is achieved, and a noise generation loss function L ARP The calculation is as shown in the formula Where t represents the tth iteration in the image reconstruction process.

[0052] In this embodiment, the EfficientNet network is used as the encoder E, and multi-scale feature extraction is performed on the input packaging container image through convolution kernels of different depths and sizes. The encoder E is responsible for feature extraction and fully utilizes the advantages of different feature extraction networks, has high universality, and can seamlessly integrate various mainstream feature extraction networks such as ResNet, EfficientNet, Vision Transformer, etc. The EfficientNet network extracts features at different levels through convolution kernels of different depths and sizes, and can generate multi-scale features. In defect detection, this multi-scale feature extraction capability helps to capture features of defects of different sizes.

[0053] Referring to Figure 5 , Figure 5 The specific structure of the decoder D is shown. The decoder D includes an attention-based multi-scale feature extraction module AMFE and a multi-scale feature fusion module MFC.

[0054] The attention-based multi-scale feature extraction module AMFE extracts features of different receptive fields through multi-scale convolution, enhances the stability of the features by using group normalization and average fusion, and generates robust and generalizable defect features by combining the multi-head attention module MHA to focus on the defect area.

[0055] The multi-scale feature fusion module MFC extracts features through multi-scale convolution, adjusts the channel dimension and maintains the spatial resolution through upsampling and downsampling, and generates a probability matrix of the same size as the input packaging container image after batch normalization and GeLU activation function, and performs pixel-level prediction on the defects.

[0056] Different sizes of convolution kernels in the convolutional neural network correspond to different receptive fields, which can extract high-frequency detail features such as edges and textures, and low-frequency semantic features such as overall contours. By fusing features of different receptive fields, the understanding ability of the decoder D for images is enhanced. Since the multi-head attention module MHA can disperse attention to different subspaces, reducing the influence of local bias on the whole, the output of the multi-head attention module MHA is fused in the embodiment to obtain comprehensive and rich feature representation.

[0057] The attention-based multi-scale feature extraction module AMFE first performs convolution operation on the feature map X output by the encoder D with 3x3, 5x5 and 7x7 convolution kernels respectively; then the convolution results are group normalized GroupNorm, and then averaged AVG to fuse them into a feature map in the channel dimension; then the feature map is processed by the multi-head attention module MHA to form multiple weight matrices, which are linearly transformed (Linear Transformation, LN) with the fused feature map to form an attention feature map focusing on the defect area; finally, the feature map is activated by the ReLU function to reduce parameter coupling and enhance the generalization and robustness of the attention-based multi-scale adaptive reconstruction barrel body defect detection model.

[0058] Since GroupNorm does not depend on the statistical information of small batches of samples, the normalization effect will not fluctuate greatly due to the change of small batches of samples, so that the attention-based multi-scale adaptive reconstruction barrel body defect detection model can be smoothly trained on small batches of samples. Therefore, GroupNorm is selected for normalization operation in the embodiment.

[0059] Since the feature map Y output by the attention-based multi-scale feature extraction module AMFE usually contains repetitive or low-differentiation information, up-sampling (Upsampled) operation can be used to enhance small defect features, and down-sampling (Subsampled) operation can be used to filter normal area and background features.

[0060] The multi-scale feature fusion module MFC first copies the feature map Y three times, and then performs convolution operation with 3x3, 5x5 and 7x7 convolution kernels respectively, followed by up-sampling (Upsampled) and down-sampling (Subsampled) operations, and finally obtains a probability matrix Z through batch normalization BN and GeLU activation function.

[0061] Upsampled is to expand the number of channels by EXPAND; Subsampled is to compress the number of channels by REDUCE; BN is used to normalize the distribution of feature maps, stabilize the training process, and enhance the generalization ability of the barrel body defect detection model based on the attention-based multi-scale adaptive reconstruction; GeLU is used as an activation function, which is smoother than ReLU activation function, and helps to alleviate the problem of gradient disappearance. The size of the probability matrix Z is the same as the size of the input packaging container image, and the closer the value is to 0, the greater the possibility that the position is a normal area, and the closer the value is to 1, the greater the possibility that the position is a defect area.

[0062] In this embodiment, the cross-entropy truncated loss L P To judge the effect of the decoder D in dividing the defect area and the normal area in the image, the calculation formula is as follows:

[0063] Wherein, W and H are the width and height of the probability matrix Z respectively, and a represents a weighting factor for adjusting the loss weight of the defect area and the normal area. In the training process, a is dynamically adjusted according to the proportion of the defect area in the current batch, and when the proportion of the defect area is small, a is increased to enhance the weight of the defect area. ij P represents the probability of a predicted pixel point in Z belonging to a defect area, the loss value of the defect area is reserved, the contribution of the defect area is highlighted, and only the part with a larger loss value is reserved in the normal area to avoid overfitting.

[0064] Since the probability matrix Z output by the multi-scale feature fusion module MFC contains noise, in order to restore the defect area to the normal area as much as possible and complete defect detection, the adaptive reconstruction network AR is used to remove the noise in the probability matrix Z to generate a reconstructed image, and the processing flow is as shown in Figure 6 .

[0065] Referring to Figure 6 , Figure 6 the specific process of denoising and reconstruction of the adaptive reconstruction network AR is shown. The process of removing noise in the probability matrix Z and generating a reconstructed image by the adaptive reconstruction network AR includes multiple iterations, and the calculation formula of the image after denoising t times is as follows: Wherein, t represents the tth iteration, is a self-defined parameter that gradually decreases in a cosine annealing manner, and ∈ θ (x t , t) is the model predicted noise.

[0066] In the denoising process of the adaptive reconstruction network AR, the difference β between the images before and after denoising is compared step by step, and when the difference β is less than a threshold value γ, the denoising is stopped, and the calculation formula is as follows: ​The probability matrix Z, the image after the t-th denoising and the original image x a are fused to obtain a feature highlighting a defect region The calculation is as shown in the formula The reconstructed image I is obtained through the generative adversarial network (GAN), and the calculation is as shown in the formula The adversarial network (GAN) trained by artificially adding noise can better restore the defect region and has generalization ability for the morphological changes of the real defects. The restored image is compared with the input image to locate the defect region.

[0067] In the following, a specific embodiment is used to introduce the specific application of the method in the filling barrel defect detection business. Taking a full-automatic filling machine as an example, the full-automatic filling machine has a host computer, a slave computer, an industrial camera for acquiring a packaging container image, a filling business execution module, and a machine vision defect detection software. The machine vision defect detection software is embedded with a barrel body defect detection model based on attention multi-scale adaptive reconstruction. The barrel body defect detection model based on attention multi-scale adaptive reconstruction includes an encoder E, a decoder D, and an adaptive reconstruction network AR. The decoder D includes an attention-based multi-scale feature extraction module AMFE and a multi-scale feature fusion module MFC.

[0068] Referring to Figure 7 , Figure 7 the barrel body defect detection method based on attention multi-scale adaptive reconstruction is shown in the overall process of the filling business.

[0069] First, the host computer, the slave computer, and the machine vision defect detection software perform real-time communication. After the host computer issues a detection task, the industrial camera captures real-time pictures, which are input into the barrel body defect detection model based on attention multi-scale adaptive reconstruction after preprocessing, and then the processing result is returned to the slave computer. The slave computer controls the filling business execution module to complete the subsequent filling task.

[0070] Referring to Figure 8 , Figure 8 the working flowchart of the filling machine using the barrel body defect detection method based on attention multi-scale adaptive reconstruction is shown. The specific process includes:

[0071] S1, an image acquisition step, acquiring a packaging container image, and inputting the acquired packaging container image into the barrel body defect detection model based on attention multi-scale adaptive reconstruction.

[0072] S2, a feature extraction step, the encoder E converts the input packaging container image into a high-dimensional feature.

[0073] S3, a feature fusion step, the decoder D converts the features into a probability matrix. Specifically, the high-dimensional feature map is input into the attention-based multi-scale feature extraction module AMFE, different receptive field information is extracted by using 3x3, 5x5 and 7x7 convolution in parallel, and attention feature maps are generated through a multi-head attention mechanism to highlight potential defect areas; the attention feature map is then input into the multi-scale feature fusion module MFC to obtain a probability matrix of the same size as the input through upsampling, downsampling and channel expansion.

[0074] S4, an adaptive reconstruction step, the adaptive reconstruction network AR adaptively reconstructs the probability matrix output by the decoder D and the denoised input image into a normal image.

[0075] S5, a defect determination step, finally, the reconstructed image and the original image are pixel by pixel, and whether the input image has defects is determined by the abnormal score, and the mask is used to locate the defects, and the detection results including the defect category, position and confidence are output.

[0076] S7, a control execution step, the processing result is returned to the lower computer, and the lower computer controls the filling service execution module to complete the subsequent filling task.

[0077] Embodiment two

[0078] Referring to Figure 9 The embodiment provides a barrel body defect detection device based on an attention-based multi-scale adaptive reconstruction, and the device comprises:

[0079] A model construction module 100 is configured to construct a barrel body defect detection model based on an attention-based multi-scale adaptive reconstruction, and the barrel body defect detection model based on the attention-based multi-scale adaptive reconstruction comprises an encoder, a decoder and an adaptive reconstruction network.

[0080] A data set production module 200 is configured to produce a packaging container image data set, and train the barrel body defect detection model based on the attention-based multi-scale adaptive reconstruction by using the packaging container image data set.

[0081] An image acquisition module 300 is configured to acquire a packaging container image and input the packaging container image into the barrel body defect detection model based on the attention-based multi-scale adaptive reconstruction.

[0082] The defect detection module 400 is configured to perform inference on the input packaging container image by the barrel body defect detection model based on the attention multi-scale adaptive reconstruction, specifically: first, the encoder converts the input packaging container image into high-dimensional features, then the decoder converts the features into a probability matrix, and then the adaptive reconstruction network adaptively reconstructs the probability matrix output by the decoder and the denoised input image into a normal image, and finally, the reconstructed image and the original image are pixel by pixel, and whether the input image has defects is determined by the abnormal score, and the mask is used to locate the defects, and the detection result is output.

[0083] In the embodiment, the model construction module further includes a data enhancement module 500, which is configured to add pepper and salt noise to simulate defects in the images in the packaging container image dataset, and balance the number of normal images and defect images in the packaging container image dataset. By calculating the mean square error of the added noise and the model predicted noise, the model predicted noise is close to the real defect, and the image reconstruction effect is achieved. The noise generation loss function L ARP The calculation is as shown in the formula Where t represents the tth iteration in the image reconstruction process.

[0084] In the embodiment, the encoder adopts an EfficientNet network, which extracts multi-scale features of the input packaging container image through convolution kernels of different depths and sizes.

[0085] The decoder includes an attention-based multi-scale feature extraction module AMFE and a multi-scale feature fusion module MFC. The attention-based multi-scale feature extraction module AMFE extracts features of different receptive fields through multi-scale convolution, uses group normalization and average fusion to enhance feature stability, and combines a multi-head attention module MHA to focus on defect areas to generate robust and generalizable defect features. The multi-scale feature fusion module MFC extracts features through multi-scale convolution, adjusts the channel dimension and maintains the spatial resolution through up-sampling and down-sampling, and generates a probability matrix of the same size as the input packaging container image after batch normalization and GeLU activation function, and performs pixel-level prediction on the defects.

[0086] The attention-based multi-scale feature extraction module AMFE first performs convolution operation on the feature map X output by the encoder with 3x3, 5x5 and 7x7 convolution kernels respectively; then the convolution results are subjected to group normalization GroupNorm and then averaged AVG to fuse them into a feature map in the channel dimension; then the feature map is processed by a multi-head attention module MHA to form a plurality of weight matrices, which are subjected to linear transformation (LN) with the fused feature map to form an attention feature map focusing on the defect area; finally, the feature map is subjected to a ReLU activation function to reduce parameter coupling and enhance the generalization and robustness of the attention-based multi-scale adaptive reconstruction barrel defect detection model.

[0087] The multi-scale feature fusion module MFC first copies the feature map Y three times, and then performs convolution operation with 3x3, 5x5 and 7x7 convolution kernels respectively, and then performs up-sampling (Upsampled) and down-sampling (Subsampled) operations in turn, and finally obtains a probability matrix Z through batch normalization BN and GeLU activation function.

[0088] Since the probability matrix Z output by the multi-scale feature fusion module MFC contains noise, in order to restore the defect area to the normal area as much as possible and complete defect detection, the adaptive reconstruction network is used to remove the noise in the probability matrix Z to generate a reconstructed image.

[0089] The process of removing noise in the probability matrix Z and generating a reconstructed image by the adaptive reconstruction network includes multiple iterations, and the image after denoising t times is calculated as where t represents the tth iteration, is a custom parameter that gradually decreases in a cosine annealing manner, and ∈ θ (x t , t) is the model predicted noise.

[0090] In the denoising process of the adaptive reconstruction network, the difference β between the images before and after denoising is compared step by step, and when the difference β is less than a threshold value γ, the denoising is stopped, and the calculation formula is The probability matrix Z, the image after t times of denoising and the original image x a are fused to obtain a feature highlighting the defect area The calculation formula is The reconstructed image I is obtained through the generative adversarial network GAN, and the calculation formula is The adversarial network GAN trained by artificially adding noise can better restore the defect area, has generalization ability for the morphological change of the real defect, and can locate the defect area by comparing the restored image with the input image.

[0091] Embodiment three

[0092] Based on the same technical concept, the embodiment also provides an electronic device, including at least one processor and a memory connected with the at least one processor, and in the embodiment, the connection between the processor and the memory is taken as an example of bus connection, but the specific connection medium between the processor and the memory is not limited. The bus can be divided into an address bus, a data bus, a control bus and the like.

[0093] The processor is the control center of the electronic device, can connect various parts of the electronic device through various interfaces and lines, and realize data processing by running or executing instructions stored in the memory and calling data stored in the memory. Optionally, the processor can include one or more processing units, and the processor can integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user page and an application program, and the modem processor mainly processes an issued instruction. It can be understood that the above-mentioned modem processor can also be not integrated into the processor. In some embodiments, the processor and the memory can be realized on the same chip, and in some embodiments, they can also be realized on independent chips respectively.

[0094] The processor can be a general processor, for example, a central processing unit (CPU), a digital signal processor, an application specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can realize or execute the methods, steps and logic block diagrams disclosed in the embodiments of the application. The general processor can be a microprocessor or any conventional processor. The steps of the method disclosed in combination with the problem positioning method embodiment of the system can be directly embodied as the execution of the hardware processor or the execution of the combination of hardware and software modules in the processor.

[0095] The memory is a non-volatile computer readable storage medium, which can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory can include at least one type of storage medium, for example, can include flash memory, hard disk, multimedia card, card type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic memory, magnetic disk, optical disk, etc. The memory is any other medium capable of carrying or storing desired program code in the form of instructions or data structures and capable of being accessed by a computer, but is not limited to this. The memory in the embodiments of the present application can also be a circuit or any other device capable of realizing the storage function, used to store program instructions and / or data.

[0096] In the present embodiment, the memory stores a computer program which, when executed by the processor, causes the processor to perform the barrel defect detection method based on attention multi-scale adaptive reconstruction described above.

[0097] Since the electronic device is the electronic device in the method in the present embodiment, and the principle of solving the problem of the electronic device is similar to that of the method, the implementation of the electronic device can be referred to the implementation of the method, and the repeated parts will not be repeated.

[0098] Based on the same inventive concept, the embodiments of the present application also provide a computer program product, which comprises computer program code, when the computer program code runs on a computer, causes the computer to execute the barrel defect detection method based on attention multi-scale adaptive reconstruction as described above.

[0099] Since the principle of solving the problem of the above-mentioned computer program product is similar to that of the barrel defect detection method based on attention multi-scale adaptive reconstruction, the implementation of the above-mentioned computer program product can be referred to the implementation of the method, and the repeated parts will not be repeated.

[0100] The above describes in detail the barrel defect detection method, device, equipment and storage medium based on attention multi-scale adaptive reconstruction provided by the present application. The principles and implementation manners of the present application are described by using specific examples in this paper, and the above description of the embodiments is only used to help understand the method of the present application and its core idea. It should be pointed out that, for those skilled in the art, without departing from the principles of the present application, some improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

[0101] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation manner can be realized by means of software and necessary general hardware platform, and of course, it can also be realized by hardware. In addition, the computer program in the memory can be realized in the form of software functional units and sold or used as an independent product when used, and can be stored in a computer readable storage medium. Based on such understanding, the above technical solutions can be embodied in the form of a software product, and the computer software product can be stored in a computer readable storage medium, and the storage medium includes a read-only memory (Read-Only Memory, ROM), a random access memory (Random Access Memory, RAM), a programmable read-only memory (Programmable Read-only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read Only Memory, EEPROM), a one-time programmable read-only memory (One-time Programmable Read-Only Memory, OTPROM), an electrically erasable programmable read-only memory (Electrically-Erasable Programmable Read-Only Memory, EEPROM), a compact disc read-only memory (Compact Disc Read-Only Memory, CD-ROM) or other optical disk storage, a magnetic disk storage, a magnetic tape storage, or any other computer readable medium capable of carrying or storing data.

Claims

1. A barrel defect detection method based on attention-based multi-scale adaptive reconstruction, characterized in that, The method includes: A barrel defect detection model based on attention-based multi-scale adaptive reconstruction is constructed, which includes an encoder, a decoder, and an adaptive reconstruction network. A packaging container image dataset is created, and the attention-based multi-scale adaptive reconstruction barrel defect detection model is trained using the packaging container image dataset. The packaging container image is acquired and input into the attention-based multi-scale adaptive reconstruction barrel defect detection model; The attention-based multi-scale adaptive reconstruction barrel defect detection model infers from the input packaging container image. Specifically, the encoder first converts the input packaging container image into high-dimensional features, then the decoder converts the features into a probability matrix, and then the adaptive reconstruction network adaptively reconstructs a normal image from the probability matrix output by the decoder and the denoised input image. Finally, the reconstructed image is pixel-by-pixel differentiated from the original image, and the presence of defects in the input image is determined by the anomaly score. The defects are then located based on the obtained mask, and the detection result is output.

2. The method according to claim 1, characterized in that, During the creation of the packaging container image dataset, salt and pepper noise is added to the images in the packaging container image dataset to simulate defects, thereby balancing the number of normal images and defective images in the packaging container image dataset.

3. The method according to claim 1, characterized in that, The encoder uses the EfficientNet network, which extracts multi-scale features from the input packaging container image through convolutional kernels of different depths and sizes.

4. The method according to claim 3, characterized in that, The decoder includes an attention-based multi-scale feature extraction module and a multi-scale feature fusion module. The attention-based multi-scale feature extraction module extracts features from different receptive fields through multi-scale convolution, enhances feature stability by using group normalization and averaging fusion, and combines a multi-head attention module to focus on defect regions to generate robust and generalizable defect features. The multi-scale feature fusion module extracts features through multi-scale convolution, adjusts channel dimensions using upsampling and downsampling while maintaining spatial resolution, and generates a probability matrix of the same size as the input packaging container image after batch normalization and GeLU activation function, thus performing pixel-level prediction of defects.

5. The method according to claim 4, characterized in that, The adaptive reconstruction network involves multiple iterations in removing noise from the probability matrix Z and generating a reconstructed image. The image after denoising t times is shown below. The calculation is as follows: Where t represents the t-th iteration. It is a custom parameter that gradually decreases according to the cosine annealing method, ∈ θ (x t ,t) represents the model prediction noise.

6. The method according to claim 5, characterized in that, During the denoising process, the adaptive reconstruction network progressively compares the difference β between the images before and after denoising. Denoising stops when the difference β is less than a threshold γ. The calculation formula is as follows: The probability matrix Z and the image after the t-th denoising step are used. and the original image x a By fusing the components, the prominent features of the defective areas are obtained. The calculation is as follows: The reconstructed image I is obtained after passing through a Generative Adversarial Network (GAN), and the calculation is as follows:

7. A barrel defect detection device based on attention-based multi-scale adaptive reconstruction, characterized in that, The device includes: The model building module is used to build a barrel defect detection model based on attention and multi-scale adaptive reconstruction. The barrel defect detection model based on attention and multi-scale adaptive reconstruction includes an encoder, a decoder and an adaptive reconstruction network. The dataset creation module is used to create a packaging container image dataset and to train the attention-based multi-scale adaptive reconstruction barrel defect detection model using the packaging container image dataset. The image acquisition module is used to acquire images of the packaging container and input them into the attention-based multi-scale adaptive reconstruction barrel defect detection model. The defect detection module is used to infer the input packaging container image through the attention-based multi-scale adaptive reconstruction barrel defect detection model. Specifically: first, the encoder converts the input packaging container image into high-dimensional features; then, the decoder converts the features into a probability matrix; then, the adaptive reconstruction network adaptively reconstructs a normal image from the probability matrix output by the decoder and the denoised input image; finally, the reconstructed image is pixel-by-pixel differentiated from the original image, and the presence of defects in the input image is determined by the anomaly score. The defects are then located based on the obtained mask, and the detection result is output.

8. The apparatus according to claim 7, characterized in that, The model building module also includes a data augmentation module, which is used to add salt and pepper noise to the images in the packaging container image dataset to simulate defects and balance the number of normal images and defective images in the packaging container image dataset.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor is configured to execute the computer program to implement the attention-based multi-scale adaptive reconstruction barrel defect detection method as described in any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the attention-based multi-scale adaptive reconstruction barrel defect detection method as described in any one of claims 1 to 6.