Colored spun yarn sample data generation method, model training method, and blending category prediction method

CN122929321APending Publication Date: 2026-10-16XINJIANG UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611222226.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-12
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0004]然而,在实际应用中,受限于色纺纱品类繁多、人工采集与标注成本较高等因素,可获取的训练图像样本数量往往较为有限,导致基于上述训练样本所训练得到的配比类别预测模型在预测准确率上不足

Benefits of technology

[0016] (1) By dividing the training image samples of colored yarn into blocks and constructing image quality indicators based on the uniformity of color distribution and texture distribution, multiple candidate image blocks can be expanded from a single training image when the number of sample sources is limited, which can effectively alleviate the problem of insufficient training samples of colored yarn. At the same time, the candidate image blocks can be objectively evaluated through quantitative quality indicators to avoid subjective bias caused by manual experience screening.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122929321A_ABST
    Figure CN122929321A_ABST
Patent Text Reader

Abstract

The application provides a color spun yarn sample data generation method, a model training method and a matching category prediction method, and relates to the technical field of image processing. The method comprises: performing block processing on color spun yarn training image samples of multiple categories to obtain multiple candidate image blocks corresponding to each training image sample; calculating image quality indexes of the multiple candidate image blocks, wherein the image quality indexes comprise color uniformity indexes and texture consistency indexes; assigning quality weights to the multiple candidate image blocks according to the image quality indexes to obtain a candidate image block set with quality weights; training a deep learning model based on the candidate image block set with quality weights to obtain an image generation model; for each category, inputting a corresponding category label and a hidden space noise vector into the image generation model to generate a synthetic image sample of the corresponding category, and merging the synthetic image sample with a training image sample of the corresponding category to obtain a sample data set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to a sample data generation method, a model training method, and a matching category prediction method. Background Technology

[0002] Colored yarn is a type of yarn made by blending two or more fibers of different colors, resulting in a unique mixed-color effect on its surface. It is widely used in knitting, weaving, and other textile industries. In the production and quality control of colored yarn, accurate identification and prediction of its color categories are necessary to facilitate product sorting, inventory management, and order matching.

[0003] With the development of deep learning technology, the color prediction model based on convolutional neural networks has been introduced into the color prediction task of colored yarn. By collecting a large number of colored yarn images with labeled categories as training samples, the color prediction model can be trained in a supervised manner, enabling the trained model to output the corresponding color category for the colored yarn image to be identified.

[0004] However, in practical applications, due to the wide variety of colored yarns and the high cost of manual collection and labeling, the number of training image samples that can be obtained is often limited, resulting in insufficient prediction accuracy of the matching category prediction model trained based on the above training samples. Summary of the Invention

[0005] In view of the above problems, this application provides a method for generating sample data of colored spun yarn, a model training method, and a method for predicting the proportion category.

[0006] The first aspect of this application provides a method for generating sample data of colored yarn, comprising: dividing training image samples of multiple categories into blocks to obtain multiple candidate image blocks corresponding to each training image sample; calculating image quality indices for the multiple candidate image blocks, the image quality indices including color uniformity indices and texture consistency indices; assigning quality weights to the multiple candidate image blocks according to the image quality indices to obtain a set of candidate image blocks with quality weights; training a deep learning model based on the category labels and latent space noise vectors of the set of candidate image blocks with quality weights to obtain an image generation model; for each category, inputting the corresponding category labels and latent space noise vectors into the image generation model to generate synthetic image samples of the corresponding category, and merging the synthetic image samples with the training image samples of the corresponding category to obtain a sample dataset.

[0007] Furthermore, the image quality index of multiple candidate image patches is calculated, including: calculating the color difference between any two local regions in multiple local regions within a candidate image patch to obtain the color uniformity index of the candidate image patch; and calculating the difference between the texture features of the candidate image patch and the texture features of the original image corresponding to the training image sample to obtain the texture consistency index of the candidate image patch.

[0008] Furthermore, quality weights are assigned to multiple candidate image patches based on image quality indicators to obtain a set of candidate image patches with quality weights. This includes: normalizing the color uniformity index and texture consistency index respectively, and calculating the joint quality score of the candidate image patches; dividing the multiple candidate image patches into multiple quality levels based on the joint quality score; and assigning initial quality weights to the multiple candidate image patches according to the quality level to obtain a set of candidate image patches with quality weights. Among these, the candidate image patch with the smaller joint quality score belongs to the higher quality level and has a larger initial quality weight.

[0009] Furthermore, the deep learning model is trained based on the class labels of the candidate image patch set with quality weights and the latent space noise vector to obtain an image generation model. This includes: obtaining the class labels corresponding to each candidate image patch in the candidate image patch set with quality weights; concatenating the class labels with the latent space noise vector to obtain a conditional input vector; inputting the conditional input vector into the generator to obtain multiple generated images at different resolutions; calculating the discriminator loss and updating the discriminator parameters based on the candidate image patch set with quality weights and the generated images; calculating the generator loss and updating the generator parameters based on the output of the discriminator to the generated images after parameter updates; iteratively executing the above steps of updating the discriminator parameters and generator parameters until a preset training stopping condition is met to obtain the image generation model.

[0010] Further, based on the set of candidate image patches with quality weights and the generated image, the discriminator loss is calculated and the discriminator parameters are updated, including: inputting candidate image patches from the set of candidate image patches with quality weights as real samples into the discriminator to obtain the real discrimination score output by the discriminator for the real samples and the multi-scale reconstructed image corresponding to the real samples; calculating a first adversarial loss based on the real discrimination score, and weighting the first adversarial loss sample by sample according to the quality weight corresponding to the real samples to obtain the weighted real sample adversarial loss; calculating a multi-scale perceptual reconstruction loss based on the multi-scale reconstructed image and the image region in the real samples corresponding to the multi-scale reconstructed image; inputting the generated image into the discriminator to obtain the false discrimination score output by the discriminator for the generated image, and calculating a second adversarial loss based on the false discrimination score; adding the weighted real sample adversarial loss, the multi-scale perceptual reconstruction loss, and the second adversarial loss to obtain the discriminator loss, and updating the discriminator parameters based on the discriminator loss.

