Embedded equipment broad bean screening method based on random forest

Through the embedded broad bean screening method of embedded equipment based on random forests, combined with color, shape and texture characteristics, the problems of low efficiency and high computational complexity of traditional broad bean screening methods are solved, and efficient and fast broad bean screening effect is achieved.

CN119273961APending Publication Date: 2025-01-07XIAN UNIV OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411206797.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

The traditional broad bean screening method has low sorting efficiency and high complexity in the calculation of manual design features, resulting in insufficient generalization ability and low accuracy, making it difficult to meet the real-time requirements.

Method used

The embedded device broad bean screening method based on random forests is adopted, and efficient broad bean screening is achieved through image preprocessing, feature extraction, random forest model construction and parameter quantization, combining color, shape and texture features.

Benefits of technology

It improves the efficiency and accuracy of broad bean screening, reduces the computational complexity, and is suitable for embedded devices with resource-constrained, achieving fast and efficient broad bean screening.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119273961A_ABST
    Figure CN119273961A_ABST
Patent Text Reader

Abstract

The invention discloses an embedded equipment broad bean screening method based on random forest, and the method specifically comprises the following steps: S1, collecting and preprocessing an original image, and obtaining a data set; s2, performing feature extraction on the data set, calculating importance of features, and removing redundant features to obtain features highly contributing to screening accuracy; s3, constructing a random forest model, calculating a feature gain according to the image features, determining a decision order of the features, and determining the structure and parameters of the random forest model through training adjustment; s4, performing parameter quantization on the random forest model, and performing embedded device parallel deployment on the quantized model; and S5, screening the input image data by using a random forest screening model, and rejecting by using a pneumatic mode according to a target category output after decision making to complete screening. The technical problems that a traditional screening method is low in sorting efficiency and high in manual design feature calculation complexity are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of agricultural embedded screening systems, and in particular relates to a broad bean screening method using an embedded device based on random forest. Background Art

[0002] With the development of social economy, people pay more and more attention to food safety and healthy diet. As one of the main beans, the output of broad beans has increased year by year, and its export share and market size have also been growing continuously. However, broad beans will deteriorate during the transportation and storage stages after harvesting, and the untreated broad beans after harvest are mixed with good and bad, which affects the economic use distribution of broad beans of different grades. Therefore, it is necessary to study the grade screening of broad beans, which will help improve the market competitiveness of the domestic broad bean-related products and screening equipment manufacturing industry and ensure people's dietary health and food safety.

[0003] The efficiency and accuracy of crop sorting are affected by many factors. The size, shape, color, texture and other factors of the material may affect the screening effect. In order to solve the challenges faced by color sorters in practical applications, many researchers have tried to introduce advanced image processing algorithms in recent years, combined with deep learning models corresponding to material characteristics, to improve the color sorter's ability to recognize different materials. Machine learning algorithms can improve the recognition ability and adaptability of color sorters by learning from large amounts of data, enabling them to perform well in different scenarios.

[0004] In the field of crop screening, especially in scenarios with simple backgrounds and uncomplicated targets, traditional machine learning methods, such as support vector machines (SVM) and K-nearest neighbor algorithms (KNN), can accomplish tasks to a certain extent, but they have many shortcomings. First, these methods usually rely on manually designed features. For simpler backgrounds, traditional methods often have overfitting problems, resulting in insufficient generalization of the model in practical applications. Secondly, since these methods are highly dependent on feature selection, the feature extraction process may ignore certain key features, thereby affecting the accuracy of screening. In addition, the computational complexity of traditional machine learning methods is high, and their efficiency is often unsatisfactory for screening tasks with high real-time requirements. Summary of the invention

[0005] The purpose of the present invention is to provide a broad bean screening method for embedded devices based on random forests, which solves the technical problems of low sorting efficiency and high calculation complexity of manually designed features in traditional screening methods.

[0006] The technical solution adopted by the present invention is a method for screening broad beans for embedded devices based on random forests, which is specifically implemented according to the following steps:

[0007] S1, collect original images and preprocess them to obtain data sets;

[0008] S2, extract features from the data set constructed in S1, calculate the importance of features using the Pearson correlation coefficient, perform feature selection on the feature data to remove redundant features, and obtain features that contribute most to screening accuracy;

[0009] S3, constructing a random forest model, calculating feature gains based on the image features obtained in S2, determining the decision order of features, and determining the structure and parameters of the random forest model through training and adjustment;

[0010] S4, quantize the parameters of the random forest model trained in S3, and deploy the quantized model in parallel on embedded devices;

