Test case priority ranking method fusing clustering algorithm and diversity
Through the integration of clustering algorithms and diversity indicators, the problem of doubtful neuron coverage indicators and ignoring test cases far away from the decision boundary in the prioritization of deep neural network test cases is solved, and efficient test case screening and model fault detection are achieved. Marking costs are reduced and model stability is improved.
Patent Information
- Application Number
- CN202410954101.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-22
AI Technical Summary
In existing deep neural network test case prioritization methods, the neuron coverage indicator is questionable and test cases far away from the decision boundary are ignored, resulting in high detection efficiency and cost.
Using the fusion clustering algorithm and diversity index, through cluster analysis of the training data, the cosine similarity and cluster standard deviation between the test sample and the cluster center are calculated, combined with the maximum-minimum normalization method for weighted sorting, and test cases are generated Priority list.
With limited resources, we can screen out more test cases that expose DNN model faults, improve testing efficiency and coverage, reduce marking costs, and improve model stability and reliability.
Smart Images

Figure CN118820101A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of deep neural network testing, and in particular relates to a test case priority sorting method integrating clustering algorithm and diversity. Background Art
[0002] In the era of big data and artificial intelligence, deep neural networks (DNNs) are developing rapidly and have been widely used in various fields such as computer vision, natural language processing, and speech recognition. Unlike traditional software testing, DNN testing emphasizes the performance and generalization ability of the model, facing the challenges brought by high-dimensional and random inputs. Small perturbations in the data may cause the network to misclassify and produce wrong results, which may lead to loss of life and property. The development of deep neural networks follows a data-centric programming paradigm and is closed to the outside world during runtime, so it is crucial to use sufficient test cases to detect the erroneous behavior of deep neural networks. However, most of the original test cases lack label information, and labeling these test cases is a costly task, especially in some professional fields such as medical imaging and financial analysis.
[0003] In order to improve the efficiency of DNN testing and detect defects in the model at the lowest cost, researchers have proposed a test case prioritization method. This method aims to rearrange the execution order of test cases based on certain indicators of test cases, such as error disclosure ability and test case execution time, and screen out the most representative test cases that are most likely to cause system failures within a limited annotation budget. Nowadays, researchers have proposed a variety of test case prioritization methods for DNN model testing, including coverage-based methods and prediction uncertainty-based methods.
[0004] Coverage-based methods are usually guided by the neuron coverage metric and select test cases that can cover more different neurons. Intuitively, test cases with higher neuron coverage are more likely to find defects in the model. However, during the research process, it was found that only a few test cases are usually needed to achieve a high neuron coverage. In addition, in the traditional software field, the code has a clear running logic, but in DNN, the running logic is usually hidden. For the above reasons, some researchers have questioned the neuron coverage metric. Uncertainty-based methods assign different priorities to test cases by measuring the distance between the test cases and the decision boundary. This method focuses on finding test cases near the boundary. However, test cases close to the boundary are not necessarily misclassified, and this method will also ignore test cases far away from the decision boundary. Summary of the invention
[0005] In view of the deficiencies of the above-mentioned prior art, the purpose of the present invention is to provide a test case prioritization method that integrates clustering algorithms and diversity, so as to solve the problems of questionable neuron coverage indicators and ignoring test cases far from the decision boundary in the test case prioritization method in the prior art. The present invention implements clustering of training data based on a clustering algorithm, and prioritizes test data in combination with two different diversity indicators. The provided method can screen out as many test cases as possible that reveal DNN model faults under limited resources, thereby reducing the test marking cost while improving the testing efficiency of DNN.
[0006] In order to achieve the above object, the present invention adopts the following technical scheme:
[0007] A test case prioritization method integrating clustering algorithm and diversity of the present invention comprises the following steps:
[0008] 1) Use the pre-trained deep neural network model to extract features from the training set and the newly constructed test set to obtain data feature sets of the training set and the test set;
[0009] 2) Use the clustering algorithm to perform cluster analysis on the data features extracted from the training set, and predict each data feature in the test set based on the generated clustering results to obtain the cluster to which each test sample belongs;
[0010] 3) Based on the clustering results, the cosine similarity between the data features of each test sample and the centroid of the cluster to which it belongs is calculated as an indicator to measure the diversity between the test sample and the training set;
[0011] 4) Extract the feature vector of each test sample in the test set, and calculate the standard deviation of each test case cluster based on the clustering results as an indicator to measure the diversity of the test set itself;
[0012] 5) For the values of cosine similarity and cluster standard deviation calculated in step 3) and step 4), the maximum-minimum normalization method is used to process the data, and the normalized results of the two are weighted according to different weights to obtain the final sorting basis, and then generate the final test case priority sorting list.
[0013] Furthermore, the step 1) specifically includes:
[0014] 11) For each test sample in the test set, use the two adversarial attack methods FGSM and BIM to perturb it and generate two adversarial sample sets;
[0015] 12) Randomly select 25% of the adversarial samples from the two adversarial sample sets and select 50% of the test samples from the original test set to form a new test set with different data distribution;
[0016] 13) Input the test cases in the training set and the new test set into the pre-trained DNN model, extract the output of the fully connected layer as the data features of the samples, and obtain the data feature sets of the training set and the new test set;
[0017] 14) Compare and analyze the feature changes of the original test samples and adversarial samples to ensure that the adversarial samples can effectively reveal the uncertainties of the DNN model.
[0018] Furthermore, the step 2) specifically includes:
[0019] 21) Use the elbow method to determine the optimal number of clusters. By plotting the relationship between the clustering loss function value and the number of clusters, find the inflection point as the optimal number of clusters.
[0020] 22) Use K-means clustering algorithm to perform cluster analysis on the data features extracted from the training set, optimize the position of the cluster center through multiple iterations, and finally form a stable cluster;
[0021] 23) Record the center vector of each cluster and save the cluster information to which each sample belongs;
[0022] 24) Verify the stability of the clustering results and repeat the clustering process with different initial conditions to ensure the reliability of the final clustering results;
[0023] 25) Use the clustering results to predict each data feature contained in the test feature set to obtain the cluster to which each test sample belongs.
[0024] Furthermore, the step 3) specifically includes:
[0025] 31) According to the center vector of the cluster obtained in step 21) and step 22) and the cluster prediction result, the cosine similarity between the data feature of each test sample and the centroid of the cluster to which it belongs is calculated to measure the feature difference between the test sample and the cluster to which it belongs;
[0026] 32) Perform statistical analysis on the feature difference values of all test samples to evaluate the similarity distribution of different test samples relative to their respective cluster centers. Test samples with low similarity may represent some uncertainty in the model when processing these samples, and need to be given higher priority during the test process;
[0027] 33) For samples with lower similarity, further analyze their possible misclassification risks and determine their importance in test priority sorting.
[0028] Furthermore, the step 4) specifically includes:
[0029] 41) Use the feature extraction model to extract the feature vector of each test sample in the test set to ensure that the features can fully represent the diversity of the samples;
[0030] 42) Based on the cluster prediction results in step 2), calculate the standard deviation of each test case cluster, measure the dispersion of samples within the cluster, and evaluate the distribution of samples in the cluster;
[0031] 43) By comparing the standard deviations of different clusters, we can identify test samples with higher diversity, which may be more likely to reveal potential defects of the model due to the diversity of their features.
[0032] Furthermore, the step 5) specifically includes:
[0033] 51) According to the values of cosine similarity and standard deviation calculated in step 3) and step 4), the data scales of features of different orders of magnitude are unified by using the maximum-minimum normalization method and mapped to the value range of [0, 1] to ensure consistency of data processing;
[0034] 52) The normalized cosine similarity and standard deviation are weighted according to the preset weights to obtain a comprehensive score for each test sample;
[0035] 53) Generate a priority list of test cases based on the comprehensive scores, give priority to test samples with higher comprehensive scores, and maximize the utilization efficiency of test resources;
[0036] 54) Verify the effectiveness of the sorting results, evaluate the performance of the sorting method on different test sets through experiments, and adjust the parameters to obtain the best test results.
[0037] Beneficial effects of the present invention:
[0038] The present invention sorts deep neural network test cases. Firstly, a trained DNN model is used to extract features from a training set and a newly constructed test set, respectively, to obtain data feature sets of the training set and the test set. Secondly, a clustering algorithm is used to perform cluster analysis on the data features extracted from the training set, and each data feature in the test set is predicted according to the generated clustering results to obtain the cluster to which each test sample belongs. Then, the cosine similarity between the test case and the cluster center and the standard deviation of the test case set are calculated, and the test data are prioritized by combining two different diversity indicators.
[0039] Specifically, there are the following advantages:
[0040] 1. The present invention realizes efficient priority sorting of deep neural network test cases by integrating clustering algorithm and diversity analysis. The clustering algorithm can effectively classify the training data, while the diversity analysis can evaluate the diversity of test cases and improve the pertinence of test case selection, thereby improving the test efficiency.
[0041] 2. This paper uses two diversity indicators, cosine similarity and standard deviation, to sort test cases, ensuring that not only the similarity between test cases and training data is considered, but also the diversity between test cases is taken into account. In this way, more test cases that may reveal defects in the DNN model can be screened out under limited resources, thereby improving the coverage and effectiveness of the test.
[0042] 3. By giving priority to test cases with high diversity and potential defect revealing capabilities, the present invention can reduce unnecessary test case labeling work and reduce testing costs. Especially in fields with high labeling costs, such as medical imaging and financial analysis, the method of the present invention has significant economic benefits.
[0043] 4. The method of the present invention can not only effectively identify defects in the DNN model, but also guide the retraining of the model, thereby improving the robustness of the model. By prioritizing the marking of high-priority test cases and retraining the model, the stability and reliability of the model in practical applications can be significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 Schematic diagram of the method of the present invention.
[0045] Figure 2 This is a schematic diagram of clustering the data features extracted from the training set in the present invention.
[0046] Figure 3 A flowchart for constructing a sorted list in the present invention. DETAILED DESCRIPTION
[0047] In order to facilitate the understanding of those skilled in the art, the present invention is further described below in conjunction with embodiments and drawings. The contents mentioned in the implementation modes are not intended to limit the present invention.
[0048] Reference Figure 1 As shown, a test case prioritization method integrating clustering algorithm and diversity of the present invention comprises the following steps:
[0049] Step 1): Use the trained LeNet-1, LeNet-5, and ResNet-20 DNN models to extract features from the training set and the newly constructed test set to obtain the data feature sets of the training set and the test set. In the example,
[0050] 11) Use the CIFAR-10 training set to train the ResNet-20 model, optimize the model's weight parameters through multiple rounds of iterations, and obtain a trained model (abbreviated as D);
[0051] 12) Use two adversarial attack methods FGSM and BIM to slightly perturb the CIFAR10 test set, and merge 25% of the perturbed test set of the FGSM method, 25% of the perturbed test set of the BIM method, and 50% of the original test set into a new test set (abbreviated as T). The new test set T contains 10,000 test samples;
[0052] 13) Input the training set and the new test set T into the ResNet-20 model, extract the output of the fully connected layer of the model as the data feature, and obtain the data feature set F of the training set train And the data feature set F of the new test set T test .
[0053] Step 2): Use the K-means clustering algorithm to perform cluster analysis on the data features extracted from the training set, and predict each data feature in the test set based on the generated clustering results to obtain the cluster to which each test sample belongs; refer to Figure 2 As shown in the example,
[0054] 21) Use the elbow method to determine the optimal number of clusters k. By plotting the relationship between the clustering loss function value and the number of clusters, find the inflection point as the optimal number of clusters k;
[0055] 22) Use K-means clustering algorithm to extract data features F from the training set train Perform cluster analysis and optimize the location of cluster centers through multiple iterations;
[0056] 23) Record the center vector of each cluster as {Q 1 , Q 2 , …, Q k}, where Q k Represents the center vector of the kth cluster, saving the cluster information to which each sample belongs;
[0057] 24) Verify the stability of the clustering results, repeat the clustering process with different initial conditions to ensure the reliability of the results, and record the predicted results as R;
[0058] 25) Use the clustering result R to test the feature set F test Each feature in is predicted to obtain the cluster to which each test sample belongs.
[0059] Step 3): According to the clustering results obtained in step 2), the feature difference value between the data feature of each test sample and the centroid of the cluster to which it belongs is calculated as an indicator to measure the diversity between the test sample and the training set; in the example,
[0060] 31) In the test set T, given a test sample t(t∈T), assume that the output vector of the fully connected layer of t on the tested model D is P = {p 1 , p 2 , ..., p n}, the center vector of the cluster to which the test sample belongs is Q = {q 1 ,q 2 , ..., q n}, calculate the cosine similarity between the test sample t and the centroid of the cluster to which it belongs:
[0061]
[0062] 32) The cosine similarity value is used as the characteristic difference value of the test sample for statistical analysis to evaluate the similarity distribution of different test samples relative to their respective cluster centers.
[0063] 4) Use the feature extraction model to extract the feature vector of each test sample in the test set. According to the prediction results in step 2), calculate the standard deviation of each test case cluster as an indicator to measure the diversity of the test set itself; in the example,
[0064] 41) Use the feature extraction model VGG-16 to extract the feature vector of each test sample in the test set T, combine all the feature vectors, and obtain the feature matrix F vgg ;
[0065] 42) Define the STD metric as the L1 norm of the standard deviation of each feature in the test case set. Based on the clustering prediction results in step 25), calculate the standard deviation of each test case cluster. Given a test case set S of size n, the specific formula for calculating the standard deviation between test cases in the set is as follows:
[0066]
[0067] Where m is the number of features, μ j Yes F vgg The average value of the jth feature in .
[0068] 43) By comparing the standard deviations of different clusters, we can identify test samples with higher diversity.
[0069] 5) For the values of cosine similarity and standard deviation within the cluster calculated in step 3) and step 4), the data is processed by the maximum-minimum normalization method, and the normalized results of the two are weighted according to different weights to obtain the final sorting basis, and then generate the final test case priority sorting list; refer to Figure 3 As shown in the example,
[0070] 51) According to the cosine similarity and standard deviation values calculated in step 3) and step 4), the data scales of features of different orders of magnitude are unified using the maximum-minimum normalization method and mapped to the value range of [0, 1]. The normalization calculation of the standard deviation is as follows:
[0071]
[0072] Where STD is the original data, STD norm is the normalized data, STD min is the minimum value of the data, STD max is the maximum value of the data.
[0073] 52) The normalized cosine similarity and standard deviation are weighted with weights of 0.7 and 0.3 to obtain a comprehensive score for each test sample;
[0074] 53) Generate a prioritized list of test cases for the test set T based on the comprehensive scores, and give priority to selecting the top 100 test samples with the comprehensive scores to test the model D, and observe whether the test cases can reveal as many model errors as possible;
[0075] The present invention has many specific application paths. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements can be made without departing from the principle of the present invention. These improvements should also be regarded as the protection scope of the present invention.
Claims
1. A test case prioritization method integrating clustering algorithm and diversity, characterized in that: Here are the steps: 1) Use the pre-trained deep neural network model to extract features from the training set and the newly constructed test set to obtain data feature sets of the training set and the test set; 2) Use the clustering algorithm to perform cluster analysis on the data features extracted from the training set, and predict each data feature in the test set based on the generated clustering results to obtain the cluster to which each test sample belongs; 3) Based on the clustering results, the cosine similarity between the data features of each test sample and the centroid of the cluster to which it belongs is calculated as an indicator to measure the diversity between the test sample and the training set; 4) Extract the feature vector of each test sample in the test set, and calculate the standard deviation of each test case cluster based on the clustering results as an indicator to measure the diversity of the test set itself; 5) For the values of cosine similarity and cluster standard deviation calculated in step 3) and step 4), the maximum-minimum normalization method is used to process the data, and the normalized results of the two are weighted according to different weights to obtain the final sorting basis, and then generate the final test case priority sorting list.
2. The test case prioritization method integrating clustering algorithm and diversity according to claim 1, characterized in that: The step 1) specifically includes: 11) For each test sample in the test set, use the two adversarial attack methods FGSM and BIM to perturb it and generate two adversarial sample sets; 12) Randomly select 25% of adversarial samples from each of the two adversarial sample sets, and select 50% of the test samples from the original test set to form a new test set with different data distribution; 13) Input the test cases in the training set and the new test set into the pre-trained DNN model, extract the output of the fully connected layer as the data features of the samples, and obtain the data feature sets of the training set and the new test set; 14) Compare and analyze the feature changes of the original test samples and adversarial samples to ensure that the adversarial samples can effectively reveal the uncertainties of the DNN model.
3. The test case prioritization method integrating clustering algorithm and diversity according to claim 1, characterized in that: The step 2) specifically includes: 21) Use the elbow method to determine the optimal number of clusters. By plotting the relationship between the clustering loss function value and the number of clusters, find the inflection point as the optimal number of clusters. 22) Use K-means clustering algorithm to perform cluster analysis on the data features extracted from the training set, optimize the position of the cluster center through multiple iterations, and finally form a stable cluster; 23) Record the center vector of each cluster and save the cluster information to which each sample belongs; 24) Verify the stability of the clustering results and repeat the clustering process with different initial conditions to ensure the reliability of the final clustering results; 25) Use the clustering results to predict each feature in the test feature set to obtain the cluster to which each test sample belongs.
4. The test case prioritization method integrating clustering algorithm and diversity according to claim 1, characterized in that: The step 3) specifically includes: 31) According to the center vector of the cluster obtained in step 2) and the result of cluster prediction, the cosine similarity between the data feature of each test sample and the centroid of the cluster to which it belongs is calculated to measure the feature difference between the test sample and the cluster to which it belongs; 32) Perform statistical analysis on the feature difference values of all test samples to evaluate the similarity distribution of different test samples relative to their respective cluster centers; 33) For samples with lower similarity, further analyze their possible misclassification risks and determine their importance in test priority sorting.
5. The test case prioritization method integrating clustering algorithm and diversity according to claim 1, characterized in that: The step 4) specifically includes: 41) Use the feature extraction model to extract the feature vector of each test sample in the test set to ensure that the features can fully represent the diversity of the samples; 42) Based on the cluster prediction results in step 2), calculate the standard deviation of each test case cluster, measure the dispersion of samples within the cluster, and evaluate the distribution of samples in the cluster; 43) By comparing the standard deviations of different clusters, we can identify test samples with higher diversity, which may be more likely to reveal potential defects of the model due to the diversity of their features.
6. The test case prioritization method integrating clustering algorithm and diversity according to claim 1, characterized in that: The step 5) specifically includes: 51) According to the values of cosine similarity and standard deviation calculated in step 3) and step 4), the data scales of features of different orders of magnitude are unified by using the maximum-minimum normalization method and mapped to the value range of [0, 1] to ensure consistency of data processing; 52) The normalized cosine similarity and standard deviation are weighted according to the preset weights to obtain a comprehensive score for each test sample; 53) Generate a priority list of test cases based on the comprehensive scores, give priority to test samples with higher comprehensive scores, and maximize the utilization efficiency of test resources; 54) Verify the effectiveness of the sorting results, evaluate the performance of the sorting method on different test sets through experiments, and adjust the parameters to obtain the best test results.
Citation Information
Cited By
Test case dynamic priority scheduling method for automobile electronic chip
CN120973693A
