Ceramic package detection method based on auto-encoder and improved ResNet18 model

By using a combination method of autoencoder and improved ResNet18 model in ceramic packaging detection, the problem of low detection accuracy in the prior art in complex environments is solved, and higher detection reliability and efficiency are achieved.

CN119831991AActive Publication Date: 2025-04-15HUAQIAO UNIVERSITY
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510305282.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-14
Publication Date
2025-04-15
Estimated Expiration
2045-03-14

AI Technical Summary

Technical Problem

When faced with complex environments such as light changes, equipment jitters and color interference, the existing ceramic packaging detection technology has low detection accuracy, which is prone to misjudgment or misjudgment, and has limited ability to deal with light fluctuations and ceramic reflection.

Method used

The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model is adopted. The packaging box image is converted into feature vectors through the autoencoder, and matched with the images in the database to obtain position information, and feature extraction and detection are combined with the improved ResNet18 and CBAM modules.

Benefits of technology

It significantly improves the reliability and accuracy of inspection, can accurately judge the packaging status in complex environments, reduces dependence on a large amount of labeled data, and improves the detection efficiency and production line stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119831991A_ABST
    Figure CN119831991A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of target detection, and discloses a ceramic package detection method based on an auto-encoder and an improved ResNet18 model, and the method comprises the following steps: a database construction step: constructing a ceramic package box image database; a model construction step: constructing a product packaging box state detection model in combination with the improved ResNet18 and CBAM; an image acquisition step: acquiring an image of a to-be-detected ceramic packaging box as a detection image, and matching the detection image with the ceramic packaging box image database by using the auto-encoder model to obtain position information; an image segmentation step: performing region segmentation on the detection image by using the position information, and extracting a sub-image to be detected; and a packaging detection step: inputting the sub-image into a product packaging box state detection model, and detecting whether the ceramic is neglected to be loaded or not. The method shows excellent adaptability and robustness in a complex industrial environment, and lays a solid foundation for the accuracy and reliability of intelligent package detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of target detection technology, and in particular to a ceramic packaging detection method based on an autoencoder and an improved ResNet18 model. Background Art

[0002] In the ceramic packaging inspection process, the system mainly faces challenges such as illumination changes, equipment jitter and color interference. Due to the unstable lighting conditions in the factory environment, the lighting may change over time or location, coupled with the slight jitter of the equipment and the deviation of the shooting angle, the images of the same packaging box taken at different times will produce obvious differences. These changes can easily lead to inaccurate matching between the sample image and the database template, affecting the accuracy of the inspection. In addition, when the color of the ceramic is similar to the background color of the packaging box, the boundary between the object and the background becomes blurred, and it is difficult for the model to effectively distinguish between the two. This visual confusion can cause missed or misjudgment, especially in the scenario of high-frequency inspection on the assembly line, where frequent errors may lead to reduced production efficiency. Light fluctuations and reflections on the ceramic surface will also form highlights or shadows in the image, further interfering with the system's capture of the object's outline. In this complex environment, the model needs to have strong feature extraction and generalization capabilities to ensure that the packaging status can still be accurately judged in the case of close colors, unstable lighting or occlusion interference, and timely alarms can be issued when there is a missing package to ensure the stable and efficient operation of the production line.

[0003] There are still many deficiencies in the application of existing methods in ceramic packaging inspection. Manual inspection is inefficient, and long-term operation can easily lead to fatigue, which increases the risk of missed and misjudgment. At the same time, the inconsistent judgment standards among different operators will also lead to instability in the inspection results. Although deep learning technology has shown certain potential, it is highly dependent on a large amount of labeled data, which makes the cost of data collection and annotation high in actual production. In addition, the model has limited performance in dealing with complex scenes such as lighting changes, ceramic reflections, and object occlusions, and it is difficult to maintain consistent detection accuracy. The problem of class imbalance further exacerbates the difficulty of missed assembly detection because the model tends to predict common categories and ignore abnormal situations. These deficiencies reflect the lack of generalization and adaptability of the current methods, and further optimization is urgently needed to meet the inspection needs in complex industrial environments. Summary of the invention

[0004] The purpose of the present invention is to solve the problems in the prior art.

[0005] The technical solution adopted by the present invention to solve the technical problem is: to provide a ceramic packaging detection method based on an autoencoder and an improved ResNet18 model, comprising the following steps:

[0006] Database construction step, building a ceramic packaging box image database;

[0007] Model building step: combining improved ResNet18 and CBAM to build a product packaging box status detection model;

[0008] An image acquisition step is to acquire an image of the ceramic packaging box to be detected as a detection image, and use an autoencoder model to match the detection image with a ceramic packaging box image database to obtain position information;

[0009] The image segmentation step uses the position information to segment the detection image into regions and extract the sub-image to be detected;

[0010] In the packaging inspection step, the sub-image is input into the product packaging box status inspection model to detect whether ceramics are missing. If there are no missing ceramics, the inspection is terminated. If there are missing ceramics, ceramics are refilled and the image acquisition step is re-entered.