[0011] Further, the first adversarial loss is weighted sample-by-sample based on the quality weights corresponding to the real samples to obtain the weighted real sample adversarial loss. This includes: obtaining the initial quality weights corresponding to the real samples; determining the training process ratio based on the ratio of the current iteration number to the maximum iteration number, and determining a smoothing stage function that changes with the training process ratio based on the training process ratio; determining the stage adjustment factor of the real samples according to the quality level to which the real samples belong and the smoothing stage function; using the product of the initial quality weights and the stage adjustment factor as the dynamic sample weights of the real samples, and normalizing the dynamic sample weights of each real sample in the current batch; and using the normalized dynamic sample weights to weight the first adversarial loss sample-by-sample to obtain the weighted real sample adversarial loss.

[0012] Furthermore, candidate image patches from the set of candidate image patches with quality weights are used as real samples input to the discriminator to obtain the true discrimination score output by the discriminator for the real samples and the multi-scale reconstructed image corresponding to the real samples. This includes: inputting the real samples and target quadrant indices randomly selected from a preset quadrant index set into the discriminator, which includes a discrimination branch, a full-image reconstruction branch, a small-scale reconstruction branch, and a local reconstruction branch; processing the real samples through the discrimination branch to obtain the true discrimination score; processing the real samples through the full-image reconstruction branch to obtain a full-image reconstructed image of the first resolution; processing the real samples through the small-scale reconstruction branch to obtain a small-scale full-image reconstructed image of the second resolution, which is smaller than the first resolution; processing the quadrant region corresponding to the target quadrant index in the real samples through the local reconstruction branch to obtain a local block reconstructed image of the second resolution; and combining the full-image reconstructed image, the small-scale full-image reconstructed image, and the local block reconstructed image into a multi-scale reconstructed image.

[0013] The second aspect of this application provides a method for training a colored yarn model, comprising: acquiring a sample dataset, wherein the sample dataset is generated according to the above-mentioned method for generating colored yarn sample data; and training a ratio category prediction model based on the colored yarn sample dataset to obtain a trained ratio category prediction model.

[0014] A third aspect of this application provides a method for predicting the color spun yarn proportion category, comprising: acquiring a target color spun yarn image to be predicted; inputting the target color spun yarn image into a trained proportion category prediction model to obtain the color prediction result output by the proportion category prediction model, wherein the trained proportion category prediction model is trained according to the above-mentioned color spun yarn model training method.

[0015] Compared with existing technologies, the method for generating sample data of colored yarn, the model training method, and the method for predicting the proportion category provided in this application have at least the following beneficial effects:

[0016] (1) By dividing the training image samples of colored yarn into blocks and constructing image quality indicators based on the uniformity of color distribution and texture distribution, multiple candidate image blocks can be expanded from a single training image when the number of sample sources is limited, which can effectively alleviate the problem of insufficient training samples of colored yarn. At the same time, the candidate image blocks can be objectively evaluated through quantitative quality indicators to avoid subjective bias caused by manual experience screening.

[0017] (2) By using the color difference between multiple local regions within the candidate image block as the color uniformity index and the difference in texture features between the candidate image block and the original image as the texture consistency index, the representativeness of the candidate image block can be characterized from both color and texture dimensions, making the sample quality evaluation of the typical mixed-color fabric, the yarn, more in line with its mixed-color and weaving characteristics.

[0018] (3) By classifying candidate image patches according to image quality indicators and assigning differentiated quality weights, and then introducing the quality weights into the sample-by-sample weighting of the adversarial loss of real samples during generative adversarial training, high-quality candidate image patches play a more dominant role in model training, while the influence of low-quality samples on the model is effectively suppressed, thereby improving the image generation model's ability to learn representative features within a class from a semantic perspective.

[0019] (4) By introducing a discriminant branch, a full-image reconstruction branch, a small-scale reconstruction branch, and a local reconstruction branch driven by a random quadrant index into the discriminator, and constructing a training paradigm that optimizes the multi-scale perceptual reconstruction loss and adversarial loss together, the discriminator is forced to learn the internal structure of real samples at different scales and different spatial locations while distinguishing between real and fake samples, thereby improving the realism and consistency of the generated colored yarn composite image in terms of overall appearance and local texture.

[0020] (5) By merging the synthetic image samples with the original training image samples to construct a sample dataset, and preprocessing the training subset with enhancement methods such as hierarchical sampling, geometric transformation, size normalization and channel expansion, and then combining the segmented learning rate decay strategy and the periodic test subset verification mechanism to iteratively train the ratio category prediction model, the accuracy of the ratio category prediction model in identifying the color category of colored yarn can be improved without significantly increasing the cost of manual collection and labeling, and the generalization ability of the model to unseen samples can be enhanced, so that the trained ratio category prediction model can be directly applied to the color prediction task of the target colored yarn image to be predicted.

[0021] (6) By normalizing the color uniformity index and texture consistency index and constructing a joint quality discrimination function, the candidate image blocks are classified in a coupled weighted manner rather than a simple parallel manner. This not only eliminates the cross-class discrimination ambiguity when the two indices belong to different levels, but also adapts the quality evaluation needs of dark yarn, light yarn and yarn with different color mixing ratios by adjusting the reference threshold and weight coefficient, making the sample classification more objective and reasonable.

[0022] (7) By using dynamic sample weights that change smoothly with the training process, and combining smoothing stage functions and intra-batch normalization, the training focuses on sample diversity in the early stage and color fidelity and texture consistency in the later stage. This overcomes the problem that fixed weights cannot take into account both diversity and fidelity, and further improves the stability and convergence smoothness of generative adversarial training under small sample conditions. Attached Figure Description

[0023] The above and other objects, features and advantages of this application will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:

[0024] Figure 1 A flowchart illustrating a method for generating sample data of colored spun yarn according to an embodiment of this application is shown schematically.

