A Defect Traceability Method for Packaging Production Line Based on Lightweight Inference Network
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-20
- Publication Date
- 2026-08-14
AI Technical Summary
现有烟包缺陷追溯方法主要存在以下技术缺陷,难以满足卷包产线高速生产下的精准、高效追溯需求:
[0073] This invention achieves rapid, accurate, and efficient traceability of cigarette pack defects on the cigarette packaging production line by constructing a ternary unique association and hash verification system, a lightweight similarity defect inference network, and a spatiotemporal prior weight modeling and weight-first parallel retrieval mechanism. It uses a unique QR code identifier to achieve a ternary unique association between the cigarette pack, parameters, and image, combined with SHA-256 hash verification, effectively avoiding problems such as data mislinking, tampering, and missing data, ensuring the uniqueness, integrity, and immutability of traceability data, and improving the reliability of traceability results. Utilizing the spatiotemporal clustering of defects, the spatiotemporal prior weight modeling and weight-first parallel retrieval mechanism filter invalid data, shortening the time required for retrieving millions of images, meeting the real-time traceability needs of high-speed production on the cigarette packaging line. It employs a lightweight similarity defect inference network and a fusion-based similarity calculation method, combined with a spatiotemporal-similarity joint ranking mechanism. The precision rate for similar defects is improved, while the false negative and false positive rates are reduced, effectively avoiding these problems. The lightweight inference network has fewer parameters, making it compatible with the computing power and storage resources of industrial edge devices. It can also seamlessly integrate with existing packaging production line platforms without large-scale modifications, reducing modification costs and enhancing its practicality and promotional value. It supports one-click switching between global search and spatiotemporal prior search modes, adapting to different scenarios such as routine traceability and special defect traceability, balancing search efficiency and comprehensiveness. It can also be widely applied to similar packaging production lines in the food and pharmaceutical industries, making it applicable to a wide range of industries. Through functions such as structured report export and anomaly alerts, it provides reliable data support for defect root cause analysis, equipment maintenance, and process optimization, enabling timely detection and resolution of potential quality problems on the production line, reducing the generation of defective batches, and improving the quality control level and production efficiency of the packaging production line.
Smart Images

