A method and device for detecting the fat content of milk powder

By combining the improved Zebra Optimization Algorithm and hyperspectral imaging technology with a deep learning model, the problem of non-destructive testing of milk powder fat content was solved, achieving high-precision detection of milk powder fat content.

CN120431568BActive Publication Date: 2026-02-24INNER MONGOLIA AGRICULTURAL UNIVERSITY
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510516632.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2026-02-24
Estimated Expiration
2045-04-23

AI Technical Summary

Technical Problem

Existing methods for detecting the fat content of milk powder have the problem of environmental pollution caused by chemical reagents, and cannot meet the non-destructive requirements of food testing.

Method used

An improved zebra optimization algorithm combined with hyperspectral imaging technology and a deep learning model was used to perform non-destructive testing of the fat content in milk powder by screening spectral feature band data and using a Transformer detection model.

Benefits of technology

It achieves high-precision non-destructive testing of fat content in milk powder, improves the quality of test data and prediction accuracy, and avoids chemical reagent contamination.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120431568B_ABST
    Figure CN120431568B_ABST
Patent Text Reader

Abstract

The application discloses a milk powder fat content detection method and device, and relates to the technical field of food detection. The method comprises the following steps: improving the initialization and individual position updating stage formula of a zebra optimization algorithm, introducing an average difference mutation algorithm to correct the individual position, and obtaining an improved zebra optimization algorithm; the initialization stage is improved through a dynamic reverse learning algorithm, and the individual position updating stage is improved by introducing a multiple search mechanism of a myxomycete algorithm and a quasi-reverse learning algorithm; in the detection of the fat content of milk powder, the spectral feature band data of the sample is taken as the zebra individual position, the minimum fitness function value is taken as the target, the improved zebra optimization algorithm is used for optimization until the maximum iteration number is reached, and the target band is determined; and the spectral feature data of the target band is input into a trained Transform detection model to obtain the fat content of the milk powder to be detected. The method provided by the application realizes lossless prediction of the fat content of milk powder on the basis of high-precision prediction results.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to the technical field of food detection, in particular to a milk powder fat content detection method and device. BACKGROUND

[0002] Fat in milk powder is an important source of nutrition for people, especially infant formula milk powder, fat in milk powder is an indispensable nutrient for the growth and development of children, is the highest nutrient that provides heat energy, and is the carrier of fat-soluble vitamins such as vitamins A, D, E and K, which can only be absorbed by the human body when dissolved in fat. Fat content is an important indicator reflecting the quality of milk powder. However, there are often things such as adulterating other substances in milk powder or adulterating ordinary milk powder in infant formula milk powder on the market, which seriously damages the rights and interests of producers and consumers, therefore, the composition prediction of milk powder has a certain identification effect on the milk powder adulteration industry.

[0003] In the prior art, commonly used methods for determining fat in milk powder include Rose-Gottlieb method weight analysis, Soxhlet extraction method, Babcock method and Gerber method. However, chemical reagents may pollute the environment, and these methods cannot meet the non-destructive requirements of food detection.

[0004] Therefore, it is necessary to provide a milk powder fat content detection method to meet the non-destructive requirements of food detection. SUMMARY

[0005] Therefore, it is necessary to provide a milk powder fat content detection method and device to solve the above technical problems.

[0006] The application adopts the following technical solutions:

[0007] The application provides a milk powder fat content detection method, which comprises the following steps:

[0008] The formulae of the initialization stage and the individual position updating stage of the zebra optimization algorithm are improved, and an average differential mutation algorithm is introduced to correct the updated zebra individual position and obtain an improved zebra optimization algorithm; the formulae of the initialization stage in the zebra optimization algorithm are improved through a dynamic reverse learning algorithm; the formulae of the individual position updating stage in the zebra optimization algorithm are improved through the introduction of a multiple search mechanism of a myxomycete algorithm and a quasi-reverse learning algorithm;

[0009] Spectrum feature band data with fat content markers in milk powder image data are acquired;