[0025] Figure 2 A flowchart illustrating a model training method according to an embodiment of this application is shown schematically.

[0026] Figure 3 A flowchart illustrating a proportioning category prediction method according to an embodiment of this application is shown schematically. Detailed Implementation

[0027] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.

[0028] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.

[0029] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.

[0030] To address the problems in the field of yarn color prediction, such as high cost of real sample collection, scarcity of labeled samples, instability of traditional generative adversarial networks under small sample conditions, inconsistent quality of generated samples, and insufficient generalization ability of downstream prediction models, this application provides a sample data generation method, a model training method, and a ratio category prediction method. The system is designed from image segmentation, quality evaluation, weighted generation training to sample expansion and prediction model training to obtain synthetic samples with high fidelity and high representativeness, as well as a ratio category prediction model with strong generalization ability.

[0031] Figure 1 A flowchart illustrating a method for generating sample data of colored spun yarn according to an embodiment of this application is shown schematically.

[0032] In operation S101, the training image samples of multiple categories are divided into blocks to obtain multiple candidate image blocks corresponding to each training image sample.

[0033] In operation S102, image quality metrics for multiple candidate image patches are calculated. These metrics include color uniformity and texture consistency.

[0034] In operation S103, quality weights are assigned to multiple candidate image blocks according to the image quality index, resulting in a set of candidate image blocks with quality weights.

[0035] In operation S104, the deep learning model is trained based on the class labels of the candidate image patch set with quality weights and the latent space noise vector to obtain the image generation model.

[0036] In operation S105, for each category, the corresponding category label and latent space noise vector are input into the image generation model to generate synthetic image samples for the corresponding category. The synthetic image samples are then merged with the training image samples for the corresponding category to obtain the sample dataset.

[0037] Through the above operations S101 to S105, starting from a limited number of real-world colored yarn training image samples, the samples are first divided into blocks to expand the sample source. Then, the quality of each candidate image block is objectively evaluated based on the uniformity of color and texture distribution. The evaluation results are then introduced into the training process of the deep learning model in the form of quality weights, enabling the image generation model to learn more representative intra-class feature distributions under small sample conditions. This allows the model to generate synthetic samples of the same category and distribution as the real samples. Finally, the synthetic samples are merged with the original training samples to form an expanded sample dataset, fundamentally alleviating the problem of insufficient colored yarn samples.

[0038] The following detailed description of operations S101 to S105 is provided in conjunction with specific embodiments.

[0039] In operation S101, the training image samples of multiple categories are divided into blocks to obtain multiple candidate image blocks corresponding to each training image sample.

[0040] Specifically, the training image samples can be original images of spun yarn. Preferably, the resolution of the training image samples is 1024×1024 pixels, and the total number of categories is preferably 39, with each category corresponding to a specific color ratio of spun yarn. Block processing can be implemented using a sliding window method: multiple candidate windows of fixed size are constructed on the original training image samples. The size of the candidate windows is preferably 256×256 pixels. Multiple candidate windows are obtained by sliding along the width direction with a preset step size, and multiple candidate windows are obtained by sliding along the height direction with a preset step size. In one embodiment, 7 candidate windows are set in the width direction with a step size of 128 pixels; 4 candidate windows are set in the height direction with a step size of 256 pixels, ultimately resulting in 28 candidate image blocks on each training image sample. In other embodiments, the candidate image block size, sliding step size, and number of windows can be adjusted according to the resolution of the training image samples and the target resolution of the image to be generated. Overlapping or non-overlapping of candidate windows is allowed.

[0041] In operation S102, image quality metrics for multiple candidate image patches are calculated. These metrics include color uniformity and texture consistency.

[0042] In some embodiments, the above operation S102 may further include: calculating the color difference between any two local regions in multiple local regions within a candidate image block to obtain a color uniformity index of the candidate image block; and calculating the difference between the texture features of the candidate image block and the texture features of the original image corresponding to the training image sample to obtain a texture consistency index of the candidate image block.

[0043] For calculating the color uniformity index, several non-overlapping local regions are randomly selected within each candidate image block. Preferably, the number of local regions is 6, and the size of each local region is 16×16 pixels. Then, the color difference between any two local regions is calculated, and the arithmetic mean of the color differences is used as the color uniformity index of the candidate image block. The preferred color difference is the CMC (2:1) color difference, and its calculation formula is as follows:

[0044]

[0045]

[0046]

[0047]

[0048]

[0049] in, This indicates the total color difference of CMC (2:1); and These are the lightness components of the sample and the standard in the CIELAB color space, respectively. This refers to the red and green hue components in the CIELAB color space. The yellow-blue hue component; The hue angle in the CIELAB color space; The brightness weighting factor. The chroma weighting factor. The three factors are hue weighting factors, and are all calculated from the lightness and chroma of the standard color according to the CMC color difference formula. The weight ratio of 2:1 represents the proportional relationship between lightness tolerance and chroma tolerance.

[0050] To calculate the texture consistency index, the relative percentage deviations in angular second moment (ASM) and entropy (ENT) between the candidate image patch and the original image corresponding to the training image sample are calculated respectively, and the arithmetic mean of the two is taken as the texture consistency index T. The calculation formula is as follows:

[0051]

[0052]

[0053]

[0054] Where ASM is the second moment of the angle and ENT is the entropy, both of which are texture statistics calculated based on the gray-level co-occurrence matrix; The elements of the normalized gray-level co-occurrence matrix represent the joint probability of gray values ​​i and j of two pixels in the image with a distance d and an angle θ, respectively. It is obtained by dividing the original counting matrix by the total number of pixel pairs. i and j are the row index and column index of the gray-level co-occurrence matrix, respectively, corresponding to the gray levels of the two pixels. Preferably, the distance d is taken as the adjacent pixel value 1, and the angle θ is taken as the average of four directions: 0°, 45°, 90°, and 135°, so as to eliminate the dependence on texture direction. and These are the second angular moment and entropy of the candidate image patch, respectively. and These are the second angular moments and entropy of the original images corresponding to the training image samples, respectively. This is a texture consistency index, expressed as a percentage. The smaller the value, the higher the texture consistency between the candidate image patch and the original image.

