Model conversion method, device and equipment

By creating multiple model conversion subtasks under different quantization accuracy and selecting the optimal model, the problem of cumbersome and erroneous operation of the model conversion process in the existing technology is solved, and efficient and accurate model conversion is achieved.

CN113962368BActive Publication Date: 2025-08-01CHONGQING SAIDIQIZHI ARTIFICIAL INTELLIGENCE TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111356401.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-16
Publication Date
2025-08-01
Estimated Expiration
2041-11-16

AI Technical Summary

Technical Problem

In the prior art, the model conversion process is complicated, and multiple selections of model quantization accuracy and multiple tests are required, resulting in high time cost and prone to misoperation, resulting in unsatisfactory results.

Method used

By obtaining the original model file, quantized image set and model conversion configuration information, receiving a variety of quantization accuracy instructions entered by the user, creating multiple model conversion subtasks under each accuracy, generating a converted model set, and selecting the optimal model from it.

Benefits of technology

It realizes efficient conversion of the optimal model, saves the time of the algorithm personnel, and avoids failure or undesirable results caused by misoperation in multiple operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113962368B_ABST
    Figure CN113962368B_ABST
Patent Text Reader

Abstract

The present application provides a model conversion method, apparatus, and device. The method includes: obtaining an original model file, a quantization image set, and model conversion configuration information; when receiving an automatic conversion instruction entered by a user, obtaining multiple quantization precisions entered by the user on a parameter configuration page; creating multiple model conversion subtasks for the original model file respectively at each of the quantization precisions based on the configuration information and the quantization image set; executing each of the model conversion subtasks to generate a converted model set, and selecting a target model from the converted model set. The present application saves the time of algorithm personnel and also avoids the problem that the result fails or does not reach the ideal result due to misoperations during multiple operations, achieving the conversion of the optimal model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more particularly, to a model conversion method, apparatus, and device. Background Art

[0002] Model conversion refers to transplanting the same neural network model onto different chip platforms so that the algorithm model is applicable to different platforms.

[0003] Currently, when algorithm personnel perform model conversion, they often need to select different model quantization precisions one by one, upload quantization images to perform multiple model conversions, and then run the test service on the several converted models, and then select the optimal model according to the relevant indicators in the test results.

[0004] In the above solution, the operation is cumbersome. If the developer is not satisfied with the result after optimizing the model and wants to perform conversion again, the developer still needs to execute the same operation multiple times, wasting a large amount of time cost. Summary of the Invention

[0005] The purpose of the embodiments of this application is to provide a model conversion method, apparatus, and device, which realizes the conversion of the optimal model, saves the time of algorithm personnel, and also avoids the problem that the result fails or does not reach the ideal result due to misoperations during multiple operations.

[0006] The first aspect of the embodiments of this application provides a model conversion method, including: obtaining an original model file, a quantization image set, and model conversion configuration information; when receiving an automatic conversion instruction entered by a user, obtaining multiple quantization precisions entered by the user on a parameter configuration page; creating multiple model conversion subtasks for the original model file respectively under each quantization precision based on the configuration information and the quantization image set; executing each model conversion subtask, generating a set of converted models, and selecting a target model from the set of converted models.

[0007] In one embodiment, the creating multiple model conversion subtasks for the original model file respectively under each quantization precision based on the configuration information and the quantization image set includes: for each quantization precision, compressing the original model file using the quantization precision to generate a compressed model file; randomly selecting multiple quantization image subsets from the quantization image set for each quantization precision; creating multiple model conversion subtasks for the compressed model file based on the configuration information and the multiple quantization image subsets.

[0008] In one embodiment, performing each of the model conversion subtasks to generate a set of converted models includes: for each of the model conversion subtasks, inputting a subset of the quantized images into the compressed model file, adjusting the parameters of the compressed model file to obtain a converted model, and the set of converted models includes the converted models generated by each of the model conversion subtasks.