[0011] The product packaging box state detection model includes a CBR module, a maximum pooling layer, a first improved residual unit, a first CBAM module, a second improved residual unit, a second CBAM module, a Conv AvgPool module and a fully connected layer connected in sequence; the CBR module is composed of convolution, batch normalization and ReLU activation functions, and is used to extract features from the input image; the maximum pooling layer is used to downsample the features extracted by the CBR module; the first improved residual unit includes an improved residual block, which is used to further extract features from the features output by the maximum pooling layer; the first CBAM module includes a channel attention and a spatial attention mechanism, which is used to dynamically adjust the weights of important channels and regions in the feature map output by the first improved residual unit; the second improved residual unit includes a plurality of improved residual blocks, which are used to perform multiple further feature extractions on the feature map output by the first CBAM module; the second CBAM module includes a channel attention and a spatial attention mechanism, which is used to dynamically adjust the weights of important channels and regions in the feature map output by the second improved residual unit; Conv The AvgPool module further extracts features from the feature map output by the second CBAM module through convolution operations, and downsamples the extracted features through average pooling; the fully connected layer converts the features output by the Conv AvgPool module into probability distribution, thereby outputting the classification result of whether the ceramic is missing;

[0012] The improved residual block includes a first residual layer and a second residual layer connected in sequence. The first residual layer adopts a dual-path interaction mechanism. One path quickly extracts shallow texture features through a single ALC, and the other path deeply mines semantic information through two ALCs connected in series. Finally, the extraction results of the two paths are added and then passed through a ReLU activation function. The second residual layer adopts a single-path structure. The input features are directly processed by two ALCs connected in series, then added to the input features through a skip connection, and then passed through a ReLU activation function.

[0013] The ALC includes a variable batch normalization, a LeakyReLU activation function, a first convolutional layer, a variable batch normalization, a LeakyReLU activation function, and a second convolutional layer connected in sequence, and the input of the ALC is added to the output of the second convolutional layer through a skip connection to obtain the final output of the ALC;

[0014] The variable batch normalization is expressed as:

[0015] ;in, represents the original input, Represents the result of variable batch normalization; and are the mean and variance of the current batch, and For dynamically generated parameters; A small positive number used to prevent division by zero.

[0016] Preferably, the construction of the ceramic packaging box image database comprises the following steps:

[0017] Collect images of ceramic packaging boxes without ceramics inside;

[0018] The collected images are manually annotated to mark the empty spaces in the packaging box where ceramics need to be placed, and auxiliary frames are annotated.

[0019] Preferably, the CBAM module performs the following steps on the input feature map:

[0020] For the input feature map , calculate the channel attention weights respectively and spatial attention weights , respectively expressed as:

[0021] ;

[0022] ;

[0023] in, is the Sigmoid function, Represents the concatenation operation on the channel dimension; MLP represents the multi-layer perceptron operation; AvgPool represents the average pooling operation; MaxPool represents the maximum pooling operation; Conv 7×7 Indicates a convolution operation using a 7×7 convolution kernel;

[0024] Multiply the channel attention weight by the original feature map to obtain the channel-weighted feature map , expressed as:

[0025] ;

[0026] in, Represents element-wise multiplication;

[0027] Add spatial attention weights to channel-weighted feature maps Multiply to get the final output feature map , expressed as:

[0028] .

[0029] Preferably, the loss function of the product packaging box status detection model is expressed as:

[0030] ;

[0031] ;

[0032] ;

[0033] in, represents the loss function of the product box state detection model; represents the cross entropy loss, the total number of samples is N, the total number of categories is C, Indicates whether sample i belongs to category c. If yes, ,otherwise ; is the predicted probability that sample i belongs to category c; is the regularization term, is the regularization coefficient, which is used to control the strength of regularization. represents the total number of all trainable parameters in the model, Indicates the parameter index, are model parameters.

[0034] Preferably, the method of matching the detection image with the ceramic packaging box image database by using the autoencoder comprises the following steps:

[0035] The encoder is used to compress the input detection image into a feature vector and reconstruct a high-quality image;

[0036] Compare the feature vector generated by the encoder with the images in the ceramic packaging box image database, identify the best matching image, and extract the position information therein;

[0037] The decoder uses the feature vector output by the encoder to reconstruct an output image of the same size as the input detection image.

[0038] Preferably, the encoder is used to compress the input detection image into a feature vector, and specifically a 2D convolution layer is used to extract features from the detection image, and the SENet channel attention mechanism is introduced to calculate the channel weight when performing feature extraction, which is expressed as:

[0039] ;

[0040] Among them, z represents the original feature map, and are the learning parameters, represents the LeakyReLU activation function, Represents the sigmoid activation function;

[0041] Multiply the weight s by the original feature map to complete the feature recalibration.

[0042] Preferably, the decoder uses the feature vector output by the encoder to reconstruct an output image of the same size as the input detection image, specifically by expanding the feature vector into a larger feature map through a fully connected layer, and then using a deconvolution operation to convert the feature map to the same size as the input image.

[0043] Preferably, the feature vector generated by the encoder is compared with the image in the ceramic packaging box image database, specifically by calculating cosine similarity to compare the feature vector generated by the encoder with the image feature vector in the ceramic packaging box image database, and the calculation formula of the cosine similarity is:

[0044] ;

[0045] Among them, A and B are two eigenvectors.

[0046] Preferably, the loss function of the autoencoder is:

[0047] ;

[0048] Where n represents the number of pixels. represents the actual value of the i-th pixel, Represents the predicted value of the i-th pixel output by the decoder.

[0049] The present invention has the following beneficial effects:

