AI target detection model rapid training method and device, equipment and medium
By optimizing the training data size through memory mapping and dynamic adjustment technology, and combining the parallel computing of multi-core CPUs and GPUs, the problem of large amounts of calculation and high hardware performance requirements in AI target detection model training is solved, achieving low-cost and high-efficiency training effects. .
Patent Information
- Application Number
- CN202410596097.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-08-30
AI Technical Summary
In AI target detection business scenarios, existing technologies are difficult to achieve low-cost, high-efficiency model training, mainly due to the huge amount of calculation and high hardware performance requirements, resulting in high equipment costs and long optimization time.
Using memory mapping technology and dynamic adjustment to optimize the size of training data, combined with parallel computing of multi-core CPU and GPU, it establishes a one-to-one mapping relationship between images and annotated data through memory mapping, dynamically calculates the height and width of training data, and uses multi-threading to This method performs image preprocessing and backpropagation calculation of high-precision small models to improve data throughput and calculation speed.
It achieves low-cost and high-efficiency AI target detection model training, reduces memory overhead and calculation time, and improves data throughput and training speed.
Smart Images

Figure CN118568488A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of AI model training technology, and in particular to a method, device, equipment and medium for rapid training of an AI target detection model. Background Art
[0002] Artificial intelligence has developed rapidly in recent years. In the field of artificial intelligence, supervised learning based on clearly labeled training samples is still a major model training method. In AI target detection business scenarios, a large amount of images and annotated data needs to be input into the model for training and iterative optimization of the algorithm model.
[0003] However, the large amount of image data processing and input into the model for calculation requires extremely high hardware performance. The performance of ordinary graphics cards is limited, and high equipment costs are required. In addition, due to the huge amount of calculation, the model optimization time is also long, which affects efficiency. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for rapid training of an AI target detection model, which adopts memory mapping and dynamically adjusts and optimizes the size of training data to improve data throughput and realize low-cost and high-efficiency AI target detection model training.
[0005] In a first aspect, the present invention provides a method for quickly training an AI target detection model, which is applied to a device with a multi-core CPU, and the method comprises:
[0006] Step 1: read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain training data;
[0007] Step 2: Get a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory;
[0008] Step 3: randomly combine the image data and annotation data obtained in step 2 according to the set batch number to form a batch data set;
[0009] Step 4: Assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU;
[0010] Step 5: Use GPU to perform back propagation and parallel calculation of loss function for each batch data set using a high-precision small model to obtain the weight parameters of each batch data set. After synchronizing the weight parameters, determine whether the training end indicators are met. If not, return to step 2 for the next iterative calculation.
[0011] In a second aspect, the present invention provides an AI target detection model rapid training device, which is applied to a device with a multi-core CPU, and the device comprises:
[0012] The training data acquisition module is used to read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain the training data;
[0013] The dynamic adjustment module is used to obtain a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory;
[0014] A data combination module, used to randomly combine the image data and the annotation data obtained by the dynamic adjustment module according to a set batch number to form a batch data set;
[0015] The multi-threaded preprocessing module is used to assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU;
[0016] The iterative update module is used to use the GPU to perform back propagation and parallel calculation of the loss function for each batch of data sets using a high-precision small model, obtain the weight parameters of each batch of data sets, synchronize the weight parameters, and determine whether the training end indicators are met. If not, return to the dynamic adjustment module for the next iterative calculation.
[0017] In a third aspect, the present invention provides an electronic device comprising a memory, a multi-core CPU processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.
[0018] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0019] The technical solution provided in the embodiments of the present invention has at least the following technical effects:
[0020] Memory mapping technology and dynamic adjustment and optimization size technology are used to improve data throughput; combined image enhancement algorithm and high-precision small model algorithm are used to improve data calculation speed and reduce memory overhead; it can realize a low-cost and high-efficiency AI target detection training system.
[0021] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.
[0023] Figure 1 Schematic diagram of the process of the method in Embodiment 1 of the present invention;
[0024] Figure 2 It is a structural schematic diagram of the device in the second embodiment of the present invention;
[0025] Figure 3 This is a schematic diagram of the structure of an electronic device in Embodiment 3 of the present invention;
[0026] Figure 4 Schematic diagram of the structure of the medium in the fourth embodiment of the present invention. DETAILED DESCRIPTION
[0027] The embodiments of the present invention provide a method, apparatus, device and medium for rapid training of an AI target detection model, adopt memory mapping and dynamically adjust and optimize the size of training data to improve data throughput, and realize low-cost and high-efficiency AI target detection model training.
[0028] The technical solution in the embodiment of the present invention has the following general idea:
[0029] Read all annotated image files and annotation files into memory, establish a one-to-one mapping relationship; dynamically calculate the height and width of the training data according to the size of the smallest annotated rectangular box in the annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the mapped training data in the memory; randomly combine image data and annotation data to form a batch data set; assign each batch data set to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer it to the GPU; use the GPU to perform back propagation and parallel calculation of the loss function for each batch data set using a high-precision small model, and obtain the weight parameters of each batch data set respectively, and synchronize the weight parameters before the next iteration calculation until the training is completed. The present invention can achieve low-cost and efficient AI target detection model training.
[0030] Embodiment 1
[0031] This embodiment provides a method for quickly training an AI target detection model. Figure 1 As shown, including:
[0032] Step 1: read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain training data;
[0033] Step 2: Get a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory;
[0034] For example, the minimum resolution that can be processed by the current multi-core CPU device is 5×5, and the size of the smallest annotation rectangle in the current annotation data is 10×10. The width and height of the image in the training data and the width and height of the annotation data are proportionally reduced to 1 / 2 of the original according to the ratio, so that the smallest annotation rectangle is reduced to 5×5. That is, the image size can be greatly reduced and the amount of calculation can be reduced without affecting the training accuracy while meeting the resolution requirements. Similarly, if the size of the smallest annotation rectangle in the current annotation data is 50×50, the width and height of the image in the training data and the width and height of the annotation data are proportionally reduced to 1 / 10 of the original according to the ratio.
[0035] On the contrary, if the size of the smallest annotation rectangle is less than or equal to the minimum resolution, the training data is kept unchanged to ensure the training accuracy.
[0036] The use of memory mapping technology and dynamic resizing optimization technology can improve data throughput.
[0037] Step 3: Randomly combine the image data and annotation data obtained in step 2 according to the set batch number to form a batch data set; the batch number should be smaller than the number of CPU cores. For example, a common multi-core CPU has 16 or 32 cores, and the batch number can be set in the range of 4-8.
[0038] Step 4: Assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU through GPUDirect technology; GPUDirect technology can achieve high-speed data transmission between the CPU and GPU.
[0039] Among them, the image preprocessing adopts a random combination image enhancement algorithm, which is formed by a random combination of multiple existing image data enhancement algorithms (such as translation, rotation, flipping, filling, noise disturbance, contrast transformation, etc.), and can be obtained by combining the algorithms and then processing the image once. Compared with the traditional method of using image data enhancement algorithms to process images multiple times, this embodiment first combines the algorithms and then processes the image data, which can improve the operation speed, reduce memory access overhead, and achieve better training effects.
[0040] Step 5: Use GPU to perform back propagation and parallel calculation of loss function for each batch of data sets using a high-precision small model (e.g., hrnet-lite), obtain the weight parameters of each batch of data sets, and after synchronizing the weight parameters, determine whether the training end indicator is met. If not, return to step 2 for the next iterative calculation. The use of a combined image enhancement algorithm and a high-precision small model algorithm can increase data calculation speed and reduce memory overhead.
[0041] The steps of this embodiment can be combined to realize a low-cost and high-efficiency AI target detection training system.
[0042] Based on the same inventive concept, the present application also provides a device corresponding to the method in Example 1, see Example 2 for details.
[0043] Embodiment 2
[0044] In this embodiment, a fast training device for an AI target detection model is provided, which is applied to a device with a multi-core CPU, such as Figure 2 As shown, the device comprises:
[0045] The training data acquisition module is used to read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain the training data;
[0046] The dynamic adjustment module is used to obtain a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory;
[0047] A data combination module, used to randomly combine the image data and the annotation data obtained by the dynamic adjustment module according to a set batch number to form a batch data set;
[0048] The multi-threaded preprocessing module is used to assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU;
[0049] The iterative update module is used to use the GPU to perform back propagation and parallel calculation of the loss function for each batch of data sets using a high-precision small model, obtain the weight parameters of each batch of data sets, synchronize the weight parameters, and determine whether the training end indicators are met. If not, return to the dynamic adjustment module for the next iterative calculation.
[0050] Specifically, in the dynamic adjustment module, the width and height of the training data are dynamically calculated according to the size of the smallest annotation rectangle in each annotation data and the minimum resolution that can be processed by the current multi-core CPU device, specifically including:
[0051] Obtain the size of the smallest annotation rectangle in each annotation data in turn, and then compare it with the minimum resolution that can be processed by the current multi-core CPU device;
[0052] If the size of the smallest annotation rectangle is larger than the minimum resolution, the ratio of the minimum resolution to the size of the smallest annotation rectangle is calculated, and then the width and height of the image in the training data and the width and height of the annotation data are proportionally reduced according to the ratio;
[0053] If the size of the smallest annotation rectangle is less than or equal to the minimum resolution, the training data remains unchanged.
[0054] Specifically, in the multi-thread preprocessing module, the image preprocessing specifically adopts a random combination image enhancement algorithm, and the random combination image enhancement algorithm is formed by randomly combining multiple image enhancement algorithms.
[0055] Preferably, in the multi-thread preprocessing module, the CPU transmits data with the GPU through GPUDirect technology.
[0056] Since the device introduced in the second embodiment of the present invention is a device used to implement the method of the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device based on the method introduced in the first embodiment of the present invention, so it is not described here in detail. All devices used in the method of the first embodiment of the present invention belong to the scope of protection of the present invention.
[0057] Based on the same inventive concept, the present application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details.
[0058] Embodiment 3
[0059] This embodiment provides an electronic device, such as Figure 3 As shown, it includes a memory, a multi-core CPU processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in Example 1 can be implemented.
[0060] Since the electronic device introduced in this embodiment is a device used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the device used by the method in the embodiment of the present application, it belongs to the scope of protection of the present application.
[0061] Based on the same inventive concept, the present application provides a storage medium corresponding to the first embodiment, see the fourth embodiment for details.
[0062] Embodiment 4
[0063] This embodiment provides a computer-readable storage medium, such as Figure 4 As shown, a computer program is stored thereon, and when the computer program is executed by a processor, any implementation method in Example 1 can be implemented.
[0064] Since the computer-readable storage medium introduced in this embodiment is a computer-readable storage medium used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the computer-readable storage medium of the present embodiment and its various variations, so how the computer-readable storage medium implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the computer-readable storage medium used in the method in the embodiment of the present application, it belongs to the scope of protection of the present application.
[0065] The present invention adopts memory mapping technology and dynamic adjustment optimization size technology to improve data throughput; adopts a combined image enhancement algorithm and a high-precision small model algorithm to improve data calculation speed and reduce memory overhead; and can realize a low-cost and high-efficiency AI target detection training system.
[0066] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0067] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0068] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0069] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0070] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A method for rapid training of an AI target detection model, characterized in that: Applied to a device with a multi-core CPU, the method comprises: Step 1: read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain training data; Step 2: Get a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory; Step 3: randomly combine the image data and annotation data obtained in step 2 according to the set batch number to form a batch data set; Step 4: Assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU; Step 5: Use GPU to perform back propagation and parallel calculation of loss function for each batch data set using a high-precision small model to obtain the weight parameters of each batch data set. After synchronizing the weight parameters, determine whether the training end indicators are met. If not, return to step 2 for the next iterative calculation.
2. The method according to claim 1, characterized in that: In step 2, the width and height of the training data are dynamically calculated according to the size of the smallest annotated rectangular box in each annotated data and the minimum resolution that can be processed by the current multi-core CPU device, specifically including: Obtain the size of the smallest annotation rectangle in each annotation data in turn, and then compare it with the minimum resolution that can be processed by the current multi-core CPU device; If the size of the smallest annotation rectangle is larger than the minimum resolution, the ratio of the minimum resolution to the size of the smallest annotation rectangle is calculated, and then the width and height of the image in the training data and the width and height of the annotation data are proportionally reduced according to the ratio; If the size of the smallest annotation rectangle is less than or equal to the minimum resolution, the training data remains unchanged.
3. The method according to claim 1, characterized in that: In the step 4, the image preprocessing specifically adopts a random combination image enhancement algorithm, and the random combination image enhancement algorithm is formed by randomly combining multiple image enhancement algorithms.
4. The method according to claim 1 or 3, characterized in that: In step 4, the CPU transmits data to the GPU through the GPUDirect technology.
5. A rapid training device for an AI target detection model, characterized in that: Applied to a device with a multi-core CPU, the device comprises: The training data acquisition module is used to read all the annotated image files and annotation files into the memory, and then establish a one-to-one mapping relationship between the image data of the annotated image files and the annotation data of the annotation files in the memory to obtain the training data; The dynamic adjustment module is used to obtain a specified amount of training data, dynamically calculate the height and width of the training data according to the size of the smallest annotation rectangle in each annotated data and the minimum resolution that the current multi-core CPU device can handle, and update the training data mapped in the memory; A data combination module, used to randomly combine the image data and the annotation data obtained by the dynamic adjustment module according to a set batch number to form a batch data set; The multi-threaded preprocessing module is used to assign each batch of data sets to the corresponding CPU core, perform image preprocessing in a multi-threaded manner, and then transfer them to the GPU; The iterative update module is used to use the GPU to perform back propagation and parallel calculation of the loss function for each batch of data sets using a high-precision small model, obtain the weight parameters of each batch of data sets, synchronize the weight parameters, and determine whether the training end indicators are met. If not, return to the dynamic adjustment module for the next iterative calculation.
6. The device according to claim 5, characterized in that: In the dynamic adjustment module, the width and height of the training data are dynamically calculated according to the size of the smallest annotation rectangle in each annotation data and the minimum resolution that can be processed by the current multi-core CPU device, specifically including: Obtain the size of the smallest annotation rectangle in each annotation data in turn, and then compare it with the minimum resolution that can be processed by the current multi-core CPU device; If the size of the smallest annotation rectangle is larger than the minimum resolution, the ratio of the minimum resolution to the size of the smallest annotation rectangle is calculated, and then the width and height of the image in the training data and the width and height of the annotation data are proportionally reduced according to the ratio; If the size of the smallest annotation rectangle is less than or equal to the minimum resolution, the training data remains unchanged.
7. The device according to claim 5, characterized in that: In the multi-thread preprocessing module, the image preprocessing specifically adopts a random combination image enhancement algorithm, and the random combination image enhancement algorithm is formed by randomly combining multiple image enhancement algorithms.
8. The device according to claim 5 or 7, characterized in that: In the multi-thread preprocessing module, the CPU transmits data with the GPU through the GPUDirect technology.
9. An electronic device comprising a memory, a multi-core CPU processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
