Training device of yolox model for face and face attribute detection
Patent Information
- Application Number
- CN202211363343.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-02
- Publication Date
- 2026-10-16
- Estimated Expiration
- 2042-11-02
AI Technical Summary
[0005]本发明要解决的技术问题在于,针对现有技术的上述缺陷,提供一种用于人脸及人脸属性检测的yolox模型的训练装置,旨在解决现有技术中采用深度学习模型进行人脸检测和人脸属性检测,模型加载时间、推理时间以及训练时间长的问题
[0016]The beneficial effects of this invention are as follows: The face reconstruction model constructed using the YOLOx model can simultaneously output the detection results of the face and its attributes, reducing model loading and inference time. Furthermore, the training device of this invention includes a data processing and reading unit. During supervised training of the face reconstruction model, the detection data in TXT format can be read through this unit, reducing the difficulty of data reading during model training. This solves the problems of long model loading, inference, and training times in existing technologies using deep learning models for face detection and facial attribute detection.
Smart Images

Figure CN115690879B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more particularly to a training device for a YOLOx model for face and face attribute detection. Background Technology
[0002] With the rise of fields such as target monitoring, target tracking, human-computer interaction, and people flow statistics, face detection technology has received increasing attention. Face detection technology based on neural network models has made great progress. However, existing technologies typically use two neural network models to implement face detection and face attribute detection separately, such as whether the face is wearing sunglasses, glasses, or a mask. This increases model loading and inference time, making it difficult to quickly complete face detection and face attribute detection.
[0003] With the development of deep learning technology, the YOLO series models have demonstrated outstanding performance in object detection. The YOLO series is a novel end-to-end object detection model capable of predicting the location and category of objects, while the end-to-end training method improves accuracy. The YOLO series has continuously evolved from YOLOv1 to YOLOv5 and then to YOLOX, and is widely used in the field of object detection. YOLOX offers relatively fast detection speed, but its underlying backbone network structure for feature extraction is complex, with numerous parameters and high computational cost. Furthermore, because YOLOX uses the COCO format, data reading during model training is complex, increasing training time.
[0004] Therefore, existing technologies still need improvement and development. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a training device for a YOLOx model for face and face attribute detection, which addresses the above-mentioned deficiencies of the prior art. The aim is to solve the problems of long model loading time, inference time and training time when using deep learning models for face detection and face attribute detection in the prior art.
[0006] The technical solution adopted by this invention to solve the problem is as follows:
[0007] In a first aspect, embodiments of the present invention provide a training apparatus for a YOLOx model for face and face attribute detection, comprising: a prediction unit for inputting an image to be detected into an initial YOLOx model to perform face and face attribute detection and obtain detection results; a training data storage unit for storing training data in TXT format; a data processing and reading unit for reading the training data and calculating the loss function of the initial YOLOx model with the detection results; and an iterative correction unit for iteratively correcting the initial YOLOx model according to the loss function of the initial YOLOx model until a preset condition is reached to end the training, and using the YOLOx model that has reached the preset condition as the target face reconstruction model.
[0008] In one implementation, the initial YOLOx model includes: a feature extraction unit built on a lightweight DepthNet, used to extract features from the image to be detected to obtain a target feature map; and a detection unit used to perform face and face attribute detection on the target feature map to obtain the detection result, wherein the detection result includes the attribute category, face bounding box coordinates, and face judgment result corresponding to the image to be detected.
[0009] In one embodiment, the feature extraction unit includes a first feature extraction unit, a second feature extraction unit, and a merging unit. The step of extracting features from the image to be detected to obtain a target feature map includes: inputting the image to be detected into the first feature extraction unit and the second feature extraction unit respectively; and inputting the output data corresponding to the first feature extraction unit and the second feature extraction unit respectively into the merging unit to obtain the target feature map.
[0010] In one embodiment, both the first feature extraction unit and the second feature extraction unit include a first convolutional layer, a normalization layer, a first activation layer, a second convolutional layer, and a second activation layer cascaded in sequence; the second convolutional layer corresponding to the first feature extraction unit includes two convolutional blocks, the output data of one convolutional block of the second convolutional layer corresponding to the first extraction unit is directly input into the merging unit, and the output data of the other convolutional block is input into the merging unit after passing through the second activation layer corresponding to the first extraction unit.
[0011] In one embodiment, the detection unit includes a classification branch and a regression and judgment branch. The step of performing face and face attribute detection on the target feature map to obtain the detection result includes: inputting the target feature map into the classification branch and the regression and judgment branch respectively; outputting the attribute category through the classification branch; and outputting the face bounding box coordinates and the confidence level corresponding to the face judgment result through the regression and judgment branch.
[0012] In one implementation, the regression and judgment branches include a regression branch and a judgment branch; the calculation process of the loss function of the initial YOLOx model includes: determining the classification loss function corresponding to the classification branch based on the attribute category output by the classification branch and the classification label in the training data; determining the regression loss function corresponding to the regression branch based on the face bounding box coordinates output by the regression branch and the face bounding box label in the training data; determining the judgment loss function corresponding to the judgment branch based on the confidence level corresponding to the face judgment result output by the judgment branch and the confidence level label in the training data; and determining the loss function of the initial YOLOx model based on the classification loss function, the regression loss function, and the judgment loss function.
[0013] In one implementation, the loss function of the initial YOLOx model is calculated as follows: loss = reg_weight * loss_bbox + loss_cls + loss_obj, where loss is the loss function of the initial YOLOx model; loss_bbox is the regression loss function; reg_weight is the weight corresponding to the regression loss function; loss_cls is the classification loss function; and loss_obj is the decision loss function. The regression loss function is calculated as follows: loss_bbox = 1 - IoU * IoU; where IoU is the ratio of the intersection to the union of the bounding box corresponding to the face bounding box coordinates and the bounding box corresponding to the face bounding box label. The classification loss function is the cross-entropy between the attribute category output by the classification branch and the classification label; the decision loss function is the cross-entropy between the confidence score output by the decision branch and the confidence score label.
[0014] Secondly, embodiments of the present invention also provide a method for detecting faces and facial attributes, characterized in that the method includes: acquiring a face image to be detected; inputting the face image to be detected into a target face reconstruction model to obtain the face and facial attribute detection results corresponding to the face image to be detected, wherein the target face reconstruction model is pre-trained by a training device for a YOLOx model for face and facial attribute detection as described above.
[0015] Thirdly, embodiments of the present invention also provide a computer-readable storage medium storing a plurality of instructions, wherein the instructions are adapted to be loaded and executed by a processor to implement the steps of the face and face attribute detection method described above.
[0016] The beneficial effects of this invention are as follows: The face reconstruction model constructed using the YOLOx model can simultaneously output the detection results of the face and its attributes, reducing model loading and inference time. Furthermore, the training device of this invention includes a data processing and reading unit. During supervised training of the face reconstruction model, the detection data in TXT format can be read through this unit, reducing the difficulty of data reading during model training. This solves the problems of long model loading, inference, and training times in existing technologies using deep learning models for face detection and facial attribute detection. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is a schematic diagram of a unit of a training device for a YOLOx model for face and face attribute detection provided in an embodiment of the present invention.
[0019] Figure 2 This is a schematic diagram of the structure of the YOLOX model provided in an embodiment of the present invention.
[0020] Figure 3 This is a schematic diagram of the detection unit for wearing a mask provided in an embodiment of the present invention.
[0021] Figure 4 This is a flowchart illustrating the face and face attribute detection method for pure human faces provided in an embodiment of the present invention.
[0022] Figure 5 This is a schematic diagram of the terminal provided in the embodiment of the present invention. Detailed Implementation
[0023] This invention discloses a training apparatus for a YOLOx model used for face and face attribute detection. To make the objectives, technical solutions, and effects of this invention clearer and more explicit, the invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only for explaining the invention and are not intended to limit the invention.
[0024] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0025] It will be understood by those skilled in the art that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0026] With the rise of fields such as target monitoring, target tracking, human-computer interaction, and people flow statistics, face detection technology has received increasing attention. Face detection technology based on neural network models has made great progress. However, existing technologies typically use two neural network models to implement face detection and face attribute detection separately, such as whether the face is wearing sunglasses, glasses, or a mask. This increases model loading and inference time, making it difficult to quickly complete face detection and face attribute detection.
[0027] With the development of deep learning technology, the YOLO series models have demonstrated outstanding performance in object detection. The YOLO series is a novel end-to-end object detection model capable of predicting the location and category of objects, while the end-to-end training method improves accuracy. The YOLO series has continuously evolved from YOLOv1 to YOLOv5 and then to YOLOX, and is widely used in the field of object detection. YOLOX offers relatively fast detection speed, but its underlying backbone network structure for feature extraction is complex, with numerous parameters and high computational cost. Furthermore, because YOLOX uses the COCO format, data reading during model training is complex, increasing training time.
[0028] To address the aforementioned deficiencies in existing technologies, this invention provides a training device for a YOLOx model used for face and facial attribute detection. The training device includes: a prediction unit for inputting an image to be detected into an initial YOLOx model to perform face and facial attribute detection and obtain detection results; a training data storage unit for storing training data in TXT format; a data processing and reading unit for reading the training data and calculating the loss function of the initial YOLOx model using the detection results; and an iterative correction unit for iteratively correcting the initial YOLOx model according to its loss function until a preset condition is met to terminate training, and using the YOLOx model that meets the preset condition as the target face reconstruction model. This invention's face reconstruction model constructed using a YOLOx model can simultaneously output face and facial attribute detection results, reducing model loading and inference time. Furthermore, the training device of this invention includes a data processing and reading unit, which allows for the reading of TXT format detection data during supervised training of the face reconstruction model, reducing the difficulty of data reading during model training. This solves the problems of long model loading time, inference time, and training time in existing technologies that use deep learning models for face detection and face attribute detection.
[0029] Exemplary device
[0030] like Figure 1 As shown, the training device for a YOLOx model for face and face attribute detection includes: a prediction unit 01, used to input the image to be detected into an initial YOLOx model to perform face and face attribute detection and obtain detection results; a training data storage unit 02, used to store training data in txt format; a data processing and reading unit 03, used to read the training data and calculate the loss function of the initial YOLOx model with the detection results; and an iterative correction unit 04, used to iteratively correct the initial YOLOx model according to the loss function of the initial YOLOx model until a preset condition is reached to end the training, and use the YOLOx model that has reached the preset condition as the target face reconstruction model.
[0031] Specifically, in this embodiment, a face reconstruction model is pre-constructed using an initial YOLOx model. The prediction unit inputs the image to be detected into the initial YOLOx model, which then obtains the detection results of the face and face attributes corresponding to the image. Since the detection results output by the untrained initial YOLOx model deviate significantly from the true results, a training data storage unit is also included in the training device to quickly improve the prediction performance of the initial YOLOx model. The training data provided by the training data storage unit is equivalent to real labels, allowing for supervised training of the initial YOLOx model. Furthermore, since the training data storage unit stores training data in TXT format, it effectively reduces the difficulty of data retrieval during model training. The detection results output by the prediction unit and the training data in the training data storage unit are input together into the data processing and reading unit, which calculates the loss function of the initial YOLOx model. Since the loss function can reflect the degree of deviation between the detection results output by the initial YOLOx model and the true results, after the training data and detection results are input into the iterative correction unit, the iterative correction unit can use the loss function as a guide to iteratively correct the model parameters of the initial YOLOx model until the preset conditions are met, indicating that the prediction performance of the current initial YOLOx model has met the standards, then the training ends and the target face reconstruction model is obtained.
[0032] like Figure 2 As shown, the initial YOLOx model in this embodiment mainly includes a feature extraction unit and a detection unit. The feature extraction unit is the basic backbone network of the initial YOLOx model, which is the DepthNet network. To further improve the efficiency of the feature extraction unit, this embodiment uses a lightweight DepthNet to construct the feature extraction unit, which is used to extract features from the image to be detected to obtain the target feature map. The image to be detected, containing facial information, is input into the feature extraction unit, which extracts features from it and outputs the corresponding target feature map. The detection unit is the YOLOx head of the initial YOLOx model. The target feature map output by the feature extraction unit is input into the detection unit, which is used to detect faces and facial attributes on the target feature map to obtain the detection result. To simultaneously obtain the face and facial attribute detection results, the detection unit includes three outputs: the attribute category of the image to be detected, the coordinates of the face bounding box, and the face judgment result. The initial YOLOx model provided in this embodiment can effectively reduce model loading time and inference time.
[0033] In one implementation, the feature extraction unit includes a first feature extraction unit, a second feature extraction unit, and a merging unit. The feature extraction unit extracts features from the image to be detected to obtain a target feature map, including the following steps:
[0034] Step S100: Input the image to be detected into the first feature extraction unit and the second feature extraction unit respectively;
[0035] Step S101: Input the output data corresponding to the first feature extraction unit and the second feature extraction unit into the merging unit to obtain the target feature map.
[0036] Specifically, such as Figure 2 As shown, the image to be detected input to the feature extraction unit undergoes feature extraction through two pathways: a first feature extraction unit and a second feature extraction unit. The output data of the first and second feature extraction units are aggregated in a merging unit, which then outputs a target feature map. In one implementation, both the first and second feature extraction units include a first convolutional layer, a normalization layer, a first activation layer, a second convolutional layer, and a second activation layer, all cascaded sequentially. The second convolutional layer corresponding to the first feature extraction unit includes two convolutional blocks. The output data of the first activation layer serves as the input data for the two convolutional blocks, with the output data of one convolutional block serving as the input data for the second activation layer corresponding to the first feature extraction unit. The output data of the other convolutional block and the output data of the second activation layer corresponding to the first feature extraction unit serve as the output data for the first feature extraction unit.
[0037] The first extraction unit and the second extraction unit each have a cascaded convolutional layer, a normalization layer, and an activation layer, followed by a downsampling operation through the convolutional layers, and finally an activation layer. For ease of distinction, this embodiment defines the first convolutional layer passed through after the input image as the first convolutional layer, and the second convolutional layer as the second convolutional layer; similarly, the first activation layer is defined as the first activation layer, and the second activation layer as the second activation layer. The difference between the first and second extraction units is that the second convolutional layer of the first extraction unit includes two convolutional blocks, while the convolutional layer of the second extraction unit includes only one convolutional block. The output data of one convolutional block in the second convolutional layer of the first extraction unit is directly input to the merging unit, while the output data of the other convolutional block is input to the merging unit after passing through the second activation layer. This embodiment, through the three convolutional blocks corresponding to the two second convolutional layers, can perform a downsampling operation on the feature map, uniformly reducing the resolution of the feature map to a specific value, facilitating the subsequent merging into a single target feature map in the merging unit.
[0038] For example, an image to be detected with a resolution of 112*112 is input into the feature extraction unit. After two-way feature extraction, it first goes through a 3*3 convolutional layer, a normalization layer (BN layer), and a ReLU activation layer. Then it goes through three 1*1 convolutions, each with 64 output channels. After convolution, a downsampling operation is performed to reduce the resolution of the feature map to 20*20. After passing through the concatenation unit (concat), the number of channels of the output feature map becomes 192. That is, the output of the feature extraction unit (backbone) is now an image [batchsize, 192, 20, 20].
[0039] In one implementation, the detection unit includes a classification branch, a regression branch, and a judgment branch. The detection unit performs face and face attribute detection on the target feature map to obtain the detection result, including the following steps:
[0040] Step S200: Input the target feature map into the classification branch and the regression and judgment branch respectively;
[0041] Step S201: Output attribute categories through the classification branch;
[0042] Step S202: Output the face bounding box coordinates and the confidence level corresponding to the face judgment result through regression and judgment branches.
[0043] Specifically, the detection unit in this embodiment includes two main branches: a classification branch and a regression and judgment branch. For the classification branch, the number of output channels corresponds to the number of classification categories. For example, if the number of channels is 5, it corresponds to five attributes: whether sunglasses are worn, whether glasses are worn, whether the face is obscured, and whether a mask is worn. For the regression and judgment branch, the number of output channels corresponds to the coordinates of the face bounding box (4 values) and the confidence level of whether it is the target face.
[0044] like Figure 2 As shown, the specific structure of the detection unit includes a third convolutional layer and a third activation layer cascaded sequentially. The target feature map undergoes a 1*1 convolution with a stride of 1, primarily to reduce the number of channels, for example, from 192 to 32. The output data of the third activation layer are the input data for the classification branch and the regression and judgment branches, respectively. The classification branch includes several cascaded convolutional layers, for example... Figure 3 As shown, it includes two 3x3 convolutions cascaded in sequence, followed by a 1x1 convolution. The regression and decision branches include a regression branch and a decision branch, which partially overlap. They also include several cascaded convolutional layers. The output of the regression branch corresponds to the coordinates of the face bounding box (4 values), and the output of the decision branch corresponds to the confidence score of whether it is the target face.
[0045] In one implementation, the calculation process of the loss function of the initial YOLOx model includes:
[0046] Step S300: Determine the classification loss function corresponding to the classification branch based on the attribute category output by the classification branch and the classification label in the training data;
[0047] Step S301: Determine the regression loss function corresponding to the regression branch based on the face bounding box coordinates output by the regression branch and the face bounding box labels in the training data;
[0048] Step S302: Determine the judgment loss function corresponding to the judgment branch based on the confidence score of the face judgment result output by the judgment branch and the confidence score label in the training data;
[0049] Step S303: Determine the loss function of the initial YOLOx model based on the classification loss function, regression loss function, and judgment loss function.
[0050] In this embodiment, the classification branch, regression branch, and decision branch are coupled together during training. Therefore, the initial loss function of the YOLOx model is calculated from three types of data: the classification loss function corresponding to the classification branch, the regression loss function corresponding to the regression branch, and the decision loss function corresponding to the decision branch. Specifically, the training data is the actual results corresponding to the prediction results output by the YOLOx model. Since the output of the YOLOx model includes the classification result, face bounding box coordinates, and confidence score, the training result also includes classification labels, face bounding box labels, and confidence score labels. The loss function corresponding to each branch is obtained by comparing the output data of each branch with the corresponding label. Because the three branches are coupled together during training, the output needs to be decoupled during detection; otherwise, the difference in magnitude between the face bounding box and the confidence score will cause a large quantization error.
[0051] In one implementation, the loss function of the initial YOLOx model is calculated as follows:
[0052] loss=reg_weight*loss_bbox+loss_cls+loss_obj
[0053] Here, `loss` is the initial loss function of the YOLOx model; `loss_bbox` is the regression loss function; `reg_weight` is the weight corresponding to the regression loss function; `loss_cls` is the classification loss function; and `loss_obj` is the decision loss function. Specifically, the total loss of the YOLOx model is equivalent to the loss of the face bounding box multiplied by its corresponding weight, plus the classification loss, plus the loss indicating whether it is the target. In one implementation, `reg_weight` is set to 5.0.
[0054] In one implementation, the regression loss function is calculated as follows:
[0055] loss_bbox = 1 - IoU * IoU;
[0056] Here, `loss_bbox` is the regression loss function, and `IoU` is the ratio of the intersection to the union of the bounding boxes corresponding to the face bounding box coordinates and the bounding boxes corresponding to the face bounding box labels. Specifically, `loss_bbox` is obtained by calculating `IoU`, which is the intersection of the actual face bounding box coordinates (labels) and the predicted face bounding box coordinates, divided by the union of the two boxes.
[0057] In one implementation, the classification loss function is the cross-entropy between the attribute category labels output by the classification branch; the decision loss function is the cross-entropy between the confidence score output by the decision branch and the confidence score label. Specifically, `loss_cls` and `loss_obj` represent the decision category and whether it is a target face, respectively. Essentially, they are both binary classification problems, so the loss can be calculated using cross-entropy loss (BCE loss). For example, the library function `nn.BCEWithLogitsLoss` can be used to calculate the cross-entropy between the true label and the predicted label. `BCEWithLogitsLoss` is a combination of sigmoid and BCE loss, so the output does not need to be normalized using a sigmoid layer.
[0058] For example, the formula for calculating the cross-entropy loss function in binary classification is as follows: Let N represent the number of samples, z n y represents the score for predicting the nth sample as a positive example. n Let represent the label of the nth sample, and δ represent the sigmoid function. Then:
[0059] loss(z, y) = mean{l0, ...,l N-1};
[0060] l n =-(y n *log(δ(z n ))+(1-y n )*log(1-δ(z n ))).
[0061] Exemplary methods
[0062] Based on the above embodiments, the present invention also provides a method for detecting faces and facial attributes, such as... Figure 4 As shown, the method includes:
[0063] Step S10: Obtain the image of the face to be detected;
[0064] Step S20: Input the face image to be detected into the target face reconstruction model to obtain the face and face attribute detection results corresponding to the face image to be detected. The target face reconstruction model is pre-trained by the training device of the YOLOX model for face and face attribute detection as described above.
[0065] Exemplary device
[0066] Based on the above embodiments, the present invention also provides a terminal, the principle block diagram of which can be as follows: Figure 5 As shown, the terminal includes a processor, memory, network interface, and display screen connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When executed by the processor, the computer program implements a face and face attribute detection method. The display screen can be an LCD screen or an e-ink screen.
[0067] Those skilled in the art will understand that Figure 5 The schematic diagram shown is merely a partial structural diagram related to the present invention and does not constitute a limitation on the terminal to which the present invention is applied. A specific terminal may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0068] In one implementation, the terminal's memory stores one or more programs, and is configured to be executed by one or more processors. The one or more programs contain instructions for performing face and face attribute detection methods.
[0069] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0070] In summary, this invention discloses a training device for a YOLOx model for face and facial attribute detection. The training device includes: a prediction unit for inputting the image to be detected into an initial YOLOx model to perform face and facial attribute detection and obtain detection results; a training data storage unit for storing training data in TXT format; a data processing and reading unit for reading the training data and calculating the loss function of the initial YOLOx model with the detection results; and an iterative correction unit for iteratively correcting the initial YOLOx model according to its loss function until a preset condition is met to end the training, and using the YOLOx model that meets the preset condition as the target face reconstruction model. The face reconstruction model constructed using the YOLOx model in this invention can simultaneously output the detection results of both the face and facial attributes, reducing model loading time and inference time. Furthermore, the training device of this invention includes a data processing and reading unit, which can read the detection data in TXT format during supervised training of the face reconstruction model, reducing the difficulty of data reading during model training. This solves the problems of long model loading time, inference time, and training time in existing technologies using deep learning models for face detection and facial attribute detection.
[0071] It should be understood that the application of the present invention is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A training device for a YOLOx model for face and face attribute detection, characterized in that, include: The prediction unit is used to input the image to be detected into the initial YOLOx model to detect faces and facial attributes and obtain detection results; The initial YOLOv model includes a feature extraction unit and a detection unit. The feature extraction unit includes a first feature extraction unit, a second feature extraction unit, and a merging unit. Both the first and second feature extraction units have sequentially cascaded first convolutional layers, normalization layers, first activation layers, second convolutional layers, and second activation layers. The second convolutional layer of the first feature extraction unit includes two convolutional blocks, while the second convolutional layer of the second feature extraction unit includes only one convolutional block. The output data of one convolutional block in the second convolutional layer of the first feature extraction unit is directly input to the merging unit, while the output data of the other convolutional block is input to the merging unit after passing through the second activation layer. The output data of the second feature extraction unit is input to the merging unit. The feature map is downsampled using the three convolutional blocks corresponding to the two second convolutional layers, reducing the resolution of the feature map to a uniform value. The merging unit then combines these into a single target feature map. The detection unit includes sequentially cascaded third convolutional layers and a third activation layer. The third convolutional layer performs channel dimensionality reduction on the target feature map, and the output data of the third activation layer serves as input data for the classification branch and the regression and judgment branches, respectively. The classification branch includes three convolutional layers cascaded in sequence, used to output the attribute category; The regression and judgment branches include a regression branch and a judgment branch. The regression branch and the judgment branch include partially overlapping convolutional layers. The regression branch outputs the coordinate values of the face bounding box, and the judgment branch outputs the confidence score of whether it is the target face. A training data storage unit is used to store training data in txt format; the training data in txt format includes classification labels, face box labels, and confidence labels corresponding to the attribute category, the face box coordinates, and the confidence score, respectively. The data processing and reading unit is used to read the training data and calculate the loss function of the initial YOLOx model with the detection results, including: determining a classification loss function based on the attribute category and the classification label; determining a regression loss function based on the face bounding box coordinates and the face bounding box label; determining a judgment loss function based on the confidence score and the confidence score label; and determining the loss function of the initial YOLOx model based on the classification loss function, the regression loss function, and the judgment loss function. The iterative correction unit is used to iteratively correct the initial YOLOx model according to the loss function of the initial YOLOx model until the preset conditions are met to end the training, and the YOLOx model that meets the preset conditions is used as the target face reconstruction model.
2. The training apparatus for a YOLOx model for face and face attribute detection according to claim 1, characterized in that, The initial YOLOX model includes: A feature extraction unit based on lightweight DepthNet is used to extract features from the image to be detected to obtain a target feature map. The detection unit is used to perform face and face attribute detection on the target feature map to obtain the detection result, wherein the detection result includes the attribute category, face bounding box coordinates, and face judgment result corresponding to the image to be detected.
3. The training apparatus for a YOLOx model for face and face attribute detection according to claim 1, characterized in that, The loss function of the initial YOLOx model is calculated as follows: loss = reg_weight loss_bbox + loss_cls + loss_obj Where loss is the loss function of the initial YOLOx model; loss_bbox is the regression loss function; reg_weight is the weight corresponding to the regression loss function; loss_cls is the classification loss function; and loss_obj is the decision loss function. The regression loss function is calculated as follows: loss_bbox = 1-IoU IoU; Wherein, IoU is the ratio of the intersection to the union of the boxes corresponding to the face frame coordinates and the boxes corresponding to the face frame labels.
4. The training apparatus for a YOLOx model for face and face attribute detection according to claim 1, characterized in that, The classification loss function is the cross-entropy between the attribute category output by the classification branch and the classification label; the judgment loss function is the cross-entropy between the confidence score output by the judgment branch and the confidence score label.
5. A method for detecting faces and facial attributes, characterized in that, The method includes: Acquire the image of the face to be detected; The face image to be detected is input into the target face reconstruction model to obtain the face and face attribute detection results corresponding to the face image to be detected. The target face reconstruction model is pre-trained by the training device for the YOLOX model for face and face attribute detection as described in any one of claims 1-4. The initial YOLOv model includes a feature extraction unit and a detection unit. The feature extraction unit includes a first feature extraction unit, a second feature extraction unit, and a merging unit. The first and second feature extraction units each have a first convolutional layer, a normalization layer, a first activation layer, a second convolutional layer, and a second activation layer, which are cascaded sequentially. The second convolutional layer of the first feature extraction unit includes two convolutional blocks, while the second convolutional layer of the second feature extraction unit includes only one convolutional block. The output data of one convolutional block in the second convolutional layer of the first feature extraction unit is directly input into the merging unit, and the output data of the other convolutional block is input into the merging unit after passing through the second activation layer. Through the three convolutional blocks corresponding to the two second convolutional layers, the feature map is downsampled to a specific value, and the resolution of the feature map is uniformly reduced to a specific value. The feature map is then merged into a target feature map in the merging unit.
6. A computer-readable storage medium storing a plurality of instructions, characterized in that, The instructions are applicable to be loaded and executed by a processor to implement the steps of the face and face attribute detection method as described in claim 5.
Citation Information
Patent Citations
Face recognition method and device based on multiple tasks, server and readable storage medium
CN111598000A
Robot end face detection method based on YOLO-RGGNet
CN112464912A