[0050] (1) The present invention converts the packaging box image into a feature vector through an autoencoder and matches it with samples in the database, effectively reducing the interference of factors such as lighting changes and shooting angle differences on detection. This process ensures the accuracy of auxiliary frame annotation and precise position matching, allowing subsequent ceramic missing detection to be performed in a more complex environment, thereby significantly improving the reliability of detection.

[0051] (2) The present invention introduces improved ResNet18 and CBAM modules in feature extraction, which enhances the overall performance of the model. ResNet18 can capture multi-level visual features through its deep residual structure, while the CBAM module enhances the ability to focus on key features through channel attention mechanism and spatial attention mechanism. This combination greatly improves the recognition accuracy of the model in complex scenes such as lighting changes, object overlap and visual similarity, ensuring the robustness of the system in practical applications.

[0052] (3) The present invention reduces the reliance on large amounts of labeled data. Through lightweight autoencoder design and feature optimization, it not only improves detection efficiency, but also can respond to production line needs in real time, allowing ceramic packaging detection to adapt to different production conditions more quickly, thereby improving overall production efficiency and accuracy.

[0053] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments, but the present invention is not limited to the embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 A method step diagram of an embodiment of the present invention;

[0055] Figure 2 A schematic diagram of a flow chart of an embodiment of the present invention;

[0056] Figure 3 Schematic diagram of ceramic packaging box images according to an embodiment of the present invention; wherein (a) is an image of an empty ceramic packaging box, and (b) and (c) are images of empty ceramic packaging boxes with auxiliary frames marked;

[0057] Figure 4 A network structure diagram of an autoencoder model according to an embodiment of the present invention;

[0058] Figure 5 A network structure diagram of a product packaging box status detection model according to an embodiment of the present invention;

[0059] Figure 6 is a diagram of an ALC network structure according to an embodiment of the present invention;

[0060] Figure 7 CBAM attention mechanism diagram of an embodiment of the present invention;

[0061] Figure 8 A schematic diagram of packaging detection according to an embodiment of the present invention;

[0062] Fig. 9 This is a test effect diagram of an embodiment of the present invention. DETAILED DESCRIPTION

[0063] See also Figure 1FIG. 1 is a diagram showing steps of a method according to an embodiment of the present invention, comprising the following steps:

[0064] S101, database construction step, constructing a ceramic packaging box image database;

[0065] S102, model building step, combining improved ResNet18 and CBAM to build a product packaging box status detection model;

[0066] S103, an image acquisition step, acquiring an image of the ceramic packaging box to be detected as a detection image, matching the detection image with a ceramic packaging box image database using an autoencoder model, and obtaining position information;

[0067] S104, an image segmentation step, using the position information to segment the detection image into regions and extracting a sub-image to be detected;

[0068] S105, packaging detection step, the sub-image is input into the product packaging box status detection model to detect whether ceramics are missing; if there are no missing ceramics, the detection is ended; if there are missing ceramics, the ceramics are refilled and the image acquisition step is re-entered.

[0069] See also Figure 2 As shown, the entire workflow of ceramic packaging inspection can be divided into two key stages.

[0070] Specifically, phase one includes database establishment, auxiliary box annotation, and position matching.

[0071] Database establishment. In order to build a database for the packaging detection system, the embodiment of the present invention collects images of ceramic packaging boxes of various specifications, and annotates the positions where the ceramics are to be loaded with auxiliary frames. The establishment of the database aims to provide reliable training data and reference standards for subsequent detection models, so as to achieve accurate identification of missing ceramics. First, different types of packaging box images are collected by industrial cameras in a standardized factory environment. In order to ensure the consistency of the data, the shooting conditions are strictly controlled during the image acquisition process to minimize the image quality differences caused by lighting changes, shooting angle deviations and reflection interference. In addition, to ensure that the subsequent algorithm can effectively extract the detailed information in the packaging box, the collected images will undergo preprocessing steps, including unified resolution, denoising and color correction, to improve the clarity and stability of the image. Some pictures of empty packaging boxes are shown below. Figure 3 As shown in (a).

[0072] Auxiliary frame annotation. Use manual annotation tools to annotate the area to be installed inside the box with auxiliary frames for the original box photos. According to the internal design of each type of box, draw accurate auxiliary frames for each reserved position for placing ceramics, such as Figure 3As shown in (b) and (c). These auxiliary frame information is not only used to record the layout of different packaging boxes, but also provides the model with key target position data during the training process to ensure that the detection system can efficiently identify the area to be installed and reduce misjudgments caused by misalignment or occlusion. Finally, the annotated images and their auxiliary frame information will be stored in the database according to the type and size of the packaging box, providing structured data support for the system. In actual applications, when a new packaging box image is collected, the system will retrieve similar packaging boxes from the database through feature matching, and use the corresponding auxiliary frame information to detect the filling status of the ceramics, thereby achieving efficient and accurate missing parts recognition.