[0055] In operation S103, quality weights are assigned to multiple candidate image blocks according to the image quality index, resulting in a set of candidate image blocks with quality weights.

[0056] In some embodiments, the above operation S103 may further include: normalizing the color uniformity index and the texture consistency index respectively, and calculating the joint quality score of the candidate image blocks; dividing the multiple candidate image blocks into multiple quality levels according to the joint quality score; assigning initial quality weights to the multiple candidate image blocks according to the quality level to obtain a set of candidate image blocks with quality weights, wherein the candidate image block with a smaller joint quality score belongs to a higher quality level and has a larger initial quality weight.

[0057] Specifically, to comprehensively characterize the representativeness of candidate image patches in both color and texture dimensions, and to avoid the ambiguity caused by simply judging color uniformity and texture consistency indices side-by-side, the color uniformity and texture consistency indices can be normalized separately, and a joint quality discrimination function can be constructed:

[0058]

[0059] In the formula, The joint quality score for candidate image patches; This is a color uniformity index for candidate image patches; This is a texture consistency index for candidate image patches; The preferred value for the color uniformity reference threshold is 1. The preferred value for the texture consistency reference threshold is 0.2. and These are the weighting coefficients for the color uniformity index and the texture consistency index, respectively, and they satisfy... + =1, preferably =0.6、 =0.4, so that color uniformity has a higher weight in the quality evaluation of colored yarn samples, while also taking into account texture consistency.

[0060] Then, the quality level is determined based on the combined quality score: when Samples with a quality weight <0.8 are considered excellent and assigned an initial quality weight of 1.2; samples with a quality weight ≤0.8 are considered excellent. Samples with a quality weight <1.5 are classified as medium-quality samples and assigned an initial quality weight of 1.0; when... Samples with a quality score ≥1.5 are considered poor and assigned an initial quality weight of 0.9; when... When the value is exactly equal to the interval boundary value, it is classified as the inferior category. Because this joint discriminant function couples the color and texture indicators in the form of a normalized weighted sum, it can be adjusted for dark yarn, light yarn, and yarns with different color mixing ratios. , , , This ensures that the quality discrimination threshold matches the actual color mixing and texture characteristics of this type of colored yarn.

[0061] In operation S104, the deep learning model is trained based on the class labels of the candidate image patch set with quality weights and the latent space noise vector to obtain the image generation model.

[0062] In some embodiments, the deep learning model employs a class conditional generative adversarial network architecture, which includes a generator and a discriminator. Only a single general generator needs to be trained to achieve directional generation of images for multiple yarn color categories. Specifically, the above operation S104 may further include: obtaining the class labels corresponding to each candidate image patch in a set of candidate image patches with quality weights; concatenating the class labels with a latent space noise vector to obtain a conditional input vector; inputting the conditional input vector into the generator to obtain multiple generated images at different resolutions; calculating the discriminator loss and updating the discriminator parameters based on the set of candidate image patches with quality weights and the generated images; calculating the generator loss and updating the generator parameters based on the output of the discriminator to the generated images after parameter updates; iteratively executing the above parameter update steps for the discriminator and generator until a preset training stopping condition is met to obtain the image generation model.

[0063] Specifically, for the latent space noise vector z, the sampling follows a standard normal distribution z ~ N(0,1), with dimensions [B, ], where B is the batch size, For the hidden space dimension, preferably B=8. =256. The category labels corresponding to the candidate image patches are encoded and concatenated with the latent space noise vector z to form a conditional input vector, which is then input into the generator.

[0064] The generator's internal operation flow is as follows: First, the one-dimensional conditional input vector is projected into an initial high-dimensional feature map with a resolution of 4×4 by transposing the convolution and adding Leaky ReLU activation (α=0.2). The dimensions are [B, 1024, 4, 4]. Then, the resolution is gradually increased through 8 upsampling blocks. Each upsampling block first doubles the resolution through nearest-neighbor upsampling, then uses a 3×3 convolution with LeakyReLU to maintain the size. The number of channels is halved in the first 4 upsampling blocks, while the number of channels remains unchanged at 64 in the last 4 upsampling blocks to preserve texture details. After the 6th, 7th, and 8th upsampling blocks, independent 1×1 convolutions are used to convert the 64-channel feature map into a 3-channel RGB image. Finally, Tanh activation is used to normalize the pixel values ​​to [-1, 1], resulting in three generated images at different resolutions. These are combined in descending order to form a multi-scale generated image list. , , The dimensions are [B,3,1024,1024], [B,3,512,512], and [B,3,256,256], respectively.

[0065] In some embodiments, calculating the discriminator loss and updating the discriminator parameters based on a set of candidate image patches with quality weights and a generated image may further include: inputting candidate image patches from the set of candidate image patches with quality weights as real samples into the discriminator to obtain a real discrimination score output by the discriminator for the real samples and a multi-scale reconstructed image corresponding to the real samples; calculating a first adversarial loss based on the real discrimination score, and weighting the first adversarial loss sample-by-sample according to the quality weights corresponding to the real samples to obtain a weighted real sample adversarial loss; calculating a multi-scale perceptual reconstruction loss based on the multi-scale reconstructed image and the image regions in the real samples that correspond to the multi-scale reconstructed image; inputting the generated image into the discriminator to obtain a false discrimination score output by the discriminator for the generated image, and calculating a second adversarial loss based on the false discrimination score; adding the weighted real sample adversarial loss, the multi-scale perceptual reconstruction loss, and the second adversarial loss to obtain the discriminator loss, and updating the discriminator parameters based on the discriminator loss.