[0009] In one embodiment, the configuration information further includes: test parameters; selecting a target model from the set of converted models includes: testing each model in the set of converted models using a preset test set and the test parameters, and outputting test results; selecting the target model with the highest test metric score from the set of converted models according to the test results.

[0010] In one embodiment, after obtaining the original model file, the quantized image set, and the model conversion configuration information, it further includes: when the automatic conversion instruction is not received, obtaining a quantization precision entered by the user on the parameter configuration page; compressing the original model file using the quantization precision to generate a compressed model file; creating a model conversion task for the compressed model file based on the configuration information and the quantized image set, and performing the model conversion task to generate a converted model.

[0011] A second aspect of the embodiments of the present application provides a model conversion device, including: a first acquisition module for acquiring an original model file, a quantized image set, and model conversion configuration information; a second acquisition module for acquiring multiple quantization precisions entered by the user on the parameter configuration page when an automatic conversion instruction entered by the user is received; a first creation module for creating multiple model conversion subtasks for the original model file based on the configuration information and the quantized image set at each of the quantization precisions; and an execution module for performing each of the model conversion subtasks to generate a set of converted models and selecting a target model from the set of converted models.

[0012] In one embodiment, the first creation module is configured to: for each of the quantization precisions, compress the original model file using the quantization precision to generate a compressed model file; randomly select multiple subsets of quantized images from the quantized image set for each of the quantization precisions; and create multiple model conversion subtasks for the compressed model file based on the configuration information and the multiple subsets of quantized images.

[0013] In one embodiment, the execution module is configured to: for each of the model conversion subtasks, input a subset of the quantized images into the compressed model file, perform parameter adjustment processing on the compressed model file to obtain a converted model, and the converted model set includes the converted models generated by each of the model conversion subtasks; and the configuration information further includes: test parameters; the execution module is further configured to: test each model in the converted model set by using a preset test set and the test parameters, and output a test result; and select the target model with the highest test index score from the converted model set according to the test result.

[0014] In one embodiment, a third acquisition module is configured to, after acquiring the original model file, the quantized image set, and the model conversion configuration information, and when the automatic conversion instruction is not received, acquire a quantization precision entered by the user on the parameter configuration page; a quantization module is configured to compress the original model file by using the quantization precision to generate a compressed model file; a second creation module is configured to create a model conversion task for the compressed model file based on the configuration information and the quantized image set, and execute the model conversion task to generate a converted model.

[0015] A third aspect of the embodiments of the present application provides an electronic device, including: a memory for storing a computer program; a processor for executing the computer program to implement the method according to the first aspect and any one of its embodiments of the present application.

[0016] The model conversion method, device, and equipment provided by the present application first acquire an original model file, a quantized image set, and model conversion configuration information, then when an automatic conversion instruction entered by the user is received, acquire multiple quantization precisions entered by the user on the parameter configuration page, and then, based on the configuration information and the quantized image set, create multiple model conversion subtasks for the original model file under each quantization precision, and finally, execute each model conversion subtask to generate a converted model set, and select a target model from the converted model set, thus saving the time of algorithm personnel and avoiding the problem that the result fails or does not reach the ideal result due to misoperations during multiple operations, and realizing the conversion of the optimal model. Description of the Drawings

[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required to be used in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0018] Figure 1 Schematic diagram of the structure of an electronic device according to an embodiment of the present application;

[0019] Figure 2 Schematic flowchart of a model conversion method according to an embodiment of the present application;

[0020] Figure 3 Schematic flowchart of a model conversion method according to an embodiment of the present application;

[0021] Figure 4 Schematic diagram of the structure of a model conversion device according to an embodiment of the present application. Detailed implementation manners

[0022] Next, the technical solutions in the embodiments of the present application will be described with reference to the accompanying drawings in the embodiments of the present application. In the description of the present application, terms such as "first", "second", etc. are only used for distinguishing descriptions, and cannot be understood as indicating or implying relative importance.