[0073] Position matching. In the process of matching the packaging box samples with the database, ensuring the consistency of the captured images is the main challenge. The lighting conditions in the factory environment are unstable, coupled with equipment jitter and differences in shooting angles, resulting in significant changes in the images of the same packaging box taken at different times. To solve this problem, an autoencoder algorithm is introduced, which compresses the input image into a feature vector through the encoder and reconstructs a high-quality image. The feature vector generated by the encoder is compared with the image feature vector in the database through cosine similarity to identify the best matching image. After a successful match, the system applies the auxiliary box position information in the database image to the sample image to ensure the accuracy of ceramic missing assembly detection. The decoder is responsible for reconstructing an image of the same size as the input image to ensure the quality of the output. The network structure of the autoencoder model of an embodiment of the present invention is as follows: Figure 4 As shown in the figure, it consists of two main parts: the encoder and the decoder. The encoder extracts features from the input packaging box image samples, extracts key features layer by layer through a multi-layer convolutional neural network, and compresses the high-dimensional image data into a low-dimensional feature vector, retaining important information in the image, such as shape, color and texture, while removing redundant information. In this way, the packaging box image is represented as a 128-dimensional feature vector after being processed by the encoder. The decoder is responsible for reconstructing this feature vector into a reconstructed image close to the original image, and converts low-dimensional features into high-dimensional data through inverse operations, so that the model learns how to restore image details from feature vectors. In the position matching stage, after the autoencoder encodes the new sample into a feature vector, it compares it with the feature vector in the database and finds the closest database image by calculating the similarity. The position information of the associated auxiliary box is extracted to confirm the filling status of the packaging box. This process ensures accurate judgment of whether there is any missing packaging in the packaging box, thereby improving the overall efficiency and reliability of the production line.

[0074] The core task of the encoder is to convert the input image into a low-dimensional feature vector. In this stage, a 2D convolutional layer (Conv2D) is used to extract features from the image, and appropriate convolution kernel parameters are set to generate feature maps. At the same time, LeakyReLU is used as the activation function to enhance the model's ability to capture important features and reduce the risk of neuron inactivation. In addition, the SENet (Squeeze-and-Excitation Network) channel attention mechanism is introduced. SENet compresses the feature map into a channel descriptor by performing global average pooling on the feature map output by each convolutional layer to capture the global information of the feature map. Then, two fully connected layers (a compression layer and an expansion layer) are used to generate channel weights, and the weight calculation formula is:

[0075] ;

[0076] Among them, z is the input feature map, and are the learning parameters, represents the LeakyReLU activation function, Represents the sigmoid activation function. Finally, these weights are multiplied by the original feature map to complete the feature recalibration, enhancing the response of important features while suppressing less important features.

[0077] The main task of the decoder is to reconstruct the feature vector output by the encoder into the original image. Its structure is similar to that of the encoder. First, the feature vector is expanded into a larger feature map through a fully connected layer, and then the feature map is converted to the same size as the input image using a deconvolution operation. Through this process, the decoder ensures the quality of the reconstructed image, thereby ensuring the effectiveness of the subsequent matching process.

[0078] In the image retrieval stage, the cosine similarity is used to measure the similarity between the feature vector of the sample image and the feature vector of the database image. Cosine similarity is an effective distance measurement method that can evaluate the angle between two feature vectors, thereby reflecting their similarity. Its calculation formula is:

[0079] ;

[0080] Among them, A and B are two feature vectors. By calculating the cosine distance between the feature vectors, we can accurately find the best matching database image and extract the corresponding ceramic loading position information.

[0081] After the encoding and decoding operations are completed, the mean square error (MSE) is used to calculate the loss, and the autoencoder model weights are continuously adjusted through the optimizer to minimize the loss. MSE is used in the box matching task to evaluate the pixel-level difference between the reconstructed image and the original image to ensure that the model maintains high accuracy and consistency during the reconstruction process. By minimizing MSE, the model learns to capture the detailed features of the box more accurately and optimizes the image feature extraction capability. Its calculation formula is as follows:

[0082] ;

[0083] Where n represents the number of pixels. represents the actual value of the ith Indicates the i-th predicted value. During the optimization process, the Adam optimizer is used to adjust the model parameters to accelerate convergence and improve stability. Finally, by reducing the MSE loss, the model can accurately extract the packaging box features and improve the matching accuracy.

[0084] The autoencoder model effectively extracts the key features of the packaging box image and combines cosine similarity for image matching, ensuring accurate detection of the ceramic loading status. This method not only improves the efficiency and accuracy of detection, but also provides reliable support for subsequent production processes, and has high practical application value.

[0085] Specifically, the second phase is the factory production detection phase. In this phase, a product packaging box status detection model based on improved ResNet18 and CBAM was built to cope with multiple challenges in complex industrial environments; the overall framework of the product packaging box status detection model is as follows Figure 5 shown.

[0086] First, the CBR module composed of convolution, batch normalization (BN) and ReLU activation function extracts features from the input image, starting from low-level features such as edges and textures, and performs feature mapping through convolution operations. BN is used to improve training stability, while the ReLU activation function gives the model nonlinear capabilities. Next, downsampling is performed through the MaxPool layer to reduce the amount of data and retain the main features, significantly reducing the computational burden. After that, complex high-level features are further extracted through multiple layers of improved residual blocks. The "skip connection" is introduced in the improved residual block structure. This design can alleviate the gradient vanishing problem in deep networks, allowing information to flow smoothly between network layers and ensure the stable transmission of deep features. The CBAM module is also added to the model to improve the accuracy of feature extraction. The CBAM module includes channel attention and spatial attention mechanisms, which can dynamically adjust the weights of important channels and regions in the feature map, so that the model pays more attention to key features and ignores irrelevant information. This is particularly important for distinguishing objects of similar colors (such as ceramics and packaging boxes), allowing the model to accurately identify target objects even when the lighting changes or is obstructed, significantly reducing the misjudgment rate.