[0010] The number of feature bands in the spectral feature band data labeled with fat content is used as the zebra individual position in the improved zebra optimization algorithm. The goal is to minimize the fitness function of the spectral feature band data. The improved zebra optimization algorithm filters the features of the spectral feature band data until it reaches a preset maximum number of iterations. The number of spectral bands reaching the maximum number of iterations is then determined as the number of feature bands in the filtered spectral feature band data. The fitness function of the spectral feature band data is constructed from the root mean square error predicted by the regressor and the number of feature bands in each iteration.

[0011] The spectral feature band data after feature filtering is input into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

[0012] Preferably, the implementation process of the improved zebra optimization algorithm specifically includes:

[0013] Based on the upper and lower boundaries of the search range, a random population is generated, and dynamic back-learning is performed on the random population to generate an initial population.

[0014] Calculate the fitness function value of each zebra individual in the initial population, and determine the optimal position of the zebra individual in the initial population based on the fitness function value;

[0015] The initial population is searched by the optimal location of zebra individuals to obtain the locations of zebra individuals after the initial search.

[0016] The zebra individual positions are updated using the slime mold algorithm's multiple search mechanism and quasi-backward learning algorithm after the initial search.

[0017] The updated zebra individual positions are corrected using the average difference mutation algorithm to obtain the initial population for the next iteration.

[0018] Recalculate the fitness function value of each zebra individual in the initial population, and update the initial population according to the fitness function until the preset maximum number of iterations is reached.

[0019] Preferably, the formula for calculating the initial population is:

[0020] X DOL =X in +r1*(r2*(lb+ub-X in )-X in );

[0021] In the formula, X DOL Representing the initial population, r1 and r2 are random numbers distributed in [0, 1], X in , .

[0022] Preferably, the formula for calculating the location of individual zebras after the initial search is as follows:

[0023] X prey (t)=X i (t)+r*(Pz-I*X i (t));

[0024] Among them, X prey(t) Let Pz be the zebra's position after the t-th iteration, Pz be the optimal zebra position after the t-th iteration, I be the position change control parameter between [1, 2], t be the current iteration number, r be a random number between [0, 1], and X be the zebra's position after the t-th iteration. i (t) represents the position of the i-th zebra individual in the t-th iteration;

[0025] Preferably, the calculation formula for updating the zebra individual positions after the initial search using the slime mold algorithm's multiple search mechanism and quasi-backward learning algorithm is as follows:

[0026]

[0027] In the formula, X i (t+1) represents the position of the i-th zebra after iteration t+1, X prey (t) represents the position of the zebra individual during the initial search process, v b This represents the information exchange process among individuals within a slime mold population, where W is the weighting factor for each individual in the slime mold population, and X... A (t) represents the random individual position, v b Simulating the interaction process of individual slime mold information, X B (t) represents the optimal individual position after the t-th iteration, r is a random number distributed in [0, 1], z is the proportion of randomly distributed slime mold individuals to the total population, and v c The parameters decrease linearly from 1 to 0, X(t) is the position of the slime mold in the t-th iteration, r1 is a random parameter between [0, 1], and p i p is a conditional parameter used to control how the location of slime mold individuals is updated. i =tanh|S(i)-DF|, where S(i) is the fitness value of the i-th individual, DF is the optimal fitness value in all iterations, ub and lb are the upper and lower boundaries of the search range, respectively, and X obl The position of the zebra individual after quasi-reverse learning.

[0028] Preferably, the formula for calculating the initial population in the next iteration is:

[0029]

[0030] In the formula, X i (t+1) represents the corrected zebra individual position, X i (t) represents the position of the slime mold in the t-th iteration, F1 and F2 are variation factors, which are random numbers between [0, 0.35] and [-0.15, 0.15], respectively, w is the inertia coefficient, which gradually decreases with iteration, X c1 Let X be the mean of two random zebra individuals. c2 Let X be the mean of a random zebra and the best zebra. prey (t) represents the zebra individual position after the initial search, pm is the mutation control parameter, and maxiter is the maximum number of iterations.

[0031] Preferably, acquiring spectral feature band data with fat content markers from milk powder image data specifically includes:

[0032] Hyperspectral image data of milk powder is acquired using a hyperspectral camera; multiple regions of interest are obtained from the hyperspectral image data of the milk powder; the regions of interest are the milk powder image data.

[0033] Extract the spectral reflectance from the milk powder image data to obtain the original spectral feature band data;