[0011] S5, uses the random forest screening model deployed in S4 to screen the input image data, and uses pneumatic method to eliminate the target category output after the decision to complete the screening.

[0012] The present invention is also characterized in that:

[0013] The specific preprocessing in S1 is:

[0014] The collected original image is filtered as shown in formula (1.1):

[0015]

[0016] In formula (1.1), I′(x, y) represents the pixel value after filtering, I(x, y) represents the pixel value of the original image, N(x, y) is the neighborhood containing the pixel (x, y), and N is the number of pixels in the neighborhood;

[0017] The original image after filtering is subjected to linear normalization as shown in formula (1.2) to adjust the pixel values ​​of the original image to within the standard range:

[0018]

[0019] In formula (1.2), I′(x, y) is the normalized pixel value, I max is the maximum pixel value in the image, I min The minimum pixel value in the image, a and b are the normalized target ranges;

[0020] The normalized original image is subjected to gamma correction as shown in formula (1.3) to adjust the color distortion of the original image:

[0021] I′(x,y)=I(x,y) γ (1.3)

[0022] In formula (1.3), γ is the gamma value, which is usually in the range of 0.8≤γ≤2.2.

[0023] The feature extraction in S2 is specifically as follows: extracting the color histogram, shape contour and texture features of the image in the S1 data set to obtain the image feature data of the training set.

[0024] S3 is specifically:

[0025] S3.1, build a random forest model, set the number of decision trees, maximum depth of decision trees, maximum number of features, and minimum number of sample splits used by the random forest model;

[0026] S3.2, calculate the information gain of the color histogram, shape contour and texture features with high accuracy contribution in S2, as shown in equations (3.1), (3.2) and (3.3):

[0027]

[0028] In formula (3.1), D is the current data set, p i is the probability of the i-th category in the data set, that is, the number of samples in the i-th category divided by the total number of samples, and n is the number of categories;

[0029] According to the entropy obtained by formula (3.1), the conditional entropy of the feature is calculated as shown in formula (3.2):

[0030]

[0031] In formula (3.2), values(A) is all possible values ​​of feature A, D υ is the data subset when feature A takes the value of υ, |D v | is the data subset D v is the number of samples in the original dataset D, |D| is the number of samples in the original dataset D, H(D v ) is the data subset D v Entropy of

[0032] According to the conditional entropy obtained from formula (3.2), the feature information gain is calculated as shown in formula (3.3):

[0033] IG(D,A)=H(D)-H(D|A) (3.3)

[0034] In formula (3.3), IG(D,A) is the information gain of feature A on data set D, H(D) is the entropy of data set D, and H(D|A) is the conditional entropy of feature A;

[0035] Determine the decision order of features used in decision making based on information gain;

[0036] S3.3, split the preprocessed image data set of S1 into a training set and a test set according to a certain ratio, the training set is used to build the random forest model, and the test set is used to evaluate the performance of the model. Before training the model, the parameters of the random forest model are initialized, where the parameters include the number of trees, the maximum depth, the maximum number of features, and the minimum number of sample splits;

[0037] The training set is used to train the initialized random forest model. During the training process, the random forest model generates multiple decision trees by randomly selecting samples and features, and uses out-of-bag data to estimate the model error. Through multiple iterations, the optimal value of each parameter is determined to obtain the optimal model structure and classification performance.

[0038] S4 is as follows: firstly, the parameter range analysis is performed on the random forest model trained by S3, the distribution range of the parameters of each layer in the trained random forest model is analyzed, and the minimum value, maximum value and dynamic range of each parameter are determined; according to the processing power and memory limitation of the embedded device, the fixed-point quantization bit width is selected, and the floating-point number parameters are mapped to the fixed-point representation, as shown in formula (4):

[0039] q=round(x×scale) (4)

[0040] In formula (4), x is a floating point number, scale is a scaling factor, and q is a fixed point representation;

[0041] After quantization is completed, the quantized random forest model is evaluated on the validation set. The quantization error of the random forest model is calculated and the performance is compared with the model in floating-point form. If quantization causes a significant performance degradation, the quantization bit width or scaling factor can be adjusted. After completing the fixed-point quantization of the random forest model parameters, the random forest model is deployed on the target embedded device.