[0066] In some embodiments, candidate image patches from a set of candidate image patches with quality weights are used as real samples input to the discriminator to obtain the true discrimination score output by the discriminator for the real samples and the multi-scale reconstructed image corresponding to the real samples. This may further include: inputting the real samples and target quadrant indices randomly selected from a preset quadrant index set into the discriminator, where the discriminator includes a discrimination branch, a full-image reconstruction branch, a small-scale reconstruction branch, and a local reconstruction branch; processing the real samples through the discrimination branch to obtain the true discrimination score; processing the real samples through the full-image reconstruction branch to obtain a full-image reconstructed image of a first resolution; processing the real samples through the small-scale reconstruction branch to obtain a small-scale full-image reconstructed image of a second resolution, where the second resolution is smaller than the first resolution; processing the quadrant region corresponding to the target quadrant index in the real samples through the local reconstruction branch to obtain a local patch reconstructed image of a second resolution; and combining the full-image reconstructed image, the small-scale full-image reconstructed image, and the local patch reconstructed image into a multi-scale reconstructed image.

[0067] Specifically, the preset quadrant index set is preferably {0,1,2,3}, where 0 represents the upper left quadrant, 1 represents the upper right quadrant, 2 represents the lower left quadrant, and 3 represents the lower right quadrant. In each iteration, a target quadrant index `part` is randomly selected from the preset quadrant index set. The discriminator's discrimination branch processes the real samples and outputs the true discrimination score. The dimension is [B], and a larger value indicates that the discriminator considers it a real sample. The full-image reconstruction branch of the discriminator processes the real sample to obtain a full-image reconstruction image rec at the first resolution (preferably H / 2, where H is the resolution of the real sample). all The dimensions are [B, 3, H / 2, W / 2]. The small-scale reconstruction branch of the discriminator processes the real samples to obtain a small-scale full-image reconstruction image rec at a second resolution (preferably H / 4). small The dimensions are [B, 3, H / 4, W / 4]. The local reconstruction branch of the discriminator only processes the quadrant region corresponding to the target quadrant index `part` in the real sample, obtaining a local block reconstruction image `rec` with a second resolution. part The dimensions are [B, 3, H / 4, W / 4]. Finally, rec... all rec small rec part Combined into a multi-scale reconstructed image.

[0068] Furthermore, to improve the stability of generative adversarial training under small sample conditions, DiffAugment color enhancement with translation can be applied to both real samples and generated images to obtain enhanced real samples. and the enhanced list of generated images (fake) images_augThe enhanced sample is then input into the discriminator for subsequent loss calculation.

[0069] In some embodiments, to enable candidate image patches of different quality levels to play a differentiated role at different stages of training, the first adversarial loss employs a sample-by-sample weighted method with dynamically adjusted sample weights as the training progresses. Let the i-th real sample... The initial quality weights corresponding to the k-th candidate window of the n-th image. The preprocessing module assigns quality values ​​of 1.2, 1.0, and 0.9 respectively. The training process ratio is defined. With smoothing phase function ( The stage adjustment factor is:

[0070]

[0071] in, , , The preset adjustment coefficient is preferably set to a value between 0.05 and 0.50. =0.30、 =0.10、 =0.20. The dynamic weights and intra-batch normalization at the t-th iteration are: , The weighted adversarial loss for real samples is then:

[0072]

[0073] in, B represents the adversarial loss of the discriminator on the real samples at the t-th iteration; B is the batch size. The i-th true sample input to the discriminator is a candidate image patch in the set of candidate image patches with quality weights; Let be the dynamic weight of the i-th real sample at the t-th iteration; To modify the activation function of the linear unit, the expression is: ; It is a uniform random variable in the range of [0,1], used to prevent the discriminator from being overconfident; For the discriminator's judgment of the real sample at the t-th iteration The output true discrimination score; the larger the value, the more the discriminator considers the input to be a true sample.

[0074] In this way, poor samples are given relatively high weights in the early stages of training to increase sample diversity and suppress overfitting, while excellent samples are given gradually higher weights in the later stages of training to improve the color fidelity and texture consistency of the generated images; intra-batch normalization ensures the stability of the batch loss scale.

[0075] In some embodiments, the multi-scale perceptual reconstruction loss is based on extracting multi-layer features from a pre-trained VGG network and calculating the LPIPS distance:

[0076]

[0077] in, For multi-scale sensing reconstruction loss; (a,b)= For perceptual similarity loss based on pre-trained VGG networks, For the layer index of the pre-trained VGG network, For pre-training the VGG network Feature maps extracted from layers, For the first Preset channel weights corresponding to layer features The full-image reconstruction image output by the full-image reconstruction branch of the discriminator. The small-scale full-image reconstruction output of the discriminator's small-scale reconstruction branch is the small-scale full-image reconstruction. The local block reconstruction image output by the local reconstruction branch of the discriminator; This indicates downsampling to s×s resolution; H is the scale of the true sample. This represents the part quadrant region from which the real sample x is extracted, where part is the target quadrant index randomly selected from the quadrant index set {0,1,2,3}.

[0078] The second adversarial loss is calculated based on spurious discrimination scores:

[0079]

[0080] in, denoted as , where z is the adversarial loss of the discriminator on the generated image; z is the latent space noise vector sampled from the standard normal distribution N(0,1). It follows the standard normal distribution; The synthesized image generated by the generator with z as input; For the discriminator to generate the image The output spurious discrimination score, the smaller the value, the more the discriminator considers the input to be a synthetic image; Let be a random label smoothing variable that follows a uniform distribution in [0,1].

[0081] In some embodiments, to make the image generation model more closely match the nonlinear spatial color mixing characteristics formed by multi-fiber blending of colored yarn, the discriminator further includes a color mixing consistency discrimination head. This discrimination head extracts the i-th real sample respectively. Corresponding generated image Color distribution characteristics in CIELAB color space , Color distribution characteristics may include , , The color histograms of the three channels, the proportion of the dominant color, or the distribution of color cluster centers are used to calculate the color mixing consistency loss according to the following formula:

[0082]

[0083] Where B is the batch size. denoted by the norm distance. It is used to constrain the generated image to maintain consistency with the real samples of the same class in terms of color proportions and spatial color mixing distribution formed by multi-fiber blends. Accordingly, the discriminator loss is updated as follows:

[0084]

[0085] in This represents the weighting coefficient for color mixing consistency loss. Therefore, without requiring additional annotation of fiber component proportions, the nonlinear spatial color mixing effect can be constrained using the image's own color distribution characteristics, improving the realism of the generated image in terms of color proportions, local color mixing distribution, and fiber interweaving color transitions.

[0086] After backpropagation, it is passed through the Adam optimizer (with a learning rate preferably of 0.0002 and a first-order moment decay coefficient). =0.5) Update discriminator parameters .