[0023] As Figure 1 shown, this embodiment provides an electronic device 1, including: at least one processor 11 and a memory 12, Figure 1 Taking one processor as an example. The processor 11 and the memory 12 are connected through a bus 10. The memory 12 stores instructions executable by the processor 11. When the instructions are executed by the processor 11, the electronic device 1 can execute all or part of the processes of the methods in the following embodiments, so as to create multiple model conversion subtasks at a random quantization precision through a quantization image set and configuration information, execute the model conversion subtasks, generate a model set, and select the optimal model as the target model.

[0024] In one embodiment, the electronic device 1 may be a mobile phone, a tablet computer, a notebook computer, a desktop computer, or a large computing system composed of multiple computers, etc.

[0025] Please refer to Figure 2 , which is a model conversion method according to an embodiment of the present application. This method can be executed by the Figure 1 electronic device 1 shown. The method includes the following steps:

[0026] Step 210: Obtain an original model file, a quantization image set, and model conversion configuration information.

[0027] In this step, the original model file refers to the file exported by the original model on a certain platform. For example, the file exported by a convolutional neural network model on TensorFlow includes a dataset file, a code file with the suffix ".py", etc. The quantization image set refers to the image set obtained after quantizing a group of image sets, and the number of quantization levels can be set to 2, 8, 64, etc.

[0028] Step 220: When receiving the automatically converted instruction entered by the user, obtain various quantization precisions entered by the user on the parameter configuration page.

[0029] In this step, the quantization precision may refer to the type of quantization, such as int8, int16, etc.

[0030] Step 230: Based on the configuration information and the quantization image set, create multiple model conversion subtasks for the original model file under each quantization precision.

[0031] In this step, the configuration information may include information such as the model, framework, conversion configuration, quantization image file, etc.

[0032] In one embodiment, if the number of quantization precisions is M, and each quantization precision is used to convert N images randomly selected from the uploaded quantization images for 5 rounds, then M * 5 conversion subtasks will be generated.

[0033] Step 240: Execute each model conversion subtask, generate a set of converted models, and select a target model from the set of converted models.

[0034] In one embodiment, if the original model is the picture recognition algorithm a, and the recognition accuracy rate on platform A is 98%, now the model a is converted so that it can run on platform B, and it is stipulated that the recognition accuracy rate can reach 75%. Therefore, a subset of quantization images is input into the compressed original model, and the parameters of the compressed model file are adjusted so that the recognition accuracy rate of the model after running is above 75%, then a converted model can be obtained. The set of converted models includes the converted models generated by all model conversion subtasks of a.

[0035] The above model conversion method first obtains the original model file, quantization image set, and model conversion configuration information, then when receiving the automatically converted instruction entered by the user, obtains various quantization precisions entered by the user on the parameter configuration page. After that, based on the configuration information and the quantization image set, create multiple model conversion subtasks for the original model file under each quantization precision. Finally, execute each model conversion subtask, generate a set of converted models, and select a target model from the set of converted models. In this way, it saves the time of algorithm personnel and also avoids the problem that the result fails or does not reach the ideal result due to misoperations during multiple operations, realizing the conversion of the optimal model.

[0036] Please refer to Figure 3 , which is the model conversion method of an embodiment of the present application. The method includes the following steps:

[0037] Step 310: Obtain the original model file, the quantization image set, and the model conversion configuration information. For details, please refer to the description of Step 210 in the above embodiments.

[0038] Step 320: When receiving the automatic conversion instruction entered by the user, obtain various quantization precisions entered by the user on the parameter configuration page. For details, please refer to the description of Step 220 in the above embodiments.

[0039] Step 330: For each quantization precision, compress the original model file using the quantization precision to generate a compressed model file.

[0040] In one embodiment, compress the file of the convolutional neural network model, that is, convert the original float32-bit convolutional operation (multiplication and addition instruction) into an int8 convolutional operation. In this way, the calculation becomes 1 / 4 of the original, but the memory access does not decrease because the float32 is only converted to int8 for calculation inside the kernel. Since removing the bias value has not much impact on the accuracy, the bias is removed.

