Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a search-based expandable optimal test image set generation method, which can generate an optimal test image set with small scale, high coverage rate and strong expandability.
The invention is realized by the following technical scheme:
a method for generating an expandable optimal test image set based on search comprises the following steps:
step S1, a plurality of test images are randomly selected from the test pool to form a test image set, and then the plurality of test image sets form an initial current population;
step S2, for each test image set individual in the current population, calculating the corresponding coverage rate of each test image set under the image classification deep neural network system to be tested and the scale of each test image set, and selecting M optimal test image sets in the current population as the population of the next iteration by using a tournament selection method according to the steps S21-S26;
step S21, initializing the population of the next iteration as an empty set;
step S22, randomly selecting from the current population
A test image set as an contestant of the tournament selection method;
step S23, sorting the selected competitors from small to large according to the scale of the test image set to obtain a sorted competitor list;
step S24, sorting the sorted election competitor lists according to the coverage rate from large to small to obtain a secondarily sorted election competitor list;
step S25, according to the secondarily sorted competitor list obtained in step S24, selecting the test image set with the first rank in the list as a winner to enter a population of the next iteration;
step S26, repeating the step S22-the step S25 for M times to obtain M optimal test image sets as a population of the next iteration;
step S3, taking the population of the next iteration selected in the step S2 as a parent, and performing operation by using a cross operator to obtain a new population;
step S4, performing mutation operation on the test image layer and the test image set layer on the new population obtained in the step S3 to obtain a mutated offspring individual; wherein, the mutation operation of the test image set level means: for each test image set, randomly reducing one test image or randomly increasing one test image from a test pool by a first set probability; the mutation operation of the test image layer is as follows: for each test image set, selecting one test image from the test image set according to a second set probability to perform affine transformation and/or pixel transformation;
step S5, selecting the current population which is obtained in step S4 and has the coverage rate higher than that of the parent individuals or the coverage rate which is the same as that of the parent individuals but smaller in scale to form the next iteration, and then repeating the steps S2-S5; and (4) presetting an iteration termination condition according to the allocated time and space resources, judging whether the iteration termination condition is met or not in each iteration, stopping if the iteration termination condition is met, and otherwise, continuing to perform the subsequent steps.
In the above technical solution, in step S2, the measurement is calculated according to the following formulaAttempting to cover the individual image set
:
Wherein N represents the total neuron set of the deep neural network to be tested, N represents the total neuron set of the deep neural network to be tested
NL represents the number of neurons in the deep neural network to be tested,
kthe number of intervals into which the value of each neuron is divided is represented,
indicating that the test image T covers the ith interval in the test image set individual T,
is a set of k intervals into which the neuron n is sliced.
In the above technical solution, step S3 is performed according to the following steps:
step S31, grouping the test image sets in the next iteration population obtained in the step S2 into two groups;
step S32, for two test image sets in the same group, a value between 0 and 1 is randomly selected as a percentage threshold, the test image data before the percentage threshold in each test image set is kept unchanged, and the test image data after the percentage threshold is subjected to equal sequence interchange between the two test image sets.
In the above technical solution, the affine transformation includes: translation, zoom, flip, rotate, and shear; the pixel transformation performs transformation of pixel point values by adjusting contrast and brightness.
In the foregoing technical solution, step S4 further includes setting constraint conditions for mutation, where the constraint conditions for mutation include that a rotation angle in image transformation is less than 15 degrees, affine transformation is allowed at most once, and a pixel ratio of each mutation cannot exceed 2%.
The invention also provides a computer-readable storage medium, in which a computer program is stored which, when being executed, carries out the above-mentioned method steps.
The invention has the advantages and beneficial effects that:
the invention creatively provides an extensible optimal test image set generation framework based on search, which generates a test image set aiming at an image classification neural network with the coverage rate as high as possible and the scale as small as possible by modifying a genetic algorithm and utilizing iterative operation of selection, intersection and mutation operators. Particularly, by setting the fitness giving consideration to both the coverage rate and the scale of the test image set, the invention innovatively achieves the optimal balance under two incompatible targets of high coverage rate and small scale, thereby ensuring that the test of the image classification neural network model can be completed as comprehensively as possible with the minimum labeling cost.
Detailed Description
In order to make the technical solution of the present invention better understood, the technical solution of the present invention is further described below with reference to specific examples.
Example one
Referring to fig. 1, a method for generating a search-based expandable optimal test image set includes the following steps:
step S1, a test pool P is formed by a plurality of unmarked test images, a plurality of test images are randomly selected from the test pool P to form a test image set, and a plurality of test image sets T are used1,T2 ......TnConstituting the initial current population.
Step S2, for each test image set individual in the current population, calculating the corresponding coverage rate of each test image set under the deep neural network system to be tested and the scale of each test image set so as to obtain the fitness of each test image set, and selecting M test image set individuals with the best fitness as the population of the next iteration; specifically, step S2 is performed as follows:
step S21, for each individual T of the test image sets in the current population, calculating the coverage rate cov (T) of each test image set according to the selected evaluation index; in this example, KMNC is selected as an index for measuring the coverage, which is defined as the ratio of the coverage fraction to the total number of parts, and the coverage cov (T) of the individual T of the test image set is calculated according to the following formula:
wherein N represents the total neuron set of the deep neural network to be tested, N represents the total neuron set of the deep neural network to be tested
NL represents the number of neurons in the deep neural network to be tested,
kthe number of intervals into which the value of each neuron is divided is represented,
indicating that the test image T covers the ith interval in the test image set individual T,
is a set of k intervals into which neuron n is sliced;
step S22, calculating the number of the test images of each test image set individual T in the current population to obtain len (T);
step S23, calculating the fitness of each test image set according to the coverage index of each test image set and the number of the test images calculated in steps S21 and S22, that is, for a given test image set T, the coverage cov (T) of each test image set calculated in steps S21 and S22 and the number len (T) of the test images are merged (i.e. two values are merged into a tuple) to form a fitness tuple fitness (T) = (cov (T), len (T));
step S24, selecting a certain number of best test image sets with good fitness as the population of the next iteration by using a championship algorithm, specifically, the step S24 is performed according to the following steps:
step S241, initializing the population of the next iteration as an empty set;
step S242, randomly selecting from the current population
A test image set as an contestant of the tournament selection method;
step S243, sorting the selected competitors in ascending order according to the scale of the test image set to obtain a sorted competitor list;
step S244, sorting the sorted election competitor list according to the coverage rate to obtain a secondarily sorted election competitor list;
step S245, according to the election list obtained in step S244 after secondary sorting, selecting a test image set ranked first in the list as a winner to enter a next iteration population, namely selecting an individual with the best fitness to enter the next iteration population;
and step S246, repeating the steps S242 to S245 for M times, so as to obtain M optimal test image sets as the population of the next iteration.
Step S3, taking the population of the next iteration selected in the step S2 as a parent, and performing operation by using a cross operator to obtain a new population; specifically, step S3 is performed as follows:
step S31, grouping the test image sets in the next iteration population obtained in step S2 in pairs to obtain
,
), … ,
;
Step S32, for two test image sets in the same group, a value between 0 and 1 is randomly selected as a percentage threshold, the test image data in front of the percentage threshold in each test image set is kept unchanged, and the test image data behind the percentage threshold are exchanged between the two test image sets in an equal sequence to obtain a new population. For example, if each test image set includes 100 test image data, and 0.5 is selected as the percentage threshold (i.e., 50%), then the data of the first 50 test images of each test image set in the same group remains unchanged, and the data of the last 50 test images are interchanged in equal order between the two test image sets, e.g., the 51 st test image data in one test image set is interchanged with the 51 st test image data in the other test image set, the 52 nd test image data in one test image set is interchanged with the 52 nd test image data in the other test image set, and so on.
Step S4, performing variation operation on the test image level and the test image set level on the new population obtained in the previous step to obtain a variant offspring individual; the method comprises the following steps:
step S41, for each test image set in the population, randomly increasing or decreasing the test images to implement the variation on the test image set level, specifically: for each test image set in the population, randomly selecting a test image from the test pool with a probability of ε (e.g., randomly selecting a test image from the test pool with a probability of 50% to add, i.e., a 50% probability would be selected for a test image and a 50% probability would not be selected for either; for each test image set in the population, randomly deleting a test image therefrom with a probability of η (e.g., randomly deleting a test image therefrom with a probability of 30%, i.e., a 30% likelihood that a test image will be deleted, a 70% likelihood that neither will be deleted; if a test image is deleted, the test image is a random one of the test image sets);
step S42, randomly mutating the test image of each individual in the population obtained in step S41; specifically, step S42 includes:
step S421, selecting one of the test images with a probability of ξ for each test image set in the population obtained in step S41, and performing step S422 (that is, one of the test images may not be selected and at most one is selected);
step S422, performing image mutation on the test image selected in step S421, where the common methods of image mutation are affine transformation and pixel transformation, the affine transformation is a linear transformation from two-dimensional coordinates to two-dimensional coordinates, and the affine transformation can be implemented by compounding a series of atomic transformations, including: translation (Translation), scaling (Scale), Flip (Flip), Rotation (Rotation), and cut (Shear); the pixel transformation performs transformation of pixel point values by adjusting contrast and brightness.
And step S423, making a proper constraint condition to ensure that the test images before and after the mutation are still highly similar. Suitable constraint conditions include that the rotation angle in image transformation is less than 15 degrees, affine transformation is allowed at most once, and the percentage of pixels mutated at each time cannot exceed 2%. In specific implementation, appropriate constraint conditions can be formulated according to actual conditions and optimization objectives.
Step S5, selecting the current population which is obtained in the last step and has the coverage rate higher than that of the parent individuals or the coverage rate which is the same as that of the parent individuals but smaller in scale to form the next iteration, and then repeating the steps S2-S5; and presetting a proper iteration termination condition according to the allocated time and space resources, judging whether the iteration termination condition is met or not in each iteration, stopping if the iteration termination condition is met, and otherwise, continuing to perform the subsequent steps.
Example two
On the basis of the above embodiment, the search-based extensible optimal test image set generation method of the present invention is described and verified below with reference to specific experimental data.
Currently, common public image datasets are MNIST, CIFAR-10, and the like.
The MNIST image data set comprises 60000 training images and 10000 training images, each image is a black and white image of a handwritten number, and for the data set, the LeNet image classification neural network model is trained in the embodiment, LeNet is a classical image classification deep learning convolution neural network model, and the commonly used versions comprise: LeNet-1, LeNet-4 and LeNet-5.
The CIFAR-10 image data set is composed of 50000 training images and 10000 training images, each image is a color image, and for the data set, two image classification deep learning convolutional neural network models of VGG-16 and ResNet-20 are trained in the embodiment.
To verify the effect of the search-based expandable optimal test image set generation method (DS method), the present embodiment uses 5 test indexes (NC, KMNC, NBC, SNAC, TKNC) to perform experiments on the MNIST image data set and the CIFAR-10 image data set to verify that the optimal trade-off can be achieved on two incompatible objectives, i.e., high test fullness and small test image set size. Experiments were performed on a total of 5 image classification deep neural network models, namely LeNet-1, LeNet-4, LeNet-5, which were experimented on the MNIST image dataset, and VGG-16 and ResNet-20, which were experimented on the CIFAR-10 image dataset.
Moreover, comparison experiments are carried out on the DS method of the invention and three methods of a traditional gradient-based method, a greedy algorithm (the maximum experiment frequency is 80) and a k-clustering algorithm (k is 10 in the experiment) in an experimental test image set consisting of 5000 test images randomly selected from an original data set. Each method was run for 30 rounds. For the DS method of the present invention, the number of individuals in the initial current population is 80, and each individual contains 6 test image inputs randomly selected from the test pool. The probability of mutation operation, including addition, deletion and mutation, is 0.3, and the DS method and the greedy algorithm of the present invention are set to the same mutation constraint condition for controlling the variables. The experimental data are shown in the following table:
in the table, M: a class of deep neural network models representing image classification; m1: representing a LeNet-1 image classification depth neural network model; m2: representing a LeNet-4 image classification depth neural network model; m3: representing a LeNet-5 image classification depth neural network model; m4: a deep neural network model representing ResNet-20 image classification; m5: representing a VGG-16 image classification deep neural network model; mtd: representing the kind of test image set generation method; CL: the Clustering Algorithm represents a k-Clustering Algorithm; GE: the Greedy Algorithm, namely The Greedy Algorithm; GA: the Gradient-based Algorithm, represents a Gradient-based approach; and (2) DS: namely, the expandable optimal test image set generation method DeepsuiteAlgorithm based on search of the invention; NC, KMNC, NBC, SNAC, TKNC are some common coverage indicators, where NC: NeuronCoverage, which represents the neuron coverage rate and represents the percentage of the number of neurons covered by the test image set T in the total number of neurons; KMNC: ratio of fraction covered to total number of fractions; NBC, neuro boundarycoverage, neuron boundary coverage, represents the percentage of the number of neurons whose neuron values exceed the upper and lower bounds of the training set relative to the total number of neurons; SNAC, Strong Neuron Activation Coverage; TKNC: top-k Neuron Coverage, which indicates the presence of images from the test image set T, is such that the number of neurons having a value of k, which is the maximum of the Neuron values in the current layer, is a percentage of the total number of neurons.
The previous data in each data box in the table represents the highest coverage (%), and the second data represents the test image set size. For example: 28.8 (19) in the first data box, 28.8 indicates the highest coverage is 28.8%, and 19 indicates the test image set size is 19.
As can be seen from the table, the DS method of the present invention achieves the highest coverage in 21 of 25 sample cases, so that the test image sets generated by the DS method are more diverse than those generated by other methods. For example, the index advantage of the DS method on NC coverage rate indicates that the test image set obtained by the DS method can activate neurons which are not activated by the test image set obtained by some other method.
Meanwhile, the DS method of the invention achieves the aim of considering both high coverage rate and minimizing the scale of the test image set in 13 cases of 25 samples. Furthermore, it can be seen that in some cases, the DS method does not obtain the smallest-scale test image set, but the coverage rate is much higher than that of the test image sets obtained by other methods.
The invention has been described in an illustrative manner, and it is to be understood that any simple variations, modifications or other equivalent changes which can be made by one skilled in the art without departing from the spirit of the invention fall within the scope of the invention.