[0087] The generator is then trained: the generator gradient is reset to zero, and a list of enhanced fake images with unclipped gradients is input into the discriminator whose parameters have been updated to obtain the discrimination score. Calculate generator loss =- (The goal is to maximize the discriminator's score for fake images), and after backpropagation, the generator parameters are updated using the Adam optimizer. .

[0088] Furthermore, to smooth training fluctuations and improve the quality of generated images, an exponential moving average (EMA) update can be performed on the generator parameters:

[0089]

[0090] Where t is the training iteration step index; Let be the set of exponential moving averages of the generator parameters after the t-th iteration; The parameters are the current parameters obtained by updating the generator using the Adam optimizer after the t-th iteration; the smoothing coefficient of 0.999 indicates that 99.9% of the historical parameter information is retained.

[0091] The parameter update steps for the discriminator and generator are iteratively executed until a preset training stopping condition is met. This preset stopping condition can be reaching a preset maximum number of iterations (preferably 50,000), or the generator and discriminator losses stabilizing or reaching a preset threshold on the validation metric. After training, the EMA parameters are output as the final generator parameters, resulting in the image generation model.

[0092] The model training configuration can use a PyTorch 2.0.0, Python 3.8, CUDA 11.8 environment, and an RTX 4090D (24GB) single GPU for training, in batches. size The preferred value is 8.

[0093] In operation S105, for each category, the corresponding category label and latent space noise vector are input into the image generation model to generate synthetic image samples for the corresponding category. The synthetic image samples are then merged with the training image samples for the corresponding category to obtain the sample dataset.

[0094] Specifically, in the generation phase, for each target category, the category label of the specified category is input into the trained image generation model. This category label input vector is then fed into the generator, which can output synthetic image samples corresponding to the specified category label in a single forward inference. Since the generator has learned the correspondence between categories and image distributions through the category-conditional generation architecture during the training phase, it can generate synthetic image samples corresponding to any input category label in the generation phase, eliminating the need to train a separate generation model for each category of yarn coloring. The category label of the generated image is automatically assigned by the conditional generation process and corresponds one-to-one with the input category label. Preferably, the same color uniformity and texture consistency quality screening process as for real samples is applied to the generated synthetic image samples, retaining only qualified synthetic image samples, with 200 qualified synthetic image samples retained for each category. Then, the synthetic image samples for each category are merged with the corresponding high-quality real training image samples (e.g., each category is merged with 28 high-quality real samples, resulting in an expanded dataset of 228 images per category), and stored according to the category directory, ultimately forming a sample dataset containing both real and synthetic samples.

[0095] In other implementations, the number of synthetic samples generated for each type and the merging ratio of synthetic samples to real samples can be adjusted according to actual data requirements.

[0096] Based on the sample dataset generated by the above-described sample data generation method, this application embodiment also provides a model training method.

[0097] Figure 2 A flowchart illustrating a model training method according to an embodiment of this application is shown schematically.

[0098] like Figure 2 As shown, the model training method in this embodiment includes operations S201 to S202.

[0099] In operation S201, the colored yarn sample dataset is obtained. The colored yarn sample dataset is generated according to the above-mentioned colored yarn sample data generation method.

[0100] In operation S202, the ratio category prediction model is trained based on the colored yarn sample dataset to obtain the trained ratio category prediction model.

[0101] Through the above operations S201~S202, the color spun yarn sample dataset constructed by the aforementioned color spun yarn sample data generation method is first used to conduct supervised training on the ratio category prediction model. Since the color spun yarn sample dataset contains both real color spun yarn image samples and quality-screened synthetic image samples, it can effectively improve the generalization ability of the ratio category prediction model under small sample conditions, enabling the trained ratio category prediction model to cope with the color prediction task of color spun yarn in real-world scenarios.

[0102] In some embodiments, the above operation S202 may further include: dividing the sample dataset according to a preset ratio to obtain a training subset and a test subset, wherein the sample ratio of each category in the training subset and the test subset is consistent with the sample ratio of each category in the sample dataset; performing geometric transformation processing on the image samples in the training subset; scaling the image samples after geometric transformation processing to the input size of the matching category prediction model, and performing channel expansion processing on the single-channel image samples to obtain enhanced training samples with the number of channels matching the number of input channels of the matching category prediction model; inputting the enhanced training samples into the matching category prediction model, calculating the prediction loss based on the predicted category probability output by the matching category prediction model and the corresponding category label, and iteratively updating the parameters of the matching category prediction model based on the prediction loss to obtain the trained matching category prediction model.

[0103] Specifically, the matching category prediction model preferably uses a ResNet network. Images from all subfolders within the folder containing the sample dataset can be read via imageDatastore, and the subfolder names can be used as category labels to obtain N×1 image data storage imds, where N is the total number of samples. The splitEachLabel function is then used to randomly partition imds into the same category according to a preset ratio (preferably 8:2), ensuring that the proportion of each category in the training and test subsets remains consistent with that in the sample dataset, resulting in the training subset imdTrain. ×1, =0.8N) and test subset imdTest ( ×1, =0.2N).

[0104] The total number of categories can be obtained by setting `numClasses = numel(categories(imdTrain.Labels))`; load the ResNet network `lgraph` and extract its input size `img`. size =[224,224]; Replace the original fc1000 fully connected layer used for ImageNet 1000 class prediction with a custom fully connected layer with an output dimension of numClasses, and replace the original prediction layer with a custom prediction layer based on cross-entropy loss, where the cross-entropy loss is:

[0105]