[0034] Calculate the average value at each spectral feature band position in all the original spectral feature band data;

[0035] Subtract the average value at the corresponding characteristic band position from each original spectral characteristic band data to remove the mean offset of the samples;

[0036] For the original spectral characteristic band data after subtracting the average value, calculate the standard deviation at the position of each characteristic band.

[0037] Divide each original spectral feature band data by the standard deviation of its corresponding feature band position to obtain the spectral feature band data.

[0038] Based on the spectral band data of standard samples with known fat content, the fat content is labeled on the preprocessed raw spectral characteristic band data to obtain spectral characteristic band data with fat content labeling.

[0039] Preferably, the formula for constructing the fitness function of the spectral characteristic band data is:

[0040]

[0041] In the formula, Fitness(i) is the fitness value of the i-th optimal zebra individual's position. To test the coefficient of determination, RMSE pdenoted as the root mean square error of the regressor prediction in each iteration, i.e., the prediction accuracy; N and G are the total number of feature bands and the number of feature bands corresponding to the optimal zebra individual position in each iteration, respectively; a and b are weight parameters.

[0042] This invention provides a device for detecting the fat content of milk powder, comprising:

[0043] The data acquisition module is used to acquire spectral feature band data of the sample milk powder with fat content markers in the sample image;

[0044] The feature selection module is used to select the band as the zebra individual position of the improved zebra optimization algorithm. With the goal of minimizing the fitness function value, the improved zebra optimization algorithm is used to optimize the bands of the sample spectral feature band data until the improved zebra optimization algorithm reaches the preset maximum number of iterations. The band that reaches the maximum number of iterations is determined as the target band.

[0045] The fat content prediction module is used to acquire the spectral feature band data of the milk powder image to be detected, and to filter the spectral feature band data from the spectral feature band data according to the target band. The filtered spectral feature band data is then input into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

[0046] The present invention provides a computer-readable storage medium, characterized in that the storage medium stores a computer program, which, when executed by a processor, implements the above-mentioned method for detecting the fat content of milk powder.

[0047] The present invention provides a computer device, characterized in that it includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the above-mentioned method for detecting the fat content of milk powder.

[0048] The above-mentioned at least one technical solution adopted in this invention can achieve the following beneficial effects:

[0049] In the milk powder fat content detection method provided by this invention, the spectral feature band data of the milk powder image is input into a spectral feature selection algorithm to generate an initial population and a reverse population. The initial population and the reverse population are merged to obtain a historical population. Since this invention uses a dynamic reverse strategy in the algorithm initialization stage, the diversity of the population is improved. The quasi-reverse learning algorithm is integrated into the slime mold algorithm to update the positions of individuals in the historical population, thereby obtaining the updated positions of individuals in the population. This enhances the global search capability of the algorithm and avoids the problem of the algorithm getting trapped in local optima when facing complex problems. By introducing average difference mutation to correct the updated positions of individuals in the population, the optimal positions of individuals in the population are obtained, avoiding the algorithm getting trapped in local optima and preventing premature convergence. Through multiple iterations, the optimal individuals in the population are obtained in each iteration, and a fitness function is constructed to calculate the best fitness value, thereby obtaining the spectral feature band data after feature selection, which improves the quality of the model input data.

[0050] In summary, the feature selection algorithm employed in this invention increases population diversity by performing reverse learning on the initial population. Based on this, a quasi-reverse learning algorithm is integrated into the slime mold algorithm, enhancing its global search capability. Finally, average differential mutation is introduced, and a fitness function based on the optimal population individuals and prediction accuracy is constructed, achieving efficient screening of spectral features in milk powder data and effectively improving data quality. Through deep learning model prediction, lossless prediction of milk powder fat content is achieved while maintaining high-precision prediction results. Attached Figure Description

[0051] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0052] Figure 1 A flowchart illustrating a method for detecting the fat content of milk powder provided by this invention;

[0053] Figure 2 A flowchart of the improved Zebra optimization algorithm for a method of detecting fat content in milk powder provided by the present invention;

[0054] Figure 3 This is a schematic diagram of a milk powder fat content detection device provided by the present invention;

[0055] Figure 4 This is a schematic diagram of a computer device for implementing a method for detecting the fat content of milk powder, as provided by the present invention. Detailed Implementation