[0042] S5 is specifically as follows: using the image sensor on the embedded device to continuously collect images of broad bean samples, converting the collected image data into a data format that matches the input format of the random forest model, performing feature extraction on the converted image data, and the extracted features will be used as the input of the random forest model. The extracted feature vector is input into the random forest model trained in S4 for inference. The random forest model makes classification decisions based on the input features and outputs screening results. According to the decision output of the random forest model, the samples are classified as qualified or unqualified, qualified samples are retained, and unqualified samples are marked as targets that need to be eliminated. After the random forest model makes a decision, the position of the unqualified samples in the image is located and marked in real time. When the marked samples pass the predetermined position, the control system triggers the pneumatic device to generate a high-pressure airflow to remove the unqualified samples from the conveyor belt. After removal, the screening results are recorded, and the qualified and unqualified samples are classified and counted. The overall effect of the screening model and the pneumatic rejection mechanism is evaluated through the statistical results.

[0043] The beneficial effects of the present invention are:

[0044] The present invention aims at the problem that the current screening equipment has a single sorting mode and the sorting efficiency is weak. The present invention proposes a broad bean sorting algorithm based on a machine learning method, combines the machine learning technology with the broad bean sorting task, combines the shape features improved for the common forms of broad beans, and the texture features and color features, and performs parameter optimization research on the improved shape features and color and texture features. By reducing the characteristic parameters to reduce the calculation complexity and performing fixed-point quantization of the parameters, the screening model can be deployed in embedded devices, and the parallel computing characteristics of the field programmable gate array (Field-Programmable Gate Array, FPGA) are efficiently utilized to achieve fast and efficient broad bean screening. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 It is a flow chart of a method for screening broad beans in an embedded device based on random forests of the present invention;

[0046] Figure 2 is a shape feature importance distribution diagram in Example 2 of the present invention;

[0047] Figure 3 is a line graph showing the relationship between the number of shape features and screening accuracy in Example 2 of the present invention;

[0048] Figure 4 is a line graph showing the relationship between shape feature screening accuracy and the number of random forest decision trees in Example 2 of the present invention;

[0049] Figure 5is a line graph showing the relationship between shape feature screening accuracy and the maximum depth of the random forest decision tree in Example 2 of the present invention;

[0050] Figure 6 is a line graph showing the relationship between texture feature screening accuracy and the number of random forest decision trees in Example 2 of the present invention;

[0051] Figure 7 is a line graph showing the relationship between texture feature screening accuracy and the maximum depth of the random forest decision tree in Example 2 of the present invention;

[0052] Figure 8 is a line graph showing the relationship between the color feature screening accuracy and the number of random forest decision trees in Example 2 of the present invention;

[0053] Fig. 9 is a line graph showing the relationship between the color feature screening accuracy and the maximum depth of the random forest decision tree in Example 2 of the present invention;

[0054] Fig.10 It is a schematic diagram of the decision order and elimination of color, shape and texture features in the present invention. DETAILED DESCRIPTION

[0055] The present invention will be further explained below in conjunction with the accompanying drawings and specific embodiments.

[0056] Example 1

[0057] like Figure 1 As shown, the embedded device broad bean screening method based on random forest disclosed by the present invention is specifically implemented according to the following steps:

[0058] S1, collect original images and preprocess them to obtain data sets;

[0059] S2, extract features from the data set constructed in S1, calculate the importance of features using the Pearson correlation coefficient, perform feature selection on the feature data to remove redundant features, and obtain features that contribute most to screening accuracy;

[0060] S3, constructing a random forest model, calculating feature gains based on the image features obtained in S2, determining the decision order of features, and determining the structure and parameters of the random forest model through training and adjustment;

[0061] S4, quantize the parameters of the random forest model trained in S3, and deploy the quantized model in parallel on embedded devices;

[0062] S5, uses the random forest screening model deployed in S4 to screen the input image data, and uses pneumatic method to eliminate the target category output after the decision to complete the screening.

[0063] The present invention is suitable for crop screening scenarios with simple backgrounds and uncomplicated targets. By combining multiple feature information such as color, texture, and shape, and adopting a lightweight random forest model, it can effectively capture the key features of the target and avoid the problems caused by complex feature design in traditional methods. Especially under simple backgrounds, it can complete target classification and screening faster and more accurately, making full use of the simplified characteristics of the background to achieve an efficient screening process. In addition, by optimizing and quantifying the random forest model, it can run efficiently on embedded devices, is suitable for resource-constrained environments, realizes the automation and intelligence of screening tasks, and greatly improves the accuracy and efficiency of screening.

[0064] Example 2

[0065] Based on Example 1, the pretreatment in S1 is specifically as follows:

[0066] The collected original image is filtered as shown in formula (1.1):

[0067]

[0068] In formula (1.1), I′(x, y) represents the pixel value after filtering, I(x, y) represents the pixel value of the original image, N(x, y) is the neighborhood containing the pixel (x, y), and N is the number of pixels in the neighborhood;