Figure CN122573286A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of cigarette production line defect traceability technology, and also relates to the fields of cigarette production quality inspection, machine vision defect identification and industrial big data traceability technology. Specifically, it relates to a cigarette production line defect traceability method based on a lightweight inference network, which is a fast and accurate traceability method for defective products based on QR code association, lightweight similar defect area inference network and parallel inference. Background Technology
[0002] Cigarette packaging production lines operate at high speeds, and the types of defects in cigarette packs are diverse. Some defects are also minute and difficult to detect, posing a significant challenge to defect traceability. Existing cigarette pack defect traceability methods suffer from the following technical shortcomings, making it difficult to meet the precise and efficient traceability requirements of high-speed cigarette packaging production lines:
[0003] Existing methods often use a single identifier to bind partial production data, failing to establish a unique association between cigarette packs, process parameters, and inspection images. Furthermore, they lack effective data integrity verification mechanisms, making them prone to issues such as broken data links, tampering, and missing data, resulting in unreliable traceability results. The cigarette packaging production line generates millions of inspection images daily. Existing methods often employ a global, full-data blind search mode, failing to utilize the spatiotemporal clustering characteristics of defects. This leads to significant retrieval redundancy and severe waste of computational resources; retrieving millions of images typically takes 5-10 minutes, failing to meet real-time traceability requirements. Existing methods often use a single similarity calculation method, resulting in insufficient accuracy in feature extraction for minor and complex defects. They also fail to consider the spatiotemporal correlation of defects for sorting, easily leading to missed detections and false detections, and low precision for similar defects. Existing deep learning traceability models have large parameter counts and high computational costs, making them difficult to adapt to the computing power and storage resources of industrial edge devices. Simultaneously, most methods require large-scale modifications to existing production line platforms, resulting in long modification cycles and high costs, limiting their practicality and promotional value. Existing methods only support a single search mode, unable to flexibly adjust to different traceability scenarios (routine traceability, special defect traceability), making it difficult to balance search efficiency and comprehensiveness.
[0004] To address the aforementioned technical shortcomings, there is an urgent need for a method for tracing cigarette packaging defects that can achieve rapid, accurate, and efficient traceability under massive data, is adaptable to edge deployment, has low modification costs, and is highly adaptable, in order to overcome the deficiencies of existing technologies and improve the quality control level of cigarette packaging production lines. Summary of the Invention
[0005] The purpose of this invention is to overcome the above-mentioned defects of the prior art and provide a defect tracing method for cigarette packaging production lines based on a lightweight inference network. By constructing a ternary unique association and hash verification system, a lightweight similar defect inference network, spatiotemporal prior weight modeling and weight-first parallel retrieval mechanism, the invention achieves real-time, accurate and efficient tracing of cigarette packaging defects, while reducing the difficulty of deployment and transformation costs at the edge, and improving the practicality and promotion value of the method.
[0006] The present invention employs the following technical solution.
[0007] A defect tracing method for package production lines based on lightweight inference networks includes:
[0008] Step 1: Assign a unique QR code index to each cigarette pack, and bind it to multi-dimensional data such as production time, equipment information, process parameters and inspection images to form a unique three-dimensional association between cigarette pack, parameters and images;
[0009] Step 2: Use the SHA-256 one-way hash encryption algorithm to verify the integrity of the unique three-element associated data;
[0010] Step 3: Construct a lightweight inference network based on depthwise separable convolution and spatial attention mechanism, extract defect image features, and calculate the similarity between the target defect and the candidate defect by combining cosine similarity and Euclidean distance;
[0011] Step 4: Extract the spatiotemporal prior information of the target defect, construct a temporal sliding window weight model and a device matching weight model, and calculate the comprehensive spatiotemporal weight;
[0012] Step 5: Divide the data into blocks according to both device and time dimensions, and allocate calculation threads based on the comprehensive spatiotemporal weights. High-weight data blocks are processed in real time first, while low-weight data blocks are processed asynchronously in the background to achieve parallel retrieval.
[0013] Step 6: Combine defect similarity with comprehensive spatiotemporal weights to calculate the final comprehensive score, and output the traceability results in sorted order of scores.
[0014] Furthermore, step 1 specifically includes:
[0015] Step 1.1: Assign a unique production line code to each roll packaging production line, assign a unique equipment code to each piece of equipment on each roll packaging production line, and assign a unique workstation code to each workstation on each roll packaging production line;
[0016] Furthermore, in step 1.1, the QR code index generation module generates a unique QR code index Q for each cigarette pack based on the rules of sequentially connected production line codes, equipment codes, workstation codes, timestamps, and random sequences;
[0017] Step 1.2: After the QR code index Q is generated, the data acquisition module synchronously collects multi-dimensional data of the cigarette pack and uniquely binds it with the QR code index Q to form a unique ternary association data of the cigarette pack, parameters and image;
[0018] Furthermore, in step 1.2, the multi-dimensional data used as parameters includes:
[0019] The production timestamp T uses the system time of the edge device.
[0020] The equipment information for the production line includes equipment number E, production line number L, and workstation number W;
[0021] The process parameter set P includes: packaging speed, packaging temperature, packaging pressure, glue level, sealing position, and raw material batch number;
[0022] The equipment status S of the production line is uploaded in real time by the equipment's PLC control system, which includes five statuses: equipment operation, shutdown, alarm, and normal or abnormal status.
[0023] A unique set of six-sided image identifiers, with each of the six images of the cigarette pack assigned a unique identifier I.
[0024] Step 1.3: The bound ternary unique association data is first stored in the SSD of the edge device; at the same time, it is synchronized in real time to the cloud server to store the ternary unique association data of all cigarette packs.
[0025] Furthermore, step 2 specifically includes:
[0026] Step 2.1: After the unique association between the cigarette pack, parameters, and images is formed, the QR code index Q of the cigarette pack, the set of process parameters P, and the unique identifier set of the six-sided detection images are automatically concatenated into a string Str in a fixed order;
[0027] The SHA-256 one-way hash encryption algorithm is used to encrypt the concatenated string Str, generating a globally unique hash checksum. The calculation formula is as follows:
[0028] ;
[0029] Here, Hash() represents the SHA-256 hash encryption function, and Str is the concatenated string.
[0030] Step 2.2: When defect tracing is required, staff scan the QR code index Q of the defective cigarette pack using a QR code scanning module. Based on the QR code index Q, they retrieve the corresponding ternary unique association data from the edge device or cloud server and concatenate it into a new string in a fixed order. ;
[0031] Using the same SHA-256 hash encryption algorithm, calculate Hash value (Hash) ), and compare it with the stored The comparison will be performed according to the following rules:
[0032] If Hash( )= If the data is found to be complete, unaltered, and without incorrect links, the search process will proceed to the next step.
[0033] If Hash( )≠ If the data is found to be abnormal, an alarm will be triggered immediately, and the tracing process will be terminated.
[0034] Furthermore, step 3 specifically includes:
[0035] Step 3.1: Construct a lightweight similarity defect inference network by using a depthwise separable convolutional structure combined with a spatial attention mechanism;
[0036] Step 3.2: Calculate the defect similarity. The formula for calculating defect similarity is as follows:
[0037] ;
[0038] In the formula for calculating the defect similarity, S is the defect similarity score; The cosine similarity weight coefficient is... For feature vectors , The Euclidean distance between them; T is the temperature coefficient.
[0039] Furthermore, in step 3.1, the overall structure of the lightweight similarity defect inference network includes, in sequence: an input layer, three layers of depthwise separable convolutional units, a batch normalization unit, a ReLU activation unit, a spatial attention module, and a feature output layer;
[0040] The input layer receives defect images from the six-sided inspection images of the cigarette pack. The defect image data from the six-sided inspection images is normalized, and the calculation formula is as follows:
[0041] ;
[0042] In this calculation formula, These are the original pixel values of the defect image in the six-sided inspection image. This represents the minimum pixel value in the defect image from the six-sided inspection image. The maximum pixel value in the defect image from the six-sided inspection image. These are the normalized pixel values;
[0043] The specific parameters of the 3-layer depthwise separable convolutional unit are as follows:
[0044] The first layer of depthwise separable convolution has a kernel size of 3×3, a stride of 1, a padding method of Same, and 32 output channels; the pointwise convolution kernel has a kernel size of 1×1, a stride of 1, and 64 output channels.
[0045] The second layer of depthwise separable convolution has a depthwise convolution kernel size of 3×3, a stride of 1, a padding method of Same, and 64 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 128 output channels.
[0046] The third layer of depthwise separable convolution has a 3×3 kernel size, a stride of 1, Same padding, and 128 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 256 output channels.
[0047] After each depthwise separable convolutional unit, a batch normalization unit is added to normalize the batch data of the feature map output by that depthwise separable convolutional unit. The calculation formula for the batch normalization unit is as follows:
[0048] ;
[0049] In this calculation formula, The mean of the batch data. The variance of the batch data. To The standardized result, where m is the number of feature values in the batch of data. For the first in the batch data 1 eigenvalue, To prevent tiny values with a denominator of 0, γ and β are learnable parameters. These are the feature values after batch normalization unit processing;
[0050] After batch normalization, ReLU activation units are added. The activation function f(x) of the ReLU activation unit is calculated as follows:
[0051] f(x) = max(0,x);
[0052] A spatial attention module is added to the end of the lightweight similarity defect inference network;
[0053] The feature output layer will take the spatial attention-weighted feature vectors. , The vector is flattened to obtain a one-dimensional feature vector, which is used as the input for defect similarity calculation.
[0054] Furthermore, in step 3.1, the implementation process of the spatial attention module is as follows:
[0055] Global average pooling and global max pooling are performed on the feature maps output by the ReLU activation units to obtain two 1×1×256 feature maps respectively.
[0056] The two feature maps are concatenated to obtain a 1×1×512 feature map;
[0057] The concatenated feature map is compressed to 1×1×256 by using a 1×1 convolution kernel, and then the spatial attention weight map Att(F) is obtained by using the Sigmoid activation function.
[0058] Multiply the spatial attention weight map Att(F) element-wise with the feature map F output by the lightweight similarity defect inference network to obtain the spatial attention-weighted feature map. ;
[0059] The formula for calculating spatial attention weighting is as follows:
[0060] ;
[0061] In this calculation formula, The feature vector of the target defect image. Spatial attention weight map for the target defect image. This is the target defect feature vector after spatial attention weighting; The feature vector of the candidate defect image. Spatial attention weight map of candidate defect images. This is the candidate defect feature vector after spatial attention weighting.
[0062] Furthermore, step 4 specifically includes:
[0063] Step 4.1: Perform spatiotemporal prior extraction, that is, when a defective cigarette pack is detected, extract key spatiotemporal prior information from the ternary unique association data of the cigarette pack;
[0064] Step 4.2: Based on the temporal prior characteristics, construct a temporal sliding window weight model, that is, set a time window range and assign different temporal weights to candidate defect images within different time ranges. ;
[0065] Step 4.3: Based on spatial prior characteristics, construct an equipment matching weight model, that is, assign different equipment matching weights according to the degree of correlation between the production equipment of the candidate defective cigarette pack and the target equipment. ;
[0066] Step 4.4: Perform comprehensive spatiotemporal weight calculation. Time weight Device matching weight The product;
[0067] Step 4.5: Perform retrieval weight priority sorting, i.e., based on the comprehensive spatiotemporal weight. The search weight priority of candidate defect data blocks is determined by sorting them from highest to lowest size.
[0068] Furthermore, step 5 specifically includes:
[0069] Step 5.1: Divide the data into blocks according to the data block partitioning rules;
[0070] Step 5.2: Perform weight-priority thread allocation, that is, the edge device adopts a multi-threaded parallel processing architecture, sets up 8 computing threads, and allocates computing threads according to the retrieval weight priority of data blocks;
[0071] Step 5.3: Execute the parallel retrieval process, which is to perform a parallel retrieval process based on the data blocks with retrieval weight priority.
[0072] The beneficial effects of the present invention are as follows, compared with the prior art:
[0073] This invention achieves rapid, accurate, and efficient traceability of cigarette pack defects on the cigarette packaging production line by constructing a ternary unique association and hash verification system, a lightweight similarity defect inference network, and a spatiotemporal prior weight modeling and weight-first parallel retrieval mechanism. It uses a unique QR code identifier to achieve a ternary unique association between the cigarette pack, parameters, and image, combined with SHA-256 hash verification, effectively avoiding problems such as data mislinking, tampering, and missing data, ensuring the uniqueness, integrity, and immutability of traceability data, and improving the reliability of traceability results. Utilizing the spatiotemporal clustering of defects, the spatiotemporal prior weight modeling and weight-first parallel retrieval mechanism filter invalid data, shortening the time required for retrieving millions of images, meeting the real-time traceability needs of high-speed production on the cigarette packaging line. It employs a lightweight similarity defect inference network and a fusion-based similarity calculation method, combined with a spatiotemporal-similarity joint ranking mechanism. The precision rate for similar defects is improved, while the false negative and false positive rates are reduced, effectively avoiding these problems. The lightweight inference network has fewer parameters, making it compatible with the computing power and storage resources of industrial edge devices. It can also seamlessly integrate with existing packaging production line platforms without large-scale modifications, reducing modification costs and enhancing its practicality and promotional value. It supports one-click switching between global search and spatiotemporal prior search modes, adapting to different scenarios such as routine traceability and special defect traceability, balancing search efficiency and comprehensiveness. It can also be widely applied to similar packaging production lines in the food and pharmaceutical industries, making it applicable to a wide range of industries. Through functions such as structured report export and anomaly alerts, it provides reliable data support for defect root cause analysis, equipment maintenance, and process optimization, enabling timely detection and resolution of potential quality problems on the production line, reducing the generation of defective batches, and improving the quality control level and production efficiency of the packaging production line. Attached Figure Description
[0074] Figure 1 This is a flowchart of the defect tracing method for roll packaging production lines based on lightweight inference networks described in this invention. Detailed Implementation
[0075] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this invention. The embodiments described in this application are merely some embodiments of this invention, and not all embodiments. Based on the spirit of this invention, other embodiments obtained by those skilled in the art without creative effort are all within the protection scope of this invention.
[0076] like Figure 1 As shown, this invention proposes a defect tracing method for packaging production lines based on lightweight inference networks, comprising the following steps:
[0077] Employing an edge-cloud collaborative architecture, and combining unique QR code identification, hash integrity verification, lightweight deep learning, spatiotemporal prior weighting, and parallel retrieval technologies, the system achieves rapid end-to-end traceability of cigarette packaging defects. The specific technical solution is as follows:
[0078] The key idea of this invention is as follows: First, a unique QR code identifier is assigned to each cigarette pack, binding multi-dimensional data such as production, equipment, process, and inspection images to form a unique ternary association between the cigarette pack, parameters, and images. SHA-256 hash verification is used to ensure data integrity and immutability. Second, a lightweight similarity defect inference network is constructed, combined with a fusion-based similarity calculation method, to achieve rapid and accurate feature extraction and similarity matching of defect images. Then, the spatiotemporal prior information of defects is extracted, and a temporal sliding window weight and equipment matching weight model are constructed to calculate a comprehensive spatiotemporal weight, achieving priority ranking for retrieval. Next, data is segmented and retrieved in parallel based on weight priority to improve retrieval efficiency. Finally, defect similarity and comprehensive spatiotemporal weight are combined for joint ranking, outputting traceability results and generating structured reports. Simultaneously, it supports one-click switching between global retrieval and spatiotemporal prior retrieval modes to adapt to different traceability scenarios.
[0079] The hardware deployment of the method of this invention adopts a collaborative architecture of edge and cloud, which takes into account both real-time performance and data storage and analysis requirements. The specific hardware components are as follows:
[0080] Edge devices include an industrial edge computer, a six-sided inspection camera, a QR code index generation module, a QR code scanning module, and a data acquisition module;
[0081] Cloud devices include cloud servers and memory, used for data storage, historical data retrieval, report analysis, etc.
[0082] The communication module adopts dual-mode Ethernet and 5G communication to ensure the data transmission speed and stability between the edge and the cloud. The edge devices are connected to the existing testing equipment and PLC control system of the production line through the Modbus protocol to achieve data interoperability.
[0083] Edge devices are deployed on the roll packaging production line and are responsible for tasks with high real-time requirements, such as real-time data acquisition, QR code index generation and scanning, lightweight inference, and parallel retrieval. Cloud devices are responsible for non-real-time tasks such as data storage, historical data tracing, report generation and analysis. The edge devices and the cloud synchronize data in real time to ensure data consistency.
[0084] The method of this invention solves the defects of existing technologies such as chaotic data association, low retrieval efficiency, insufficient matching accuracy, difficulty in deployment at the edge, high transformation cost, and single retrieval mode, and realizes fast, accurate and efficient tracing under massive data.
[0085] Specifically, the technical solution of this invention includes the following six key steps, each step being interconnected and working collaboratively to ensure the efficiency and accuracy of the traceability process:
[0086] Step 1: Assign a unique QR code index to each cigarette pack, and bind it to multi-dimensional data such as production time, equipment information, process parameters and inspection images to form a unique three-dimensional association between cigarette pack, parameters and images;
[0087] In a preferred but non-limiting embodiment of the present invention, step 1 specifically includes:
[0088] The main purpose of this step is to assign a unique identifier to each cigarette pack, bind it to multi-dimensional production and inspection data, and form a unique ternary association between the cigarette pack, parameters, and image. This solves the problems of chaotic data association and broken links in existing technologies, and provides basic data support for subsequent traceability. The specific implementation process is as follows:
[0089] Step 1.1: Assign a unique production line code (e.g., L01, L02) to each roll packaging production line, assign a unique equipment code (e.g., E01, E02) to each piece of equipment on each roll packaging production line, and assign a unique workstation code (e.g., W01, W02) to each workstation on each roll packaging production line.
[0090] In a preferred but non-limiting embodiment of the present invention, in step 1.1, the QR code index generation module generates a unique QR code index Q for each cigarette pack according to the rules of sequentially connected production line codes, equipment codes, workstation codes, timestamps and random sequences (6 bits);
[0091] For example, the encoding format of the QR code index Q is: L01-E01-W01-20260511140000123-123456, where 20260511140000123 is the production timestamp (format: year, month, day, hour, minute, second, millisecond), and 123456 is a random sequence to ensure the uniqueness of the QR code index; the QR code index Q adopts the QR code format, with a size of 15mm×15mm, is generated on the side of the cigarette pack, and has a resolution of 300dpi to ensure that the QR code is clear and legible and can be quickly recognized by the scanning module.
[0092] Step 1.2: After the QR code index Q is generated, the data acquisition module synchronously collects multi-dimensional data of the cigarette pack and uniquely binds it with the QR code index Q to form a unique ternary association data of the cigarette pack, parameters and image;
[0093] In a preferred but non-limiting embodiment of the present invention, in step 1.2, the multi-dimensional data as parameters includes:
[0094] The production timestamp T uses the system time of the edge device and is in the format "YYYYMMDDHHMMSSmmm" (e.g., 20260511140000123) to ensure that the production time of each cigarette pack can be accurately traced.
[0095] The equipment information of the production line, including equipment number E (e.g., E01), production line number L (e.g., L01), and workstation number W (e.g., W01), is automatically uploaded by the equipment PLC control system to ensure a one-to-one correspondence with the cigarette packaging production equipment;
[0096] The process parameter set P is collected in real time by the production line PLC control system. The collected process parameters include: packaging speed, packaging temperature, packaging pressure, glue level, sealing position and raw material batch number.
[0097] The equipment status S of the production line is uploaded in real time by the equipment's PLC control system. It includes five statuses: equipment operation, shutdown, alarm, and normal or abnormal status. The alarm status needs to record the alarm code and alarm time to provide a basis for subsequent root cause analysis.
[0098] A unique set of images for six-sided detection is provided. Six cameras (corresponding to the front, back, left, right, top, and bottom of the cigarette pack, respectively) simultaneously acquire images of the six sides of the cigarette pack. Each image of the six sides of the cigarette pack is assigned a unique identifier I (format: Q-side, such as L01-E01-W01-20260511140000123-123456-front). The image format is JPG, the resolution is 1280×720 pixels, and the compression ratio is 1:5 to ensure image clarity and low storage resource consumption.
[0099] Step 1.3: The bound ternary unique association data is first stored in the SSD of the edge device for real-time retrieval and inference; at the same time, it is synchronized to the cloud server in real time through Ethernet and 5G dual-mode communication. The cloud server adopts a distributed storage architecture to store the ternary unique association data of all cigarette packs for no less than one year to meet the requirements of quality traceability and compliance archiving.
[0100] Data synchronization adopts an incremental synchronization mechanism, which only synchronizes newly added and modified data, reducing the amount of data transmission and avoiding inconsistencies between edge devices and the cloud.
[0101] Step 2: Use the SHA-256 one-way hash encryption algorithm to perform integrity verification on the three unique linked data to ensure that the data has not been tampered with or the chain is not broken, thus providing a reliable data foundation for traceability;
[0102] In a preferred but non-limiting embodiment of the present invention, step 2 specifically includes:
[0103] The main purpose of this step is to verify the integrity and immutability of the ternary unique association data of cigarette packs, parameters, and images, preventing data tampering and broken links, and ensuring the reliability of traceability data. The specific implementation process is as follows:
[0104] Step 2.1: After the unique association between the cigarette pack, parameters, and images is formed, the QR code index Q, the process parameter set P, and the unique identifier set of the six-sided detection images of the cigarette pack are automatically concatenated into a string Str in a fixed order. The concatenation order is from Q, P (sorted by the first letter of the process parameter name) to I (sorted by the face: from the front, back, left, right, top to bottom).
[0105] For example, the splicing example is: Str=Q+packaging speed+packaging temperature+packaging pressure+glue height+sealing position+raw material batch number+I_front+I_back+...+I_bottom.
[0106] The SHA-256 one-way hash encryption algorithm is used to encrypt the concatenated string Str, generating a globally unique hash checksum. The hash checksum is 64 bits long, and its calculation formula is as follows:
[0107] ;
[0108] Here, Hash() represents the SHA-256 hash encryption function, and Str is the concatenated string. The SHA-256 algorithm is irreversible and unique; that is, the same Str can only generate the same string. Different Strs generate different And cannot pass Push Str to ensure the immutability of data.
[0109] generated The hash check code is stored together with the unique three-element associated data on the edge device and the cloud server to establish a one-to-one correspondence between the hash check code and the associated data.
[0110] Step 2.2: When defect tracing is required, staff scan the QR code index Q of the defective cigarette pack using a QR code scanning module. Based on the QR code index Q, they retrieve the corresponding ternary unique association data from the edge device or cloud server and concatenate it into a new string according to the fixed order in Step 2.1. ;
[0111] Using the same SHA-256 hash encryption algorithm, calculate Hash value (Hash) ), and compare it with the stored The comparison will be performed according to the following rules:
[0112] If Hash( )= If the data is found to be complete, unaltered, and without incorrect links, the search process will proceed to the next step.
[0113] If Hash( )≠ If the associated data is found to be abnormal (tampered with, incorrectly linked, or missing), a data anomaly alarm will be triggered immediately, the tracing process will be terminated, and the anomaly information will be recorded (including the QR code index Q of the abnormal cigarette pack, the anomaly time, and the hash). )and The comparison results are provided for staff to investigate and handle.
[0114] Hash verification is quick and does not affect the real-time nature of tracing, while ensuring the credibility of tracing data and providing a reliable foundation for subsequent defect reasoning and retrieval.
[0115] Step 3: Construct a lightweight inference network based on depthwise separable convolution and spatial attention mechanism, extract defect image features, and calculate the similarity between the target defect and the candidate defect by combining cosine similarity and Euclidean distance;
[0116] In a preferred but non-limiting embodiment of the present invention, step 3 specifically includes:
[0117] The main purpose of this step is to construct a lightweight similarity defect inference network to achieve rapid feature extraction from defect images. Combining cosine similarity and Euclidean distance, the similarity between the target defect (the defective image of the substandard cigarette pack) and candidate defects (detected images of other cigarette packs) is calculated, providing a basis for subsequent defect matching and retrieval. The specific implementation process is as follows:
[0118] Step 3.1: To address the problems of large number of parameters, slow inference speed, and difficulty in deployment at the edge of existing deep learning models, this invention adopts a depthwise separable convolutional structure and combines it with a spatial attention mechanism to construct a lightweight similar defect inference network. The network structure is simple, has few parameters, and fast inference speed, while also having high defect feature extraction accuracy.
[0119] In a preferred but non-limiting embodiment of the present invention, in step 3.1, the overall structure of the lightweight similarity defect inference network includes, in sequence: an input layer, three layers of depthwise separable convolutional units, a batch normalization (BN) unit, a ReLU activation unit, a spatial attention module, and a feature output layer;
[0120] The input layer receives defect images (target defect images or candidate defect images) from the six-sided inspection images of the cigarette pack. The image size is uniformly adjusted to 224×224 pixels, and the number of channels is 3 (RGB). The defect image data in the input six-sided inspection images are normalized (the pixel values are normalized to the [0,1] interval), and the calculation formula is as follows:
[0121] ;
[0122] In this calculation formula, These are the original pixel values of the defect image in the six-sided inspection image. This represents the minimum pixel value in the defect image from the six-sided inspection image. The maximum pixel value in the defect image from the six-sided inspection image. These are the normalized pixel values; normalization can accelerate network convergence and improve inference accuracy.
[0123] The traditional convolutional unit is replaced by a 3-layer depthwise separable convolutional unit. The 3-layer depthwise separable convolutional unit splits the traditional convolution into depthwise convolution and pointwise convolution, which can significantly reduce the number of model parameters and computation without reducing the accuracy of feature extraction.
[0124] The specific parameters of the 3-layer depthwise separable convolutional unit are as follows:
[0125] The first layer of depthwise separable convolution has a kernel size of 3×3, a stride of 1, a padding method of Same, and 32 output channels; the pointwise convolution kernel has a kernel size of 1×1, a stride of 1, and 64 output channels.
[0126] The second layer of depthwise separable convolution has a depthwise convolution kernel size of 3×3, a stride of 1, a padding method of Same, and 64 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 128 output channels.
[0127] The third layer of depthwise separable convolution has a 3×3 kernel size, a stride of 1, Same padding, and 128 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 256 output channels.
[0128] Depthwise separable convolutions reduce computational cost and parameter count compared to traditional convolutions, effectively lowering the computational burden on the model and improving inference speed.
[0129] After each depthwise separable convolutional unit, a batch normalization (BN) unit is added to normalize the batch data of the feature maps output by that depthwise separable convolutional unit, reducing gradient vanishing, accelerating network convergence, and improving the model's generalization ability. The calculation formula for the batch normalization (BN) unit is as follows:
[0130] ;
[0131] In this calculation formula, The mean of the batch data. The variance of the batch data. To After standardization, m represents the number of feature values in the batch of data (in this invention, m can be 32). For the first in the batch data 1 eigenvalue, To prevent tiny values with a denominator of 0 ( =1e-5), γ and β are learnable parameters (the initial values of γ and β are 1 and 0, respectively). These are the feature values after batch normalization (BN) unit processing;
[0132] Following the batch normalization (BN) unit, a ReLU activation unit is added to introduce nonlinear factors, enhance the feature representation capability of the lightweight similarity defect inference network, and address the problem of insufficient fitting ability of linear models. The activation function f(x) of the ReLU activation unit is calculated as follows:
[0133] f(x) = max(0,x);
[0134] The ReLU activation unit has a simple activation function calculation and fast convergence speed, which can effectively avoid the gradient vanishing problem and improve the training and inference efficiency of lightweight similar defect inference networks.
[0135] A spatial attention module is added to the end of the lightweight similar defect inference network to focus on the defect region and improve the extraction accuracy of defect features. In particular, for complex and small defects such as wrinkles and minor damage, it can effectively enhance the feature response of the defect region and suppress the interference of the background region.
[0136] In a preferred but non-limiting embodiment of the present invention, the implementation process of the spatial attention module in step 3.1 is as follows:
[0137] Global average pooling and global max pooling are performed on the feature map output by the ReLU activation unit (size 224×224×256) to obtain two 1×1×256 feature maps respectively.
[0138] The two feature maps are concatenated to obtain a 1×1×512 feature map;
[0139] The concatenated feature map is compressed to 1×1×256 by a 1×1 convolution kernel, and then the spatial attention weight map Att(F) (size is 224×224×256) is obtained by passing the Sigmoid activation function. The weight values range from [0,1].
[0140] Multiply the spatial attention weight map Att(F) element-wise with the feature map F output by the lightweight similarity defect inference network to obtain the spatial attention-weighted feature map. This allows for focusing on the defective area;
[0141] The formula for calculating spatial attention weighting is as follows:
[0142] ;
[0143] In this calculation formula, The feature vector of the target defect image is obtained by flattening the feature map after processing with 3 layers of depthwise separable convolution, BN, and ReLU, with dimensions of 1×224×224×256. Spatial attention weight map (dimension 224×224×256) for the target defect image. This is the target defect feature vector after spatial attention weighting; The feature vector of the candidate defect image. Spatial attention weight map of candidate defect images. This is the candidate defect feature vector after spatial attention weighting.
[0144] The feature output layer will take the spatial attention-weighted feature vectors. , The vector is flattened to obtain a one-dimensional feature vector (1×12544, i.e., 224×224×256 after flattening), which is used as the input for defect similarity calculation.
[0145] The lightweight similarity defect inference network constructed in this invention has few parameters, low inference time per image, can run quickly and stably at the industrial edge, and has high defect feature extraction accuracy.
[0146] Step 3.2: Calculate defect similarity. To improve the accuracy of defect matching, this invention combines cosine similarity and Euclidean distance to design a fusion-type defect similarity calculation method. This method can measure both the directional similarity and the distance similarity of two defect feature vectors, effectively improving the matching accuracy of complex and minute defects. The formula for calculating defect similarity is shown below:
[0147] ;
[0148] In the formula for calculating defect similarity, S is the defect similarity score. The larger S is, the higher the similarity between the target defect and the candidate defect; the smaller S is, the lower the similarity. The cosine similarity weight coefficient is set according to specific requirements, and its value ranges from 0.6 to 0.8. Because cosine similarity can effectively measure the directional similarity of feature vectors and is sensitive to the morphological features of defects, the weight can be preferably set to 0.7 to highlight the influence of morphological features. The cosine similarity is the closest to 1, indicating that the two feature vectors are more consistent in direction and have more similar defect morphologies. For feature vectors , The Euclidean distance between two feature vectors is used to measure the spatial distance between them. The smaller the distance, the closer the features of the two defects are. T is a temperature coefficient, which can be set according to specific requirements. The value range is 10~20. The temperature coefficient is used to smooth the Euclidean distance term and avoid excessive fluctuations in the distance term from affecting the similarity calculation results. When T is set to 15, it can smooth the distance term while retaining the influence of distance differences on similarity. This is the exponential smoothing term of the Euclidean distance. The smaller the Euclidean distance, the closer this smoothing term is to 1, and the greater its contribution to the similarity score. A similarity threshold is set. The value is set according to specific requirements, and its range is 0.85~0.95; when S≥ When S < , the target defect image and the candidate image are determined to be similar defects; when S < , If the condition is not met, it is considered a dissimilarity defect and excluded from the search results.
[0149] This fusion-based similarity calculation method can effectively improve the matching accuracy of complex and minute defects. Compared with the single cosine similarity calculation method, the false negative rate and false positive rate are reduced respectively.
[0150] Step 4: Extract the spatiotemporal prior information of the target defect, construct a temporal sliding window weight model and a device matching weight model, and calculate the comprehensive spatiotemporal weight;
[0151] In a preferred but non-limiting embodiment of the present invention, step 4 specifically includes:
[0152] The main purpose of this step is to extract the spatiotemporal prior information of the target defects, construct a temporal sliding window weight model and a device matching weight model, calculate the comprehensive spatiotemporal weight, and utilize the spatiotemporal clustering of defects in the packaging production line to filter invalid search data, providing a basis for subsequent weight-priority parallel retrieval. The specific implementation process is as follows:
[0153] Step 4.1: Perform spatiotemporal prior extraction. Spatiotemporal prior information refers to information related to the spatiotemporal aggregation characteristics of defects in the packaging production line, specifically including temporal priors and spatial priors:
[0154] Time-priority: Defects on the roll packaging production line usually occur in a concentrated period of time. For example, after equipment wears out, similar defects are likely to appear within the next 30 minutes; after process parameters are adjusted, defects are likely to appear within 15-30 minutes after the adjustment.
[0155] Spatial prior: Defects in the roll packaging production line are usually concentrated on the same equipment or adjacent equipment on the same production line. For example, if a wrinkle defect occurs at a certain station of the same equipment, other stations of the same equipment may also have the same defect. Adjacent equipment on the same production line may also have the same defect due to process coordination.
[0156] The specific process of spatiotemporal prior extraction includes: when a defective cigarette pack (target defective cigarette pack) is detected, key spatiotemporal prior information is extracted from the ternary unique association data of the cigarette pack, which includes the target equipment number E0 (the equipment number that produces the defective cigarette pack), the target production timestamp T0 (the time when the defective cigarette pack was produced), and the target production line number L0 (the production line number that produces the defective cigarette pack).
[0157] The extracted key spatiotemporal prior information is stored in the cache of the edge device for subsequent weight modeling and retrieval optimization.
[0158] Step 4.2: Based on the temporal prior characteristics, construct a temporal sliding window weight model, that is, set a time window range and assign different temporal weights to candidate defect images within different time ranges. Prioritize candidate defects from recent time periods and filter out invalid data from distant time periods; the specific implementation is as follows:
[0159] Time-series sliding window setting: Set the time window ΔT = ±30 minutes, that is, based on the target production timestamp T0, trace back 30 minutes and extend forward 30 minutes to form a time window [T0-30min, T0+30min];
[0160] Time weighting allocation: Time weight within the time window (where the production time T of the candidate defective cigarette pack satisfies T0-30min≤T≤T0+30min). = 1.0 indicates that the time correlation between the candidate defect and the target defect within this time period is strong, and it is very likely to be the same type of defect; the time weight outside the time window (the production time T of the candidate defect cigarette pack satisfies T < T0 - 30 min or T > T0 + 30 min) = 0.3; it indicates that the time correlation between the candidate defect and the target defect within this time period is weak, and the probability of being the same type of defect is low, so its retrieval priority can be reduced.
[0161] Basis for the value of the time window ΔT: Through the statistical analysis of the historical defect data of the cigarette making and packing production line, it is found that the vast majority of the same type of defects are concentrated within ±30 minutes of the occurrence time of the target defect. Therefore, ΔT = ±30 minutes is set, which can filter a large amount of invalid data in the far time period and ensure that the same type of defects are not missed.
[0162] Time weight Basis for the value: The probability of the same type of defect within the time window is higher than that outside the time window. Therefore, the weight within the time window is set to 1.0, and the weight outside the time window is set to 0.3, which can effectively highlight the priority of the candidate defects in the recent time period.
[0163] Step 4.3: Based on the spatial prior characteristics, construct an equipment matching weight model, that is, according to the association degree between the production equipment of the candidate defect cigarette pack and the target equipment, different equipment matching weights are assigned ; Highlight the priority of the candidate defects of the same equipment and the adjacent equipment on the same production line, and filter the invalid data of other equipment. The specific settings are as follows:
[0164] For the same equipment (the equipment number E of the candidate defect cigarette pack = the target equipment number E0), the equipment matching weight = 1.0; it indicates that the spatial correlation between the candidate defect produced by this equipment and the target defect is the strongest, and it is very likely to be the same type of defect (such as the defect caused by equipment wear);
[0165] For the adjacent equipment on the same production line (the production line number L of the candidate defect cigarette pack = the target production line number L0, and the equipment numbers E and E0 are adjacent equipment, such as E0 = E01, and the adjacent equipment are E02, E00): the equipment matching weight = 0.6; it indicates that this equipment belongs to the same production line as the target equipment, has strong process synergy, and the probability of the same type of defect appearing is relatively high;
[0166] For other equipment (the production line number L of the candidate defect cigarette pack ≠ the target production line number L0, or although it is the same production line but not adjacent equipment), the equipment matching weight = 0.2; it indicates that the association between this equipment and the target equipment is weak, and the probability of the same type of defect appearing is low, so its retrieval priority can be reduced.
[0167] Equipment matching weight The basis for the value is: through statistical analysis of historical defect data of the packaging production line, the probability of the same type of defect in the same equipment is much higher than that in other equipment, and the probability of the same type of defect in adjacent equipment in the same production line is also higher than that in other equipment. Therefore, setting the above weight values can effectively highlight the priority of candidate defects with strong spatial correlation.
[0168] Step 4.4: Perform comprehensive spatiotemporal weight calculation. Time weight Device matching weight The product of these two factors is used to comprehensively measure the spatiotemporal correlation between candidate defects and target defects.
[0169] Step 4.5: Perform retrieval weight priority sorting, i.e., based on the comprehensive spatiotemporal weight. The search weight priority of candidate defect data blocks is determined by sorting them from highest to lowest size.
[0170] By prioritizing the sorting by weight, the order of retrieval can be clearly defined, prioritizing the retrieval of candidate defect data with strong spatiotemporal correlation, filtering out a large amount of invalid data with weak spatiotemporal correlation, reducing retrieval redundancy and invalid calculations, and improving retrieval efficiency.
[0171] Step 5: Divide the data into blocks according to both device and time dimensions, and allocate calculation threads based on the comprehensive spatiotemporal weights. High-weight data blocks are processed in real time first, while low-weight data blocks are processed asynchronously in the background to achieve parallel retrieval.
[0172] In a preferred but non-limiting embodiment of the present invention, step 5 specifically includes:
[0173] The main purpose of this step is to divide the massive detection image data into blocks based on the priority of comprehensive spatiotemporal weights, and to allocate computing threads using a weight-first parallel retrieval mechanism to achieve efficient retrieval, thus solving the problems of unreasonable thread allocation and wasted computing power in existing parallel retrieval systems. The specific implementation process is as follows:
[0174] Step 5.1: Divide the data into blocks according to the data block partitioning rules;
[0175] The roll packaging production line generates millions of inspection images daily. To achieve efficient parallel retrieval, the massive images are divided into multiple data blocks based on both equipment and time dimensions. The size of each data block is controlled between 1,000 and 2,000 images to ensure a balance between data block processing efficiency and memory usage.
[0176] Data block partitioning rules include:
[0177] By equipment: Using equipment number E as the unit, the inspection images of cigarette packs produced by the same equipment are divided into one large data block;
[0178] Divided by time: The data block of each device is further divided into smaller data blocks according to the time window ΔT=±30 minutes, that is, each data block corresponds to the detection image of a certain device and a certain 30-minute time period;
[0179] Data block identifier: Each data block is assigned a unique identifier in the format of E-time period, such as E01-202605111400-1430 (representing the image data block detected by device E01 during the time period from 14:00 to 14:30 on May 11, 2026).
[0180] After the data blocks are divided, each data block is associated with its corresponding spatiotemporal weight. Associative storage facilitates subsequent thread allocation.
[0181] Step 5.2: Perform weight-priority thread allocation. The edge device adopts a multi-threaded parallel processing architecture, setting up 8 computing threads. These threads are allocated based on the retrieval weight priority of the data blocks. The specific allocation rules are as follows:
[0182] High-weight data blocks ( =1.0, i.e., data blocks within the same device and time window): 4 computing threads are allocated first to perform real-time reasoning and similarity calculation to ensure that highly correlated defects of the same type are retrieved as quickly as possible to meet the real-time traceability requirements;
[0183] Medium-to-high weighted data blocks ( =0.6, which refers to adjacent equipment and data blocks within the same production line and time window): Two computing threads are allocated to process data in parallel while searching high-weight data blocks, balancing search efficiency and comprehensiveness.
[0184] Medium and low weight data blocks ( =0.3, i.e., data blocks outside the same device and window): allocate 1 computing thread and use background asynchronous processing mode to not affect the retrieval speed of high priority data blocks;
[0185] Low-weight data blocks ( ≤0.2, i.e., data blocks from other devices / other time periods): Allocate 1 computing thread and adopt background batch asynchronous processing mode to complete the retrieval during idle periods to avoid occupying core computing power.
[0186] The thread allocation criteria include: reserving 6 threads for basic tasks such as data acquisition, hash verification, and data synchronization, and using the remaining 8 threads for retrieval processing; high-weight data blocks have the highest retrieval priority, and allocating 4 threads can ensure their processing speed; medium-high, medium-low, and low-weight data blocks are allocated threads in order of relevance, which avoids wasting computing power and ensures the comprehensiveness of the retrieval.
[0187] Step 5.3: Execute the parallel retrieval process, which is a parallel retrieval process based on the data blocks with retrieval weight priority. The specific process is as follows:
[0188] Staff scan the QR code index Q of the substandard cigarette packs, complete the hash verification, and automatically extract the spatiotemporal prior information (E0, T0, L0) of the target defect, then calculate the comprehensive spatiotemporal weight of each candidate data block. And sort them by priority;
[0189] Based on the retrieval weight priority, corresponding computing threads are allocated to data blocks with different retrieval weight priorities. High-weight data blocks are started first, and medium-high, medium-low, and low-weight data blocks are started in sequence to achieve parallel processing.
[0190] Each thread synchronously invokes the lightweight similarity defect inference network to extract features and calculate similarity for candidate defect images in the corresponding data blocks, selecting those with S≥ Similar defects;
[0191] Each thread caches the filtered similar defect data (including QR code index Q, production time T, equipment information E, process parameters P, defect similarity S, and comprehensive spatiotemporal weight W_ST) in real time to the memory of the edge device to ensure that the data can be accessed quickly.
[0192] When the high-weight data block retrieval is completed, and more than 80% of the medium-to-high-weight data blocks are retrieved, or the total retrieval time reaches 1 second (meeting the real-time traceability requirement), the retrieval of the low-weight data block will be automatically terminated, and the retrieved similar defect results will be output first; if similar defects are subsequently retrieved from the low-weight data block, they will be updated synchronously as supplementary results.
[0193] Compared with traditional parallel retrieval, the parallel retrieval mechanism of this invention has more reasonable thread allocation, improved computing power utilization, and shortened the time for retrieving millions of images, fully meeting the real-time traceability requirements of high-speed production lines for packaging.
[0194] Step 6: Combine defect similarity with comprehensive spatiotemporal weights to calculate the final comprehensive score, sort the results by score and output the traceability results, and support the export of structured reports for quality analysis and archiving.
[0195] In a preferred but non-limiting embodiment of the present invention, step 6 specifically includes:
[0196] The main purpose of this step is to jointly sort the similar defect data selected through parallel retrieval, output accurate and orderly traceability results, and generate structured reports to provide reliable support for defect root cause analysis, quality control, and compliance archiving. The specific implementation process is as follows:
[0197] Step 6.1: Perform spatiotemporal similarity joint ranking;
[0198] To address the insufficient precision caused by single similarity ranking, this invention combines defect similarity S with comprehensive spatiotemporal weights. A joint ranking mechanism is designed to calculate the final comprehensive score of each similar defect and sort them from high to low according to the comprehensive score, so as to ensure the accuracy and rationality of the search results.
[0199] The formula for calculating the final overall score is as follows:
[0200] ;
[0201] In the formula for calculating the final comprehensive score, Score is the final comprehensive score of similar defects; the larger the Score, the higher the matching degree between the similar defect and the target defect, the stronger the spatiotemporal correlation, and the higher the ranking. The similarity weight coefficient is set according to specific requirements, and its value ranges from 0.6 to 0.7. Defect similarity is an important indicator for judging the same type of defects, which can highlight the importance of defect morphology matching; at the same time, it takes into account the spatiotemporal correlation to avoid omitting the same type of defects with strong spatiotemporal clustering.
[0202] By using a joint ranking mechanism, similar defects with strong spatiotemporal correlations can be prioritized for output. Compared with single similarity ranking, the accuracy of detecting similar defects is improved, effectively avoiding false detections and missed detections.
[0203] Step 6.2: Output the traceability results;
[0204] After the joint sorting is completed, structured traceability results are automatically output and displayed on the edge device's display interface. The output includes the following key information to facilitate quick viewing and analysis by staff:
[0205] Target defect information: QR code index Q of the target cigarette pack, production time T0, equipment number E0, production line number L0, defect type (e.g., wrinkles, damage), defect location (e.g., front, side), and defect similarity threshold.
[0206] Similar Defect List: Sorted from highest to lowest based on overall score. Each similar defect includes: QR code index on cigarette pack, production time T, equipment number E, production line number L, process parameters P (packaging speed, temperature, pressure, etc.), defect similarity S, and overall spatiotemporal weight. Final overall score;
[0207] Statistical information: total number of similar defects, number and percentage of similar defects for each device, number and percentage of similar defects for each time period, average similarity score, highest / lowest comprehensive score, intuitively presenting the distribution pattern of similar defects, providing data support for root cause analysis;
[0208] Anomaly alert: If the number of similar defects found exceeds the preset threshold (e.g., more than 5 similar defects on a single device within 1 hour), an anomaly alert will be automatically triggered to remind staff to promptly investigate potential problems with equipment and processes to prevent batch defects from occurring.
[0209] The output interface supports multi-dimensional filtering functions. Staff can filter similar defects by equipment number, production time period, defect type, etc. It also supports zooming in on defect images to facilitate comparative analysis of defect details and quick location of common defect features.
[0210] Step 6.3: Export structured reports;
[0211] To meet the needs of quality control archiving, compliance inspection, and root cause analysis, the system supports the export of structured traceability reports in two common formats: Excel and PDF. The reports are complete and standardized, and include the following modules:
[0212] Basic report information: report generation time, traceability task number, operator, target defective cigarette pack QR code and core information;
[0213] Target defect details: defect type, defect location, production equipment, production time, process parameters, defect image thumbnail and unique identifier;
[0214] Similar Defect Details: Sorted by comprehensive score, each similar defect is listed with its QR code, production information, process parameters, similarity score, comprehensive spatiotemporal weight, and comprehensive score.
[0215] Statistical analysis module: total number of similar defects, equipment distribution statistics, time distribution statistics, similarity distribution statistics, with simple analysis conclusions (such as similar defects mainly concentrated in the E01 equipment between 14:00 and 14:30, which is speculated to be related to abnormal packaging pressure during this period).
[0216] Verification information includes hash verification results, retrieval time, and retrieval mode (global / spatiotemporal prior) to ensure the traceability and reliability of the report.
[0217] The report export operation is convenient, supporting the export of single traceability task reports as well as batch traceability task report summary export. The export process is quick, and the exported reports can be directly used for quality analysis meetings, compliance archiving, and equipment maintenance records.
[0218] Step 6.4: Switch between dual search modes.
[0219] This invention supports one-click switching between global search and spatiotemporal prior search modes to adapt to different tracing scenarios. The specific switching logic and application scenarios are as follows:
[0220] Spatiotemporal prior retrieval mode (default mode): After startup, it automatically extracts the spatiotemporal prior information of the target defect and performs block-based parallel retrieval according to the comprehensive spatiotemporal weight priority. It is suitable for conventional defect tracing scenarios, taking into account both retrieval efficiency and accuracy, with less retrieval time, and meets the needs of real-time tracing.
[0221] Global search mode: After manual switching by staff, the system ignores the spatiotemporal prior weights and performs parallel search on all detection data. It is suitable for special defect tracing (such as sporadic defects, cross-device and cross-time period defects), ensuring that no similar defects are missed. The search time is short and the efficiency is improved compared to the traditional global blind search.
[0222] The dual-mode switching is achieved through a one-click button on the edge display interface. The switching process does not interrupt the current search task, adapting to the needs of different quality control scenarios and improving the flexibility and adaptability of the method.
[0223] This invention constructs an integrated system of ternary unique association and hash verification, using QR code unique identifiers to bind multi-dimensional data, combined with SHA-256 hash verification, to ensure the uniqueness, integrity, and immutability of data, solving problems such as chaotic data association and tampering, and providing a reliable foundation for traceability. It designs a lightweight similar defect inference network, replacing traditional convolution with depthwise separable convolution, and combining it with a spatial attention mechanism, reducing the number of model parameters and computational cost while improving the feature extraction accuracy of complex and minute defects, making it suitable for deployment at industrial edge computing. It proposes a spatiotemporal prior extraction and temporal sliding window weight modeling method, fully utilizing the spatiotemporal clustering of defects in the packaging production line, upgrading the traditional global full-scale blind search to a time-series sliding window weight model. The system employs a priori retrieval mechanism to filter invalid data, significantly improving retrieval efficiency. A weight-priority parallel retrieval mechanism is established, allocating computation threads based on comprehensive spatiotemporal weights to prioritize high-weight data blocks while asynchronously processing low-weight data blocks in the background, avoiding wasted computational power and further enhancing retrieval speed. A spatiotemporal-similarity joint ranking mechanism is proposed, combining defect similarity with spatiotemporal weights to calculate a comprehensive score, addressing the insufficient precision caused by single similarity ranking and improving the precision of similar defects. Integrated control of all modules is achieved, supporting one-click switching between global retrieval and spatiotemporal priori retrieval modes. It can seamlessly integrate with existing roll packaging production line platforms without large-scale modifications, reducing modification costs and risks, and enhancing practicality and promotional value.
[0224] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention without departing from the spirit and scope of the present invention. Any modifications or equivalent substitutions should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for tracing defects in a roll packaging production line based on a lightweight inference network, characterized in that, include: Step 1: Assign a unique QR code index to each cigarette pack, and bind it to multi-dimensional data such as production time, equipment information, process parameters and inspection images to form a unique three-dimensional association between cigarette pack, parameters and images; Step 2: Use the SHA-256 one-way hash encryption algorithm to verify the integrity of the unique three-element associated data; Step 3: Construct a lightweight inference network based on depthwise separable convolution and spatial attention mechanism, extract defect image features, and calculate the similarity between the target defect and the candidate defect by combining cosine similarity and Euclidean distance; Step 4: Extract the spatiotemporal prior information of the target defect, construct a temporal sliding window weight model and a device matching weight model, and calculate the comprehensive spatiotemporal weight; Step 5: Divide the data into blocks according to both device and time dimensions, and allocate calculation threads based on the comprehensive spatiotemporal weights. High-weight data blocks are processed in real time first, while low-weight data blocks are processed asynchronously in the background to achieve parallel retrieval. Step 6: Combine defect similarity with comprehensive spatiotemporal weights to calculate the final comprehensive score, and output the traceability results in sorted order of scores.
2. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 1, characterized in that, Step 1 specifically includes: Step 1.1: Assign a unique production line code to each roll packaging production line, assign a unique equipment code to each piece of equipment on each roll packaging production line, and assign a unique workstation code to each workstation on each roll packaging production line; Step 1.2: The data acquisition module synchronously collects multi-dimensional data of the cigarette pack and uniquely binds it with the QR code index Q to form a unique ternary association data of the cigarette pack, parameters and image; Step 1.3: The bound ternary unique association data is first stored in the SSD of the edge device; at the same time, it is synchronized in real time to the cloud server to store the ternary unique association data of all cigarette packs.
3. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 2, characterized in that, In step 1.1, when the cigarette packs enter the packaging process of the cigarette production line, the QR code index generation module generates a unique QR code index Q for each cigarette pack according to the rules of sequentially connected production line codes, equipment codes, workstation codes, timestamps and random sequences.
4. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 3, characterized in that, In step 1.2, the multi-dimensional data used as parameters includes: The production timestamp T uses the system time of the edge device. The equipment information for the production line includes equipment number E, production line number L, and workstation number W; The process parameter set P includes: packaging speed, packaging temperature, packaging pressure, glue level, sealing position, and raw material batch number; The equipment status S of the production line is uploaded in real time by the equipment's PLC control system, which includes five statuses: equipment operation, shutdown, alarm, and normal or abnormal status. A unique set of six-sided image identifiers, with each of the six images of the cigarette pack assigned a unique identifier I.
5. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 4, characterized in that, Step 2 specifically includes: Step 2.1: After the unique association between the cigarette pack, parameters, and images is formed, the QR code index Q of the cigarette pack, the set of process parameters P, and the unique identifier set of the six-sided detection images are automatically concatenated into a string Str in a fixed order; The SHA-256 one-way hash encryption algorithm is used to encrypt the concatenated string Str, generating a globally unique hash checksum. The calculation formula is as follows: ; Where Hash() represents the SHA-256 hash encryption function, and Str is the concatenated string; Step 2.2: When defect tracing is required, staff scan the QR code index Q of the defective cigarette pack using a QR code scanning module. Based on the QR code index Q, they retrieve the corresponding ternary unique association data from the edge device or cloud server and concatenate it into a new string in a fixed order. ; Using the same SHA-256 hash encryption algorithm, calculate Hash value (Hash) ), and compare it with the stored The comparison will be performed according to the following rules: If Hash( )= If the data is found to be complete, unaltered, and without incorrect links, the search process will proceed to the next step. If Hash( )≠ If the data is found to be abnormal, an alarm will be triggered immediately, and the tracing process will be terminated.
6. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 5, characterized in that, Step 3 specifically includes: Step 3.1: Construct a lightweight similarity defect inference network by using a depthwise separable convolutional structure combined with a spatial attention mechanism; Step 3.2: Calculate the defect similarity. The formula for calculating defect similarity is as follows: ; In the formula for calculating the defect similarity, S is the defect similarity score; The cosine similarity weight coefficient is... For feature vectors , The Euclidean distance between them; T is the temperature coefficient.
7. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 6, characterized in that, In step 3.1, the overall structure of the lightweight similarity defect inference network includes, in sequence: an input layer, three layers of depthwise separable convolutional units, a batch normalization unit, a ReLU activation unit, a spatial attention module, and a feature output layer; The input layer receives defect images from the six-sided inspection images of the cigarette pack. The defect image data from the six-sided inspection images is normalized, and the calculation formula is as follows: ; In this calculation formula, These are the original pixel values of the defect image in the six-sided inspection image. This represents the minimum pixel value in the defect image from the six-sided inspection image. The maximum pixel value in the defect image from the six-sided inspection image. These are the normalized pixel values; The specific parameters of the 3-layer depthwise separable convolutional unit are as follows: The first layer of depthwise separable convolution has a kernel size of 3×3, a stride of 1, a padding method of Same, and 32 output channels; the pointwise convolution kernel has a kernel size of 1×1, a stride of 1, and 64 output channels. The second layer of depthwise separable convolution has a depthwise convolution kernel size of 3×3, a stride of 1, a padding method of Same, and 64 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 128 output channels. The third layer of depthwise separable convolution has a 3×3 kernel size, a stride of 1, Same padding, and 128 output channels; the pointwise convolution kernel size is 1×1, a stride of 1, and 256 output channels. After each depthwise separable convolutional unit, a batch normalization unit is added to normalize the batch data of the feature map output by that depthwise separable convolutional unit. The calculation formula for the batch normalization unit is as follows: ; In this calculation formula, The mean of the batch data. The variance of the batch data. To After standardization, m represents the number of feature values in the batch of data. For the first in the batch data 1 eigenvalue, To prevent tiny values with a denominator of 0, γ and β are learnable parameters. These are the feature values after batch normalization unit processing; After batch normalization, ReLU activation units are added. The activation function f(x) of the ReLU activation unit is calculated as follows: f(x) = max(0,x); A spatial attention module is added to the end of the lightweight similarity defect inference network; The feature output layer will take the spatial attention-weighted feature vectors. , The vector is flattened to obtain a one-dimensional feature vector, which is used as the input for defect similarity calculation.
8. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 7, characterized in that, In step 3.1, the implementation process of the spatial attention module is as follows: Global average pooling and global max pooling are performed on the feature map output by the ReLU activation unit to obtain two 1×1×256 feature maps respectively. The two feature maps are concatenated to obtain a 1×1×512 feature map; The concatenated feature map is compressed to 1×1×256 by using a 1×1 convolution kernel, and then the spatial attention weight map Att(F) is obtained by using the Sigmoid activation function. Multiply the spatial attention weight map Att(F) element-wise with the feature map F output by the lightweight similarity defect inference network to obtain the spatial attention-weighted feature map. ; The formula for calculating spatial attention weighting is as follows: ; In this calculation formula, The feature vector of the target defect image. Spatial attention weight map for the target defect image. This is the target defect feature vector after spatial attention weighting; The feature vector of the candidate defect image. Spatial attention weight map of candidate defect images. This is the candidate defect feature vector after spatial attention weighting.
9. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 8, characterized in that, Step 4 specifically includes: Step 4.1: Perform spatiotemporal prior extraction, that is, when a defective cigarette pack is detected, extract key spatiotemporal prior information from the ternary unique association data of the cigarette pack; Step 4.2: Based on the temporal prior characteristics, construct a temporal sliding window weight model, that is, set a time window range and assign different temporal weights to candidate defect images within different time ranges. ; Step 4.3: Based on spatial prior characteristics, construct an equipment matching weight model, that is, assign different equipment matching weights according to the degree of correlation between the production equipment of the candidate defective cigarette pack and the target equipment. ; Step 4.4: Perform comprehensive spatiotemporal weight calculation. Time weight Device matching weight The product; Step 4.5: Perform retrieval weight priority sorting, i.e., based on the comprehensive spatiotemporal weight. The search weight priority of candidate defect data blocks is determined by sorting them from highest to lowest size.
10. The defect tracing method for roll packaging production lines based on lightweight inference networks according to claim 9, characterized in that, Step 5 specifically includes: Step 5.1: Divide the data into blocks according to the data block partitioning rules; Step 5.2: Perform weight-priority thread allocation, that is, the edge device adopts a multi-threaded parallel processing architecture, sets up 8 computing threads, and allocates computing threads according to the retrieval weight priority of data blocks; Step 5.3: Execute the parallel retrieval process, which is to perform a parallel retrieval process based on the data blocks with retrieval weight priority.