[0106] Where L is the cross-entropy prediction loss; numClasses is the total number of predicted classes, which is equal to the number of subfolders in the sample dataset; i is the class index, with a value ranging from 1 to numClasses; For the i-th component in the one-hot encoding of the real label, This is the predicted probability of class i output by the matching category prediction model after Softmax activation.

[0107] Geometric transformation processing preferably includes at least one of the following: random rotation, random flipping, and random translation. Specifically, a random rotation of ±10° (affine transformation) can be performed on the image. ′= , ∈[−10°,10°], (for rotation matrix), random horizontal flip ( =flip(x,2)), random horizontal / vertical translation ±10 pixels (affine transformation) ′= +[ , ], , ∈[−10,10], unit: pixels).

[0108] Subsequently, an augmentedImageDatastore is created to uniformly scale the images from both the training and testing subsets to the size of an img file. size The single-channel grayscale image samples are subjected to channel expansion processing (automatically copied to 3-channel RGB) to match the number of channels of the ResNet input, and the output is an enhanced training sample with a batch dimension of B×224×224×3, where B is the number of training samples in a single batch, preferably 64.

[0109] The enhanced training samples are input into the matching category prediction model. The batch prediction loss L is calculated through forward propagation, and the parameter gradient is calculated through backpropagation. Then, the network parameters are iteratively optimized using Adam to update the rules:

[0110]

[0111] Where t is the training iteration step index; Let be the set of trainable parameters for the proportion category prediction model after the t-th iteration; This is the first moment estimate of the gradient at step t. For the second moment estimation of the gradient, = For numerically stable terms, The current learning rate is dynamically adjusted using a segmented decay strategy.

[0112] In some embodiments, the parameters include a learning rate. Iteratively updating the parameters of the matching category prediction model based on the prediction loss may further include: randomly shuffling the image samples in the training subset before each round of iterative update; adjusting the learning rate according to a preset segmented decay strategy, wherein the learning rate decays by a preset decay factor every preset number of training rounds; iteratively updating the parameters of the matching category prediction model based on the adjusted learning rate according to the prediction loss; and validating the matching category prediction model based on a test subset every preset number of iterations during the iterative update process until a preset training stopping condition is reached.

[0113] Specifically, the segmented decay strategy of the learning rate can be expressed as:

[0114]

[0115] in, The learning rate used in the current training round; The initial learning rate is preferably [value missing]. ; The learning rate decrease factor is preferably 0.1; T is the learning rate decrease period, preferably 20. Indicates rounding down;

[0116] epoch represents the current training epoch. Before each training epoch, the training subset is randomly shuffled, and the test subset is used as the validation set. Every preset number of iterations (preferably 20), the matching category prediction model is validated based on the test subset, and a training progress curve is plotted. The iteration continues until the preset maximum number of training epochs (preferably E=30 epochs) is reached or other preset training stopping conditions are met.

[0117] After training, the `classify` function can be called to make predictions on the training and test subsets respectively, according to the accuracy formula:

[0118]

[0119] The accuracy of the training subset and the accuracy of the test subset are calculated to evaluate the model performance, and the trained network model is saved as a model file for subsequent inference or deployment.

[0120] Based on the matching category prediction model trained by the above model training method, this application embodiment also provides a matching category prediction method.

[0121] Figure 3 A flowchart illustrating a proportioning category prediction method according to an embodiment of this application is shown schematically.

[0122] like Figure 3 As shown, the proportion category prediction method in this embodiment includes operations S301 to S302.

[0123] In operation S301, the target color yarn image to be predicted is obtained.

[0124] Specifically, the target color yarn image to be predicted can be acquired under uniform light source conditions using an industrial camera or image acquisition device. The target color yarn image can be in common image formats such as BMP, JPG, or PNG, with no strict limitations on image resolution and color space. If necessary, basic preprocessing such as size normalization, single-channel expansion, or radiometric correction can be performed on it.

[0125] In operation S302, the target color yarn image is input into the trained color ratio category prediction model to obtain the color prediction result output by the color ratio category prediction model. The trained color ratio category prediction model is trained according to the above-mentioned color yarn model training method.

[0126] Specifically, the preprocessed target color spinning image is input into the ratio category prediction model trained according to the above model training method. The ratio category prediction model performs forward inference on it and outputs the predicted color category probability distribution. The category corresponding to the maximum probability is used as the color prediction result of the target color spinning image.

[0127] The above-mentioned color prediction method can quickly, objectively and stably predict the color of colored yarn images without relying on manual visual comparison and physical sampling. This shortens the product development and quality inspection cycle of colored yarn, reduces material and labor costs, and enables virtual design and intelligent recognition of colored yarn.

[0128] Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application.

[0129] The embodiments of this application have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of this application. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Without departing from the scope of this application, those skilled in the art can make various substitutions and modifications, all of which should fall within the scope of this application.

Claims

1. A method for generating sample data of colored spun yarn, characterized in that, include: The training image samples of multiple categories are divided into blocks to obtain multiple candidate image blocks corresponding to each training image sample; Calculate the image quality index of the plurality of candidate image patches, wherein the image quality index includes a color uniformity index and a texture consistency index; Based on the image quality index, quality weights are assigned to the multiple candidate image blocks to obtain a set of candidate image blocks with quality weights; The deep learning model is trained based on the category labels and latent space noise vectors of the candidate image patch set with quality weights to obtain the image generation model. For each category, the corresponding category label and latent space noise vector are input into the image generation model to generate synthetic image samples for the corresponding category. The synthetic image samples are then merged with the training image samples for the corresponding category to obtain the sample dataset.

2. The method according to claim 1, characterized in that, The calculation of the image quality index of the plurality of candidate image patches includes: Calculate the color difference between any two local regions within multiple local regions of the candidate image block to obtain the color uniformity index of the candidate image block; The difference between the texture features of the candidate image patch and the texture features of the original image corresponding to the training image sample is calculated to obtain the texture consistency index of the candidate image patch.