[0069] The original image after filtering is subjected to linear normalization as shown in formula (1.2) to adjust the pixel values ​​of the original image to within the standard range:

[0070]

[0071] In formula (1.2), I′(x, y) is the normalized pixel value, I max is the maximum pixel value in the image, I min The minimum pixel value in the image, a and b are the normalized target ranges;

[0072] The normalized original image is subjected to gamma correction as shown in formula (1.3) to adjust the color distortion of the original image and make the color of the image more realistic and consistent:

[0073] I′(x,y)=I(x,y) γ (1.3)

[0074] In formula (1.3), γ is the gamma value, which is usually in the range of 0.8≤γ≤2.2.

[0075] According to equations (1.1) to (1.3), image data preprocessing is completed for training the dataset.

[0076] Specifically, S2 is as follows: extract color, shape, and texture features from each image in the dataset preprocessed by S1, and select the features to be used:

[0077] S2.1, extracting the color histogram, shape contour features and texture features of the image data to obtain image feature data of the data set;

[0078] S2.2, applying feature selection technology to the image feature data extracted in S2.1, selecting and using features with high importance and removing redundant features.

[0079] S2.1 specifically:

[0080] First, the color histogram features of the image data are extracted: the image data after S1 preprocessing is color quantized, the value range of the pixel value is limited, and the pixel intensity interval is quantized. After quantization, the color histogram is calculated. The color histogram features of the image data are obtained according to equations (2.1) and (2.2):

[0081]

[0082] In formula (2.1), H(r,g,b) represents the value of the color histogram at the position (r,g,b), which represents the number of pixels of color (r,g,b) in the image; W and H are the width and height of the image; r′(x,y), g′(x,y), b′(x,y) are the color values ​​of the pixel (x,y) in the image; δ(·) is the Dirac function, which takes the value of 1 when the input is 0, otherwise it is 0.

[0083] After the histogram calculation is completed according to formula (2.1), it is usually normalized to make it a probability distribution:

[0084]

[0085] In formula (2.1), H′(r,g,b) is the normalized color histogram.

[0086] Image shape feature extraction is performed according to formulas (2.3)-(2.5):

[0087] First, the image geometric moment is calculated: for a two-dimensional image f(x, y), its (p+q)-order geometric moment m pq Defined as:

[0088]

[0089] In formula (2.3), p and q are non-negative integers, representing the order of the moment; f(x, y) is the grayscale value of the image at position (x, y), or for a binary image, f(x, y) is 0 or 1.

[0090] Secondly, the central moment is calculated: In order to obtain the translation-invariant property of the image, the central moment μ is defined pq , as the moment about the image's center of gravity:

[0091]

[0092] In formula (2.4), and are the centroid coordinates of the image respectively.

[0093] In order to obtain the invariant property to scaling, the central moment is normalized and the normalized

[0094]

[0095] In formula (2.5),

[0096] After completing the above calculations, perform specific calculations of the 7 Hu moments:

[0097] Hu 1 =η 20 +η 02

[0098] Hu 2 =(η 20 -η 02 ) 2 +4η 11 2

[0099] Hu 3 =(η 30 -3η 12 ) 2 +(3η 21 -3η 03 ) 2

[0100] Hu 4 =(η 30 +η 12 ) 2 +(η 21 +η 03 ) 2

[0101] Hu 5 =(η 30 -3η 12 )(η 30 +η 12 )[(η 30 +η 12 ) 2 -3(η 21 +η 03) 2 ]+3(η 21 -η 03 )(η 21 +η 03 )[3(η 30 +η 12 ) 2 -(η 21 +η 03 ) 2 ]

[0102] Hu 6 =(η 20 -η 02 )[(η 30 +η 12 ) 2 -(η 21 +η 03 ) 2 ]+4η 11 (η 30 +η 012 )(η 21 +η 03 )

[0103] Hu 7 =(3η 30 -η 03 )(η 30 +η 12 )[(η 30 +η 12 ) 2 -3(η 21 +η 03 ) 2 ]-(η 30 -3η 12 )(η 21 +η 03 )[3(η 30 +η 12 ) 2 -(η 21 +η 03 ) 2 ]

[0104] In order to clarify the spatial relationship between gray levels in the image and capture the local features of the texture, the texture features of the image are calculated according to equations (2.6)-(2.11):

[0105] Assuming the image is a matrix of size M × N, and the gray value range is 0-G-1, the gray level co-occurrence matrix P(i, j, d, θ) is calculated as:

[0106]