[0056] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments in the specification without creative effort are within the scope of protection of this application.

[0057] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.

[0058] Figure 1 This is a schematic diagram of a method for detecting the fat content of milk powder based on a spectral feature selection algorithm according to the present invention, which specifically includes the following steps:

[0059] S101: The formulas for the initialization and individual position update stages of the Zebra Optimization Algorithm are improved, and the average difference mutation algorithm is introduced to correct the updated individual zebra positions, thus obtaining an improved Zebra Optimization Algorithm; the formula for the initialization stage of the Zebra Optimization Algorithm is improved by using a dynamic back-learning algorithm; the formula for the individual position update stage of the Zebra Optimization Algorithm is improved by introducing the multiple search mechanism and quasi-back-learning algorithm of the slime mold algorithm.

[0060] S102: Obtain spectral feature band data with fat content markers from milk powder image data.

[0061] Optionally, acquiring spectral feature band data from milk powder image data includes: acquiring hyperspectral image data of milk powder using a hyperspectral camera; acquiring multiple regions of interest (ROIs) in the hyperspectral image data of milk powder; wherein the ROIs are milk powder image data; extracting the spectral reflectance of the milk powder image data to obtain raw spectral feature band data; calculating the average value at each feature band position in all raw spectral feature band data; subtracting the average value at the corresponding feature band position from each raw spectral feature band data to remove the mean shift of the sample; calculating the standard deviation at each feature band position for the raw spectral feature band data after subtracting the average value; dividing each raw spectral feature band data by the standard deviation at its corresponding feature band position to obtain spectral feature band data; and labeling the preprocessed raw spectral feature band data with fat content based on the spectral band data of a standard sample with known fat content to obtain spectral feature band data with fat content labeling.

[0062] Optionally, hyperspectral image data of milk powder is acquired using a hyperspectral camera; several regions of interest are obtained from the hyperspectral image data of milk powder, which are the milk powder image data; the spectral reflectance of the milk powder image data is extracted to obtain the original spectral band data; based on the spectral band data of a standard sample with known fat content, the original spectral band data is labeled with fat content; the average value at each spectral feature band position in all the original spectral band data is calculated; the average value at the corresponding band position is subtracted from each original spectral band data to remove the mean shift of the sample; for the spectral band data after subtracting the average value, the standard deviation at each band position is calculated; each original spectral band data is divided by the standard deviation at its corresponding band position, including: for the j-th feature variable x of the i-th original spectral band data i,j The formula for calculating the preprocessed feature variables is:

[0063]

[0064] Among them, z i,j For the preprocessed spectral band characteristics, x i,j For the j-th spectral feature band of the i-th original spectral band data, Let s be the mean of the j-th spectral characteristic band across multiple original spectral band data. j denoted as the standard deviation of the j-th spectral characteristic band across all original spectral band data.

[0065] Each milk powder image contains 125 spectral feature bands corresponding to its spectral band data.

[0066] Specifically, the hyperspectral imaging acquisition system consists of a ground-based airborne hyperspectral imager with a spectral range of 400 to 1000 nm and a resolution of 2.8 nm. The resolution of its spectral images is 777*1004 pixels. The hyperspectral equipment, after black-and-white correction, acquires spectral images of the milk powder and selects Regions of Interest (ROIs) using ENVI software. The hyperspectral equipment acquired images of five types of infant formula from Yili, using an 8mm deep disc compaction method. Twenty samples of each type of formula were collected, and each hyperspectral image had eight ROIs selected, ultimately yielding 800 data points (8*20*5 = 800 data points).

[0067] S103: Using the band as the zebra individual position of the improved zebra optimization algorithm, with the goal of minimizing the fitness function value, the improved zebra optimization algorithm is used to optimize the bands of the sample spectral feature band data until the improved zebra optimization algorithm reaches the preset maximum number of iterations. The band that reaches the maximum number of iterations is determined as the target band.

[0068] Optionally, the fitness function value is determined by the number of bands selected for each optimization, based on the accuracy of milk powder content detection using the sample spectral feature band data. Optionally, a fitness function is constructed, and the optimal fitness value is calculated, including:

[0069] The fitness function is constructed using the spectral bands corresponding to the best individuals in each iteration, as shown in the formula:

[0070]

[0071] In the formula, Fitness(i) is the fitness value of the i-th optimal individual in the population. To test the coefficient of determination, RMSE p To test the root mean square error; N and G are the total number of spectral bands and the spectral band corresponding to the best individual in the population, respectively; a and b are weighting parameters, a = 0.7, b = 1-a.

[0072] Specifically, in the feature band selection process, it is necessary to ensure that the regressor has good performance while minimizing the number of feature bands. To make the selected feature bands most representative, this invention divides the sample feature band data into a training set and a test set. The training set is used to make predictions on the regressor and compared with the test set to obtain the prediction accuracy of the test set data. The fitness function is constructed using the maximum prediction accuracy (root mean square error) and the number of bands. The improved zebra optimization algorithm is used to build a model based on the band combinations corresponding to the individuals generated in each iteration. The fitness function is constructed by calculating the weights multiplied by the model accuracy (root mean square error) and the proportion of the selected bands to the total number of bands.

[0073] Optionally, see Figure 2 The flowchart for the Zebra optimization algorithm improvement includes the following steps:

[0074] Dynamic back-learning is performed on the random population generated by the Zebra Optimization Algorithm to generate an initial population for the improved Zebra Optimization Algorithm.

[0075] A preliminary search is performed on the initialized population to obtain the locations of individual zebras.

[0076] Based on the zebra individual positions after the initial search, the quasi-backward learning algorithm is integrated into the slime mold algorithm to update the zebra individual positions after the initial search.

[0077] The average difference mutation algorithm is introduced to correct the updated zebra individual position and obtain the optimal zebra individual position.

[0078] Optionally, the population initialization process of the improved Zebra Optimization Algorithm includes: generating a random population based on the upper and lower boundaries of the search range; performing reverse learning on the random population using a dynamic reverse learning algorithm to obtain a reverse population; the reverse population is the initial population of the improved Zebra Optimization Algorithm.

[0079] Specifically, the formula for generating a random population is:

[0080] X in =lb+r*(ub-lb);

[0081] In the formula, X in The random population is obtained randomly, ub and lb are the upper and lower boundaries of the search range, respectively, and r is a random number distributed in [0, 1].

[0082] The formula for calculating the reverse population is:

[0083] X DOL =X in +r1*(r2*(lb+ub-X in )-X in );

[0084] In the formula, X DOL The reverse population represents the initial population of the improved Zebra Optimization algorithm, and r1 and r2 are random numbers distributed in [0, 1].

[0085] Specifically, the initial population is generated using the following formula:

[0086] X in =lb+r*(ub-lb);

[0087] In the formula, X in The initial population is randomly obtained, ub and lb are the upper and lower boundaries of the search range, respectively, and r is a random number distributed in [0, 1].

[0088] Based on the initial population, a dynamic reverse learning strategy is used to generate a reverse population to complete the population initialization. The formula is:

[0089] X DOL =X in +r1*(r2*(lb+ub-X in )-X in );

[0090] In the formula, X DOL For the reverse total group, X in The initial population is randomly obtained, ub and lb are the upper and lower boundaries of the search range, respectively, r1 and r2 are random numbers distributed in [0, 1], and X is the search range. DOL This represents a reverse population.

[0091] Specifically, for the best individuals in the population, a dynamic back-learning algorithm is used for learning and optimization. Dynamic back-learning is an adaptive learning algorithm that can automatically adjust parameters and search strategies according to the characteristics of the problem, improving search efficiency and accuracy. Compared with random initialization methods, the initial population generated by dynamic back-learning has a better distribution.

[0092] Optionally, a quasi-reverse learning algorithm is incorporated into the slime mold algorithm to perform preliminary search and position updates on the initial population sequentially, specifically including:

[0093] A preliminary search is performed on the initialized population, using the following formula:

[0094] X prey (t)=X i (t)+r*(Pz-I*X i (t))

[0095] X prey(t) The optimal position of the current population, Pz is the position of the pioneer population, I is the population change control parameter between [1, 2], t represents the current iteration number, r is a random number between [0, 1], and X i (t) represents the position of the i-th population in iteration t.

