Target category detection model training method, target detection method, and electronic device
By performing gradient and learning rate optimization pruning on the target category detection model, the problem of low detection efficiency on mobile terminals is solved, and fast and accurate classification and automated detection are achieved on low-hardware-configuration terminals.
Patent Information
- Application Number
- CN202210293034.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-23
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-03-23
AI Technical Summary
Existing target category detection models have difficulty guaranteeing real-time performance on mobile devices, resulting in low detection efficiency.
By acquiring sample images and their labels, the gradient and difference are calculated using a teacher category detection model. The model is then updated using a gradient threshold and learning rate. After pruning, a student category detection model is trained and run on a low-hardware-configuration terminal using a student model with a simple structure.
It improves detection efficiency, enables fast and accurate classification on mobile terminals, avoids gradient explosion problem, and ensures the reliability of the training process and the automation of detection.
Smart Images

Figure CN114663726B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to a training method for a target category detection model, a target detection method, and an electronic device. Background Art
[0002] Mobile terminals quickly and accurately classify received input images, primarily by face, ID card, passport, vehicle frame number, and license plate. This facilitates subsequent processing, such as personal identity verification, ID card number, passport, vehicle frame number, and license plate number recognition for automatic registration and verification. A common approach for mobile terminals is to provide a document type selection interface, allowing the user to select a document type before performing subsequent processing on the received image.
[0003] For example, many apps currently require manual intervention. For example, when identifying an ID card, users need to manually select the ID card; when identifying a vehicle license plate, users need to manually select the vehicle license plate. However, this object detection method requires manual type selection. Existing category detection models generally have complex structures. Due to the limited processing power of mobile terminals, if they are directly ported to mobile terminals for use, their real-time performance cannot be guaranteed, resulting in low detection efficiency. Summary of the Invention
[0004] In view of this, an embodiment of the present invention provides a training method for a target category detection model, a target detection method, and an electronic device to solve the problem of low detection efficiency.
[0005] According to a first aspect, an embodiment of the present invention provides a method for training an object category detection model, comprising:
[0006] Obtaining sample images of at least two categories and labels thereof, wherein the labels include the categories of the sample images;
[0007] Inputting the sample image into a teacher category detection model to obtain a prediction result, so as to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model;
[0008] Based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate, updating the parameters of the teacher category detection model to determine a target teacher category detection model and a student category detection model, where the student category detection model is obtained by pruning the target teacher category detection model;
[0009] The student category detection model is trained based on the sample image and a second learning rate to determine a target category detection model, wherein the first learning rate is greater than the second learning rate.
[0010] The training method of the target category detection model provided by the embodiment of the present invention uses a first learning rate and a second learning rate to train a teacher category detection model and a student category detection model, respectively. Since the first learning rate is greater than the second learning rate and combined with the gradient threshold, it can ensure that the teacher category detection model can converge faster while avoiding gradient explosion; at the same time, the target teacher category recognition model is used to guide the training of the student category detection model, which can improve the training efficiency. Since the trained student category detection model has a simple structure, it can run on a terminal with a lower hardware configuration, thereby improving the detection efficiency.
[0011] In combination with the first aspect, in the first implementation of the first aspect, updating the parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate to determine the target teacher category detection model and the student category detection model includes:
[0012] updating the gradient based on a magnitude relationship between the gradient and the gradient threshold to determine a target gradient;
[0013] Based on the difference, the target gradient, and the first learning rate, updating the parameters of the teacher category detection model to determine a target teacher category detection model;
[0014] The target teacher category detection model is pruned to determine the student category detection model.
[0015] The training method of the target category detection model provided by the embodiment of the present invention uses the relationship between the gradient and the gradient threshold to update the gradient, which can avoid the gradient explosion problem under large learning rates and ensure the reliability of the training process.
[0016] In combination with the first embodiment of the first aspect, in the second embodiment of the first aspect, updating the gradient based on the magnitude relationship between the gradient and the gradient threshold to determine the target gradient includes:
[0017] Calculating the norm corresponding to the gradient;
[0018] When the calculated norm is greater than the gradient threshold, calculating a ratio of the gradient threshold to the norm, and determining a scaling factor;
[0019] The target gradient is determined based on a product of the scaling factor and the gradient.
[0020] In combination with the first aspect, in a third implementation of the first aspect, acquiring sample images of at least two categories includes:
[0021] Acquire an original sample set, the original sample set including original images of at least two categories, the categories including faces, identity cards, passports, vehicle frame numbers, or license plates;
[0022] Preprocessing the original image to expand the original sample set to obtain a target sample set;
[0023] At least two categories of images are extracted from the target sample set to obtain sample images of the at least two categories.
[0024] The object category detection model training method provided by the embodiment of the present invention can expand the original sample set by preprocessing the original image, thereby achieving the purpose of enhancing the robustness of the model.
[0025] According to a second aspect, an embodiment of the present invention further provides a target detection method, comprising:
[0026] Get the image to be processed;
[0027] Inputting the image to be processed into an object category detection model to determine a detection result of the image to be processed, wherein the detection result includes a category, and the object category detection model is trained according to the object category detection model training method described in the first aspect of the present invention or any embodiment of the first aspect;
[0028] Perform corresponding target detection based on the category of the image to be processed and determine the target detection result.
[0029] The target detection method provided by the embodiment of the present invention automatically identifies the category of the input image to be processed and performs target detection corresponding to the category, thereby avoiding the process of manually entering the image category. The entire detection process is automatically processed, thereby improving the target detection efficiency.
[0030] In conjunction with the second aspect, in a first implementation of the second aspect, the detection result further includes position information of the target in the image to be detected, and the performing corresponding target detection based on the category of the image to be processed to determine the target detection result includes:
[0031] Determining a corresponding target detection module based on the category of the image to be processed;
[0032] The image to be processed and the position information are input into the target detection module to determine the target detection result.
[0033] The target detection method provided by an embodiment of the present invention also includes the target's location information in the detection results. For the target detection module, it can directly use the location information to locate the target and then detect the target. By uniformly processing the location information of the image to be processed, the location information is determined while obtaining the category, thereby further improving the detection efficiency.
[0034] According to a third aspect, an embodiment of the present invention further provides a training device for an object category detection model, comprising:
[0035] A first acquisition module is configured to acquire sample images of at least two categories and labels thereof, wherein the labels include the categories of the sample images;
[0036] A prediction module, configured to input the sample image into a teacher category detection model to obtain a prediction result, so as to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model;
[0037] an updating module, configured to update parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and a first learning rate, to determine a target teacher category detection model and a student category detection model, wherein the student category detection model is obtained by pruning the target teacher category detection model;
[0038] A training module is used to train the student category detection model based on the sample image and a second learning rate to determine a target category detection model, wherein the first learning rate is greater than the second learning rate.
[0039] According to a fourth aspect, an embodiment of the present invention further provides a target detection device, including:
[0040] A second acquisition module is used to acquire the image to be processed;
[0041] an input module, configured to input the image to be processed into an object category detection model, determine a detection result of the image to be processed, wherein the detection result includes a category, and the object category detection model is trained according to the object category detection model training method described in the first aspect of the present invention or any embodiment of the first aspect;
[0042] The determination module is used to perform corresponding target detection based on the category of the image to be processed and determine the target detection result.
[0043] According to the fifth aspect, an embodiment of the present invention provides an electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the training method of the target category detection model described in the first aspect or any one embodiment of the first aspect, or executing the target detection method described in the second aspect or any one embodiment of the second aspect.
[0044] According to the sixth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the target detection method described in the first aspect or any one of the embodiments of the first aspect.
[0045] It should be noted that the corresponding beneficial effects of the target category detection model training device, target detection device, electronic device and computer-readable storage medium provided in the embodiments of the present invention can be found in the description of the corresponding beneficial effects of the target category detection model training method and target detection method above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0047] Figure 1 is a flowchart of a method for training an object category detection model according to an embodiment of the present invention;
[0048] Figure 2 is a flowchart of a method for training an object category detection model according to an embodiment of the present invention;
[0049] Figure 3 is a flow chart of a target detection method according to an embodiment of the present invention;
[0050] Figure 4 is a structural block diagram of a training device for an object category detection model according to an embodiment of the present invention;
[0051] Figure 5 is a structural block diagram of a target detection device according to an embodiment of the present invention;
[0052] Figure 6 It is a schematic diagram of the hardware structure of the electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.
[0054] According to an embodiment of the present invention, a training method for a target category detection model and an embodiment of a target detection method are provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0055] In this embodiment, a method for training an object category detection model is provided, which can be used in electronic devices such as computers, servers, etc. Figure 1 is a flow chart of a method for training a target category detection model according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0056] S11, obtaining sample images of at least two categories and their labels.
[0057] The label includes the category of the sample image.
[0058] The object category detection model is used to perform category detection on sample images of at least two categories. For example, the object category detection model can identify identity cards, passports, license plates, etc. The specific categories to be identified are trained based on actual needs and are not limited here.
[0059] Each sample image has a corresponding label, which includes the category of the sample image, or may also include the location information of the target in the sample image. For example, for a vehicle image, its label includes the category of the vehicle image: vehicle, and the location information of the license plate in the vehicle image. It should be noted that the target in the sample image is set according to actual needs. For example, for a face image, the target is the location of the face image; for an ID card image, the target location information includes the location information of the ID card number, and so on.
[0060] The sample images are obtained by collecting images under different scenes, or rotating, stretching, etc. the collected images under different scenes to enrich the target sample set.
[0061] In some optional implementations, the above S11 may include:
[0062] (1) Obtaining an original sample set, wherein the original sample set includes original images of at least two categories, wherein the categories include faces, identity cards, passports, vehicle frame numbers, or license plates.
[0063] (2) Preprocess the original image to expand the original sample set to obtain the target sample set.
[0064] (3) Extracting at least two categories of images from the target sample set to obtain at least two categories of sample images.
[0065] The images in the original sample set include but are not limited to facial photos, ID card photos, passport photos, vehicle frame number photos, license plate photos, and pictures automatically generated according to templates, etc. taken by image acquisition equipment. These photos are regarded as the original sample set, and the images in the original sample set are called original images.
[0066] After obtaining the original sample set, the original images are preprocessed, including but not limited to scaling, cropping, mirroring, and normalization, to expand the original sample set and obtain a target sample set. When training the recognition and detection model, the electronic device extracts at least two categories of images from the target sample set as sample images.
[0067] By preprocessing the original image, the original sample set can be expanded, thereby achieving the purpose of enhancing the robustness of the model.
[0068] S12, inputting the sample image into the teacher category detection model to obtain the prediction result to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model.
[0069] The teacher category detection model can be a CenterNet model or a detection model with other structures, depending on actual needs. The electronic device inputs a sample image into the teacher category detection model and outputs a prediction result, which includes the predicted category of the sample image.
[0070] The electronic device calculates the loss value using the difference between the prediction result and the label, and calculates the gradient of each parameter in the teacher category detection model. The gradient calculation can be calculated for all parameters in the teacher category detection model, or for specific parameters, etc.
[0071] S13, based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate, the parameters of the teacher category detection model are updated to determine the target teacher category detection model and the student category detection model.
[0072] The student category detection model is obtained by pruning the target teacher category detection model.
[0073] The gradient threshold is set according to actual needs. Since the first learning rate is large, the gradient explosion is prevented by the size relationship between the gradient and the gradient threshold. Based on this, when updating the parameters of the teacher category detection model, it is necessary not only to combine the difference calculated in S12 above, but also to include the comparison result of the first learning rate and the gradient and the gradient threshold. In each cycle, the parameters of the teacher category detection model are updated by the size relationship between the gradient and the gradient threshold. After multiple trainings, the target teacher category detection model is determined.
[0074] The student detection model has a simpler structure than the target teacher detection model. It is achieved by pruning the target teacher detection model. For example, the number of channels in the target teacher detection model is reduced by 1 / 2 or 1 / 3, etc. The specific number of channels reduced is set based on actual needs. The student detection model retains the corresponding parameters of the target teacher detection model, and the second learning rate is used to fine-tune the parameters of the student detection model.
[0075] S14: training the student category detection model based on the sample image and the second learning rate to determine the target category detection model.
[0076] The first learning rate is greater than the second learning rate.
[0077] After determining the student category detection model, since the target teacher category detection model has been trained before, on this basis, the sample images and the second learning rate are used to train the student category detection model, and the parameters of the student category detection model are fine-tuned to determine the target category detection model.
[0078] During training, the relationship between the gradient and the gradient threshold is increased to prevent gradient explosion, which is easily caused by high learning rates. Specifically, the teacher detection model is first trained thousands of times with a high learning rate to determine the target teacher and student detection models. The student detection model is then fine-tuned with a small learning rate. This reduces the training iterations that originally required hundreds of thousands to a maximum of 100,000 for convergence, significantly reducing training time and improving training efficiency.
[0079] The training method of the target category detection model provided in this embodiment uses a first learning rate and a second learning rate to train a teacher category detection model and a student category detection model, respectively. Since the first learning rate is greater than the second learning rate and combined with the gradient threshold, it can ensure that the teacher category detection model can converge faster while avoiding gradient explosion; at the same time, the target teacher category recognition model is used to guide the training of the student category detection model, which can improve the training efficiency. Since the trained student category detection model has a simple structure, it can run on terminals with lower hardware configurations, thereby improving the detection efficiency.
[0080] In this embodiment, a method for training an object category detection model is provided, which can be used in electronic devices such as computers, servers, etc. Figure 2 is a flow chart of a method for training a target category detection model according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0081] S21, obtaining sample images of at least two categories and their labels.
[0082] The label includes the category of the sample image.
[0083] For details, please see Figure 1 S11 of the illustrated embodiment will not be described in detail here.
[0084] S22, input the sample image into the teacher category detection model to obtain the prediction result to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model.
[0085] For details, please see Figure 1 S12 of the illustrated embodiment will not be described in detail here.
[0086] S23, based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate, update the parameters of the teacher category detection model to determine the target teacher category detection model and the student category detection model.
[0087] The student category detection model is obtained by pruning the target teacher category detection model.
[0088] Specifically, the above S23 includes:
[0089] S231 , updating the gradient based on the magnitude relationship between the gradient and the gradient threshold, and determining a target gradient.
[0090] The gradient is compared with the gradient threshold. If the gradient is greater than the gradient threshold, the gradient needs to be reduced to obtain the target gradient; otherwise, the gradient remains unchanged and is used as the target gradient for subsequent processing.
[0091] In some optional implementations, the above S231 may include:
[0092] (1) Calculate the norm corresponding to the gradient.
[0093] (2) When the calculated norm is greater than the gradient threshold, the ratio of the gradient threshold to the norm is calculated to determine the scaling factor.
[0094] (3) Determine the target gradient based on the product of the scaling factor and the gradient.
[0095] The norm corresponding to the gradient can be the L0 norm, L1 norm, or L2 norm. This norm is compared to the gradient threshold. If it is greater than the gradient threshold, the ratio of the gradient threshold to the norm is used as the scaling factor. Therefore, when the norm is less than the gradient threshold, the scaling factor is less than 1, and the target gradient obtained by multiplying the scaling factor by the gradient is less than the calculated gradient.
[0096] S232, based on the difference, the target gradient and the first learning rate, update the parameters of the teacher category detection model to determine the target teacher category detection model.
[0097] After the electronic device determines the target gradient, it updates the parameters of the teacher category detection model using the target gradient, the difference calculated in S22, and the first learning rate. After multiple iterations, the target teacher category detection model can be determined.
[0098] S233, pruning the target teacher category detection model to determine the student category detection model.
[0099] After determining the target teacher category detection model, the number of channels is processed to reduce the number of channels, thereby determining the student category detection model. For example, it is determined in advance which channels need to be pruned, and when pruning is required, the corresponding number of channels in the target teacher category detection model is pruned to determine the student category detection model.
[0100] S24, training the student category detection model based on the sample image and the second learning rate to determine the target category detection model.
[0101] The first learning rate is greater than the second learning rate.
[0102] For details, please see Figure 1 S14 of the illustrated embodiment will not be described in detail here.
[0103] The training method of the target category detection model provided in this embodiment uses the relationship between the gradient and the gradient threshold to update the gradient, which can avoid the gradient explosion problem under large learning rates and ensure the reliability of the training process.
[0104] As a specific application example, the training process mainly includes three parts, namely network input, image preprocessing and category detection module. In particular,
[0105] (1) Network input, mainly inputting face photos, ID card photos, passport photos, vehicle frame number, license plate photos taken by mobile phones, and pictures automatically generated according to templates;
[0106] (2) Image preprocessing, which mainly involves performing preprocessing on the input image, such as scaling, cropping, mirroring, and normalization, to expand the dataset, so that the image is fed into the model with the same size supported by the model and preprocessed with the same mean and variance as during training, thereby enhancing the robustness of the model.
[0107] (3) Category detection is mainly to detect the target in the image, so as to determine the category of the image and decide which module to send it to for processing. The network model used for category detection is a variant of CenterNet, which detects the target by regressing the target center point, the offset of the boundary relative to the center point, and the width and height of the target. For example, the model used inputs a three-channel YUV image of the image, the size of which is 256*256. For example, it only contains one of the following: face, ID card, passport, frame number, license plate, or none of them, and only outputs one category with the highest confidence, which is used as the target category of the image to decide which module to send it to for processing.
[0108] (4) During the training process, since CenterNet converges very slowly, the relationship between the gradient and the gradient threshold is increased during training to prevent the gradient explosion that is easily caused by a large learning rate. First, train at a large learning rate for several thousand times, and then fine-tune the student category recognition model learned at the previous large learning rate with a small learning rate. This reduces the training that originally required hundreds of thousands of iterations to a maximum of 100,000 iterations before convergence.
[0109] In this embodiment, a target detection method is provided, which can be used in mobile terminals, such as mobile phones, tablet computers, or police terminals. Figure 3 is a flow chart of a target detection method according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0110] S31, obtaining an image to be processed.
[0111] The object category detection model trained in the above embodiment can be placed in a mobile terminal, and the mobile terminal can be used to perform object detection on the acquired image to be processed. For example, by installing the corresponding app on a mobile phone, when object detection is needed, the user can access the app, use functions such as taking a photo to acquire the image to be processed, and then use the object detection method described in this embodiment to perform object detection on the image to be processed to determine the object detection result.
[0112] During this entire processing process, there is no need for manual selection of image categories. The corresponding target detection results can be obtained by directly triggering the mobile terminal to obtain the image to be processed with one click.
[0113] In the embodiment of the present invention, there is no restriction on the specific type of the mobile terminal, and the mobile terminal can be selected and set according to actual needs.
[0114] S32: Input the image to be processed into the target category detection model to determine the detection result of the image to be processed.
[0115] Among them, the detection result includes a category, and the target category detection model is trained according to the above-mentioned target category detection model training method. For details, please refer to the above description and will not be repeated here.
[0116] The input of the target category detection model is the image to be processed, and the output is the detection result, which includes the category of the image to be processed. For example, it identifies whether the image to be processed is an ID card, passport, or license plate, etc.
[0117] S33: Perform corresponding target detection based on the category of the image to be processed and determine the target detection result.
[0118] After identifying the category of the image to be processed, the corresponding target detection method is determined based on the category. For example, for a face image, the corresponding target detection includes identifying the face and determining the corresponding person information; for a license plate image, the corresponding target detection includes license plate recognition; for an ID card image, the corresponding target detection includes detecting the ID card number, and so on.
[0119] Specifically, what kind of target detection is required for the image to be processed is set according to actual needs and is not limited here.
[0120] In some optional implementations, the detection result also includes the location information of the target in the image to be detected. Based on this, the above S33 may also include:
[0121] (1) Determine the corresponding target detection module based on the category of the image to be processed.
[0122] (2) Input the image to be processed and the position information into the target detection module to determine the target detection result.
[0123] For object classification detection models, their output includes not only the classification but also the object's location information. This information, along with the image to be processed, is fed into the object detection module for object detection. Specifically, using this information allows for rapid object location, which can then be detected, improving detection efficiency.
[0124] The target detection method provided in this embodiment automatically identifies the category of the input image to be processed and performs target detection corresponding to the category, thereby avoiding the process of manually entering the image category. The entire detection process is automatically processed, thereby improving the target detection efficiency.
[0125] As a specific application example of this embodiment, during the application process of the target category detection model, a sigmoid is performed on conv_center at the end. Specifically, the processing process of the target category detection model includes the following steps:
[0126] The first step is to input a frame of picture currently taken by the mobile app;
[0127] The second step is to preprocess the input image, scale the image to the size supported by the model, and perform mean subtraction and variance division operations;
[0128] The third step is to use the target category detection model to perform target detection on the preprocessed image and obtain the network output sigmoid_conv_center, conv_size, and conv_offset, which respectively represent the probability value of the target center point, the width and height of the target, and the offset of the boundary relative to the center point in the x and y directions;
[0129] In the fourth step, the three feature information obtained in the third step is post-processed, including non-maximum suppression (NMS). Only when the confidence is greater than the set threshold and the target with the largest confidence among all categories is taken, the target of a certain category is considered to be detected, and the image is considered to be of that category.
[0130] This target detection method detects targets in an image, outputs the category with the highest confidence as the target, and uses this category as the category of the image, so that the image and the target location information in the image can be sent to the corresponding module for processing based on the category, such as ID card number recognition, to complete automatic and rapid comparison of ID card numbers, thereby achieving the purpose of automatic classification without manual operation.
[0131] The target detection method provided by the embodiment of the present invention is mainly to quickly and accurately classify the images input by the mobile terminal, mainly classifying people, ID cards, passports, frame numbers, and license plates, so as to facilitate subsequent corresponding processing, such as personnel identity verification, ID card number, passport, frame number, and license plate number recognition for automatic registration and verification. The target category detection model that is finally run is a model with extremely low time consumption obtained by methods such as reducing channels. The category detection model before pruning initially took more than 800 milliseconds per picture on P2, and the mobile terminal was prone to overheating. After pruning optimization, the time consumption was reduced to 40 milliseconds per picture, which was reduced to 1 / 20 of the original, and the classification accuracy remained unchanged.
[0132] In this embodiment, a training device for a target category detection model and a target detection device are also provided. The device is used to implement the above-mentioned embodiments and preferred embodiments, and the details that have been described will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0133] This embodiment provides a training device for an object category detection model, such as Figure 4 Shown, including:
[0134] A first acquisition module 41 is configured to acquire at least two categories of sample images and their labels, wherein the labels include the categories of the sample images;
[0135] A prediction module 42 is configured to input the sample image into a teacher category detection model to obtain a prediction result, so as to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model;
[0136] an updating module 43 for updating parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and a first learning rate to determine a target teacher category detection model and a student category detection model, wherein the student category detection model is obtained by pruning the target teacher category detection model;
[0137] The training module 44 is configured to train the student category detection model based on the sample image and a second learning rate to determine a target category detection model, wherein the first learning rate is greater than the second learning rate.
[0138] This embodiment also provides a target detection device, such as Figure 5 Shown, including:
[0139] A second acquisition module 51 is used to acquire an image to be processed;
[0140] An input module 52 is configured to input the image to be processed into an object category detection model to determine a detection result of the image to be processed, wherein the detection result includes a category. The object category detection model is trained using the object category detection model training method described in any embodiment.
[0141] The determination module 53 is configured to perform corresponding target detection based on the category of the image to be processed and determine a target detection result.
[0142] The training device of the target category detection model and the target detection device in this embodiment are presented in the form of functional units, where the units refer to ASIC circuits, processors and memories that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0143] The further functional description of each of the above modules is the same as that of the above corresponding embodiments and will not be repeated here.
[0144] An embodiment of the present invention further provides an electronic device having the above Figure 4 The training device of the object category detection model shown, or Figure 5 The target detection device shown.
[0145] See also Figure 6 , Figure 6 is a structural diagram of an electronic device provided by an optional embodiment of the present invention, such as Figure 6 As shown, the electronic device may include: at least one processor 601, such as a CPU (Central Processing Unit), at least one communication interface 603, a memory 604, and at least one communication bus 602. The communication bus 602 is used to realize the connection and communication between these components. The communication interface 603 may include a display screen (Display), a keyboard (Keyboard), and the optional communication interface 603 may also include a standard wired interface and a wireless interface. The memory 604 may be a high-speed RAM memory (Random Access Memory, volatile random access memory) or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 604 may optionally be at least one storage device located away from the aforementioned processor 601. The processor 601 may be combined with Figure 4 or Figure 5 In the described apparatus, the memory 604 stores an application program, and the processor 601 calls the program code stored in the memory 604 to execute any of the above method steps.
[0146] The communication bus 602 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 602 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0147] Among them, the memory 604 may include volatile memory (English: volatile memory), such as random-access memory (English: random-access memory, abbreviated: RAM); the memory may also include non-volatile memory (English: non-volatile memory), such as flash memory (English: flash memory), hard disk drive (English: hard disk drive, abbreviated: HDD) or solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 604 may also include a combination of the above types of memory.
[0148] The processor 601 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.
[0149] The processor 601 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0150] Optionally, the memory 604 is further configured to store program instructions. The processor 601 may call the program instructions to implement the method shown in any embodiment of the present application.
[0151] An embodiment of the present invention further provides a non-transitory computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions can execute the training method of the target category detection model or the target detection method in any of the above method embodiments. Wherein, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.
[0152] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A training method for an object category detection model, characterized in that: include: Obtaining sample images of at least two categories and labels thereof, wherein the labels include the categories of the sample images; Inputting the sample image into a teacher category detection model to obtain a prediction result, so as to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model; Based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate, updating the parameters of the teacher category detection model to determine a target teacher category detection model and a student category detection model, where the student category detection model is obtained by pruning the target teacher category detection model; training the student category detection model based on the sample image and a second learning rate to determine a target category detection model, wherein the first learning rate is greater than the second learning rate; The updating of the parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate to determine the target teacher category detection model includes: updating the gradient based on a magnitude relationship between the gradient and the gradient threshold to determine a target gradient; Based on the difference, the target gradient, and the first learning rate, updating the parameters of the teacher category detection model to determine a target teacher category detection model; The updating of the gradient based on the magnitude relationship between the gradient and the gradient threshold to determine the target gradient includes: The gradient is compared with the gradient threshold. If the gradient is greater than the gradient threshold, the gradient is reduced to obtain the target gradient.
2. The method according to claim 1, characterized in that The updating of the gradient based on the magnitude relationship between the gradient and the gradient threshold to determine the target gradient includes: Calculating the norm corresponding to the gradient; When the calculated norm is greater than the gradient threshold, calculating a ratio of the gradient threshold to the norm, and determining a scaling factor; The target gradient is determined based on a product of the scaling factor and the gradient.
3. The method according to claim 1, characterized in that The acquiring of at least two categories of sample images includes: Acquire an original sample set, the original sample set including original images of at least two categories, the categories including faces, identity cards, passports, vehicle frame numbers, or license plates; Preprocessing the original image to expand the original sample set to obtain a target sample set; At least two categories of images are extracted from the target sample set to obtain sample images of the at least two categories.
4. A target detection method, characterized in that: include: Get the image to be processed; Inputting the image to be processed into an object category detection model to determine a detection result of the image to be processed, wherein the detection result includes a category, and the object category detection model is trained according to the object category detection model training method according to any one of claims 1 to 3; Perform corresponding target detection based on the category of the image to be processed and determine the target detection result.
5. The method according to claim 4, characterized in that The detection result also includes position information of the target in the image to be processed. The corresponding target detection is performed based on the category of the image to be processed to determine the target detection result, including: Determining a corresponding target detection module based on the category of the image to be processed; The image to be processed and the position information are input into the target detection module to determine the target detection result.
6. A training device for an object category detection model, characterized in that: include: A first acquisition module is configured to acquire sample images of at least two categories and labels thereof, wherein the labels include the categories of the sample images; A prediction module, configured to input the sample image into a teacher category detection model to obtain a prediction result, so as to determine the difference between the prediction result and the label and the gradient of each parameter in the teacher category detection model; an updating module, configured to update parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and a first learning rate, to determine a target teacher category detection model and a student category detection model, wherein the student category detection model is obtained by pruning the target teacher category detection model; a training module, configured to train the student category detection model based on the sample image and a second learning rate to determine a target category detection model, wherein the first learning rate is greater than the second learning rate; The updating of the parameters of the teacher category detection model based on the difference, the relationship between the gradient and the gradient threshold, and the first learning rate to determine the target teacher category detection model includes: updating the gradient based on a magnitude relationship between the gradient and the gradient threshold to determine a target gradient; Based on the difference, the target gradient, and the first learning rate, updating the parameters of the teacher category detection model to determine a target teacher category detection model; The updating of the gradient based on the magnitude relationship between the gradient and the gradient threshold to determine the target gradient includes: The gradient is compared with the gradient threshold. If the gradient is greater than the gradient threshold, the gradient is reduced to obtain the target gradient.
7. A target detection device, characterized in that: include: A second acquisition module is used to acquire the image to be processed; an input module, configured to input the image to be processed into an object category detection model, determine a detection result of the image to be processed, wherein the detection result includes a category, and the object category detection model is trained according to the object category detection model training method according to any one of claims 1 to 3; The determination module is used to perform corresponding target detection based on the category of the image to be processed and determine the target detection result.
8. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the training method of the target category detection model according to any one of claims 1 to 3, or executes the target detection method according to claim 4 or 5 by executing the computer instructions.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, which are used to enable a computer to execute the training method of the target category detection model described in any one of claims 1 to 3, or to execute the target detection method described in claim 4 or 5.
Citation Information
Patent Citations
Feature coding model, training method of visual relationship detection model and detection method
CN110390340A
Model training method, device and equipment and computer storage medium
CN113222123A
Detection model training method and device, target detection method and device and electronic system
CN113239982A
Neural network compression method and related equipment
CN114169501A