[0107] In formula (2.6): P(i, j) represents the number of times gray level i and gray level j appear at the same time at a given spatial distance and direction. I(x, y) represents the gray value of the image at position (x, y); d is the distance between pixels (usually 1); θ is the direction angle, usually 0°, 45°, 90°, 135°. According to different values ​​of θ, the values ​​of Δx and Δy are as follows:

[0108] When θ=0°, (Δx,Δy)=(d,0).

[0109] When θ=45°, (Δx,Δy)=(d,-d).

[0110] When θ=90°, (Δx,Δy)=(0,d).

[0111] When θ=135°, (Δx,Δy)=(-d,-d).

[0112] In order to avoid the influence of image size on the co-occurrence matrix, the gray-level co-occurrence matrix is ​​usually normalized, that is, the following calculation is performed on P(i,j) calculated in the previous step:

[0113]

[0114] In formula (2.7), P′(i,j) is the normalized gray-level co-occurrence matrix.

[0115] The result P′(i,j) obtained by the above calculation is used to calculate the following texture features:

[0116] Calculate the energy signature,

[0117]

[0118] Compute contrast features,

[0119]

[0120] Calculate the entropy feature,

[0121]

[0122] Calculate the inverse moment,

[0123]

[0124] S2.2 specifically:

[0125] After completing the feature extraction in S2.1, it is necessary to perform feature selection on the feature data to remove redundant features and obtain features that contribute highly to screening accuracy. The Pearson correlation coefficient is used in the present invention to calculate the importance of the feature, which is calculated according to the following formula:

[0126]

[0127] In formula (2.12), r xy is the Pearson correlation coefficient between variables x and y; x i and i are the i-th observation values; and are the sample means of x and y respectively; n is the number of samples.

[0128] Specifically, S3 is:

[0129] S3.1, since the model is to be deployed on embedded devices, it is necessary to achieve efficient screening performance under limited resources. Therefore, it is necessary to reasonably set the number of decision trees used in the model to ensure that the model has sufficient expressive power and control the amount of calculation; the depth of the decision tree determines the complexity of the model and the risk of overfitting. Shallow trees can reduce overfitting and are suitable for embedded systems. Therefore, it is necessary to reasonably set the maximum depth of the decision tree used in the model to ensure the lightweight of the model and avoid the computational complexity and overfitting problems caused by too deep trees. Setting the minimum number of samples for leaf nodes ensures the generalization ability of the tree and avoids excessive growth of the tree, which helps to reduce overfitting. The number of features randomly selected at each node split is the square root or logarithm of the total number of features to improve the generalization ability of the model. When constructing the sub-sample set, since a smaller sub-sample ratio can improve the generalization ability of the model, the sub-sample ratio is set to ensure the stability and performance of the model.

[0130] S3.2, calculate the information gain of the color histogram, shape contour and texture features with high accuracy contribution in S2, as shown in equations (3.1), (3.2) and (3.3):

[0131]

[0132] In formula (3.1), D is the current data set, p i is the probability of the i-th category in the data set, that is, the number of samples in the i-th category divided by the total number of samples, and n is the number of categories;

[0133] According to the entropy obtained by formula (3.1), the conditional entropy of the feature is calculated as shown in formula (3.2):

[0134]

[0135] In formula (3.2), values(A) is all possible values ​​of feature A, D υ is the data subset when feature A takes the value of υ, |D υ | is the data subset D υis the number of samples in the original dataset D, |D| is the number of samples in the original dataset D, H(D υ ) is the data subset D υ Entropy of

[0136] According to the conditional entropy obtained from formula (3.2), the feature information gain is calculated as shown in formula (3.3):

[0137] IG(D,A)=H(D)-H(D|A) (3.3)

[0138] In formula (3.3), IG(D, A) is the information gain of feature A to data set D, H(D) is the entropy of data set D, and H(D|A) is the conditional entropy of feature A. The larger the information gain value, the more the uncertainty of feature A to the data set is reduced, so the feature is more suitable as the splitting node of the decision tree. When constructing a decision tree, the feature with the largest information gain is usually selected as the splitting feature of the current node. After completing the information gain calculation of color, shape and texture features according to the above formula, the decision order of the features used in the decision is determined.

[0139] S3.3, split the preprocessed image dataset of S1 into a training set and a test set in an 8:2 ratio. The training set is used to build a random forest model, and the test set is used to evaluate the performance of the model. Before training the model, the parameters of the random forest model are initialized, where the parameters include the number of trees, maximum depth, maximum number of features, and minimum number of sample splits; where the number of trees is the number of decision trees set; the maximum depth is the maximum depth of each tree set to control the complexity of the model; the maximum number of features is the number of features considered when defining each split, usually set to the square root or logarithm of the total number of features; the minimum number of sample splits is the minimum number of samples required to set a node split to avoid overfitting.