[0096] Optionally, a quasi-backward learning algorithm can be incorporated into the slime mold algorithm to update the population position after the initial search, using the following formula:

[0097]

[0098] In the formula, X i (t+1) represents the position of an individual in the slime mold population after the (t+1)th iteration, X prey (t) represents the optimal position of the population during the initial search process, v b This represents the information exchange process among individuals within a slime mold population, where W is the weighting factor for each individual in the slime mold population, and X... A (t) represents the random individual position, v b Simulating the interaction of individual information within a slime mold population, X B (t) represents the current location of the individual with the best fitness, r is a random number distributed in [0, 1], z is the proportion of randomly distributed slime mold individuals in the total population, and v c The parameters decrease linearly from 1 to 0, X(t) is the position of the slime mold in the t-th iteration, r1 is a random parameter between [0, 1], and p i p is a conditional parameter used to control how the location of individuals in a slime mold population is updated. i=tanh|S(i)-DF|, where S(i) is the individual fitness value, DF is the optimal fitness value in all iterations, ub and lb are the upper and lower boundaries of the search range, respectively, and X obl The individual position after quasi-reverse learning.

[0099] Specifically, addressing the issue of the Zebra Optimization Algorithm (ZEM) easily getting trapped in local optima when facing complex problems, this paper introduces the multi-search mechanism of the slime mold algorithm into its search phase to enhance the global search capability of the ZEM. Furthermore, considering that in the traditional slime mold algorithm, when r < z, the slime mold population is randomly generated from the solution space to simulate the behavior of slime molds separating some individuals to explore other possible food sources, this paper incorporates quasi-backward learning to replace the random individual strategy when r < z in the slime mold algorithm into the SMA.

[0100] Specifically, in the formula, the first two lines are the update formulas in the slime mold algorithm, simulating the oscillating contraction of slime mold searching for physical objects. The third formula is quasi-backward learning, used to separate the current population to search for other valuable regions.

[0101] Optionally, the updated population individuals can be corrected by introducing mean difference variation, specifically including:

[0102] Based on the updated individual locations in the population, the average difference variation is introduced to correct the updated individual locations in the population, as shown in the formula:

[0103]

[0104] In the formula, X i (t+1) represents the corrected position of an individual in the population, X i (t) represents the position of the slime mold in the t-th iteration, F1 and F2 are variation factors, which are random numbers between [0, 0.35] and [-0.15, 0.15], respectively, w is the inertia coefficient, which gradually decreases with iteration, X c1 Let X be the mean of two random zebras obtained using the ZOA algorithm. c2 Let X be the mean of a random zebra and the best zebra. prey (t) represents the optimal position of the population during the initial search process, pm is the mutation control parameter, and maxiter is the maximum number of iterations.

[0105] Specifically, because the Zebra Optimization algorithm in the population clusters towards the optimal individual during iteration, if a local optimum exists, the algorithm tends to cluster around this local optimum as the number of iterations increases, potentially leading to a decrease in population diversity. To avoid the algorithm getting trapped in local optima and prevent premature convergence, average difference mutation is introduced to correct for individual populations and the global optimum. Two different strategies are adopted depending on the iteration stage: in the early stages, the mutation searches near the individual population, while in the later stages it tends to explore near the global optimum, helping the algorithm escape local optima.

[0106] Specifically, based on the Zebra optimization algorithm, a dynamic inverse algorithm is used in the initialization stage to initialize the population and improve its diversity. An improved slime mold algorithm and a quasi-inverse learning algorithm are proposed to improve the overall convergence accuracy of the algorithm and give it better global search capability. Finally, an average difference mutation algorithm is added to avoid premature convergence, and the optimal utility value is compared to search for the optimal position.

[0107] S104: Obtain the spectral feature band data of the milk powder image to be detected, and filter the spectral feature band data from the spectral feature band data according to the target band. Then, input the spectral feature band data after feature filtering into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

[0108] Specifically, hyperspectral data of five milk powders were collected. After extracting reflectance using ENVI software, 800 data points were generated, each containing 125 bands. The data were preprocessed using Standard Normal Variational Transform (SNV). 2) After processing, the number of feature bands was reduced from 125 to 77 using an improved Zebra optimization algorithm. 3) After reducing the number of bands, the data were used to predict the fat content of the milk powder using a Transformer model to complete the quantitative analysis.

