Algorithm model conversion detection method and device
After converting the neural network learning algorithm model, the input of the sample to be detected and the method of comparing the detection results is solved in the prior art that the model detection accuracy cannot be judged after the format conversion, and the effect of quickly judging the converted model detection accuracy is achieved.
Patent Information
- Application Number
- CN202510098689.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-22
- Publication Date
- 2025-05-13
AI Technical Summary
The prior art cannot effectively judge the impact of the detection accuracy of neural network learning algorithm models after format conversion, resulting in the inability to quickly judge the detection accuracy of model after format conversion.
By obtaining the first format detection model trained, converting it according to the preset conversion parameters, obtaining the second format detection model, and then inputting the samples to be detected into the two models respectively, comparing the detection results to judge the validity of the converted model.
It can quickly judge the detection accuracy of the neural network learning algorithm model after format conversion, ensure that the converted model is consistent with the original model detection results, thereby ensuring detection accuracy.
Smart Images

Figure CN119989094A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of conversion model detection, and in particular to an algorithm model conversion detection method and device. Background Art
[0002] With the development of neural network learning algorithm models, the application scenarios of neural network learning algorithm models are becoming more and more extensive. In different application scenarios, the application formats of neural network learning algorithm models will also be different, which will cause the file format of the trained neural network learning algorithm model to be inconsistent with the file format of the neural network learning algorithm model required for application. Therefore, it is necessary to convert the format of the neural network learning algorithm model before the file format of the neural network learning algorithm model required for application can be obtained. However, the format conversion may affect the performance of the neural network learning algorithm model, and the existing technology cannot determine whether the detection accuracy of the neural network learning algorithm model after the format conversion is affected by the format conversion. Summary of the invention
[0003] The purpose of this application is to provide an algorithm model conversion detection method and device that can overcome the shortcomings and deficiencies in the prior art.
[0004] A first aspect of an embodiment of the present application provides an algorithm model conversion detection method, comprising:
[0005] Obtain the trained first format detection model;
[0006] According to preset conversion parameters, the first format detection model is converted to obtain a second format detection model;
[0007] Inputting the sample to be detected into the first format detection model and the second format detection model respectively to obtain a first detection result and a second detection result;
[0008] According to the comparison result of the first detection result and the second detection result, the validity of the converted second format detection model is obtained.
[0009] Furthermore, the step of inputting the sample to be detected into the first format detection model and the second format detection model respectively to obtain the first detection result and the second detection result includes:
[0010] Loading the first format detection model and the second format detection model;
[0011] Preprocessing the sample to be detected to obtain a preprocessed sample to be detected;
[0012] The first format detection model and the second format detection model are driven to detect the preprocessed sample to be detected, respectively, to obtain the first detection result and the second detection result.
[0013] Furthermore, the step of obtaining the validity of the converted second format detection model according to the comparison result of the first detection result and the second detection result includes:
[0014] comparing the first test result and the second test result;
[0015] If they are the same, the second format detection model obtained by conversion is determined to be a valid model; if they are different, the second format detection model obtained by conversion is determined to be an invalid model.
[0016] Furthermore, the step of comparing the first test result and the second test result includes:
[0017] Comparing the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determining that the first detection result and the second detection result are different;
[0018] If the detection boxes are the same, the result text of the first detection result is compared with the result text of the second detection result. If the result texts are the same, it is determined that the first detection result and the second detection result are the same; otherwise, it is determined that the first detection result and the second detection result are not the same.
[0019] Furthermore, the first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used during model training or testing.
[0020] A second aspect of an embodiment of the present application provides an algorithm model conversion detection device, including:
[0021] A first model acquisition module, used to acquire a trained first format detection model;
[0022] A second model acquisition module, used to convert the first format detection model according to preset conversion parameters to obtain a second format detection model;
[0023] A detection result acquisition module, used to input the sample to be detected into the first format detection model and the second format detection model respectively, to obtain a first detection result and a second detection result;
[0024] A comparison and judgment module is used to obtain the validity of the converted second format detection model based on the comparison result of the first detection result and the second detection result.
[0025] Furthermore, the detection result acquisition module includes:
[0026] A model loading submodule, used for loading the first format detection model and the second format detection model;
[0027] A preprocessing submodule, used for preprocessing the sample to be detected to obtain a preprocessed sample to be detected;
[0028] The detection submodule is used to drive the first format detection model and the second format detection model to detect the pre-processed sample to be detected respectively, so as to obtain the first detection result and the second detection result.
[0029] Furthermore, the comparison and judgment module includes:
[0030] A comparison submodule, used for comparing the first detection result with the second detection result;
[0031] The judgment module is used to determine that the second format detection model obtained by conversion is a valid model if they are the same; if they are different, determine that the second format detection model obtained by conversion is an invalid model.
[0032] Furthermore, the comparison submodule is used to perform the following steps:
[0033] Comparing the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determining that the first detection result and the second detection result are different;
[0034] If the detection boxes are the same, the result text of the first detection result is compared with the result text of the second detection result. If the result texts are the same, it is determined that the first detection result and the second detection result are the same; otherwise, it is determined that the first detection result and the second detection result are not the same.
[0035] Furthermore, the first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used during model training or testing.
[0036] Compared with the prior art, the present application converts the trained first format detection model according to preset conversion parameters to obtain a second format detection model, and then inputs the samples to be detected into the first format detection model and the second format detection model respectively to obtain a first detection result and a second detection result, and then obtains the validity of the converted second format detection model based on the comparison result of the first detection result and the second detection result, so as to judge whether the second format detection model obtained by format conversion is consistent with the detection result of the first format detection model, thereby quickly judging the detection accuracy of the second format detection model obtained by format conversion.
[0037] In order to provide a clearer understanding of the present application, the specific implementation of the present application will be described below in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 This is a flowchart of an algorithm model conversion detection method according to an embodiment of the present application.
[0039] Figure 2 A schematic diagram of model connection of an algorithm model conversion detection device according to an embodiment of the present application.
[0040] 100. Algorithm model conversion detection device; 101. First model acquisition module; 102. Second model acquisition module; 103. Detection result acquisition module; 104. Comparison and judgment module. DETAILED DESCRIPTION
[0041] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0042] It should be clear that the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the embodiments of the present application.
[0043] When the following description relates to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. In the description of the present application, it should be understood that the terms "first", "second", "third", etc. are only used to distinguish similar objects, and do not have to be used to describe a specific order or sequence, nor can they be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances. The singular forms of "a", "said" and "the" used in the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. The words "if" / "if" used herein can be interpreted as "at the time of" or "when" or "in response to determination".
[0044] In addition, in the description of this application, unless otherwise specified, "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0045] See also Figure 1 , which is a flow chart of an algorithm model conversion detection method according to an embodiment of the present application, comprising:
[0046] S1: Get the trained first format detection model.
[0047] S2: According to preset conversion parameters, convert the first format detection model to obtain a second format detection model.
[0048] Among them, the first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used in model training or testing.
[0049] S3: Input the sample to be detected into the first format detection model and the second format detection model respectively to obtain a first detection result and a second detection result.
[0050] S4: Obtaining the validity of the converted second format detection model based on the comparison result of the first detection result and the second detection result.
[0051] Taking yolov7 as an example, steps S1-S4 can be implemented by the following steps:
[0052] 1. Open the project's yolov7 / export.py and prepare to convert the model format.
[0053] 2. Modify parameters:
[0054] Modify the data and weight parameters of the parse_opt function in export.py, where data / dataset.yaml is the labels in the corresponding order used for model training, and best.pt is the model file after training.
[0055] 3. Model conversion:
[0056] Run export.py. After the run, you can see the converted best.onnx file in the yolov7 directory.
[0057] 4. Format detection:
[0058] To ensure that the onnx format inference is correct, set the weights parameter of detect.py to best.onnx, open the command line, click detect->Edit Configurations, and enter the corresponding parameter command in Parameters:
[0059] python detect.py--weights best.pt-source
[0060] .. / datasets / images / val
[0061] Execute detect.py and save the inference results in the runs / detect / latest exp directory. Check whether the inference results of the onnx model are normal.
[0062] Compared with the prior art, the present application converts the trained first format detection model according to preset conversion parameters to obtain a second format detection model, and then inputs the samples to be detected into the first format detection model and the second format detection model respectively to obtain a first detection result and a second detection result, and then obtains the validity of the converted second format detection model based on the comparison result of the first detection result and the second detection result, so as to judge whether the second format detection model obtained by format conversion is consistent with the detection result of the first format detection model, thereby quickly judging the detection accuracy of the second format detection model obtained by format conversion.
[0063] In a feasible embodiment, the step S3: inputting the sample to be detected into the first format detection model and the second format detection model respectively to obtain the first detection result and the second detection result includes:
[0064] S31: Loading the first format detection model and the second format detection model.
[0065] S32: preprocessing the sample to be detected to obtain a preprocessed sample to be detected.
[0066] S33: driving the first format detection model and the second format detection model to detect the preprocessed sample to be detected respectively, to obtain the first detection result and the second detection result.
[0067] In this embodiment, through steps S31-S33, the first detection result and the second detection result are obtained more accurately.
[0068] In a feasible embodiment, S4: the step of obtaining the validity of the converted second format detection model according to the comparison result of the first detection result and the second detection result includes:
[0069] S41: Compare the first detection result and the second detection result.
[0070] S42: If they are the same, determining that the second format detection model obtained by conversion is a valid model; if they are different, determining that the second format detection model obtained by conversion is an invalid model.
[0071] In this embodiment, whether the second format detection model is a valid model can be determined based on the first detection result and the second detection result.
[0072] In a feasible embodiment, S41: the step of comparing the first detection result and the second detection result includes:
[0073] S411: Compare the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determine that the first detection result and the second detection result are different.
[0074] S412: If the detection boxes are the same, compare the result text of the first detection result with the result text of the second detection result. If the result texts are the same, determine that the first detection result and the second detection result are the same; otherwise, determine that the first detection result and the second detection result are not the same.
[0075] In this embodiment, the detection box and the result text are two important indicators of the detection results. Therefore, by first comparing the detection box of the first detection result with the detection box of the second detection result, and then comparing the result text of the first detection result with the result text of the second detection result, it is possible to accurately determine whether the first detection result and the second detection result are the same.
[0076] See also Figure 2 The second aspect of the embodiment of the present application provides an algorithm model conversion detection device 100, comprising:
[0077] A first model acquisition module 101, used to acquire a trained first format detection model;
[0078] A second model acquisition module 102, configured to convert the first format detection model according to preset conversion parameters to obtain a second format detection model;
[0079] A detection result acquisition module 103, used to input the sample to be detected into the first format detection model and the second format detection model respectively, to obtain a first detection result and a second detection result;
[0080] The comparison and judgment module 104 is used to obtain the validity of the converted second format detection model according to the comparison result of the first detection result and the second detection result.
[0081] In a feasible embodiment, the detection result acquisition module 103 includes:
[0082] A model loading submodule, used for loading the first format detection model and the second format detection model;
[0083] A preprocessing submodule, used for preprocessing the sample to be detected to obtain a preprocessed sample to be detected;
[0084] The detection submodule is used to drive the first format detection model and the second format detection model to detect the pre-processed sample to be detected respectively, so as to obtain the first detection result and the second detection result.
[0085] In a feasible embodiment, the comparison and judgment module 104 includes:
[0086] A comparison submodule, used for comparing the first detection result with the second detection result;
[0087] The judgment module is used to determine that the second format detection model obtained by conversion is a valid model if they are the same; if they are different, determine that the second format detection model obtained by conversion is an invalid model.
[0088] In a feasible embodiment, the comparison submodule is used to perform the following steps:
[0089] Comparing the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determining that the first detection result and the second detection result are different;
[0090] If the detection boxes are the same, the result text of the first detection result is compared with the result text of the second detection result. If the result texts are the same, it is determined that the first detection result and the second detection result are the same; otherwise, it is determined that the first detection result and the second detection result are not the same.
[0091] In a feasible embodiment, the first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used in model training or testing.
[0092] It should be noted that the algorithm model conversion detection device 100 provided in the second embodiment of the present application only uses the division of the above-mentioned functional modules as an example when executing the algorithm model conversion detection method. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the algorithm model conversion detection device 100 provided in the second embodiment of the present application and the algorithm model conversion detection method of the first embodiment of the present application belong to the same concept. The implementation process thereof is detailed in the method embodiment and will not be repeated here.
[0093] The device embodiments described above are merely illustrative, wherein the components described as separate parts may or may not be physically separated, and the parts displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application. Ordinary technicians in this field can understand and implement it without creative work.
[0094] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0095] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 generate 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 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the function selected in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 function selected in a box or multiple boxes.
[0096] 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 in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 steps for the function selected in a box or multiple boxes.
[0097] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0098] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0099] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0100] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0101] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. An algorithm model conversion detection method, characterized in that: include: Obtain the trained first format detection model; According to preset conversion parameters, the first format detection model is converted to obtain a second format detection model; Inputting the sample to be detected into the first format detection model and the second format detection model respectively to obtain a first detection result and a second detection result; According to the comparison result of the first detection result and the second detection result, the validity of the converted second format detection model is obtained.
2. The algorithm model conversion detection method according to claim 1, characterized in that: The step of inputting the sample to be detected into the first format detection model and the second format detection model respectively to obtain the first detection result and the second detection result includes: Loading the first format detection model and the second format detection model; Preprocessing the sample to be detected to obtain a preprocessed sample to be detected; The first format detection model and the second format detection model are driven to detect the preprocessed sample to be detected, respectively, to obtain the first detection result and the second detection result.
3. The algorithm model conversion detection method according to claim 1, characterized in that: The step of obtaining the validity of the converted second format detection model according to the comparison result of the first detection result and the second detection result includes: comparing the first test result and the second test result; If they are the same, the second format detection model obtained by conversion is determined to be a valid model; if they are different, the second format detection model obtained by conversion is determined to be an invalid model.
4. The algorithm model conversion detection method according to claim 3, characterized in that: The step of comparing the first test result and the second test result comprises: Comparing the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determining that the first detection result and the second detection result are different; If the detection boxes are the same, the result text of the first detection result is compared with the result text of the second detection result. If the result texts are the same, it is determined that the first detection result and the second detection result are the same; otherwise, it is determined that the first detection result and the second detection result are not the same.
5. The algorithm model conversion detection method according to claim 3, characterized in that: The first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used during model training or testing.
6. An algorithm model conversion detection device, characterized in that: include: A first model acquisition module, used to acquire a trained first format detection model; A second model acquisition module, used to convert the first format detection model according to preset conversion parameters to obtain a second format detection model; A detection result acquisition module, used to input the sample to be detected into the first format detection model and the second format detection model respectively, to obtain a first detection result and a second detection result; A comparison and judgment module is used to obtain the validity of the converted second format detection model based on the comparison result of the first detection result and the second detection result.
7. The algorithm model conversion detection device according to claim 6, characterized in that: The detection result acquisition module includes: A model loading submodule, used to load the first format detection model and the second format detection model; A preprocessing submodule is used to preprocess the sample to be detected to obtain a preprocessed sample to be detected; The detection submodule is used to drive the first format detection model and the second format detection model to detect the pre-processed sample to be detected respectively, so as to obtain the first detection result and the second detection result.
8. The algorithm model conversion detection device according to claim 6, characterized in that: The comparison and judgment module comprises: A comparison submodule, used for comparing the first detection result with the second detection result; The judgment module is used to determine that the second format detection model obtained by conversion is a valid model if they are the same; if they are different, determine that the second format detection model obtained by conversion is an invalid model.
9. The algorithm model conversion detection device according to claim 8, characterized in that: The comparison submodule is used to perform the following steps: Comparing the detection frame of the first detection result with the detection frame of the second detection result; if the detection frames are different, determining that the first detection result and the second detection result are different; If the detection boxes are the same, the result text of the first detection result is compared with the result text of the second detection result. If the result texts are the same, it is determined that the first detection result and the second detection result are the same; otherwise, it is determined that the first detection result and the second detection result are not the same.
10. The algorithm model conversion detection device according to claim 8, characterized in that: The first format detection model is a pt format model, the second format detection model is an onnx format model, and the conversion parameters include a configuration file path data for specifying a data set, and a weight file path weights used during model training or testing.