[0140] The training set is used to train the initialized random forest model. During the training process, the random forest model generates multiple decision trees by randomly selecting samples and features, and uses out-of-bag data to estimate the model error. Through multiple iterations, the optimal value of each parameter is determined to obtain the optimal model structure and classification performance.

[0141] Specifically, S4 is as follows: first, perform parameter range analysis on the random forest model trained by S3, analyze the distribution range of each layer parameter (such as weight and bias) in the trained random forest model, and determine the minimum, maximum and dynamic range of each parameter; select the appropriate fixed-point quantization bit width (8 or 16 bits) according to the processing power and memory limitations of the embedded device. In general, a lower bit width is selected to reduce the occupation of computing resources, and experiments are performed to ensure that quantization does not significantly reduce the accuracy of the model. The common mapping method for mapping floating-point parameters to fixed-point representation is linear quantization, that is, converting floating-point numbers to fixed-point numbers through scaling factors, as shown in formula (4):

[0142] q=round(x×scale) (4)

[0143] In formula (4), x is a floating point number, scale is a scaling factor, and q is a fixed point representation;

[0144] After quantization is completed, the quantized random forest model is evaluated on the validation set. The quantization error of the random forest model is calculated and the performance is compared with the model in floating-point form. If quantization causes a significant performance degradation, the quantization bit width or scaling factor can be adjusted. After completing the fixed-point quantization of the random forest model parameters, the random forest model is deployed on the target embedded device.

[0145] Deploy the model to the target embedded device. The specific steps are as follows:

[0146] 1. Model conversion and optimization: Convert the quantized model into a format compatible with embedded devices (Verilog). In this process, the model is optimized using the device-specific acceleration library or hardware accelerator (FPGA) to improve operating efficiency.

[0147] 2. Embedded system integration: Integrate the converted model into the embedded system. This step includes: writing interface code to connect the model to the input and output interfaces of the system; optimizing memory management to ensure that the model runs efficiently in the limited memory of the device; and testing the inference speed and power consumption of the model on the target device to ensure that it meets the requirements of actual applications.

[0148] 3. Real-time performance evaluation: Run the quantized model on an embedded device and test it on real data to evaluate the real-time performance and accuracy of the model. Based on the test results, further optimize the model or adjust the deployment parameters to ensure that the model performs as expected in the target application.

[0149] like Fig.10As shown, specifically, S5 is as follows: using an image sensor on an embedded device, such as a camera or other image sensor, to continuously collect images of broad bean samples, converting the collected image data into a data format that matches the input format of the random forest model, performing feature extraction on the converted image data, and the extracted features will be used as the input of the random forest model, and the extracted feature vector will be input into the random forest model trained in S4 for inference, and the random forest model will make classification decisions based on the input features and output screening results, and classify the samples as qualified or unqualified based on the decision output of the random forest model, retain qualified samples, and mark unqualified samples as targets that need to be eliminated, and after the random forest model makes a decision, locate and mark the position of unqualified samples in the image in real time, and when the marked samples pass the predetermined position, the control system triggers the pneumatic device to generate a high-pressure airflow to remove the unqualified samples from the conveyor belt, and after removal, record the screening results, classify and count the qualified and unqualified samples, and evaluate the overall effect of the screening model and the pneumatic rejection mechanism through the statistical results.

[0150] Example 3

[0151] On the basis of Example 2, in S2.1: perform color quantization on the image data after preprocessing in S1, quantize the pixel data in the value range of [0,255] into 8 intervals, each interval width is 32, and obtain color data represented by the intervals after quantization, which is used to calculate the color histogram and characterize the color features; perform shape feature extraction according to formulas 2.3-2.5 to obtain the shape features of the image data; perform texture feature extraction according to formulas 2.6-2.11 to obtain the texture features of the image data. S2.2, based on S2.1, use the Pearson correlation coefficient to perform importance analysis on the extracted features, wherein the importance distribution of the shape features obtained after the Pearson correlation coefficient analysis is as follows: Figure 2 As shown in the figure, the 7 moment features used by the shape feature have different importance; the relationship between the number of shape features used and the screening accuracy changes as shown in Figure 3 As shown in the figure, it can be seen that different features used in shape features have different importance to the final classification accuracy. The main purpose of this step is to remove redundant features and only retain features that contribute greatly to the classification accuracy.

