Disclosure of Invention
The invention aims to provide a high-definition image small target detection method based on an autoencoder and a YOLO algorithm aiming at overcoming the defects of the existing method, and aims to improve the detection precision of the high-definition image small target under the condition of ensuring that the detection speed of the high-definition image is not reduced.
In order to achieve the purpose, the technical scheme of the invention comprises the following steps:
(1) collecting high-definition image data to form a data set, labeling the data set to obtain correct label data, and dividing the data set and the label data into a training set and a test set according to a ratio of 8: 2;
(2) carrying out data expansion on the marked training set;
(3) for each piece of high-definition image data, generating target Mask data of a corresponding image according to the size of the image and the labeling information;
(4) building a full convolution self-encoder model comprising an encoding network and a decoding network, wherein the encoding network is used for carrying out feature extraction and data compression on a high-definition image, and the decoding network is used for restoring a compressed feature map to an original size;
(5) sending high-definition image training set data into a full convolution self-encoder model for training to obtain a trained full convolution self-encoder model:
(5a) initializing the offset of the network to 0, initializing the weight parameters of the network by adopting a kaiming Gaussian initialization method, and setting the iteration times T of the self-encoder according to the size of a high-definition image training set1;
(5b) The partition-based mean square error loss function is defined as follows:
the method comprises the following steps of (1) calculating a Mask-MSE-Loss (y, y _) according to the position of a target region, wherein the Mask-MSE-Loss (y, y _) is a Loss function to be calculated, y is an output image of a decoder, y _ is an input original high-definition image, α is a Loss penalty weight of the target region and is set to be 0.9, β is a background region penalty weight and is set to be 0.1, W is an input image size width of a self-encoder, H is an input image size width of the self-encoder, and Mask (i, j) is a value of the (i, j) th position of Mask;
(5c) inputting high-definition image training set data into a full convolution self-coding network, carrying out forward propagation to obtain a coded feature map, and recovering the feature map through a decoder;
(5d) calculating loss values of the input image and the output image by using the partition area-based mean square error loss function defined in the step (5 b);
(5e) updating the weight and the offset of the full convolution self-encoder by using a back propagation algorithm to finish one iteration of training the full convolution self-encoder;
(5f) repeating (5c) - (5e) until the iteration times T of all the self-encoders are completed1Obtaining a trained full convolution self-encoder;
(6) splicing the coding network of the trained full-convolution self-encoder with a YOLO-V3 detection network, and training the spliced network:
(6a) splicing the coding network of the trained full-convolution self-encoder to the front of a YOLO-V3 detection network to form a spliced mixed network;
(6b) training the spliced hybrid network:
(6b1) reading parameters of the trained full-convolution self-encoder, initializing the coding network by using the read parameter values, and setting the parameters of the coding network in a non-trainable state;
(6b2) setting the input image size of the YOLO-V3 network to be the same as the input size of the full-convolution self-encoder network;
(6b3) downloading pre-trained parameters on ImageNet data sets from a Yolo organ network, initializing the parameters of the Yolo-V3 network by using the parameters, and setting the iteration times T of the Yolo-V3 network according to the size of the acquired data set in the step (1)2;
(6b4) Sending the high-definition image training set data into the spliced hybrid network for forward propagation to obtain an output detection result;
(6b5) calculating a loss value between the output detection result and the correct label data marked in (1) by using a loss function in a YOLO-V3 algorithm;
(6b6) updating the weight and the offset of the hybrid network by using a back propagation algorithm according to the loss value, and completing one iteration of training the hybrid network;
(6b7) repeat (6b4) - (6b6) until all iterations T of YOLO-V3 are completed2Obtaining a trained hybrid network;
(7) and (3) inputting the test set data in the step (1) into the trained mixed model to obtain a final detection result.
Compared with the prior art, the invention has the following advantages:
the invention combines the coding network of the self-encoder with the YOLO-V3 detection network, compresses the high-definition image on the premise of little loss of the target area characteristics through the coding network, and detects the small target of the compressed image through the YOLO-V3 detection network, and the coding network only compresses the background characteristic information and retains the target characteristic information, thereby improving the detection precision of the small target in the high-definition image under the condition of ensuring the detection speed.
Detailed Description
The following describes embodiments and effects of the present invention in further detail with reference to the accompanying drawings, where the embodiments are used for detecting a small target at a sewage discharge port of a high-definition image captured by an unmanned aerial vehicle.
Referring to fig. 1, the implementation steps of this example include the following:
step 1, collecting high-definition images to obtain a training set and a test set.
Acquiring high-definition image data aerial photographed by an unmanned aerial vehicle, wherein the image width is 1920 pixels, and the image height is 1080 pixels;
performing target annotation on the acquired image data by using a common image annotation tool LabelImg to obtain correct label data, as shown in FIG. 2;
the data set and label data were divided into training and test sets in an 8:2 ratio.
And 2, performing data expansion on the marked data set.
2.1) carrying out left-right turning, rotation, translation, noise addition, brightness adjustment, contrast adjustment and saturation adjustment on each high-definition image collected in the unmanned aerial vehicle aerial photography training set;
2.2) adding the processed image data into the original training data set to obtain an expanded training data set.
And 3, generating a target Mask data image of the corresponding image.
3.1) setting a Mask data image as binary image data according to the size and the labeling information of the high-definition image acquired by the unmanned aerial vehicle aerial photography, wherein the width and the height of the Mask data image are the same as those of the high-definition image acquired by the unmanned aerial vehicle aerial photography, namely the image width of the Mask data is 1920 pixels, the height of the Mask data is 1080 pixels, and the number of channels is 1;
3.2) reading the position information of the pixel points in the original image, and setting the values of the pixel points corresponding to the Mask data through the position information:
if the pixel point is in the background area, the value of the Mask data corresponding to the pixel position is set as 0,
if the pixel point is in the target area, the value of the corresponding pixel position of the Mask data is set as 1,
the formula is expressed as follows:
and (i, j) refers to the ith row and the jth column of the pixel point in the unmanned aerial vehicle aerial image data, and Mask (i, j) is the value of the Mask image data at the (i, j) position.
The Mask map generated by the method of fig. 2 according to the 3.2) is shown in fig. 3.
And 4, building a full convolution self-encoder model.
The full convolution self-encoder model comprises an encoding network and a decoding network, wherein the encoding network is used for carrying out feature extraction and data compression on a high-definition image, the decoding network is used for restoring a compressed feature map to an original size, and the building process comprises the following steps:
4.1) building a coding network:
the coding network comprises 5 convolutional layers, wherein each convolutional layer is connected in series, and the parameters of each convolutional layer are set as follows:
a first layer: the convolution kernel size is 3 × 3, the number is 16, the convolution step size is 1, the activation function adopts ReLU, and the output feature size is 1664 × 16;
a second layer: the convolution kernel size is 3 × 3, the number is 32, the convolution step size is 2, the activation function adopts ReLU, and the output feature map size is 832 × 32;
and a third layer: the convolution kernel size is 3 × 3, the number is 64, the convolution step size is 1, the activation function adopts ReLU, and the output feature map size is 832 × 64;
a fourth layer: the convolution kernel size is 3 × 3, the number is 128, the convolution step size is 2, the ReLU is adopted as the activation function, and the output feature map size is 416 × 128;
and a fifth layer: the convolution kernel size is 1 × 1, the number is 3, the convolution step size is 1, the activation function adopts Sigmoid, and the output feature graph size is 416 × 3;
4.2) building a decoding network:
the decoding network comprises 5 deconvolution layers, wherein each deconvolution layer is connected in series, and the parameters of each deconvolution layer are set as follows:
layer 1: the convolution kernel size is 1 × 1, the number is 128, the convolution step size is 1, the ReLU is adopted as the activation function, and the output feature map size is 416 × 128;
layer 2: the convolution kernel size is 3 × 3, the number is 64, the convolution step size is 2, the activation function adopts ReLU, and the output feature map size is 832 × 64;
layer 3: the convolution kernel size is 3 × 3, the number is 32, the convolution step size is 1, the activation function adopts ReLU, and the output feature map size is 832 × 32;
layer 4: convolution kernel size is 3 × 3, number is 16, convolution step is 2, activation function adopts ReLU, output feature size is 1664 × 16;
layer 5: the convolution kernel size is 3 × 3, the number is 3, the convolution step size is 1, the activation function adopts Sigmoid, and the output feature size is 1664 × 3;
the description form of the size of the convolution kernel is w x h, and the meaning of the description form indicates that the width of the convolution kernel is w and the height of the convolution kernel is h;
the characteristic diagram size description form is w x h c, and the meaning of the characteristic diagram size description form is that the width of the characteristic diagram is w pixels, the height of the characteristic diagram is h pixels, and the number of channels is c;
the constructed full convolutional network is shown in fig. 4.
And 5, training the built full convolution self-encoder model.
5.1) initializing network parameters:
initializing the offset of the network to 0, and initializing the weight parameters of the network by adopting a kaiming Gaussian initialization method so as to ensure that the weight parameters are distributed as follows:
wherein: wlIs the weight of the l-th layer; n is Gaussian distribution, namely nominal normal distribution; a being ReLU activation function or LeakyReLU activation functionNegative half-axis slope, nlFor the data dimension of each layer, nlLength of convolution kernel edge2The number of channels is multiplied, and the channels are the number of channels input by each layer of convolution;
the iteration times of the self-encoder are set to 8000 according to the size of the high-definition image training set;
5.2) up-sampling the image data of the training set, and enabling the size of the image data of the up-sampled training set to be the same as the input size of the full convolution network, namely 1664 pixels in width, 1664 pixels in height and 3 in channel number;
5.3) performing up-sampling on the Mask data, wherein the size of the up-sampled Mask data is the same as the data width and height of the full convolution network, namely the width is 1664 pixels, the height is 1664 pixels, and the number of channels is 1;
5.4) inputting the up-sampled image into a full convolution self-coding network, carrying out forward propagation to obtain a coded feature map, and then restoring the feature map through a decoder;
5.5) constructing a mean square error loss function based on the subareas according to the following formula:
the method comprises the steps of calculating a Loss function of a decoder, calculating a Loss function of a Mask-MSE-Loss (y, y), outputting an image by the decoder, inputting an original high-definition image by y, setting α as a Loss penalty weight of a target area to be 0.9, setting β as a background area penalty weight to be 0.1, setting W as a width of input data of the encoder to be 1664, setting H as a height of the data of the encoder to be 1664, and setting Mask (i, j) as a value of the position (i, j) of the data of the Mask image subjected to upsampling;
5.6) calculating the loss value of the input image and the output image by using the loss function of 5.5):
5.7) updating the weight and the offset of the full convolution self-encoder by using a back propagation algorithm to finish one iteration of training the full convolution self-encoder:
5.7.1) updating the weight value by using a back propagation algorithm, wherein the formula is as follows:
wherein: w
t+1Is the updated weight; w
tIs the weight before update; μ is the learning rate of the back propagation algorithm, set here to 0.001;
partial derivative of the loss function of 5.5) with respect to the weight W;
5.7.2) update the offset using a back propagation algorithm, which is formulated as follows:
wherein: b
t+1Is the updated offset; b
tIs the offset before updating; mu is the learning rate of the back propagation algorithm, and the value is 0.001;
partial derivative of the loss function of 5.5) with respect to the offset b;
5.8) repeating the steps from 5.2) to 5.7) until the iteration times of the full convolution self-encoder are completed, and obtaining the trained full convolution self-encoder.
Step 6, splicing the coding network of the full convolution self-encoder and a YOLO-V3 detection network, training the spliced mixed network:
6.1) splicing the coding network of the trained full-convolution self-encoder to the front of a YOLO-V3 detection network to form a spliced mixed network, as shown in FIG. 5;
6.2) training the spliced hybrid network:
6.2.1) reading the parameters of the trained full-convolution self-encoder, initializing the encoding network by using the read parameter values, and setting the parameters of the encoding network in a non-trainable state;
6.2.2) set the input image size of the YOLO-V3 network to be the same as the input size of the full-convolution self-encoder network;
6.2.3) downloading the pre-training parameters on the ImageNet data set from the YoLO official network, initializing the parameters of the YoLO-V3 network by using the parameters, and setting the iteration times of the YoLO-V3 network to be 5000 times according to the size of the acquired data set in the step (1);
6.2.4) sending the high-definition image training set data of the unmanned aerial vehicle aerial photography into the spliced hybrid network for forward propagation to obtain an output detection result;
6.2.5) calculating a loss value between the output detection result and the correct tag data labeled in (1) using a loss function in the YOLO-V3 algorithm,
the loss function in the YOLO-V3 algorithm is expressed as follows:
wherein: lambda [ alpha ]coordSetting the penalty weight of the predicted coordinate loss as 5;
λnoobjsetting the penalty weight of confidence coefficient loss when the target is not detected to be 0.5;
k is the scale size of the output characteristic diagram;
m is the number of bounding boxes;
whether a jth bounding box of an ith unit in the output feature map contains a target or not is judged, if so, the value is 1, otherwise, the value is 0;
and
conversely, if a target is included, the value is 0, otherwise the value is 1;
xithe abscissa value of the predicted central position of the bounding box in the ith cell in the feature map output by the YOLO-V3 network;
the abscissa value of the center position of the actual boundary box in the ith cell is taken as the coordinate value;
yithe ordinate value of the predicted boundary box center position in the ith cell in the feature map output by the YOLO-V3 network;
the vertical coordinate value of the center position of the actual boundary frame in the ith cell;
withe width of the predicted bounding box in the ith cell in the feature map output for the YOLO-V3 network;
the width of an actual bounding box in the ith cell;
hipredicting the height of a bounding box in the ith cell in the feature map output by the YOLO-V3 network;
the height of the actual bounding box in the ith cell;
Ciconfidence of the ith cell prediction output for the YOLO-V3 network;
confidence that the ith cell is true;
pi(c) the probability that the ith cell type in the feature map output by the YOLO-V3 network is c;
is the probability that the ith cell category is c.
6.2.6) updating the weight and the offset of the hybrid network by using a back propagation algorithm according to the loss value calculated by 6.2.5), wherein the updating method of the weight and the offset is the same as the updating formula of 5.7), and one iteration of training the hybrid network is completed;
6.2.7) repeating (6.2.4) to (6.2.6) until all iterations of YOLO-V3 are completed, and obtaining a trained mixed network;
and 7, using the trained network to detect the target.
Inputting the test set data in the step 1 into the trained hybrid model to obtain a final detection result, and detecting a small target in the image, wherein the result is shown in fig. 6.
In fig. 6 and 7, the region where the frame is drawn and the text is noted indicates that the target is successfully detected in the region, and it can be seen from the results of the conventional method in fig. 7 that two obvious small dark-tube targets are not detected in the lower left corner, and one more obvious small dark-tube target is not detected in the lower right corner. Compared with the detection result in fig. 6, the present invention successfully detects the target at the lower left corner and the lower right corner because the spatial characteristics of the target are preserved in the image compression process. Compared with the prior art, the method has obvious advantages in the aspect of small target detection of high-definition images.