[0041] Step 340: Randomly select multiple quantization image subsets from the quantization image set for each quantization precision.

[0042] In this step, the number of randomly selected multiple quantization image subsets can be preset, such as 5, 10, etc.

[0043] Step 350: Based on the configuration information and multiple quantization image subsets, create multiple model conversion subtasks for the compressed model file.

[0044] Step 360: Execute each model conversion subtask to generate a set of converted models, and select a target model from the set of converted models.

[0045] In this step, if the model conversion fails, a re-conversion operation is performed. After successful conversion, test multiple successfully converted models, compare the test metrics, and select the model with the best metrics as the target model.

[0046] In one embodiment, the test metrics include accuracy, recall rate, F1-Score, mean squared error, root mean squared error, information entropy, etc.

[0047] In one embodiment, during the process of model testing, it is necessary to divide the dataset for model training. For example, select 70% as the training set and 30% as the test set, or 80% as the training set and 20% as the test set. The dataset can also be divided into a training set, a validation set, and a test set in a ratio of 6:2:2. Among them, the dataset can be uploaded by the user or pre-stored in the database.

[0048] In one embodiment, test sets with different ratios can be selected to evaluate different converted models, and the model with the best evaluation effect under test sets with different ratios can be comprehensively selected as the target model.

[0049] Please refer to Figure 4 , which is a model conversion device according to an embodiment of the present application. This device is applied to Figure 1 the electronic device 1 shown in the figure. The device includes: a first acquisition module 401, a second acquisition module 402, a first creation module 403, and an execution module 404. The principle relationships of each module are as follows:

[0050] The first acquisition module 401 is used to acquire the original model file, the quantization image set, and the model conversion configuration information.

[0051] The second acquisition module 402 is used to acquire multiple quantization precisions entered by the user on the parameter configuration page when receiving the automatic conversion instruction entered by the user.

[0052] The first creation module 403 is used to create multiple model conversion subtasks for the original model file at each quantization precision based on the configuration information and the quantization image set.

[0053] The execution module 404 is used to execute each model conversion subtask, generate a set of converted models, and select a target model from the set of converted models.

[0054] In one embodiment, the first creation module 401 is used for: for each quantization precision, compressing the original model file with the quantization precision to generate a compressed model file; randomly selecting multiple quantization image subsets from the quantization image set for each quantization precision; creating multiple model conversion subtasks for the compressed model file based on the configuration information and the multiple quantization image subsets.

[0055] In one embodiment, the execution module 404 is used for: for each model conversion subtask, inputting a quantization image subset into the compressed model file, adjusting the parameters of the compressed model file to obtain a converted model, and the set of converted models includes the converted models generated by each model conversion subtask; and the configuration information further includes: test parameters; the execution module 404 is further used for: testing each model in the set of converted models with a preset test set and test parameters, and outputting the test results; selecting the target model with the highest test index score from the set of converted models according to the test results.

[0056] In one embodiment, it further includes: a third acquisition module 405, configured to, after acquiring the original model file, the quantization image set, and the model conversion configuration information, and when no automatic conversion instruction is received, acquire a quantization precision entered by a user on a parameter configuration page; a quantization module 406, configured to perform compression processing on the original model file by using a quantization precision to generate a compressed model file; a second creation module 407, configured to create a model conversion task for the compressed model file based on the configuration information and the quantization image set, and execute the model conversion task to generate a converted model.

[0057] For a detailed description of the above model conversion device 400, please refer to the description of the relevant method steps in the above embodiments.

[0058] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, including: a program, which when running on an electronic device enables the electronic device to execute all or part of the processes of the methods in the above 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, 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 memories.