[0152] In S3.1, on the basis of completing S2, it is necessary to use the features after feature selection to train the classifier, so it is necessary to build a classifier model. The classifier model is mainly composed of a certain number and depth of decision trees. The initialization parameters of the random forest model are obtained using cross-validation technology, that is, the number of decision trees used by the model is set to [10, 20, 30, 50], the maximum depth of the tree is limited to [3, 5, 7, 10], the minimum number of samples of leaf nodes is set to [2, 5], and the sub-sample ratio is set to [0.7, 0.8]. After determining the above cross-validation parameter settings, the grid search method is used to automatically search for the random forest model parameters corresponding to the three features with the highest accuracy, including the number of decision trees used and the maximum depth of the decision tree. The model decision tree number parameters corresponding to the shape features obtained through cross-validation and grid search are as follows: Figure 4 As shown in Figure 1, it reflects the change in the accuracy of shape feature screening under different numbers of decision trees. According to this change curve, the number of decision trees of the model can be reasonably set to achieve a higher screening accuracy. The maximum depth parameter of the model decision tree corresponding to the obtained shape feature is shown in Figure 1. Figure 5 As shown in Figure 1, it reflects the change in the accuracy of shape feature screening under different decision tree depths. The number of model decision trees corresponding to the texture features obtained through cross-validation and grid search is shown in Figure 1. Figure 6 As shown in the figure, it reflects the change of texture feature screening accuracy under different numbers of decision trees; the maximum depth parameter of the model decision tree corresponding to the obtained texture features is as follows Figure 7 As shown in Figure 1, it reflects the change in the accuracy of texture feature screening under different decision tree depths. The number of model decision trees corresponding to the texture features obtained through cross-validation and grid search is shown in Figure 1. Figure 8 As shown in the figure, it reflects the change of color feature screening accuracy under different numbers of decision trees; the maximum depth parameter of the model decision tree corresponding to the obtained color feature is as follows Fig. 9 As shown, it reflects the change in the accuracy of color feature screening under different decision tree depths. According to the above curve chart, the random forest model parameter settings that can obtain the highest screening accuracy can be correctly set. S3.2 is to calculate the information gain of the features processed by S2 to determine the feature order used in the decision-making process during the screening process. After calculation, the feature decision order is determined to be shape-color-texture. S3.3 is to use the three features processed by S2 to train the random forest model constructed in S3.1 to obtain a screening model that can correctly process new targets.

[0153] S4 mainly quantizes the parameters of the model trained by S3, determines the parameter bit width to be 8 bits, converts the floating-point parameters of the model into fixed-point parameters, and deploys the model on embedded devices after completing the model performance evaluation.

[0154] S5 converts the collected image data into a data format that matches the input format of the random forest model, extracts features from the converted image data, and uses the extracted features as the input of the random forest model. The extracted feature vector is input into the random forest model trained in S4 for inference. The random forest model makes classification decisions based on the input features and outputs screening results. According to the decision output of the random forest model, the samples are classified as qualified or unqualified, qualified samples are retained, and unqualified samples are marked as targets that need to be eliminated. After the random forest model makes a decision, the position of the unqualified samples in the image is located and marked in real time. When the marked samples pass the predetermined position, the control system triggers the pneumatic device to generate high-pressure airflow to remove the unqualified samples from the conveyor belt. After removal, the screening results are recorded, and the qualified and unqualified samples are classified and counted. The overall effect of the screening model and the pneumatic rejection mechanism is evaluated through the statistical results.

Claims

1. A method for screening broad beans for embedded devices based on random forests, characterized in that: Follow the steps below to implement it: S1, collect original images and preprocess them to obtain data sets; S2, extract features from the data set constructed in S1, calculate the importance of features using the Pearson correlation coefficient, perform feature selection on the feature data to remove redundant features, and obtain features that contribute most to screening accuracy; S3, constructing a random forest model, calculating feature gains based on the image features obtained in S2, determining the decision order of features, and determining the structure and parameters of the random forest model through training and adjustment; S4, quantize the parameters of the random forest model trained in S3, and deploy the quantized model in parallel on embedded devices; S5, uses the random forest screening model deployed in S4 to screen the input image data, and uses pneumatic method to eliminate the target category output after the decision to complete the screening.

2. The embedded device broad bean screening method based on random forest according to claim 1 is characterized in that: The specific preprocessing in S1 is: The collected original image is filtered as shown in formula (1.1): In formula (1.1), I ′ (x, y) represents the pixel value after filtering, I(x, y) represents the pixel value of the original image, N(x, y) is the neighborhood containing the pixel (x, y), and N is the number of pixels in the neighborhood; The original image after filtering is subjected to linear normalization as shown in formula (1.2) to adjust the pixel values ​​of the original image to within the standard range: In formula (1.2), I ′ (x, y) is the normalized pixel value, I max is the maximum pixel value in the image, I min The minimum pixel value in the image, a and b are the normalized target ranges; The normalized original image is subjected to gamma correction as shown in formula (1.3) to adjust the color distortion of the original image: I ′ (x,y)=I(x,y) γ (1.3)In formula (1.3), γ is the gamma value, which is usually in the range of 0.8≤γ≤2.