[0087] In the final feature aggregation stage, the model introduces the Conv AvgPool module that combines convolution and average pooling. This module further extracts high-level features through convolution operations, while average pooling downsamples the feature map to retain overall information and reduce feature dimensions. This combined design ensures that key features are retained during the aggregation process, effectively reduces computational complexity, and improves the generalization ability and computational efficiency of the model. Finally, after being mapped to the output space through the fully connected layer, the feature vector is converted into a probability distribution through the Softmax activation function, thereby outputting the classification results of "no ceramics" or "ceramics", ensuring the accuracy and efficiency of packaging detection. When a missing package is detected, the system will automatically issue an alarm, thereby realizing the intelligence and stability of the production line. The design of the overall framework ensures the adaptability and robustness of the model, provides technical support for the realization of intelligent packaging detection, and significantly improves production efficiency.

[0088] The loss function of the product box status detection model uses cross entropy loss. The cross entropy loss function is suitable for multi-classification tasks and can effectively measure the difference between the model's predicted probability distribution and the true distribution. Specifically, the formula for cross entropy loss can be expressed as:

[0089] ;

[0090] Among them, the total number of samples is N, and the total number of categories is C. The true label is represented by one-hot encoding, where Indicates whether sample i belongs to category c. When sample i belongs to category c, ;otherwise The model predicts that the probability that sample i belongs to category c is .

[0091] During the training process, the model gradually adjusts parameters to improve the recognition accuracy of the "no ceramic" and "with ceramic" categories by minimizing the cross entropy loss. In addition, a regularization term is added to prevent overfitting to ensure that the model has good generalization ability in complex industrial environments. The L2 regularization term can be expressed as:

[0092] ;

[0093] in, is the regularization term, is the regularization coefficient, which is used to control the strength of regularization. are model parameters.

[0094] Therefore, the final loss function of the product box status detection model can be expressed as:

[0095] ;

[0096] Such a design aims to improve the classification performance and generalization ability of the model, enabling it to perform well in complex industrial environments.

[0097] Specifically, the product packaging box state detection model of the embodiment of the present invention adopts an improved ResNet18 network combined with a CBAM module, wherein the improved ResNet18 network introduces adaptive batch normalization and a leaky ReLU activation function before the convolution layer to form an improved residual block in view of the deficiency that the original residual block fails to give full play to the role of the batch normalization layer. The detailed description is as follows.

[0098] (1) The improved residual block includes a first improved residual layer and a second improved residual layer connected in sequence; the embodiment of the present invention includes a first improved residual block (Res_a1 and Res_b1), a second improved residual block (Res_a2 and Res_b2), a third improved residual block (Res_a3 and Res_b3) and a fourth improved residual block (Res_a4 and Res_b4); wherein Res_a1, Res_a2, Res_a3 and Res_a4 are the first improved residual layer, adopting a dual-path interaction mechanism, and the upper division The first branch quickly extracts shallow texture features (such as the edge contour of the packaging box) through a single ALC, and the lower branch deeply mines semantic information (such as local grayscale changes in the missing area) through two series-connected ALCs. Then the dual-path features complete weighted integration, and finally the ReLU activation module is used to constrain the nonlinear range; Res_b1, Res_b2, Res_b3 and Res_b are the second improved residual layer, which adopts a single-path structure. The input features are directly processed by two series-connected ALCs and then added with jump connections. Its advantage is that it reduces computational complexity.

[0099] Specifically, the specific structure of the ALC is shown in Figure 6 As shown in the figure, ALC (Adaptive BN->LeakyReLU->Conv) includes Adaptive BN (variable batch normalization), LeakyReLU activation function, convolution layer, Adaptive BN (variable batch normalization), LeakyReLU activation function and convolution layer connected in sequence, and introduces jump connections at the input and output. The design of labeling pre-processing enables the dynamic distribution adjustment of input features before convolution, and with the weak activation characteristics of the LeakyReLU activation function for negative intervals, it not only avoids the neuron death problem of traditional ReLU, but also enhances the adaptability to sudden changes in data distribution in industrial scenarios through the adaptive parameter mechanism.

[0100] (2) Variable batch normalization dynamically adjusts the normalization parameters according to the features of different batches, improving the robustness of the model in small-batch training or data imbalance scenarios. This optimization further improves the scale distribution of the features, increases the gradient, accelerates the convergence of the learning process, effectively alleviates the gradient vanishing problem, and retains the identity mapping characteristics in the residual block. This improvement enhances the stability and adaptability of the model in the task of missing detection. The core improvement of variable batch normalization is to dynamically adjust the normalization parameters to adapt to the distribution characteristics of different batches of data. Traditional normalization uses a fixed mean and variance to normalize each feature channel, while the improved method introduces a dynamic parameter adjustment mechanism to adaptively adjust the normalization parameters according to the feature statistics of the current batch. The specific implementation steps are as follows:

[0101] Dynamic mean and variance calculation: For each small batch of input feature maps, its mean and variance are calculated, which is consistent with the traditional BN.