[0109] When applying the milk powder fat content detection method provided by this invention, it is not necessary to rely on... Figure 1 The steps shown are executed in sequence. The specific execution order of each step can be determined as needed, and this invention does not impose any restrictions on it.

[0110] The above describes a method for detecting the fat content of milk powder according to one or more embodiments of the present invention. Based on the same idea, the present invention also provides a corresponding device for detecting the fat content of milk powder, such as... Figure 3 As shown.

[0111] Figure 3 A schematic diagram of a milk powder fat content detection device provided by the present invention includes:

[0112] The data acquisition module 601 is used to acquire the spectral feature band data of the sample milk powder image with fat content markers;

[0113] The feature selection module 602 is used to select the band as the zebra individual position of the improved zebra optimization algorithm. With the goal of minimizing the fitness function value, the improved zebra optimization algorithm is used to optimize the band of the sample spectral feature band data until the improved zebra optimization algorithm reaches the preset maximum number of iterations. The band that reaches the maximum number of iterations is determined as the target band.

[0114] The fat content prediction module 603 is used to acquire the spectral feature band data of the milk powder image to be detected, and to filter the spectral feature band data from the spectral feature band data according to the target band. The filtered spectral feature band data is then input into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

[0115] For specific limitations regarding the milk powder fat content detection device, please refer to the limitations of the milk powder fat content detection method described above, which will not be repeated here. Each module in the aforementioned milk powder fat content detection device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0116] The present invention also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 A method for detecting the fat content of milk powder is provided.

[0117] The present invention also provides Figure 3 The schematic diagram of the computer device shown is as follows: Figure 4 As shown, at the hardware level, this computer device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then executes it to achieve the above. Figure 1 A method for detecting the fat content of milk powder is provided.

[0118] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0119] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this invention.

Claims

1. A method for detecting the fat content of milk powder, characterized in that, include: The formulas for the initialization and individual position update stages of the zebra optimization algorithm are improved, and the average difference mutation algorithm is introduced to correct the updated zebra individual positions, thus obtaining the improved zebra optimization algorithm. The formula for the initialization phase of the zebra optimization algorithm is improved using a dynamic back-learning algorithm; the formula for the individual position update phase of the zebra optimization algorithm is improved by introducing the multi-search mechanism and quasi-back-learning algorithm of the slime mold algorithm; the implementation process of the improved zebra optimization algorithm specifically includes: generating a random population based on the upper and lower boundaries of the search range, and performing dynamic back-learning on the random population to generate an initial population; calculating the fitness function value of each zebra individual in the initial population, and determining the optimal zebra individual position in the initial population based on the fitness function value; performing a preliminary search on the initial population using the optimal zebra individual position to obtain the zebra individual positions after the preliminary search; updating the zebra individual positions after the preliminary search using the multi-search mechanism and quasi-back-learning algorithm of the slime mold algorithm; correcting the updated zebra individual positions using the average difference mutation algorithm to obtain the initial population in the next iteration; recalculating the fitness function value of each zebra individual in the initial population, and updating the initial population based on the fitness function, until the number of iterations reaches the preset maximum number of iterations; Obtain spectral feature band data of the sample milk powder with fat content markers from the sample milk powder image; Using the band as the zebra individual position in the improved zebra optimization algorithm, and aiming to minimize the fitness function value, the improved zebra optimization algorithm optimizes the bands of the sample spectral feature band data until it reaches a preset maximum number of iterations. The band that reaches the maximum number of iterations is determined as the target band. The fitness function value is determined by the number of bands selected in each optimization process to improve the accuracy of milk powder content detection. The spectral feature band data of the milk powder image to be detected is obtained, and the spectral feature band data is filtered from the spectral feature band data according to the target band. The spectral feature band data after feature filtering is input into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

2. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The formula for calculating the initial population is: ; In the formula, Represents the initial population. and These are random numbers distributed in [0, 1]. .

3. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The formula for calculating the location of individual zebras after the initial search is as follows: ; Among them, 𝑋 𝑝𝑟𝑒𝑦(𝑡) Indicates the first t The location of the zebra after the next iteration. It is the first t The optimal individual position of the zebra after the next iteration. I It is the control parameter for individual position changes between [1,2]. t This represents the current iteration number, where 𝑟 is a random number between [0,1]. This represents the position of the nth zebra individual in the nth iteration.

4. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The calculation formula for updating the zebra individual positions after the initial search using the slime mold algorithm's multiple search mechanism and quasi-backward learning algorithm is as follows: ; In the formula, For the nth zebra individual The location of the zebra after the next iteration. The location of individual zebras during the initial search process. This refers to the process of information exchange among individuals within a slime mold population. As a weighting factor for individuals in a slime mold population, For random individual locations, Simulates the interaction process of individual slime mold information. This represents the optimal individual position after the nth iteration. r The random numbers are distributed in [0, 1]. z The proportion of randomly distributed slime mold individuals in the total population. It is a parameter that decreases linearly from 1 to 0. For the first t The location of the slime mold in the next iteration r 1 is a random parameter between [0,1]. p i These are conditional parameters used to control how the location of slime mold individuals is updated. ,in, For the first i Individual fitness value The optimal fitness value across all iterations. and These are the upper and lower boundaries of the search range, respectively. The position of the zebra individual after quasi-reverse learning.

5. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The formula for calculating the initial population in the next iteration is: ; In the formula, This is the corrected location of the individual zebra. For the first t The location of the slime mold in the next iteration F 1 and F 2 is the mutation factor, and the two values ​​are random numbers between [0, 0.35] and [-0.15, 0.15]. w The inertia coefficient gradually decreases with iteration. The mean of two random zebra individuals. This is the mean of a random zebra and the best zebra. The locations of individual zebras after the initial search. pm These are the parameters for controlling variation. maxiter This represents the maximum number of iterations.

6. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The acquisition of spectral feature band data of the sample milk powder image with fat content markers specifically includes: Hyperspectral image data of milk powder is acquired using a hyperspectral camera; multiple regions of interest are obtained from the hyperspectral image data of the milk powder; the regions of interest are the milk powder image data. Extract the spectral reflectance from the milk powder image data to obtain the original spectral feature band data; Calculate the average value at each spectral feature band position in all the original spectral feature band data; Subtract the average value at the corresponding characteristic band position from each original spectral characteristic band data to remove the mean offset of the sample; For the original spectral characteristic band data after subtracting the average value, calculate the standard deviation at the position of each characteristic band. Divide each original spectral feature band data by the standard deviation of its corresponding feature band position to obtain the sample spectral feature band data. Based on the spectral band data of standard samples with known fat content, fat content is labeled on the preprocessed raw spectral characteristic band data to obtain sample spectral characteristic band data with fat content labeling.

7. The method for detecting the fat content of milk powder as described in claim 1, characterized in that, The formula for constructing the fitness function of the spectral feature band data is as follows: ; In the formula, Fitness ( i ) is the first i The fitness value of the optimal zebra individual's location. To test the coefficient of determination, The root mean square error of the regressor prediction at each iteration is the prediction accuracy. N and G These represent the total number of feature bands in each iteration and the number of feature bands corresponding to the optimal zebra individual position, respectively. a and b These are the weight parameters.

8. A device for detecting the fat content of milk powder, characterized in that, A method for detecting the fat content of milk powder according to any one of claims 1 to 7, comprising: The data acquisition module is used to acquire spectral feature band data of the sample milk powder with fat content markers in the sample image; The feature selection module is used to select bands as the zebra individual positions of the improved zebra optimization algorithm. With the goal of minimizing the fitness function value, the improved zebra optimization algorithm optimizes the bands of the sample spectral feature band data until it reaches a preset maximum number of iterations. The band that reaches the maximum number of iterations is then determined as the target band. The fitness function value is determined by the number of bands selected to optimize the sample spectral feature band data for milk powder content detection, thus determining the accuracy of the detection. The fat content prediction module is used to acquire the spectral feature band data of the milk powder image to be detected, and to filter the spectral feature band data from the spectral feature band data according to the target band. The filtered spectral feature band data is then input into the trained Transformer detection model to obtain the fat content in the milk powder to be detected.

Citation Information

Patent Citations

  • Wavelength selection method based on multi-strategy fusion improved zebra optimization algorithm and medium

    CN118553331A