2.

3. The embedded device broad bean screening method based on random forest according to claim 2 is characterized in that: The feature extraction in S2 is specifically: extracting the color histogram, shape contour and texture features of the image in the S1 data set to obtain the image feature data of the training set.

4. The method for screening broad beans for embedded devices based on random forest according to claim 3, characterized in that: The S3 is specifically: S3.1, build a random forest model, set the number of decision trees, maximum depth of decision trees, maximum number of features, and minimum number of sample splits used by the random forest model; S3.2, calculate the information gain of the color histogram, shape contour and texture features with high accuracy contribution in S2, as shown in equations (3.1), (3.2) and (3.3): In formula (3.1), D is the current data set, p i is the probability of the i-th category in the data set, that is, the number of samples in the i-th category divided by the total number of samples, and n is the number of categories; According to the entropy obtained by formula (3.1), the conditional entropy of the feature is calculated as shown in formula (3.2): In formula (3.2), values(A) is all possible values ​​of feature A, D υ is the data subset when feature A takes the value of υ, |D υ | is the data subset D υ is the number of samples in the original dataset D, |D| is the number of samples in the original dataset D, H(D v ) is the data subset D v Entropy of According to the conditional entropy obtained from formula (3.2), the feature information gain is calculated as shown in formula (3.3): IG(D,A)=H(D)-H(D|A)(3.3)In formula (3.3), IG(D,A) is the information gain of feature A to data set D, H(D) is the entropy of data set D, and H(D|A) is the conditional entropy of feature A; Determine the decision order of features used in decision making based on information gain; S3.3, split the preprocessed image data set of S1 into a training set and a test set according to a certain ratio, the training set is used to build the random forest model, and the test set is used to evaluate the performance of the model. Before training the model, the parameters of the random forest model are initialized, where the parameters include the number of trees, the maximum depth, the maximum number of features, and the minimum number of sample splits; The training set is used to train the initialized random forest model. During the training process, the random forest model generates multiple decision trees by randomly selecting samples and features, and uses out-of-bag data to estimate the model error. Through multiple iterations, the optimal value of each parameter is determined to obtain the optimal model structure and classification performance.

5. The method for screening broad beans for embedded devices based on random forest according to claim 4, characterized in that: S4 is as follows: firstly, the parameter range analysis is performed on the random forest model trained by S3, the distribution range of the parameters of each layer in the trained random forest model is analyzed, and the minimum value, maximum value and dynamic range of each parameter are determined; according to the processing power and memory limitation of the embedded device, the fixed-point quantization bit width is selected, and the floating-point number parameters are mapped to the fixed-point representation, as shown in formula (4): q=round(x×scale) (4) In formula (4), x is a floating point number, scale is a scaling factor, and q is a fixed point representation; After quantization is completed, the quantized random forest model is evaluated on the validation set. The quantization error of the random forest model is calculated and the performance is compared with the model in floating-point form. If quantization causes a significant performance degradation, the quantization bit width or scaling factor can be adjusted. After completing the fixed-point quantization of the random forest model parameters, the random forest model is deployed on the target embedded device.

6. The method for screening broad beans for embedded devices based on random forest according to claim 5, characterized in that: S5 is specifically as follows: using the image sensor on the embedded device to continuously collect images of broad bean samples, converting the collected image data into a data format that matches the input format of the random forest model, performing feature extraction on the converted image data, and the extracted features will be used as the input of the random forest model. The extracted feature vector is input into the random forest model trained in S4 for inference. The random forest model makes classification decisions based on the input features and outputs screening results. According to the decision output of the random forest model, the samples are classified as qualified or unqualified, qualified samples are retained, and unqualified samples are marked as targets that need to be eliminated. After the random forest model makes a decision, the position of the unqualified samples in the image is located and marked in real time. When the marked samples pass the predetermined position, the control system triggers the pneumatic device to generate a high-pressure airflow to remove the unqualified samples from the conveyor belt. After removal, the screening results are recorded, and the qualified and unqualified samples are classified and counted. The overall effect of the screening model and the pneumatic rejection mechanism is evaluated through the statistical results.

Citation Information

Cited By

  • Object image analysis-oriented feature set construction method and device, equipment and medium

    CN121353819A