[0102] Adaptive scaling and translation: After normalization, a learnable scaling factor is introduced ( ) and the translation factor ( ), but its parameter update no longer relies solely on back propagation, but is dynamically adjusted in combination with the statistics of the current batch. For example, by introducing additional fully connected layers or attention mechanisms, the batch features are dynamically generated and .

[0103] Always, assume the input features are , variable batch normalization is expressed as:

[0104] ;in, and are the mean and variance of the current batch, and Dynamically generated parameters.

[0105] Improved batch normalization enhances the robustness of the model in small-batch training or data distribution imbalance scenarios, while alleviating the gradient vanishing problem and improving the stability of feature distribution.

[0106] (3) Improved ResNet18 network uses LeakyReLU activation function as activation function in improved residual block. In the standard ResNet-18 network, ReLU (Rectified Linear Unit) is used as activation function. However, when the input value is negative, ReLU will set its output to zero, which may cause some neurons to be inactive for a long time, resulting in neuron death. This phenomenon will hinder the weight update of the network and reduce the learning ability and performance of the model. To solve this problem, LeakyReLU is used as activation function. LeakyReLU is an improved version of ReLU, which inherits its advantages of simple calculation and high efficiency, and introduces non-zero slope in the negative input area to avoid neuron death. Specifically, LeakyReLU outputs a certain proportion (usually 0.01 times) of the input value when it is negative, ensuring that there is still a non-zero gradient during back propagation, so that the weight of the model can be continuously updated and the learning efficiency is improved. Its mathematical definition is as follows.

[0107] The ReLU activation function is expressed as:

[0108] ;

[0109] The LeakyReLU activation function is expressed as:

[0110] ;

[0111] in, is a small constant (usually 0.01).

[0112] The improvement of the LeakyReLU activation function helps alleviate the gradient vanishing problem and makes the ResNet18 network more adaptable to deep learning tasks, thereby improving the modeling ability of brain tumor image features. In the task of missing detection, interference such as illumination changes and occlusion may cause some features to have negative values. LeakyReLU allows the network to effectively capture edge features and fine-grained information in complex scenes. At the same time, the introduction of non-zero gradients improves the convergence speed and classification accuracy, enhances the robustness of the model, and provides a stable and reliable solution for intelligent detection.

[0113] (4) Introducing the CBAM module. The CBAM module aims to improve the feature extraction capability of the convolutional neural network through the channel attention mechanism (CAM) and the spatial attention mechanism (SAM). The channel attention mechanism selects important features in the channel dimension of the feature map, while the spatial attention mechanism assigns weights based on the spatial position, thereby achieving an effective fusion of global and local features. The CBAM module improves the generalization ability of the detection model by enhancing the feature extraction capability of the model, enabling it to adapt to different packaging box layouts and a variety of ceramic types. Combined with ResNet18, the introduction of CBAM effectively improves the robustness and detection accuracy of the model, ensuring that even in complex industrial environments, the system can quickly identify missing packaging and issue alarms in a timely manner to ensure the smooth progress of the production process. The attention mechanism of CBAM, such as Figure 7 shown.

[0114] The channel attention mechanism extracts the global information of the feature map and assigns weights to different channels. , firstly, global average pooling and maximum pooling are performed along the spatial dimension to obtain two feature vectors of size 1×1×C. Subsequently, these two feature vectors are processed by a shared two-layer multi-layer perceptron (MLP) and element-by-element addition, and finally the channel attention weight is generated by the Sigmoid activation function. The calculation process is as follows:

[0115] ;

[0116] in represents the channel attention weight, is the Sigmoid function.

[0117] The spatial attention mechanism aims to highlight the important spatial regions in the feature map. , first perform average pooling and maximum pooling along the channel dimension to obtain two feature maps of size H×W×1. These two feature maps are concatenated in the channel dimension, and a convolution operation with a 7×7 convolution kernel is performed to generate the spatial attention weights, which are calculated as follows:

[0118] ;

[0119] in represents the spatial attention weight, Represents a concatenation operation on the channel dimension.

[0120] Specifically, the packaging inspection process of S104 is as follows: Figure 8 As shown in the figure, the sample image of the sample to be tested is collected and matched with the database image to obtain the position information; the sample image is cut into a fixed area according to the position information, the sub-image to be tested is extracted, and a series of image enhancement processes such as brightness, contrast and noise suppression are performed to improve the image quality and recognizability. The enhanced sub-image will be input into the improved ResNet18 model for feature extraction. The improved ResNet18 effectively captures the multi-level features of the image through multi-layer convolution and residual connection. The CBAM module focuses on key features through channel and spatial attention mechanisms to further improve the recognition ability of the model. After the feature extraction is completed, the model generates the classification probability distribution of each sub-image through the fully connected layer, and uses the Softmax activation function to convert the feature vector into a probability value, and finally determines whether the position is loaded with ceramics. The detection result comprehensively judges the status of each sub-image as "no missing" or "missing" for the packaging box. If the system detects a missing situation, it will trigger an alarm and refill the missing position, and then perform another sample detection process to ensure the efficiency and stability of the production line.