[0059] Although the embodiments of the present invention are described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A model conversion method, characterized in that, Including: Obtain the original model file, the quantization image set, and the model conversion configuration information; When receiving the automatic conversion instruction entered by the user, obtain various quantization precisions entered by the user on the parameter configuration page; Based on the configuration information and the quantization image set, create multiple model conversion subtasks for the original model file under each quantization precision; Execute each model conversion subtask, generate a set of converted models, and select a target model from the set of converted models; wherein, each converted model in the set of converted models is generated by executing the corresponding model conversion subtask; Wherein, the configuration information further includes: test parameters; the selecting the target model from the set of converted models includes: Use a preset test set and the test parameters to test each model in the set of converted models, and output the test results; According to the test results, select the target model with the highest test index score from the set of converted models.

2. The method according to claim 1, wherein The creating multiple model conversion subtasks for the original model file based on the configuration information and the quantization image set under each quantization precision includes: For each quantization precision, compress the original model file using the quantization precision to generate a compressed model file; Randomly select multiple quantization image subsets from the quantization image set for each quantization precision; Based on the configuration information and the multiple quantization image subsets, create multiple model conversion subtasks for the compressed model file.

3. The method according to claim 2, wherein The executing each model conversion subtask to generate a set of converted models includes: For each model conversion subtask, input one quantization image subset into the compressed model file, perform parameter tuning on the compressed model file to obtain a converted model, and the set of converted models includes the converted models generated by each model conversion subtask.

4. The method according to claim 1, wherein After obtaining the original model file, the quantization image set, and the model conversion configuration information, it further includes: When not receiving the automatic conversion instruction, obtain one quantization precision entered by the user on the parameter configuration page; Compress the original model file using the one quantization precision to generate a compressed model file; Based on the configuration information and the quantization image set, create a model conversion task for the compressed model file and execute the model conversion task to generate a converted model.

5. A model conversion device, characterized in that, Including: The first obtaining module is used to obtain the original model file, the quantization image set, and the model conversion configuration information; The second obtaining module is used to obtain various quantization precisions entered by the user on the parameter configuration page when receiving the automatic conversion instruction entered by the user; The first creating module is used to create multiple model conversion subtasks for the original model file based on the configuration information and the quantization image set under each quantization precision; An execution module, configured to execute each of the model conversion subtasks, generate a set of converted models, and select a target model from the set of converted models; wherein each of the converted models in the set of converted models is generated by executing the corresponding model conversion subtask; Wherein, the configuration information further includes: test parameters; the execution module is further configured to: Test each model in the set of converted models using a preset test set and the test parameters, and output test results; Select the target model with the highest test index score from the set of converted models according to the test results.

6. The device according to claim 5, characterized in that, The first creation module is configured to: For each of the quantization precisions, compress the original model file using the quantization precision to generate a compressed model file; Randomly select multiple quantization image subsets from the quantization image set for each of the quantization precisions; Create a plurality of the model conversion subtasks for the compressed model file based on the configuration information and the plurality of quantization image subsets.

7. The device according to claim 6, characterized in that, The execution module is configured to: For each of the model conversion subtasks, input one of the quantization image subsets into the compressed model file, perform parameter adjustment processing on the compressed model file to obtain a converted model, and the set of converted models includes the converted models generated by each of the model conversion subtasks.

8. The device according to claim 5, characterized in that, Further includes: A third acquisition module, configured to acquire a quantization precision entered by the user on the parameter configuration page when no automatic conversion instruction is received after acquiring the original model file, the quantization image set, and the model conversion configuration information; A quantization module, configured to compress the original model file using the quantization precision to generate a compressed model file; A second creation module, configured to create a model conversion task for the compressed model file based on the configuration information and the quantization image set, and execute the model conversion task to generate a converted model.

9. An electronic device, characterized in that, Includes: A memory for storing a computer program; A processor for executing the computer program to implement the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Neural network model conversion method and related device

    CN111797969A

  • Neural network training method and system adopting mixed precision quantification and knowledge distillation

    CN113313250A

  • Multi-precision quantization element neural network training and precision selection method

    CN113537474A