A Quality Inspection Method for Tobacco Products Based on AI Visual Inspection and Edge Computing
Patent Information
- Application Number
- CN202611182549.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-05
- Publication Date
- 2026-10-27
AI Technical Summary
对于人工复核或二次检测后得到的确认结果,现有系统也多停留在记录和追溯层面,缺少将复核结果持续用于模型更新的机制,使检测模型面对新批次产品、新成像条件或新型缺陷时适应能力较弱
首先,本发明通过预处理、连续帧取样和局部遮蔽重建,筛选具有异常表征价值的图像片段,减少抖动、光照变化和局部模糊造成的单帧误判,提高烟草产品异常识别的准确性。
Smart Images

Figure CN122990419A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of tobacco product quality inspection technology, and in particular to a tobacco product quality inspection method based on AI visual inspection and edge computing. Background Technology
[0002] As the automation level of tobacco product production lines continues to increase, the requirements for inspection speed and stability in quality inspection stages, such as product appearance, packaging condition, labeling information, and finished product consistency, are becoming increasingly stringent. Traditional manual sampling inspection methods are easily affected by personnel experience, fatigue levels, and sampling ratios, making them unsuitable for continuous, high-paced production environments. To reduce the discrepancies in human judgment, existing technologies are increasingly adopting machine vision to acquire images of tobacco products and using image processing or intelligent recognition models to assess product quality.
[0003] Existing visual quality inspection methods for tobacco products typically rely on a single image or a single shooting result as the basis for judgment. They identify anomalies such as stains, damage, misalignment, and unclear labeling through threshold segmentation, template matching, feature recognition, or classification models. Some systems also deploy the detection model on computing devices close to the acquisition end to reduce image transmission time and improve quality inspection response speed. These methods are effective when patterns are clear and imaging conditions are stable.
[0004] However, in actual quality inspection processes, tobacco product images are easily affected by transport vibrations, momentary occlusions, changes in lighting, image blurring, and batch variations. Relying solely on single-frame images for judgment can easily lead to inconsistencies, short-term misjudgments, and missed detections. Furthermore, existing methods do not adequately utilize the relationships between changes in consecutive images, making it difficult to correct current judgments based on previous and subsequent inspection results, resulting in insufficient stability of quality inspection results.
[0005] Furthermore, while edge-side devices can shorten detection response time, their computational resources are typically limited. Existing methods often perform complete processing on adjacent image segments repeatedly during continuous image detection, increasing the computational burden on the edge side. For confirmation results obtained after manual review or secondary inspection, existing systems mostly remain at the level of recording and tracing, lacking a mechanism to continuously use the review results for model updates. This makes the detection model less adaptable to new batches of products, new imaging conditions, or novel defects.
[0006] Therefore, how to provide a tobacco product quality inspection method based on AI visual inspection and edge computing is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0007] One objective of this invention is to propose a tobacco product quality inspection method based on AI visual detection and edge computing. This invention fully utilizes AI visual recognition, real-time edge processing, occlusion reconstruction, contrastive learning, and temporal state recursion techniques. It details the implementation process of tobacco product image acquisition, abnormal sample construction, visual quality inspection model training, continuous edge detection, quality status path determination, and review feedback update. It has the advantages of fast detection response, high discrimination accuracy, good stability of quality inspection results, and strong adaptability to different batches of products.
[0008] A method for quality inspection of tobacco products based on AI visual detection and edge computing according to an embodiment of the present invention includes the following steps: S1. Collect visual data for tobacco product quality inspection at edge nodes and preprocess it to form a standard visual sequence. S2. Perform continuous frame overlap sampling on the standard visual sequence, and perform local occlusion reconstruction on the obtained continuous image segments. Sort the continuous image segments according to the reconstruction differences to construct a quality inspection sample set. S3. A contrastive learning encoding network is used to establish a discriminative mapping relationship between continuous image segments and quality status labels. Based on the quality inspection sample set, the contrastive learning encoding network is jointly trained by supervised contrastive loss and defect response loss to construct a visual quality inspection model. S4. Deploy the visual quality inspection model on the edge node side, perform continuous window encoding on the visual sequence to be detected, calculate the window-level quality state probability through the visual quality inspection model, and use the Hidden Markov forward recursive method to recursively correct the quality state probability. S5. Construct a quality state path based on the recursively corrected quality state probability, calculate the transition cost between adjacent quality states according to the window time sequence, and use the Viterbi algorithm to backtrack and optimize the quality state path to determine the quality inspection result of tobacco products. S6. Obtain the verification data corresponding to the quality inspection results of tobacco products, and use the small-batch gradient descent method to incrementally train the visual quality inspection model.
[0009] Optionally, the preprocessing specifically includes: The visual acquisition data collected from edge nodes is frame-numbered according to the acquisition time sequence, and duplicate frames, blurry frames, and frames with abnormal exposure are removed, including: The edge node is an edge computing unit used to perform visual data access, preprocessing, model inference and result caching. The visual acquisition data is continuous frame image data formed during the tobacco product quality inspection process. The continuous frame image data carries an acquisition timestamp, acquisition channel identifier and quality inspection batch identifier. The illumination drift parameters are estimated based on the brightness change between adjacent frames, and the brightness of the visual acquisition data is compensated based on the illumination drift parameters. Background response is estimated from the brightness-compensated visual acquisition data, and the background response is subtracted from the corresponding frame image to obtain the foreground response image; Boundary registration and scale adjustment are performed on the foreground response image to place different frame images under a unified spatial size and coordinate reference. The registered foreground response images are arranged in temporal order according to frame number to form a standard visual sequence.
[0010] Optionally, S2 specifically includes: S21. Establish an overlapping sampling window according to the frame number in the standard visual sequence, merge the continuous frames at the end of the current sampling window into the front of the next sampling window, and use the dynamic time warping method to perform time axis registration on the overlapping frames in adjacent sampling windows to extract continuous image segments. S22. Divide the continuous image segments into blocks, select the image blocks with abrupt changes in grayscale response along the frame sequence as masking blocks, and use the context information of the unmasked image blocks to reconstruct the masking blocks to obtain the reconstructed image segments. S23. Extract the reconstruction error vectors of corresponding image blocks in continuous image segments and reconstructed image segments, calculate the Mahalanobis distance based on the reconstruction error distribution under normal quality conditions, and sort the continuous image segments according to the Mahalanobis distance. S24. Associate the corresponding review results with the abnormal sorting results, convert the review results into quality status labels, and perform positive and negative sample pairing on continuous image segments based on the quality status labels to construct a quality inspection sample set.
[0011] Optionally, S23 specifically includes: S231. According to the frame number and image block position, perform block-level registration on the continuous image segments and the reconstructed image segments. Using image blocks of 8×8 pixels to 32×32 pixels as processing units, perform 2 to 4 layers of convolutional coding on the registered original image blocks and reconstructed image blocks respectively. Then, through 1×1 convolution, map the two sets of block-level convolutional codes to a unified coding space of 64 to 256 dimensions to form reconstruction difference coding. S232. Based on continuous image segments labeled as normal quality, statistically reconstruct the mean vector and covariance matrix of the difference encoding, and then use... to The regularization parameter is used to perform regularization and inversion on the covariance matrix, and the normal distance threshold is set according to the 95% to 99% quantile of the Mahalanobis distance under normal quality conditions. S233. Perform centering processing on the reconstruction difference encoding of the current continuous image segments, and calculate the Mahalanobis distance of each image block by combining the covariance matrix after regularization and inversion. Scan the Mahalanobis distance along the frame number direction and mark the image blocks that exceed the normal distance threshold for 2 to 5 consecutive frames as abnormal blocks. S234. Calculate the segment anomaly score based on the number of consecutive frames, the number of segments, and the peak Mahalanobis distance of the abnormal block segments. Sort the continuous image segments according to the segment anomaly score and select the continuous image segments in the top 5% to 20% as the priority review segments.
[0012] Optionally, S3 specifically includes: S31. Based on the quality status labels in the quality inspection sample set, perform sample pairing on continuous image segments to obtain sample pairs with the same label and sample pairs with different labels. Then, use a contrastive learning coding network with shared coding parameters to encode and map the continuous image segments in the sample pairs to obtain segment coding vectors. S32. Calculate the encoding similarity of same-label sample pairs and different-label sample pairs respectively. Take the encoding similarity of same-label sample pairs as the positive similarity term and the encoding similarity of different-label sample pairs as the negative similarity term. Calculate the supervised contrastive loss using the supervised contrastive learning function. S33. Based on the segment coding vector, the quality status is judged, and the defect response reference value is set according to the order of the continuous image segments in the anomaly sorting. The defect response loss is calculated based on the quality status judgment deviation and the defect response deviation. S34. Combine the supervised contrastive loss and the defect response loss into a joint loss function, perform backpropagation training on the contrastive learning encoding network based on the joint loss function, and construct the trained contrastive learning encoding network into a visual quality inspection model.
[0013] Optionally, S33 specifically includes: S331. Perform quality state mapping based on fragment encoding vectors, and use a focal cross-entropy discriminant function with adjustment factors of 1 to 3 to process the discrimination error corresponding to the quality state label, reduce the loss weight of high-confidence continuous image fragments, and retain the loss weight of low-confidence continuous image fragments. S332. Based on the order of consecutive image segments in the anomaly sorting, construct defect response levels from level 3 to level 5. Assign consecutive image segments that are ranked higher to the high response level and consecutive image segments that are ranked lower to the low response level. Establish a regression relationship between the defect response level and the segment encoding vector. S333. The order-aware Huber loss is used to process the deviation between the defect response level and the regression result. A secondary penalty is applied to the deviation that is less than the response threshold, and a linear penalty is applied to the deviation that is not less than the response threshold. The response threshold is 0.5 to 1.5 times the interval between adjacent defect response levels. S334. The loss term corresponding to the focus cross-entropy discriminant function is used as the quality discriminant term, and the loss term corresponding to the ranking-aware Huber loss is used as the response regression term. The quality discriminant term and the response regression term constitute the defect response loss.
[0014] Optionally, S4 specifically includes: S41. Deploy the trained visual quality inspection model in the inference process of the edge node, retain the order of network weights and quality state labels required for forward inference, and stop the gradient update process in the training phase. S42. According to the preset window length and window step, the visual sequence to be detected formed in real time by the edge nodes is slidably truncated, and the incremental window coding method is adopted to reuse the existing coding of the overlapping frames of adjacent windows, and the coding is updated for the frames that newly enter the current window to form the current window coding vector. S43. The current window encoding vector is used by the visual quality inspection model to determine the quality status. The determination values of each quality status are arranged in order of quality status label, and the Softmax function is used to process the determination values probabilistically to form window-level quality status probabilities. S44. Calculate the quality state transition probability based on the frequency of occurrence of adjacent quality state labels, and use the Hidden Markov forward recursive method to recursively correct the previous window correction probability and the current window level quality state probability to form the current window recursive correction probability.
[0015] Optionally, S42 specifically includes: S421. Based on the frame rate of the visual sequence to be detected and the inference time per frame for edge nodes, set the continuous window length and window step size, where: The single-frame inference time is the average processing time required for edge nodes to complete the encoding process of a single-frame image using a visual quality inspection model. The window step size is smaller than the length of the continuous window. There are overlapping frames between adjacent continuous windows to be detected. The continuous windows to be detected are truncated by sliding along the frame order with the window step size. S422. Perform frame encoding on the first continuous window to be detected in frame order. Using the first frame encoding as the starting point of the recursion, adopt the exponential moving average recursion method to recursively aggregate the next frame encoding with the previous recursion encoding to generate the recursion encoding corresponding to each frame, and take the last frame recursion encoding to form the first window encoding vector. S423. When the next continuous window to be detected arrives, identify the overlapping frame that is the same as the previous continuous window to be detected according to the frame number, retain the frame code and recursive code corresponding to the overlapping frame, and perform frame coding on the newly entered frame in the current window. S424. Using the recursive encoding at the end of the overlapping frame as the starting point for the current window, the frame encoding of the newly entering frame is recursively calculated by exponential moving average according to the frame order to form the current window encoding vector.
[0016] Optionally, S5 specifically includes: S51. Arrange the corrected quality state probabilities according to the window time sequence, take the quality state label under each window as a candidate state, and construct the quality state path according to the connection relationship between the candidate states of adjacent windows. S52. Perform negative logarithmic cost processing on the recursive correction probability corresponding to the candidate state to form the state cost, and set the transition cost between adjacent quality states according to the connection relationship between quality state maintenance and quality state transition in adjacent windows. S53. The Viterbi algorithm is used to perform dynamic programming recursion along the window time sequence, and the state cost and transition cost are cumulatively filtered to retain the minimum cumulative path cost and the position of the previous state of the current candidate state. S54. Starting from the quality state corresponding to the minimum cumulative path cost in the end window, backtrack in reverse according to the position of the previous state to form the quality state path with the minimum total cost, and determine the quality inspection result of tobacco products based on the quality states that appear consecutively in the quality state path.
[0017] Optionally, S6 specifically includes: S61. Obtain the verification data corresponding to the tobacco product quality inspection results, and associate the verification data with the corresponding visual sequence to be detected, window-level quality state probability, and tobacco product quality inspection results to form a verification sample, wherein: The verification data refers to the confirmation data formed after manual verification or secondary testing of the quality inspection results of tobacco products, including the verification quality status, the location of the verification defects, and the verification time marker. S62. According to the quality status markers in the verification data, the verification samples are stratified and small-batch extracted, and the verification samples whose verification results are inconsistent with the tobacco product quality inspection results are added to the current small-batch training samples. S63. Use a visual quality inspection model to encode and discriminate the current small batch of training samples, and use the joint loss function composed of supervised contrast loss and defect response loss to calculate the incremental training loss of the current small batch of training samples. S64. Using the mini-batch gradient descent method, the network parameters of the visual quality inspection model are incrementally updated based on the incremental training loss, and the updated visual quality inspection model is used for the next round of edge node quality inspection.
[0018] The beneficial effects of this invention are: First, this invention uses preprocessing, continuous frame sampling, and local occlusion reconstruction to screen image segments with anomaly characterization value, reducing single-frame misjudgments caused by jitter, lighting changes, and local blurring, thereby improving the accuracy of tobacco product anomaly identification.
[0019] Secondly, this invention employs a contrastive learning coding network to learn the relationship between continuous image segments and quality status, and performs continuous window encoding and quality status probability calculation at the edge node side, reducing redundant processing and improving the response speed and processing efficiency of continuous quality inspection.
[0020] Finally, this invention uses Hidden Markov forward recursion and Viterbi backtracking optimization to perform time-series correction and path determination of quality status, reducing result jumps; at the same time, it combines verification data for incremental training to improve the model's adaptability to different batches and new defects. Attached Figure Description
[0021] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is an overall flowchart of a tobacco product quality inspection method based on AI visual detection and edge computing proposed in this invention; Figure 2 This is a flowchart of the comparative learning encoding network training process for a tobacco product quality inspection method based on AI visual detection and edge computing proposed in this invention. Figure 3 This is a flowchart of the continuous window detection process on the edge node side of a tobacco product quality inspection method based on AI visual inspection and edge computing proposed in this invention. Detailed Implementation
[0022] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0023] refer to Figures 1-3 A method for quality inspection of tobacco products based on AI visual inspection and edge computing includes the following steps: S1. Collect visual data for tobacco product quality inspection at edge nodes and preprocess it to form a standard visual sequence. S2. Perform continuous frame overlap sampling on the standard visual sequence, and perform local occlusion reconstruction on the obtained continuous image segments. Sort the continuous image segments according to the reconstruction differences to construct a quality inspection sample set. S3. A contrastive learning encoding network is used to establish a discriminative mapping relationship between continuous image segments and quality status labels. Based on the quality inspection sample set, the contrastive learning encoding network is jointly trained by supervised contrastive loss and defect response loss to construct a visual quality inspection model. S4. Deploy the visual quality inspection model on the edge node side, perform continuous window encoding on the visual sequence to be detected, calculate the window-level quality state probability through the visual quality inspection model, and use the Hidden Markov forward recursive method to recursively correct the quality state probability. S5. Construct a quality state path based on the recursively corrected quality state probability, calculate the transition cost between adjacent quality states according to the window time sequence, and use the Viterbi algorithm to backtrack and optimize the quality state path to determine the quality inspection result of tobacco products. S6. Obtain the verification data corresponding to the quality inspection results of tobacco products, and use the small-batch gradient descent method to incrementally train the visual quality inspection model.
[0024] In this embodiment, the preprocessing specifically includes: The visual acquisition data collected from edge nodes is frame-numbered according to the acquisition time sequence, and duplicate frames, blurry frames, and frames with abnormal exposure are removed, including: Edge nodes are edge computing units used to perform visual data access, preprocessing, model inference, and result caching. Visual acquisition data refers to continuous frame image data generated during the quality inspection of tobacco products. Continuous frame image data carries acquisition timestamps, acquisition channel identifiers, and quality inspection batch identifiers; The illumination drift parameters are estimated based on the brightness change between adjacent frames, and the brightness of the visual acquisition data is compensated based on the illumination drift parameters. Background response is estimated from the brightness-compensated visual acquisition data, and the background response is subtracted from the corresponding frame image to obtain the foreground response image; Boundary registration and scale adjustment are performed on the foreground response image to place different frame images under a unified spatial size and coordinate reference. The registered foreground response images are arranged in temporal order according to frame number to form a standard visual sequence; In this embodiment, the edge nodes receive continuous frame image data at a collection frequency of 25 frames / second to 60 frames / second, and configure frame numbers according to the collection timestamp. When the pixel difference between adjacent frames is less than a preset repetition threshold, the corresponding frame is marked as a repetition frame. When the Laplacian variance of a frame image is less than 80, the corresponding frame image is marked as a blurred frame. When the average grayscale value of a frame image is lower than 40 or higher than 220, the corresponding frame image is marked as an exposure abnormal frame. When performing brightness compensation on the retained frame image, if the average brightness change within 5 consecutive frames exceeds 8%, the brightness value of the corresponding frame image is corrected based on the average brightness difference between adjacent frames. When estimating the background response of the brightness-compensated frame image, a sliding statistical window of 10 to 30 frames is used to calculate the background response, and the background response is subtracted from the corresponding frame image. When scaling the foreground response image, the foreground response images are uniformly adjusted to 640×640 pixels or 1024×1024 pixels and arranged according to the frame number to form a standard visual sequence.
[0025] In this embodiment, S2 specifically includes: S21. Establish an overlapping sampling window according to the frame number in the standard visual sequence, merge the continuous frames at the end of the current sampling window into the front of the next sampling window, and use the dynamic time warping method to perform time axis registration on the overlapping frames in adjacent sampling windows to extract continuous image segments. S22. Divide the continuous image segments into blocks, select the image blocks with abrupt changes in grayscale response along the frame sequence as masking blocks, and use the context information of the unmasked image blocks to reconstruct the masking blocks to obtain the reconstructed image segments. S23. Extract the reconstruction error vectors of corresponding image blocks in continuous image segments and reconstructed image segments, calculate the Mahalanobis distance based on the reconstruction error distribution under normal quality conditions, and sort the continuous image segments according to the Mahalanobis distance. S24. Associate the corresponding review results with the abnormal sorting results, convert the review results into quality status labels, and perform positive and negative sample pairing on continuous image segments based on the quality status labels to construct a quality inspection sample set.
[0026] In this embodiment, S23 specifically includes: S231. According to the frame number and image block position, perform block-level registration on the continuous image segments and the reconstructed image segments. Using image blocks of 8×8 pixels to 32×32 pixels as processing units, perform 2 to 4 layers of convolutional coding on the registered original image blocks and reconstructed image blocks respectively. Then, through 1×1 convolution, map the two sets of block-level convolutional codes to a unified coding space of 64 to 256 dimensions to form reconstruction difference coding. S232. Based on continuous image segments labeled as normal quality, statistically reconstruct the mean vector and covariance matrix of the difference encoding, and then use... to The regularization parameter is used to perform regularization and inversion on the covariance matrix, and the normal distance threshold is set according to the 95% to 99% quantile of the Mahalanobis distance under normal quality conditions. S233. Perform centering processing on the reconstruction difference encoding of the current continuous image segments, and calculate the Mahalanobis distance of each image block by combining the covariance matrix after regularization and inversion. Scan the Mahalanobis distance along the frame number direction and mark the image blocks that exceed the normal distance threshold for 2 to 5 consecutive frames as abnormal blocks. S234. Calculate the segment anomaly score based on the number of consecutive frames, the number of segments, and the peak Mahalanobis distance of the abnormal block segments. Sort the continuous image segments according to the segment anomaly score and select the continuous image segments in the top 5% to 20% as the priority review segments.
[0027] In this embodiment, S3 specifically includes: S31. Based on the quality status labels in the quality inspection sample set, perform sample pairing on continuous image segments to obtain sample pairs with the same label and sample pairs with different labels. Then, use a contrastive learning coding network with shared coding parameters to encode and map the continuous image segments in the sample pairs to obtain segment coding vectors. S32. Calculate the encoding similarity of same-label sample pairs and different-label sample pairs respectively. Take the encoding similarity of same-label sample pairs as the positive similarity term and the encoding similarity of different-label sample pairs as the negative similarity term. Calculate the supervised contrastive loss using the supervised contrastive learning function. S33. Based on the segment coding vector, the quality status is judged, and the defect response reference value is set according to the order of the continuous image segments in the anomaly sorting. The defect response loss is calculated based on the quality status judgment deviation and the defect response deviation. S34. Combine the supervised contrastive loss and the defect response loss into a joint loss function, perform backpropagation training on the contrastive learning encoding network based on the joint loss function, and construct the trained contrastive learning encoding network into a visual quality inspection model.
[0028] In this embodiment, S33 specifically includes: S331. Perform quality state mapping based on fragment encoding vectors, and use a focal cross-entropy discriminant function with adjustment factors of 1 to 3 to process the discrimination error corresponding to the quality state label, reduce the loss weight of high-confidence continuous image fragments, and retain the loss weight of low-confidence continuous image fragments. S332. Based on the order of consecutive image segments in the anomaly sorting, construct defect response levels from level 3 to level 5. Assign consecutive image segments that are ranked higher to the high response level and consecutive image segments that are ranked lower to the low response level. Establish a regression relationship between the defect response level and the segment encoding vector. S333. The order-aware Huber loss is used to handle the deviation between the defect response level and the regression result. A secondary penalty is applied to the deviation that is less than the response threshold, and a linear penalty is applied to the deviation that is not less than the response threshold. The response threshold is 0.5 to 1.5 times the interval between adjacent defect response levels. S334. The loss term corresponding to the focus cross-entropy discriminant function is used as the quality discriminant term, and the loss term corresponding to the ranking-aware Huber loss is used as the response regression term. The quality discriminant term and the response regression term constitute the defect response loss.
[0029] In this embodiment, S4 specifically includes: S41. Deploy the trained visual quality inspection model in the inference process of the edge node, retain the order of network weights and quality state labels required for forward inference, and stop the gradient update process in the training phase. S42. According to the preset window length and window step, the visual sequence to be detected formed in real time by the edge nodes is slidably truncated, and the incremental window coding method is adopted to reuse the existing coding of the overlapping frames of adjacent windows, and the coding is updated for the frames that newly enter the current window to form the current window coding vector. S43. The current window encoding vector is used by the visual quality inspection model to determine the quality status. The determination values of each quality status are arranged in order of quality status label, and the Softmax function is used to process the determination values probabilistically to form window-level quality status probabilities. S44. Calculate the quality state transition probability based on the frequency of occurrence of adjacent quality state labels, and use the Hidden Markov forward recursive method to recursively correct the previous window correction probability and the current window level quality state probability to form the current window recursive correction probability.
[0030] In this embodiment, S42 specifically includes: S421. Based on the frame rate of the visual sequence to be detected and the inference time per frame for edge nodes, set the continuous window length and window step size, where: The single-frame inference time is the average processing time required for edge nodes to complete the encoding of a single-frame image using a visual quality inspection model. The window step size is smaller than the length of the continuous window. There are overlapping frames between adjacent continuous windows to be detected. The continuous windows to be detected are truncated by sliding along the frame order with the window step size. S422. Perform frame encoding on the first continuous window to be detected in frame order. Using the first frame encoding as the starting point of the recursion, adopt the exponential moving average recursion method to recursively aggregate the next frame encoding with the previous recursion encoding to generate the recursion encoding corresponding to each frame, and take the last frame recursion encoding to form the first window encoding vector. S423. When the next continuous window to be detected arrives, identify the overlapping frame that is the same as the previous continuous window to be detected according to the frame number, retain the frame code and recursive code corresponding to the overlapping frame, and perform frame coding on the newly entered frame in the current window. S424. Using the recursive encoding at the end of the overlapping frame as the starting point of the current window, the frame encoding of the newly entering frame is recursively calculated by exponential moving average according to the frame order to form the current window encoding vector. In this embodiment, the frame rate of the visual sequence to be detected is 30 frames / second, and the average processing time for edge nodes to complete the encoding process of a single frame image is 12 milliseconds. Based on the frame rate and single-frame inference time, the continuous window length is set to 12 frames, the window step size is set to 3 frames, 9 overlapping frames are retained between adjacent continuous windows to be detected, and the continuous windows to be detected are truncated along the frame order in a manner that advances once every 3 frames. When encoding the first continuous window to be detected, frame encoding is performed on the 12 frames of images in frame order, with the encoding of the first frame as the starting point for recursion. The exponential moving average recursive method is used to aggregate the encoding of subsequent frames. The recursion coefficient is set to 0.7 to 0.9. After 12 frames are recursively processed, the recursive encoding corresponding to the 12th frame is taken as the first window encoding vector. When the next consecutive window to be detected arrives, the 9 overlapping frames are identified according to the frame number, the frame codes and recursive codes corresponding to the overlapping frames are retained, and the frame codes of the 3 newly entered images in the current window are performed. Using the recursive encoding at the end of the overlapping frame as the starting point for the current window, the exponential moving average recursion is continued for the encoding of the newly entered 3 frames to form the current window encoding vector.
[0031] In this embodiment, S5 specifically includes: S51. Arrange the corrected quality state probabilities according to the window time sequence, take the quality state label under each window as a candidate state, and construct the quality state path according to the connection relationship between the candidate states of adjacent windows. S52. Perform negative logarithmic cost processing on the recursive correction probability corresponding to the candidate state to form the state cost, and set the transition cost between adjacent quality states according to the connection relationship between quality state maintenance and quality state transition in adjacent windows. S53. The Viterbi algorithm is used to perform dynamic programming recursion along the window time sequence, accumulating and filtering state costs and transition costs, retaining the minimum cumulative path cost and previous state position of the current candidate state. Specifically, this includes: The state cost of each candidate state in the first window is used as the initial cumulative path cost, and the previous state position of each candidate state in the first window is marked as the starting position; Starting from the second window, traverse the current candidate states according to the window sequence, and take over the cumulative path cost of each candidate state in the previous window, add the corresponding transition cost and the state cost of the current candidate state to form multiple candidate path costs; The minimum path cost is selected from multiple candidate path costs. The minimum path cost is recorded as the cumulative path cost of the current candidate state, and the previous candidate state that generated the minimum path cost is recorded as the previous state position of the current candidate state. The candidate state traversal and minimum path cost filtering are repeatedly performed according to the window sequence until the end window, forming the cumulative path cost and previous state position corresponding to each window's candidate state. S54. Starting from the quality state corresponding to the minimum cumulative path cost in the end window, backtrack in reverse according to the position of the previous state to form the quality state path with the minimum total cost, and determine the quality inspection result of tobacco products based on the quality states that appear consecutively in the quality state path.
[0032] In this embodiment, S6 specifically includes: S61. Obtain the verification data corresponding to the tobacco product quality inspection results, and associate the verification data with the corresponding visual sequence to be detected, window-level quality state probability, and tobacco product quality inspection results to form a verification sample, wherein: Verification data refers to the confirmation data formed after manual verification or secondary testing of the quality inspection results of tobacco products, including the verified quality status, the location of the verified defects, and the verification time marker. S62. According to the quality status markers in the verification data, the verification samples are stratified and small-batch extracted, and the verification samples whose verification results are inconsistent with the tobacco product quality inspection results are added to the current small-batch training samples. S63. Use a visual quality inspection model to encode and discriminate the current small batch of training samples, and use the joint loss function composed of supervised contrast loss and defect response loss to calculate the incremental training loss of the current small batch of training samples. S64. Using the mini-batch gradient descent method, the network parameters of the visual quality inspection model are incrementally updated based on the incremental training loss, and the updated visual quality inspection model is used for the next round of edge node quality inspection.
[0033] Example 1: To verify the feasibility of this invention in practice, it was applied to a continuous quality inspection scenario for tobacco products. In this scenario, tobacco products continuously pass through a visual acquisition area during transportation. Existing detection methods mainly rely on single-frame image classification results to determine whether the product has problems such as packaging damage, surface stains, unclear markings, misaligned edges, and local wrinkles.
[0034] Due to the high transmission speed, some images may be affected by slight jitter, instantaneous reflection, and local occlusion. Existing methods are prone to jumps in the judgment of the previous frame as normal and the judgment of the next frame as abnormal when continuously detecting. Manual review found that some of these were short-term imaging interferences and not real quality defects, which increased the workload of review.
[0035] In this scenario, edge nodes receive continuous frame images of the tobacco product at a frequency of 30 frames per second. First, duplicate frames, blurry frames, and frames with abnormal exposure are removed, and the remaining images are uniformly adjusted to 640×640 pixels. Then, sliding processing is performed with 12 frames as a continuous window and 3 frames as the window step size, and 9 overlapping frames are retained between adjacent windows.
[0036] For the first window, encoding is completed frame-by-frame, and an exponential moving average is used to recursively form the window encoding vector. For subsequent windows, the existing encoding of overlapping frames is retained, and encoding is only continued for the three newly entered frames to reduce redundant processing. The visual quality inspection model calculates the quality state probability for each window at the edge nodes, corrects the probabilities of adjacent windows through Hidden Markov forward recursion, and then uses the Viterbi algorithm to backtrack to obtain the continuous quality state path, finally giving the tobacco product quality inspection result. For samples that have been verified, they are added to the mini-batch training samples, and the visual quality inspection model is incrementally trained using mini-batch gradient descent.
[0037] In the verification of 8,000 tobacco products in continuous testing, 386 abnormal samples were identified by manual review, including 91 with damaged packaging, 76 with unclear labeling, 84 with surface stains, 63 with misaligned edges, and 72 with partial wrinkles.
[0038] When using the original single-frame visual inspection method, the average detection accuracy was 91.8%, the anomaly miss rate was 6.7%, the false positive rate was 5.9%, the continuous window result jump rate was 8.4%, and the average processing time per item was 47 milliseconds. After adopting the present invention, the average detection accuracy increased to 96.4%, the anomaly miss rate decreased to 3.1%, the false positive rate decreased to 2.6%, the continuous window result jump rate decreased to 2.3%, and the average processing time per item decreased to 31 milliseconds.
[0039] After three rounds of incremental training with verified data, the anomaly identification accuracy of the new batch of samples increased from 94.9% to 96.8%, indicating that the present invention has good practical effects in reducing short-term interference misjudgments, improving edge-side processing efficiency, and enhancing model adaptability.
[0040] Table 1. Comparison of Tobacco Product Quality Inspection Effects Before and After Implementation of the Invention
[0041] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for quality inspection of tobacco products based on AI visual inspection and edge computing, characterized in that, Includes the following steps: S1. Collect visual data for tobacco product quality inspection at edge nodes and preprocess it to form a standard visual sequence. S2. Perform continuous frame overlap sampling on the standard visual sequence, and perform local occlusion reconstruction on the obtained continuous image segments. Sort the continuous image segments according to the reconstruction differences to construct a quality inspection sample set. S3. A contrastive learning encoding network is used to establish a discriminative mapping relationship between continuous image segments and quality status labels. Based on the quality inspection sample set, the contrastive learning encoding network is jointly trained by supervised contrastive loss and defect response loss to construct a visual quality inspection model. S4. Deploy the visual quality inspection model on the edge node side, perform continuous window encoding on the visual sequence to be detected, calculate the window-level quality state probability through the visual quality inspection model, and use the Hidden Markov forward recursive method to recursively correct the quality state probability. S5. Construct a quality state path based on the recursively corrected quality state probability, calculate the transition cost between adjacent quality states according to the window time sequence, and use the Viterbi algorithm to backtrack and optimize the quality state path to determine the quality inspection result of tobacco products. S6. Obtain the verification data corresponding to the quality inspection results of tobacco products, and use the small-batch gradient descent method to incrementally train the visual quality inspection model.
2. The method for quality inspection of tobacco products based on AI visual inspection and edge computing according to claim 1, characterized in that, The preprocessing specifically includes: The visual acquisition data collected from edge nodes is frame-numbered according to the acquisition time sequence, and duplicate frames, blurry frames, and frames with abnormal exposure are removed, including: The edge node is an edge computing unit used to perform visual data access, preprocessing, model inference and result caching. The visual acquisition data is continuous frame image data formed during the tobacco product quality inspection process. The continuous frame image data carries an acquisition timestamp, acquisition channel identifier and quality inspection batch identifier. The illumination drift parameters are estimated based on the brightness change between adjacent frames, and the brightness of the visual acquisition data is compensated based on the illumination drift parameters. Background response is estimated from the brightness-compensated visual acquisition data, and the background response is subtracted from the corresponding frame image to obtain the foreground response image; Boundary registration and scale adjustment are performed on the foreground response image to place different frame images under a unified spatial size and coordinate reference. The registered foreground response images are arranged in temporal order according to frame number to form a standard visual sequence.
3. The tobacco product quality inspection method based on AI visual inspection and edge computing according to claim 1, characterized in that, S2 specifically includes: S21. Establish an overlapping sampling window according to the frame number in the standard visual sequence, merge the continuous frames at the end of the current sampling window into the front of the next sampling window, and use the dynamic time warping method to perform time axis registration on the overlapping frames in adjacent sampling windows to extract continuous image segments. S22. Divide the continuous image segments into blocks, select the image blocks with abrupt changes in grayscale response along the frame sequence as masking blocks, and use the context information of the unmasked image blocks to reconstruct the masking blocks to obtain the reconstructed image segments. S23. Extract the reconstruction error vectors of corresponding image blocks in continuous image segments and reconstructed image segments, calculate the Mahalanobis distance based on the reconstruction error distribution under normal quality conditions, and sort the continuous image segments according to the Mahalanobis distance. S24. Associate the corresponding review results with the abnormal sorting results, convert the review results into quality status labels, and perform positive and negative sample pairing on continuous image segments based on the quality status labels to construct a quality inspection sample set.
4. The tobacco product quality inspection method based on AI visual inspection and edge computing according to claim 3, characterized in that, S23 specifically includes: S231. According to the frame number and image block position, perform block-level registration on the continuous image segments and the reconstructed image segments. Using image blocks of 8×8 pixels to 32×32 pixels as processing units, perform 2 to 4 layers of convolutional coding on the registered original image blocks and reconstructed image blocks respectively. Then, through 1×1 convolution, map the two sets of block-level convolutional codes to a unified coding space of 64 to 256 dimensions to form reconstruction difference coding. S232. Based on continuous image segments labeled as normal quality, statistically reconstruct the mean vector and covariance matrix of the difference encoding, and then use... to The regularization parameter is used to perform regularization and inversion on the covariance matrix, and the normal distance threshold is set according to the 95% to 99% quantile of the Mahalanobis distance under normal quality conditions. S233. Perform centering processing on the reconstruction difference encoding of the current continuous image segments, and calculate the Mahalanobis distance of each image block by combining the covariance matrix after regularization and inversion. Scan the Mahalanobis distance along the frame number direction and mark the image blocks that exceed the normal distance threshold for 2 to 5 consecutive frames as abnormal blocks. S234. Calculate the segment anomaly score based on the number of consecutive frames, the number of segments, and the peak Mahalanobis distance of the abnormal block segments. Sort the continuous image segments according to the segment anomaly score and select the continuous image segments in the top 5% to 20% as the priority review segments.
5. The method for quality inspection of tobacco products based on AI visual inspection and edge computing according to claim 1, characterized in that, S3 specifically includes: S31. Based on the quality status labels in the quality inspection sample set, perform sample pairing on continuous image segments to obtain sample pairs with the same label and sample pairs with different labels. Then, use a contrastive learning coding network with shared coding parameters to encode and map the continuous image segments in the sample pairs to obtain segment coding vectors. S32. Calculate the encoding similarity of same-label sample pairs and different-label sample pairs respectively. Take the encoding similarity of same-label sample pairs as the positive similarity term and the encoding similarity of different-label sample pairs as the negative similarity term. Calculate the supervised contrastive loss using the supervised contrastive learning function. S33. Based on the segment coding vector, the quality status is judged, and the defect response reference value is set according to the order of the continuous image segments in the anomaly sorting. The defect response loss is calculated based on the quality status judgment deviation and the defect response deviation. S34. Combine the supervised contrastive loss and the defect response loss into a joint loss function, perform backpropagation training on the contrastive learning encoding network based on the joint loss function, and construct the trained contrastive learning encoding network into a visual quality inspection model.
6. The tobacco product quality inspection method based on AI visual inspection and edge computing according to claim 5, characterized in that, Specifically, S33 includes: S331. Perform quality state mapping based on fragment encoding vectors, and use a focal cross-entropy discriminant function with adjustment factors of 1 to 3 to process the discrimination error corresponding to the quality state label, reduce the loss weight of high-confidence continuous image fragments, and retain the loss weight of low-confidence continuous image fragments. S332. Based on the order of consecutive image segments in the anomaly sorting, construct defect response levels from level 3 to level 5. Assign consecutive image segments that are ranked higher to the high response level and consecutive image segments that are ranked lower to the low response level. Establish a regression relationship between the defect response level and the segment encoding vector. S333. The order-aware Huber loss is used to process the deviation between the defect response level and the regression result. A secondary penalty is applied to the deviation that is less than the response threshold, and a linear penalty is applied to the deviation that is not less than the response threshold. The response threshold is 0.5 to 1.5 times the interval between adjacent defect response levels. S334. The loss term corresponding to the focus cross-entropy discriminant function is used as the quality discriminant term, and the loss term corresponding to the ranking-aware Huber loss is used as the response regression term. The quality discriminant term and the response regression term constitute the defect response loss.
7. The tobacco product quality inspection method based on AI visual inspection and edge computing according to claim 1, characterized in that, S4 specifically includes: S41. Deploy the trained visual quality inspection model in the inference process of the edge node, retain the order of network weights and quality state labels required for forward inference, and stop the gradient update process in the training phase. S42. According to the preset window length and window step, the visual sequence to be detected formed in real time by the edge nodes is slidably truncated, and the incremental window coding method is adopted to reuse the existing coding of the overlapping frames of adjacent windows, and the coding is updated for the frames that newly enter the current window to form the current window coding vector. S43. The current window encoding vector is used by the visual quality inspection model to determine the quality status. The determination values of each quality status are arranged in order of quality status label, and the Softmax function is used to process the determination values probabilistically to form window-level quality status probabilities. S44. Calculate the quality state transition probability based on the frequency of occurrence of adjacent quality state labels, and use the Hidden Markov forward recursive method to recursively correct the previous window correction probability and the current window level quality state probability to form the current window recursive correction probability.
8. The tobacco product quality inspection method based on AI visual inspection and edge computing according to claim 7, characterized in that, S42 specifically includes: S421. Based on the frame rate of the visual sequence to be detected and the inference time per frame for edge nodes, set the continuous window length and window step size, where: The single-frame inference time is the average processing time required for edge nodes to complete the encoding process of a single-frame image using a visual quality inspection model. The window step size is smaller than the length of the continuous window. There are overlapping frames between adjacent continuous windows to be detected. The continuous windows to be detected are truncated by sliding along the frame order with the window step size. S422. Perform frame encoding on the first continuous window to be detected in frame order. Using the first frame encoding as the starting point of the recursion, adopt the exponential moving average recursion method to recursively aggregate the next frame encoding with the previous recursion encoding to generate the recursion encoding corresponding to each frame, and take the last frame recursion encoding to form the first window encoding vector. S423. When the next continuous window to be detected arrives, identify the overlapping frame that is the same as the previous continuous window to be detected according to the frame number, retain the frame code and recursive code corresponding to the overlapping frame, and perform frame coding on the newly entered frame in the current window. S424. Using the recursive encoding at the end of the overlapping frame as the starting point for the current window, the frame encoding of the newly entering frame is recursively calculated by exponential moving average according to the frame order to form the current window encoding vector.
9. The method for quality inspection of tobacco products based on AI visual inspection and edge computing according to claim 1, characterized in that, S5 specifically includes: S51. Arrange the corrected quality state probabilities according to the window time sequence, take the quality state label under each window as a candidate state, and construct the quality state path according to the connection relationship between the candidate states of adjacent windows. S52. Perform negative logarithmic cost processing on the recursive correction probability corresponding to the candidate state to form the state cost, and set the transition cost between adjacent quality states according to the connection relationship between quality state maintenance and quality state transition in adjacent windows. S53. The Viterbi algorithm is used to perform dynamic programming recursion along the window time sequence, and the state cost and transition cost are cumulatively filtered to retain the minimum cumulative path cost and the position of the previous state of the current candidate state. S54. Starting from the quality state corresponding to the minimum cumulative path cost in the end window, backtrack in reverse according to the position of the previous state to form the quality state path with the minimum total cost, and determine the quality inspection result of tobacco products based on the quality states that appear consecutively in the quality state path.
10. A method for quality inspection of tobacco products based on AI visual inspection and edge computing according to claim 1, characterized in that, S6 specifically includes: S61. Obtain the verification data corresponding to the tobacco product quality inspection results, and associate the verification data with the corresponding visual sequence to be detected, window-level quality state probability, and tobacco product quality inspection results to form a verification sample, wherein: The verification data refers to the confirmation data formed after manual verification or secondary testing of the quality inspection results of tobacco products, including the verification quality status, the location of the verification defects, and the verification time marker. S62. According to the quality status markers in the verification data, the verification samples are stratified and small-batch extracted, and the verification samples whose verification results are inconsistent with the tobacco product quality inspection results are added to the current small-batch training samples. S63. Use a visual quality inspection model to encode and discriminate the current small batch of training samples, and use the joint loss function composed of supervised contrast loss and defect response loss to calculate the incremental training loss of the current small batch of training samples. S64. Using the mini-batch gradient descent method, the network parameters of the visual quality inspection model are incrementally updated based on the incremental training loss, and the updated visual quality inspection model is used for the next round of edge node quality inspection.