[0121] In order to verify the effect of the present invention, an experimental platform was built to implement the method of the present invention. The required equipment includes hardware and software systems: the hardware part uses the MV-CS200-10GC V5.0 camera (20 million pixel IMX183 sensor) with the MVL-KF1228M-12MPE lens (12mm focal length), which is connected to the industrial computer through a gigabit network cable to ensure real-time acquisition of high-resolution images; the power supply system is provided by the KPL-060M-VI adapter (24V / 2.5A) and a dedicated I / O line to provide stable power support; at the software level, the computing platform is equipped with an Intel Core i7-8750H CPU and an NVIDIA GeForce GTX1050Ti GPU (4GB video memory), which supports accelerated reasoning of deep learning models, and builds an improved ResNet18+CBAM model based on Python 3.8.5 and PyTorch 1.8.0. The test results are as follows Fig. 9 As shown, when the packaging box is empty, the yellow light is on, indicating that no ceramics are loaded; when the packaging box is partially loaded with ceramics, the red light is on, indicating that some ceramics are missing; when the packaging box is fully loaded with ceramics, the green light is on, indicating that the packaging is complete.

[0122] This paper introduces a combination of improved ResNet18 and CBAM (Convolutional BlockAttention Module) models to detect ceramic packaging. In the ceramic packaging detection process, the system is divided into two main stages: database establishment, auxiliary frame annotation and matching stage, and factory production sample detection stage. In the first stage, the main challenge faced by the system is to ensure the matching accuracy between the sample image and the database image. Due to the unstable lighting conditions, equipment jitter and shooting angle deviation in the factory environment, the images of the same packaging box taken at different times may have significant differences, which complicates the matching process. To solve this problem, this study adopts an autoencoder algorithm, which consists of an encoder and a decoder. The encoder extracts key features through a convolutional layer and uses the activation function LeakyReLU and the SENet channel attention mechanism to enhance the focus on important features. After the feature extraction is completed, the feature vector output by the encoder will be matched with the feature vector of the image in the database through cosine similarity to find the most similar database image. Once the match is successful, the auxiliary frame position information in the database image will be passed to the sample image to ensure the accurate detection of ceramic leakage. This process not only improves the accuracy of matching, but also provides reliable position information for subsequent detection. In addition, the decoder is responsible for reconstructing the feature vector into a high-quality image of the same size as the input image to ensure the validity of the output. Through this efficient matching mechanism, the system can effectively overcome the impact caused by changes in shooting conditions and improve the overall accuracy and reliability of ceramic packaging detection.

[0123] During the factory production inspection and matching stage, the system faces multiple challenges such as the similar color of ceramics and the bottom of the packaging box, lighting changes, and object occlusion. These factors make it significantly difficult for the model to distinguish ceramics from the background. First, according to the location information provided by the database, the sample image is cut into fixed areas to extract sub-images of each location to be detected; then, these sub-images undergo a series of image enhancement processes to improve their quality and recognizability, and the enhanced sub-images will be input into the improved ResNet18 and CBAM models for feature extraction. In feature extraction, the improved ResNet18 architecture effectively captures the multi-level features of the image through multi-layer convolution and residual connections, generates high-dimensional feature maps, and improves the ability to extract details. At the same time, the CBAM module further strengthens the model's focus on key features through channel and spatial attention mechanisms. The channel attention mechanism dynamically adjusts the weights of each feature channel to emphasize important features; the spatial attention mechanism guides the model to focus on important areas in the image to ensure that a high level of recognition accuracy can be maintained under lighting changes and occlusion. After feature extraction, the model maps high-dimensional features to the output space through a fully connected layer, generates a classification probability distribution for each sub-image, and applies the Softmax activation function to convert the feature vector into a probability value to ultimately determine whether ceramics are loaded at that location. In order to improve the accuracy and robustness of classification, the present invention uses a cross-entropy loss function to optimize the classification effect of the model to ensure that the identification of missing items during training is more stable. The test results are finally sorted into "no missing items" or "missing items" to ensure the efficiency and stability of the production line. If the system determines that there is a missing item, an alarm will be automatically triggered and the missing item position will be refilled, and then the sample detection process will be re-executed. Through this systematic feature extraction and classification process, the model of this study shows excellent adaptability and robustness in a complex industrial environment, laying a solid foundation for the accuracy and reliability of intelligent packaging detection.

