Defect detection method and system for lightweight textiles
By constructing a heterogeneous model system and end-to-end knowledge distillation training, combined with quantitative perception training, high-precision and lightweight textile defect detection was achieved, solving the model deployment problem in existing technologies and improving the accuracy and real-time performance of detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANGSU JICUI FUNCTIONAL MATERIALS RES INST CO LTD
- Filing Date
- 2026-03-20
- Publication Date
- 2026-06-12
AI Technical Summary
Existing high-performance textile defect detection models have a large number of parameters and high computational complexity, making them difficult to deploy on resource-constrained industrial edge devices. They also suffer from significant accuracy loss and are difficult to migrate to heterogeneous environments, thus failing to meet the real-time detection requirements of high-speed production lines.
A heterogeneous model system is constructed, employing a teacher defect detection model and a lightweight student defect detection model. A hybrid expert mechanism is introduced, and high-precision, lightweight textile defect detection is achieved through cross-architecture alignment and end-to-end knowledge distillation training, combined with quantitative perception training.
The model volume is compressed by more than 25 times, the inference speed is increased by 8.2 times, the mAP reaches 92.1%, and the small defect recall rate is 92.5%, meeting the real-time online detection needs of edge equipment in textile production lines.
Smart Images

Figure CN122199502A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of industrial computer vision and intelligent manufacturing technology, specifically relating to a defect detection method and system for lightweight textiles. Background Technology
[0002] In the textile production process, defects such as broken yarns, oil stains, holes, stripes, and uneven density are easily generated on the fabric surface. Traditional manual visual inspection is inefficient and highly subjective, and can no longer meet the needs of high-speed production lines. In recent years, automatic inspection technology based on computer vision has been widely used.
[0003] While existing high-performance detection models (such as the YOLOv11x series) have high accuracy, they have a huge number of parameters and high computational complexity, making them difficult to deploy on resource-constrained industrial edge computing devices (such as embedded cameras and industrial cameras with built-in AI acceleration cards). The high latency and high memory consumption of these models make them unable to meet the real-time detection requirements of high-speed production lines.
[0004] To reduce model complexity, existing technologies mainly employ model compression methods, such as pruning, quantization, or knowledge distillation. However, these methods still have significant problems when applied to textile defect detection: large loss of accuracy, difficulty in heterogeneous transfer, and hardware incompatibility.
[0005] Therefore, how to design a defect detection model that combines high precision, lightweight design, and low latency, and how to achieve its efficient deployment in industrial scenarios, is a technical challenge that urgently needs to be solved in the field of intelligent textile manufacturing. Summary of the Invention
[0006] The purpose of this application is to provide a defect detection method and system for lightweight textiles, in order to solve the problems in the prior art such as the difficulty of deploying high-precision detection models at the edge, the insufficient detection accuracy of lightweight models, and the difficulty of knowledge transfer in heterogeneous architectures.
[0007] To achieve the above objectives, a specific embodiment of the present invention provides a defect detection method for lightweight textiles, the method comprising:
[0008] A heterogeneous model system is constructed, which includes a teacher defect detection model for providing supervised information and a lightweight student defect detection model for edge inference. The student defect detection model introduces a hybrid expert mechanism. The textile images are acquired and input into the teacher defect detection model and the student defect detection model respectively, to obtain teacher features and teacher detection output, as well as student features and student detection output; Cross-architecture alignment of teacher and student features is performed, and a matching relationship is established between teacher detection output and student detection output to obtain alignment supervision information for distillation. Based on the alignment supervision information, the student defect detection model is trained by end-to-end knowledge distillation. The distillation training includes at least feature distillation, classification distillation, regression distillation and hybrid expert load balancing constraints. A fixed-point quantization model is derived by performing quantization perception training on the distilled student defect detection model, and the fixed-point quantization model is deployed on an edge computing device to output defect category information, confidence information, and image location information to the input textile image.
[0009] In this embodiment, by constructing a complete link of heterogeneous model system, cross-architecture alignment, end-to-end knowledge distillation training, and deployment-level quantization perception training, the high-precision knowledge of the teacher model is efficiently transferred to the lightweight student defect detection model. The model size is compressed by more than 25 times, the inference speed is increased by 8.2 times (FPS reaches 68+), and the mAP reaches 92.1% and the small defect recall rate is 92.5%. This solves the problems of large accuracy loss, difficult heterogeneous transfer, and hardware incompatibility of the existing technology, and meets the real-time online detection needs of edge equipment in textile production lines.
[0010] In one or more embodiments of the present invention, the feature extraction stage of the student defect detection model employs a lightweight backbone network with high computational efficiency. The backbone network uses depthwise separable convolution, group convolution, or inverse residual structure to quickly extract basic texture features of textile surfaces and reduce the parameter scale of the overall model.
[0011] In this embodiment, a lightweight backbone network with depthwise separable convolution, group convolution, or inverse residual structure is adopted. While ensuring the ability to extract texture features of textiles, the number of parameters and floating-point operations are greatly reduced, so that the overall parameter size of the student defect detection model is only 6.6M and the peak memory is only 4.5MB, which significantly improves the deployment friendliness and real-time performance of edge devices.
[0012] In one or more embodiments of the present invention, the hybrid expert Transformer decoding module of the student defect detection model includes multiple expert sub-networks set in parallel and at least one gated network; the gated network dynamically calculates the activation weights of each expert sub-network based on the input feature vector, and adopts a Top-K routing strategy to select only the K experts with the highest weights to participate in the calculation, where K is less than the total number of expert sub-networks, so as to achieve a balance between high parameter capacity and low computational overhead.
[0013] In this embodiment, the hybrid expert Transformer decoding module achieves sparse activation through a gated network and Top-K routing (K=2). While maintaining a high parameter capacity (total number of experts 4 or 8), only some experts are activated in a single inference, which balances the ability to model complex defects in detail with low computational overhead and solves the problem of insufficient expressive power after the traditional Transformer is lightweight.
[0014] In one or more embodiments of the present invention, the feature adaptation module that aligns teacher features and student features in the cross-architecture alignment adopts a 1×1 convolutional structure, maps the low-dimensional textile texture features output by the backbone network of the student defect detection model to the channel dimension space consistent with the intermediate layer features of the teacher defect detection model, and achieves feature distillation by minimizing the mean square error between the two.
[0015] In this embodiment, the 1×1 convolutional feature adaptation module, combined with mean square error constraints, achieves seamless alignment between the student's low-dimensional features and the teacher's intermediate layer feature space. This effectively transmits knowledge of textile texture structure and defect morphology, enabling the student defect detection model to inherit the teacher's high-precision expressive ability during the feature distillation stage, thus avoiding the dimensional mismatch problem of traditional direct alignment.
[0016] In one or more embodiments of the present invention, establishing a matching relationship between teacher detection output and student detection output includes: constructing a cost matrix between student detection output and teacher detection output target, wherein the cost matrix is calculated based on the difference in probability distribution of defect categories and the distance of the spatial location of defect regions.
[0017] In this embodiment, a matching mechanism based on the difference in category probability and spatial location distance to construct a cost matrix is used to achieve a one-to-one correspondence between cross-architecture detection logic, ensure accurate supervision of classification distillation and regression distillation, avoid knowledge transfer failure caused by differences in heterogeneous model detection paradigms, and improve overall detection accuracy and small defect recall rate.
[0018] In one or more embodiments of the present invention, the multi-objective joint loss function for end-to-end knowledge distillation training includes: Feature distillation loss is used to constrain the ability of the student defect detection model to learn the teacher defect detection model's ability to express the texture structure and defect morphology of textiles. Defect classification distillation loss is used to constrain the ability of the student defect detection model to distinguish defect categories; Defect region regression distillation loss is used to constrain the prediction accuracy of the student defect detection model for defect location and scale; Hybrid expert load balancing loss is used to suppress the phenomenon of concentrated computational load in expert sub-networks, ensuring that each expert network gets a uniform learning opportunity during training. The aforementioned loss terms are summed using preset weight coefficients to form the overall optimization objective for end-to-end training.
[0019] In this embodiment, the multi-objective joint loss function achieves end-to-end optimization through weighted summation. This not only constrains the student defect detection model to fully inherit the teacher's knowledge but also suppresses the expert collapse phenomenon, ensuring that all experts learn evenly, resulting in faster training convergence and a final mAP comparable to the teacher model.
[0020] In one or more embodiments of the present invention, the quantization perception training adopts a hierarchical quantization strategy: fixed-point quantization is applied to convolutional layers and fully connected layers; while floating-point precision is retained for the Softmax operation in the self-attention mechanism, layer normalization, and routing calculations involving normalization in the gating network, so as to balance inference speed and detection accuracy.
[0021] In this embodiment, the layered quantization strategy performs INT8 fixed-point quantization on the convolutional / fully connected layers while preserving the floating-point precision of Softmax, LayerNorm, and routing calculations. This minimizes the loss of precision while compressing the model size to 8.56MB and reducing latency to 14.69ms, achieving training-deployment consistency and significantly reducing the deployment cost of industrial edge devices.
[0022] In one or more embodiments of the present invention, the feature extraction stage of the student defect detection model adopts a lightweight backbone network with high computational efficiency, such as MobileNet, EfficientNet-lite or variants thereof; the hybrid expert Transformer decoding module includes multiple expert sub-networks configured in parallel and at least one gating network; the quantization-aware training adopts a hierarchical quantization strategy.
[0023] In this embodiment, the MobileNet / EfficientNet-lite backbone network, the hybrid expert decoding module, and the hierarchical quantization strategy are used simultaneously to form a collaborative design of lightweight extraction, sparse high-capacity decoding, and hardware-friendly quantization. This enables the model to maintain high accuracy in complex texture backgrounds and outperforms baseline methods that only distill or only quantize.
[0024] In one or more embodiments of the present invention, the core hyperparameters for constructing the student defect detection model include the Transformer model dimension d_model=128, the number of attention heads n_head=4, the number of expert networks n_experts=4, and the K value in the Top-K routing is set to 2; the end-to-end knowledge distillation training strategy adopts gradient pruning, learning rate preheating, and cosine annealing.
[0025] In this embodiment, the specific hyperparameter configuration (d_model=128, n_head=4, n_experts=4, K=2) is combined with Warmup, Cosine Annealing, and gradient pruning training strategies to ensure that the student defect detection model converges stably on a 5000-image self-built dataset and the validation set loss decreases rapidly, providing clear parameter basis for industrial-grade reproducible implementation.
[0026] In another aspect of the invention, a defect detection system for lightweight textiles is also provided, comprising the steps of implementing a defect detection method for lightweight textiles, the defect detection system for lightweight textiles comprising: The model building module is used to build a heterogeneous model system, which includes a teacher defect detection model for providing supervised information and a lightweight student defect detection model for edge inference. The student defect detection model introduces a hybrid expert mechanism. The image acquisition module is used to acquire textile images and input them into the teacher defect detection model and the student defect detection model respectively, so as to obtain teacher features and teacher detection output, as well as student features and student detection output; The information matching module is used to perform cross-architecture alignment of teacher features and student features, and to establish a matching relationship between teacher detection output and student detection output to obtain alignment supervision information for distillation. The distillation training module is used to perform end-to-end knowledge distillation training on the student defect detection model based on the alignment supervision information. The distillation training includes at least feature distillation, classification distillation, regression distillation, and hybrid expert load balancing constraints. The quantization optimization module performs quantization perception training on the distilled student defect detection model to derive a fixed-point quantization model, and deploys the fixed-point quantization model on an edge computing device to output defect category information, confidence information, and image location information to the input textile image. Attached Figure Description
[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0028] Figure 1 This is a flowchart of a defect detection method for lightweight textiles according to one embodiment of the present invention; Figure 2 This is a schematic diagram of the overall structure of the student defect detection model in one embodiment of the present invention; Figure 3 This is a schematic diagram of the internal structure of the hybrid expert Transformer decoding layer in one embodiment of the present invention; Figure 4 This is a loss curve during distillation training according to one embodiment of the present invention; Figure 5 This is an example diagram showing the results of textile defect detection in one embodiment of the present invention; Figure 6 This is a modular schematic diagram of a defect detection system for lightweight textiles according to one embodiment of the present invention. Detailed Implementation
[0029] To enable those skilled in the art to better understand the technical solutions of this invention, the technical solutions of the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this invention.
[0030] This invention provides a defect detection method and system for lightweight textiles, solving the problems of existing textile defect detection models having large parameter counts, high computational complexity, and difficulty in deployment on resource-constrained edge devices. By constructing a heterogeneous model system, acquiring images and inputting them into dual models, cross-architecture alignment and matching, end-to-end knowledge distillation training, and quantized perception training export and deployment, a high-precision, lightweight, and low-latency textile defect detection model is achieved, improving the accuracy and real-time performance of textile defect detection.
[0031] The technical solutions of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. It should be understood that the present invention is not limited to the exemplary embodiments described herein. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention. It should also be noted that, for ease of description, only the parts related to the present invention are shown in the accompanying drawings, not all of them.
[0032] like Figure 1 As shown, this invention provides a defect detection method for lightweight textiles, wherein the defect detection method for lightweight textiles is executed by a defect detection system for lightweight textiles, and the defect detection method for lightweight textiles specifically includes the following steps: A heterogeneous model system is constructed, which includes a teacher defect detection model for providing supervision information and a lightweight student defect detection model for edge inference. The student defect detection model introduces a hybrid expert mechanism.
[0033] Furthermore, the feature extraction stage of the student defect detection model employs a lightweight backbone network with high computational efficiency. The backbone network uses depthwise separable convolution, group convolution, or inverse residual structure to quickly extract basic texture features of textile surfaces and reduce the overall model parameter scale.
[0034] Furthermore, the hybrid expert Transformer decoding module of the student defect detection model includes multiple parallel expert sub-networks and at least one gated network; the gated network dynamically calculates the activation weights of each expert sub-network based on the input feature vector, and adopts a Top-K routing strategy to select only the K experts with the highest weights to participate in the calculation, where K is less than the total number of expert sub-networks, so as to achieve a balance between high parameter capacity and low computational overhead.
[0035] Specifically, the teacher defect detection model employs a high-parameter convolutional neural network, such as the YOLOv11x series, to provide high-precision defect feature representation and detection results. The student defect detection model introduces a hybrid expert mechanism Transformer architecture for online inference in industrial settings. The student defect detection model includes an efficient feature extraction backbone network, a feature projection and location encoding module, a hybrid expert Transformer decoding module, and a defect prediction head module. Through the collaborative design of a computationally efficient feature extraction backbone network and a hybrid expert Transformer architecture with high parameter capacity but sparse activation characteristics, the model's overall lightweight design significantly improves its ability to represent complex textile defect textures.
[0036] like Figure 2 The diagram shown is a schematic representation of the overall structure of the student model of this invention. This schematic fully presents the modular architecture of the lightweight student defect detection model: the left side is the efficient feature extraction backbone network (using lightweight backbones such as EfficientNet-Lite0, outputting low-dimensional texture feature maps); the middle is the feature projection and position encoding module (1×1 convolution upsizing, flattening into sequences, and superimposing learnable positional encodings); the right side is the hybrid expert Transformer decoding module (multi-layer stacking, each layer containing multi-head self-attention sublayers and hybrid expert feedforward sublayers); and the far right is the defect prediction head module (parallel classification head outputs class probability + background class, regression head outputs normalized bounding box coordinates).
[0037] Furthermore, the specific construction of the student defect detection model is detailed, explaining how to construct a student defect detection model based on a hybrid expert mechanism, including: Model initialization: Defining the student defect detection model Student_model. The core hyperparameter settings are as follows: The backbone network uses the EfficientNet-Lite0 model; Transformer model dimension d_model=128; number of attention heads n_head=4; maximum number of queries predicted by the model num_queries=50; number of decoder layers num_decoder_layers=3; number of expert networks n_experts=4; and the K value in Top-K routing is set to 2.
[0038] In a further embodiment, the backbone network construction and feature extraction steps include: loading the EfficientNet-Lite0 backbone as a feature extractor and setting it to features_only=True to extract intermediate layer features. The backbone network receives an input image (e.g., an RGB image resized to 640×640 pixels) and outputs the final layer feature map. For example, given a 640×640 image as input, the backbone network might output a feature tensor of size 20×20 with 128 channels.
[0039] In a further embodiment, feature projection and serialization include: mapping the feature channels output by the backbone network to a model dimension d_model=128 using a 1×1 convolutional layer. The two-dimensional feature map (shape [batch_size, 128, H, W]) is flattened into a one-dimensional sequence (shape [batch_size, H...). W, 128]), and added to the learnable location encoding vector to form a feature sequence memory containing spatial location information.
[0040] In a further embodiment, the hybrid expert decoder construction includes: setting an attention sublayer to interact the query with memory features from the backbone network to associate image features with the predicted query; a hybrid expert feedforward sublayer using MoELayer instead of the traditional fully connected feedforward network; a gating network, a linear layer with an output dimension equal to the number of experts (4), outputting a 4-dimensional weight vector for each query position, which is then normalized by Softmax to obtain the activation probability of each expert; Top-K routing, selecting the K=2 experts with the highest probabilities to be activated based on their activation probabilities. For example, for a given query, experts A and C are selected; parallel expert computation: each selected expert network (structure: Linear(d_model,512) → ReLU → Linear(512, d_model)) independently processes the input; weighted summation: the outputs of the selected experts are weighted and summed according to their corresponding activation probabilities, and this summation is used as the output of the sublayer.
[0041] In a further embodiment, the prediction head construction includes: the final query sequence output by the decoder is passed through two parallel fully connected layers, where the classification head is class_embed with an output dimension of num_classes+1 (including the background class), and after passing through Softmax, the class probability distribution of each query is obtained. The regression head is bbox_embed, which contains three fully connected layers with an output dimension of 4, and after passing through the Sigmoid function, the normalized center coordinates (cx, cy) and width and height (w, h) of the predicted bounding box are obtained.
[0042] In this embodiment, textile images are acquired and input into the teacher defect detection model and the student defect detection model respectively to obtain teacher features and teacher detection output, as well as student features and student detection output.
[0043] Cross-architecture alignment of teacher and student features is performed, and a matching relationship is established between teacher detection output and student detection output to obtain alignment supervision information for distillation.
[0044] Furthermore, the present invention also includes the following steps: the feature adaptation module for aligning teacher features and student features in the cross-architecture alignment adopts a 1×1 convolutional structure, maps the low-dimensional textile texture features output by the backbone network of the student defect detection model to the channel dimension space consistent with the intermediate layer features of the teacher defect detection model, and achieves feature distillation by minimizing the mean square error between the two.
[0045] Furthermore, the present invention also includes the following steps: establishing a matching relationship between the teacher's detection output and the student's detection output includes: constructing a cost matrix between the student's detection output and the teacher's detection output target, wherein the cost matrix is calculated based on the difference in the probability distribution of defect categories and the distance of the spatial location of the defect area.
[0046] Specifically, the feature adaptation module adopts a 1×1 convolutional structure; the cost matrix for the detection logic alignment is calculated based on the differences in the probability distributions of defect categories (such as KL divergence) and the spatial distances of defect regions (such as L1 distance). Cross-architecture knowledge distillation is achieved through the alignment of the feature adaptation module and the detection logic.
[0047] The student defect detection model is trained end-to-end by knowledge distillation based on the alignment supervision information. The distillation training includes at least feature distillation, classification distillation, regression distillation, and hybrid expert load balancing constraints.
[0048] Furthermore, the present invention also includes the following steps: the multi-objective joint loss function of the end-to-end knowledge distillation training includes: feature distillation loss, used to constrain the student defect detection model's ability to learn the teacher defect detection model's ability to express the texture structure and defect morphology of textiles; defect classification distillation loss, used to constrain the student defect detection model's ability to distinguish defect categories; defect region regression distillation loss, used to constrain the student defect detection model's prediction accuracy of defect location and scale; and hybrid expert load balancing loss, used to suppress the phenomenon of concentrated computational load in expert sub-networks and ensure that each expert network obtains a uniform learning opportunity during training; the above loss terms are weighted and summed by preset weight coefficients to constitute the overall optimization objective of end-to-end training.
[0049] Specifically, by leveraging the cross-architecture knowledge distillation guidance of the high-performance teacher defect detection model, the lightweight student defect detection model can fully inherit the detection capabilities of the teacher defect detection model during end-to-end training.
[0050] Furthermore, the specific implementation of the cross-architecture knowledge distillation training illustrates how to use a teacher defect detection model (such as YOLOv11x) to guide the training of a student defect detection model, including: Teacher defect detection model preparation: Loading a pre-trained YOLOv11x model and freezing all its parameters for inference only. To extract intermediate features, forward hooks can be registered at specific layers of the YOLO model to obtain feature map output.
[0051] The data preparation before training includes: using a publicly available or self-built textile defect dataset, which must contain multiple types of defects (such as broken yarn, holes, oil stains, dirt, etc.) and be labeled in a standard format (such as YOLO format), with the labeling information including the defect category and bounding box coordinates. Common data augmentation (such as flipping, rotating, and color jittering) is then performed on the data.
[0052] The training process includes batch setup for each training iteration, specifically: Teacher forward propagation: The image is input into the teacher defect detection model, yielding its outputs: t_feature (e.g., a feature map with shape [batch, 1280, 20, 20]) and t_predictions (detection results including confidence scores and bounding boxes). Student forward propagation: The same image is input into the student defect detection model, yielding its outputs: s_feature (from the backbone network, e.g., shape [batch, 128, 20, 20]), s_logits (classification predictions), s_boxes (regression predictions), and s_lb_loss (MoE load balancing loss). The formula for calculating s_lb_loss is: ; Where N is the total number of tokens in the batch. pn,i The probability of each token being associated with the i-th expert.
[0053] Feature distillation loss calculation: Due to the inconsistent channel dimensions of s_feature and t_feature, a 1×1 convolutional feature adapter, feat_adapter, is used to increase the number of s_feature channels from 128 to 1280, resulting in s_feat_aligned. If the spatial dimensions (H, W) are inconsistent, bilinear interpolation is used for alignment. The mean squared error between the two is calculated, and the formula for calculating loss_feat is as follows: ; In a further embodiment, the resulting distillation loss is calculated and matched: The classification distillation loss (loss_cls) includes calculating the cross-entropy loss between the class probability distributions of the student's detection output and the teacher's detection output. The formula for calculating loss_cls is: ; Here, teacher_labels represents the classification predictions of the teacher defect detection model.
[0054] Regression distillation loss (loss_box): For a matched query pair, calculate the L1 loss between the coordinates of the student detection output box and the teacher detection output box. The formula for calculating loss_box is:
[0055] Here, teacher_boxes represents the regression predictions of the teacher defect detection model.
[0056] Furthermore, it also includes the calculation of the total loss, where the formula for calculating total_loss is: ; Among them, λ_feat, λ_cls, λ_box, and λ_lb are preset weights.
[0057] This also includes parameter updates: the gradient of the total loss is calculated only for the student defect detection model parameters and updated using an optimizer (such as AdamW). The teacher defect detection model parameters remain unchanged.
[0058] In this embodiment, the training strategy employs gradient pruning, learning rate warmup, and cosine annealing to stabilize the training. Training is conducted for multiple epochs (e.g., 100-200) until the validation set loss converges.
[0059] A fixed-point quantization model is derived by performing quantization perception training on the distilled student defect detection model, and the fixed-point quantization model is deployed on an edge computing device to output defect category information, confidence information, and image location information to the input textile image.
[0060] Furthermore, the present invention also includes the following steps: the quantization perception training adopts a hierarchical quantization strategy: fixed-point quantization is applied to the convolutional layer and the fully connected layer; while floating-point precision is retained for the Softmax operation in the self-attention mechanism, layer normalization, and routing calculations involving normalization in the gated network, so as to balance inference speed and detection accuracy.
[0061] Furthermore, the present invention also includes the following steps: the feature extraction stage of the student defect detection model adopts a lightweight backbone network with high computational efficiency, such as MobileNet, EfficientNet-lite or variants thereof; the hybrid expert Transformer decoding module includes multiple expert sub-networks configured in parallel and at least one gating network; the quantization-aware training adopts a hierarchical quantization strategy.
[0062] like Figure 3The diagram shown illustrates the internal structure of the hybrid expert Transformer decoding layer in this invention. This diagram details the core innovative structure of the hybrid expert Transformer decoding layer: the upper part is a multi-head self-attention sublayer (interaction between query and memory features); the lower part is a hybrid expert feedforward sublayer (a gating network outputs expert activation probabilities for each token, using Top-K routing to activate only the K experts with the highest weights; each expert has an independent MLP structure: Linear(d_model, 512) → ReLU → Linear(512, d_model), and finally, the probabilities are weighted and summed for output), clearly illustrating the dynamic routing, sparse activation, and load balancing mechanisms.
[0063] Furthermore, the present invention also includes the following steps: when constructing the student defect detection model, the core hyperparameters include the Transformer model dimension d_model=128, the number of attention heads nhead=4, the number of expert networks n_experts=4, and the K value in the Top-K routing is set to 2; the end-to-end knowledge distillation training strategy adopts gradient pruning, learning rate preheating and cosine annealing.
[0064] Specifically, consistent optimization from training to industrial deployment is achieved through quantized perception training. Fixed-point quantization error simulation nodes (pseudo-quantization nodes) are inserted into the student defect detection model to simulate the process of quantizing floating-point weights and activation values into low-bit (e.g., INT8) fixed-point numbers, introducing corresponding quantization errors. To maintain numerical stability, modules sensitive to numerical ranges, such as attention computation, layer normalization, and gating networks in the hybrid expert module, can temporarily retain floating-point precision. Finally, a fixed-point quantized textile defect detection model for deployment on edge devices in textile production lines is derived, achieving end-to-end inference from image input to defect detection result output.
[0065] Furthermore, the quantization-aware training and model conversion describes how to convert a trained FP32 student defect detection model into a deployable INT8 model, including: Quantization-aware training preparation: After distillation training, load the FP32 checkpoints of the student defect detection model. Use PyTorch's quantization tool torch.ao.quantization to configure the quantization-aware training parameters (qconfig) for the model. Selective quantization configuration: Explicitly set qconfig=None for critical but quantization-sensitive modules to preserve floating-point precision. In this invention, floating-point precision is preserved for the following modules: a) the attn submodule in MultiheadAttention; b) all LayerNorm layers; c) the gate network in MoELayer (because it involves Softmax routing). Apply the default quantization configuration to other linear and convolutional layers. Call prepare_qat(model, inplace=True) to insert "pseudo-quantization nodes" such as QuantStub and DeQuantStub into the model to simulate quantization operations.
[0066] Quantization-aware fine-tuning training: Using a small learning rate (e.g., 1 / 10 of the learning rate used in distillation training), the model with inserted pseudo-quantization nodes is fine-tuned for several rounds (e.g., 10-20 rounds). During training, forward propagation simulates the numerical truncation and accuracy loss caused by quantization, while backpropagation helps the model weights adapt to this loss. This allows the model to "pre-enact" the quantization environment at deployment during training.
[0067] like Figure 4 The figure shown is a loss curve during the distillation training process in this embodiment of the invention. The curve shows the trend of the total loss and the loss of each component (feature distillation loss, defect classification distillation loss, defect region regression distillation loss, and hybrid expert load balancing loss) with epoch when performing end-to-end distillation training on a self-built textile defect dataset: the loss decreases rapidly in the first 30 epochs and then converges steadily (the final total loss is lower than the baseline method), which verifies the effectiveness and training stability of the cross-architecture knowledge distillation framework and multi-objective joint optimization.
[0068] Model Conversion and Export: After fine-tuning, switch the model to evaluation mode and call `quant.convert(model, inplace=False)` to convert all modules configured with quantization parameters to true INT8 quantized versions. At this point, floating-point weights are converted to INT8, and quantization parameters are preserved.
[0069] In this embodiment, to verify the effectiveness of the proposed distillation model and method, experiments were conducted on a self-built textile defect dataset. The dataset contains 5000 high-resolution images, covering various complex texture backgrounds, and annotates seven types of defects, including broken yarn, holes, oil stains, and dirt. The dataset was randomly divided into training, validation, and test sets in an 8:1:1 ratio.
[0070] The experimental setup included training the teacher defect detection model (YOLOv11x) until convergence. Based on the teacher defect detection model, comparative experiments were conducted on the method of this invention and two baseline methods (A: a student defect detection model using only knowledge distillation; B: a student defect detection model trained using only quantized perception). The method of this invention adopts the complete process (distillation + QAT).
[0071] After the experiment, the detection accuracy was compared, and the average accuracy of each model was evaluated on the test set. The results are shown in Table 1: Table 1. Comparison of average accuracy of each model
[0072] Results Analysis: The overall mAP of the method presented in this invention is comparable to that of the teacher defect detection model, and superior to baselines A and B. More importantly, the method presented in this invention achieves the highest recall (92.5%) on the most challenging small defect detection, even slightly exceeding that of the teacher defect detection model, demonstrating the superiority of combining cross-architecture distillation with the MoE mechanism.
[0073] Deployment performance comparison: In a simulated edge environment, the inference speed, model size, and memory usage of each model (FP32 and INT8) were measured. The results are shown in Table 2 below: Table 2. Comparison of test results for each model
[0074] Results Analysis: The INT8 quantization student defect detection model proposed in this invention performs excellently across all deployment metrics. Compared to the teacher defect detection model, the model size is compressed by more than 25 times, peak memory usage is only 1% of that of the teacher defect detection model, and inference speed is improved by 8.2 times, meeting the stringent requirements of industrial real-time detection. Figure 5 This is an example image showing the results of textile defect detection, clearly indicating the defects in the textile.
[0075] In summary, this invention innovatively integrates a hybrid expert mechanism, cross-architecture knowledge distillation, and quantized perception training techniques to successfully construct a textile defect detection model that combines high accuracy, ultra-lightweight design, and strong real-time performance. While maintaining excellent detection performance, this model achieves breakthrough optimizations in model size, inference speed, and memory usage, providing a practical solution for deploying high-performance visual inspection technology to resource-constrained industrial edge devices, and possesses significant industrial application value.
[0076] like Figure 6 As shown, based on the same inventive concept as the defect detection method for lightweight textiles in Embodiment 1 above, the present invention also provides a defect detection system for lightweight textiles, the defect detection system for lightweight textiles comprising: The model building module is used to build the heterogeneous model system, including initializing the teacher defect detection model and introducing a student defect detection model with a hybrid expert mechanism. The cross-architecture distillation training module is used to acquire textile images and input them into the teacher and student defect detection models respectively, perform cross-architecture alignment and matching relationship establishment, and perform end-to-end knowledge distillation training on the student defect detection model based on alignment supervision information; The quantization optimization module is used to perform quantization perception training on the distilled student defect detection model to derive a fixed-point quantization model, and deploy the fixed-point quantization model on an edge computing device to output defect category information, confidence information, and image location information to the input textile image.
[0077] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The defect detection method and specific examples for lightweight textiles in the aforementioned embodiment one are also applicable to the defect detection system for lightweight textiles in this embodiment. Through the foregoing detailed description of the defect detection method for lightweight textiles, those skilled in the art can clearly understand the defect detection system for lightweight textiles in this embodiment. Therefore, for the sake of brevity, it will not be described in detail here.
[0078] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0079] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A system that specifies functions in one or more boxes.
[0080] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including an instruction set implemented in a process. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0081] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0082] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.
[0083] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.
Claims
1. A defect detection method for lightweight textiles, characterized in that, include: A heterogeneous model system is constructed, which includes a teacher defect detection model for providing supervised information and a lightweight student defect detection model for edge inference. The student defect detection model introduces a hybrid expert mechanism. The textile images are acquired and input into the teacher defect detection model and the student defect detection model respectively, to obtain teacher features and teacher detection output, as well as student features and student detection output; Cross-architecture alignment of teacher and student features is performed, and a matching relationship is established between teacher detection output and student detection output to obtain alignment supervision information for distillation. Based on the alignment supervision information, the student defect detection model is trained by end-to-end knowledge distillation. The distillation training includes at least feature distillation, classification distillation, regression distillation and hybrid expert load balancing constraints. A fixed-point quantization model is derived by performing quantization perception training on the distilled student defect detection model, and the fixed-point quantization model is deployed on an edge computing device to output defect category information, confidence information, and image location information to the input textile image.
2. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The feature extraction stage of the student defect detection model employs a computationally efficient lightweight backbone network. The backbone network uses depthwise separable convolution, group convolution, or inverse residual structures to quickly extract basic texture features from the surface of textiles and reduce the overall model parameter size.
3. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The hybrid expert Transformer decoding module of the student defect detection model includes multiple parallel expert sub-networks and at least one gated network. The gated network dynamically calculates the activation weights of each expert sub-network based on the input feature vector and adopts a Top-K routing strategy to select only the K experts with the highest weights to participate in the calculation, where K is less than the total number of expert sub-networks, so as to achieve a balance between high parameter capacity and low computational overhead.
4. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The feature adaptation module for aligning teacher and student features in the cross-architecture alignment adopts a 1×1 convolutional structure, which maps the low-dimensional textile texture features output by the backbone network of the student defect detection model to the channel dimension space consistent with the intermediate layer features of the teacher defect detection model, and achieves feature distillation by minimizing the mean square error between the two.
5. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The process of establishing a matching relationship between teacher detection output and student detection output includes: constructing a cost matrix between student detection output and teacher detection output target, wherein the cost matrix is calculated based on the difference in probability distribution of defect categories and the distance of the spatial location of defect regions.
6. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The multi-objective joint loss function for end-to-end knowledge distillation training includes: Feature distillation loss is used to constrain the ability of the student defect detection model to learn the teacher defect detection model's ability to express the texture structure and defect morphology of textiles. Defect classification distillation loss is used to constrain the ability of the student defect detection model to distinguish defect categories; Defect region regression distillation loss is used to constrain the prediction accuracy of the student defect detection model for defect location and scale; Hybrid expert load balancing loss is used to suppress the phenomenon of concentrated computational load in expert sub-networks, ensuring that each expert network gets a uniform learning opportunity during training. The aforementioned loss terms are summed using preset weight coefficients to form the overall optimization objective for end-to-end training.
7. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The quantization perception training adopts a hierarchical quantization strategy: fixed-point quantization is applied to convolutional layers and fully connected layers; while floating-point precision is retained for the Softmax operation in the self-attention mechanism, layer normalization, and routing calculations involving normalization in the gated network, in order to balance inference speed and detection accuracy.
8. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The feature extraction stage of the student defect detection model employs a lightweight backbone network with high computational efficiency, such as MobileNet, EfficientNet-lite, or variants thereof; the hybrid expert Transformer decoding module includes multiple parallel expert sub-networks and at least one gating network; the quantization-aware training adopts a hierarchical quantization strategy.
9. The defect detection method for lightweight textiles as described in claim 1, characterized in that, The core hyperparameters for constructing the student defect detection model include the Transformer model dimension d_model=128, the number of attention heads n_head=4, the number of expert networks n_experts=4, and the K value in the Top-K routing is set to 2; the end-to-end knowledge distillation training strategy adopts gradient pruning, learning rate preheating, and cosine annealing.
10. A defect detection system for lightweight textiles, characterized in that, The step of implementing the defect detection method for lightweight textiles according to any one of claims 1 to 9, wherein the defect detection system for lightweight textiles comprises: The model building module is used to build a heterogeneous model system, which includes a teacher defect detection model for providing supervised information and a lightweight student defect detection model for edge inference. The student defect detection model introduces a hybrid expert mechanism. The image acquisition module is used to acquire textile images and input them into the teacher defect detection model and the student defect detection model respectively, so as to obtain teacher features and teacher detection output, as well as student features and student detection output; The information matching module is used to perform cross-architecture alignment of teacher features and student features, and to establish a matching relationship between teacher detection output and student detection output to obtain alignment supervision information for distillation. The distillation training module is used to perform end-to-end knowledge distillation training on the student defect detection model based on the alignment supervision information. The distillation training includes at least feature distillation, classification distillation, regression distillation, and hybrid expert load balancing constraints. The quantization optimization module performs quantization perception training on the distilled student defect detection model to derive a fixed-point quantization model, and deploys the fixed-point quantization model on an edge computing device to output defect category information, confidence information, and image location information to the input textile image.