3. The method according to claim 2, characterized in that, The step of assigning quality weights to the plurality of candidate image patches according to the image quality index to obtain a set of candidate image patches with quality weights includes: The color uniformity index and the texture consistency index are normalized respectively, and the joint quality score of the candidate image patch is calculated according to the following formula: In the formula, The joint quality score for candidate image patches; This is a color uniformity index for candidate image patches; This is a texture consistency index for candidate image patches; This serves as a reference threshold for color uniformity. This serves as a reference threshold for texture consistency. and These are the weighting coefficients for the color uniformity index and the texture consistency index, respectively, and they satisfy... + =1; The candidate image blocks are divided into multiple quality levels based on the joint quality score; The candidate image blocks are assigned initial quality weights according to the quality level to obtain a set of candidate image blocks with quality weights. The candidate image block with the smaller joint quality score belongs to the higher quality level and has a larger initial quality weight.

4. The method according to claim 1, characterized in that, The deep learning model is trained based on the category labels and latent space noise vectors of the candidate image patch set with quality weights to obtain an image generation model, including: Obtain the category label corresponding to each candidate image block in the candidate image block set with quality weights, and concatenate the category label with the latent space noise vector to obtain the conditional input vector; The conditional input vector is input into the generator to obtain multiple generated images with different resolutions; Based on the set of candidate image patches with quality weights and the generated image, the discriminator loss is calculated and the parameters of the discriminator are updated; Based on the output of the discriminator on the generated image after parameter update, the generator loss is calculated and the parameters of the generator are updated; The parameters of the discriminator and the generator are updated iteratively until the preset training stopping condition is met, thus obtaining the image generation model.

5. The method according to claim 4, characterized in that, The process of calculating the discriminator loss and updating the parameters of the discriminator based on the set of candidate image patches with quality weights and the generated image includes: The candidate image blocks in the set of candidate image blocks with quality weights are used as real samples and input into the discriminator to obtain the real discrimination score output by the discriminator for the real sample and the multi-scale reconstructed image corresponding to the real sample. The first adversarial loss is calculated based on the true discrimination score, and the first adversarial loss is weighted sample by sample according to the quality weight corresponding to the true sample to obtain the weighted true sample adversarial loss. Based on the multi-scale reconstructed image and the image region in the real sample corresponding to the multi-scale reconstructed image, calculate the multi-scale perceptual reconstruction loss. The generated image is input into the discriminator to obtain the false discrimination score output by the discriminator for the generated image, and the second adversarial loss is calculated based on the false discrimination score; The weighted real sample adversarial loss, the multi-scale perceptual reconstruction loss, and the second adversarial loss are added together to obtain the discriminator loss, and the parameters of the discriminator are updated based on the discriminator loss.

6. The method according to claim 5, characterized in that, The step of weighting the first adversarial loss sample by sample according to the quality weights corresponding to the real samples to obtain the weighted real sample adversarial loss includes: Obtain the initial quality weights corresponding to the real samples; The training process ratio is determined based on the ratio of the current iteration number to the maximum iteration number, and a smoothing phase function that changes with the training process ratio is determined based on the training process ratio. The stage adjustment factor of the real sample is determined according to the quality level to which the real sample belongs and the smoothing stage function; The product of the initial quality weight and the stage adjustment factor is used as the dynamic sample weight of the real sample, and the dynamic sample weight of each real sample in the current batch is normalized. The first adversarial loss is weighted sample by sample using the normalized dynamic sample weights to obtain the weighted real sample adversarial loss.

7. The method according to claim 5, characterized in that, The calculation of multi-scale perceptual reconstruction loss based on the multi-scale reconstructed image and the image region in the real sample corresponding to the multi-scale reconstructed image includes: The multi-scale sensing reconstruction loss is calculated using the following formula: In the formula, For multi-scale sensing reconstruction loss; (a,b)= For the perceptual similarity loss of the pre-trained network, For the layer index of the pre-trained network, For the pre-trained network Feature maps extracted from layers, For the first Preset channel weights corresponding to layer features The full-image reconstruction image output by the full-image reconstruction branch of the discriminator. The small-scale full-image reconstruction output of the discriminator's small-scale reconstruction branch is the small-scale full-image reconstruction. The local block reconstruction image output by the local reconstruction branch of the discriminator; This indicates downsampling to s×s resolution; The scale is based on the real sample. Indicates the extraction of real samples The part quadrant region, where part is the target quadrant index randomly selected from the set of quadrant indices.

8. The method according to claim 5, characterized in that, The step of inputting candidate image patches from the set of candidate image patches with quality weights as real samples into the discriminator to obtain the true discrimination score output by the discriminator for the real samples and the multi-scale reconstructed image corresponding to the real samples includes: The real sample and the target quadrant index randomly selected from the preset quadrant index set are input into the discriminator, which includes a discriminator branch, a full-image reconstruction branch, a small-scale reconstruction branch, and a local reconstruction branch. The real sample is processed by the discriminant branch to obtain the real discriminant score; The real sample is processed by the full-image reconstruction branch to obtain a full-image reconstruction image with a first resolution; The real sample is processed by the small-scale reconstruction branch to obtain a small-scale full-image reconstruction image with a second resolution, which is smaller than the first resolution. The local reconstruction branch processes the quadrant region corresponding to the target quadrant index in the real sample to obtain a local block reconstruction image of the second resolution. The full-scale reconstructed image, the small-scale full-scale reconstructed image, and the local block reconstructed image are combined to form the multi-scale reconstructed image.

9. A method for training a colored yarn spinning model, characterized in that, include: Obtain a colored yarn sample dataset, wherein the colored yarn sample dataset is generated by the colored yarn sample data generation method according to any one of claims 1 to 8; The ratio category prediction model is trained based on the dyed yarn sample dataset to obtain the trained ratio category prediction model.

10. A method for predicting the proportion category of colored spun yarn, characterized in that, include: Obtain the image of the target color yarn to be predicted; The target color yarn image is input into the trained color ratio category prediction model to obtain the color prediction result output by the color ratio category prediction model. The trained color ratio category prediction model is trained by the color yarn model training method according to claim 9.