[0124] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A ceramic packaging detection method based on autoencoder and improved ResNet18 model, characterized in that: The following steps are involved: Database construction step, building a ceramic packaging box image database; Model building step: combining improved ResNet18 and CBAM to build a product packaging box status detection model; An image acquisition step is to acquire an image of the ceramic packaging box to be detected as a detection image, and use an autoencoder model to match the detection image with a ceramic packaging box image database to obtain position information; The image segmentation step uses the position information to segment the detection image into regions and extract the sub-image to be detected; In the packaging inspection step, the sub-image is input into the product packaging box status inspection model to detect whether ceramics are missing. If there are no missing ceramics, the inspection is terminated. If there are missing ceramics, ceramics are refilled and the image acquisition step is re-entered. The product packaging box state detection model includes a CBR module, a maximum pooling layer, a first improved residual unit, a first CBAM module, a second improved residual unit, a second CBAM module, a Conv AvgPool module and a fully connected layer connected in sequence; the CBR module is composed of convolution, batch normalization and ReLU activation functions, and is used to extract features from the input image; the maximum pooling layer is used to downsample the features extracted by the CBR module; The first improved residual unit includes an improved residual block, which is used to further extract features of the features output by the maximum pooling layer; The first CBAM module includes channel attention and spatial attention mechanisms for dynamically adjusting the weights of important channels and regions in the feature map output by the first improved residual unit; The second improved residual unit includes a plurality of improved residual blocks, which are used to perform multiple further feature extractions on the feature map output by the first CBAM module; The second CBAM module includes channel attention and spatial attention mechanisms, which are used to dynamically adjust the weights of important channels and regions in the feature map output by the second improved residual unit; the Conv AvgPool module further extracts features from the feature map output by the second CBAM module through convolution operations, and downsamples the extracted features through average pooling; the fully connected layer converts the features output by the Conv AvgPool module into probability distribution, thereby outputting the classification result of whether the ceramic is missing; The improved residual block includes a first residual layer and a second residual layer connected in sequence. The first residual layer adopts a dual-path interaction mechanism. One path quickly extracts shallow texture features through a single ALC, and the other path deeply mines semantic information through two ALCs connected in series. Finally, the extraction results of the two paths are added and then passed through a ReLU activation function. The second residual layer adopts a single-path structure. The input features are directly processed by two ALCs connected in series, then added to the input features through a skip connection, and then passed through a ReLU activation function. The ALC includes a variable batch normalization, a LeakyReLU activation function, a first convolutional layer, a variable batch normalization, a LeakyReLU activation function, and a second convolutional layer connected in sequence, and the input of the ALC is added to the output of the second convolutional layer through a skip connection to obtain the final output of the ALC; The variable batch normalization is expressed as: ;in, represents the original input, Represents the result of variable batch normalization; and are the mean and variance of the current batch, and For dynamically generated parameters; A small positive number used to prevent division by zero.

2. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 1 is characterized in that: The construction of the ceramic packaging box image database comprises the following steps: Collect images of ceramic packaging boxes without ceramics inside; The collected images are manually annotated to mark the empty spaces in the packaging box where ceramics need to be placed, and auxiliary frames are annotated.

3. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 1 is characterized in that: The CBAM module performs the following steps on the input feature map: For the input feature map , calculate the channel attention weights respectively and spatial attention weights , respectively expressed as: ; ; in, is the Sigmoid function, Represents the concatenation operation on the channel dimension; MLP represents the multi-layer perceptron operation; AvgPool represents the average pooling operation; MaxPool represents the maximum pooling operation; Conv 7×7 Indicates a convolution operation using a 7×7 convolution kernel; Multiply the channel attention weight by the original feature map to obtain the channel-weighted feature map , expressed as: ; in, Represents element-wise multiplication; Add spatial attention weights to channel-weighted feature maps Multiply to get the final output feature map , expressed as: 。 4. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 1 is characterized in that: The loss function of the product packaging box status detection model is expressed as: ; ; ; in, represents the loss function of the product box state detection model; represents the cross entropy loss, the total number of samples is N, the total number of categories is C, Indicates whether sample i belongs to category c. If yes, ,otherwise ; is the predicted probability that sample i belongs to category c; is the regularization term, is the regularization coefficient, which is used to control the strength of regularization. represents the total number of all trainable parameters in the model, Indicates the parameter index, are model parameters.

5. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 1 is characterized in that: The method of using the autoencoder to match the detection image with the ceramic packaging box image database includes the following steps: The encoder is used to compress the input detection image into a feature vector and reconstruct a high-quality image; Compare the feature vector generated by the encoder with the images in the ceramic packaging box image database, identify the best matching image, and extract the position information therein; The decoder uses the feature vector output by the encoder to reconstruct an output image of the same size as the input detection image.

6. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 5 is characterized in that: The encoder is used to compress the input detection image into a feature vector. Specifically, a 2D convolution layer is used to extract features from the detection image, and the SENet channel attention mechanism is introduced to calculate the channel weight during feature extraction, which is expressed as: ; Among them, z represents the original feature map, and are the learning parameters, represents the LeakyReLU activation function, Represents the sigmoid activation function; Multiply the weight s by the original feature map to complete the feature recalibration.

7. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 5 is characterized in that: The decoder uses the feature vector output by the encoder to reconstruct an output image of the same size as the input detection image, specifically by expanding the feature vector into a larger feature map through a fully connected layer, and then using a deconvolution operation to convert the feature map to the same size as the input image.

8. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 6 is characterized in that: The feature vector generated by the encoder is compared with the image in the ceramic packaging box image database, specifically by calculating the cosine similarity to compare the feature vector generated by the encoder with the image feature vector in the ceramic packaging box image database, and the calculation formula of the cosine similarity is: ; Among them, A and B are two eigenvectors.

9. The ceramic packaging detection method based on the autoencoder and the improved ResNet18 model according to claim 1 is characterized in that: The loss function of the autoencoder is: ; Where n represents the number of pixels. represents the actual value of the i-th pixel, Represents the predicted value of the i-th pixel output by the decoder.

Citation Information

Patent Citations

  • Cigarette package anomaly detection and positioning method based on deep learning

    CN111951264A

  • Ceramic tile surface defect detection method based on interactive attention and convolutional neural network

    CN113658176A

  • Method for rapidly detecting surface defects of small-size mosaic ceramic

    CN113744263A

  • Coated ceramic area virtual edge detection method based on deep learning

    CN118674723A

  • Image Authentication Method and Real-Time Product Authentication System

    US20210397897A1