Method for constructing object detection model library system based on ONNX
Through the ONNX-based object detection model library system construction method, the limitations of deep learning frameworks in the deployment and debugging process are solved, cross-frame and platform deployment of models are realized, the portability and universality of models are improved, and the deployment is simplified. and call process.
Patent Information
- Application Number
- CN202410002724.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-02
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2044-01-02
AI Technical Summary
The existing deep learning frameworks have many limitations in the deployment and debugging process, resulting in delays between research and production, and deploying multiple models in production environments with limited computing power requires huge workloads.
Using the ONNX-based object detection model library system construction method, we can realize model deployment across frameworks and platforms by selecting suitable deep learning models, preparing data sets, training and exporting them into ONNX format, and model inference and results are performed through ONNXRuntime. deal with.
Improves the portability and versatility of models, simplifies the deployment and call process, reduces the complexity of technology implementation, and provides flexible model selection and convenient tools for various industries.
Smart Images

Figure CN117975246B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of emerging software and new information technology service technology, and in particular to a method for constructing an ONNX-based target detection model library system. Background Art
[0002] After the iterative training of the deep learning model is completed, it needs to be deployed online. Deployment and online refers to the process of running the trained model in a specific environment, focusing more on the deployment scenario, deployment method, throughput and latency. The performance of the deep learning framework is related to its intermediate representation (IR). As an intermediate representation, graph can capture the specific intent of the developer's source code and help optimize and convert it to run on specific devices (CPU, GPU, FPGA, etc.).
[0003] The existing mainstream deep learning frameworks all have their own unique characteristics. Tensorflow uses static graphs for easy deployment, and TensorFlow Lite supports deployment on mobile devices, but is relatively difficult to debug; Pytorch uses dynamic graphs for easy debugging, which is relatively simple for people who are new to deep learning, but is difficult to deploy on a server; Caffe is easy to use, but in-depth learning is difficult, and it must be compiled from source code when deployed; Keras is highly integrated, making it easy for developers to verify ideas, but the high encapsulation makes it difficult for developers to add new operations or obtain underlying data information.
[0004] Developers choose a deep learning framework based on its pros and cons, but these frameworks are adapted to different development stages. When deployed online, the original model format needs to be modified, and even the parameters need to be retrained, resulting in significant delays between research and production. Suppose a scenario: developers develop a deep algorithm using a TensorFlow-based framework and need to deploy it on mobile devices. The traditional method requires rewriting the model in caffe2 format and then training the parameters. The whole process is time-consuming and laborious.
[0005] Currently, computing power is usually limited in production environments, and accelerated processing is required when deploying deep learning models. With increasing demand, a single model may not be able to meet the same type of tasks, and multiple models may need to be deployed at the same time. However, in the case of a single operating environment, deploying multiple models is time-consuming and labor-intensive, requiring a huge workload. At the same time, independent inference code needs to be written for each model, which places great demands on both developers and production environments. Summary of the invention
[0006] Purpose of the invention: In view of the problems and shortcomings of the prior art, the present invention provides a method for building a target detection model library based on ONNX, aiming to solve the limitation problems of traditional target detection models on specific frameworks and platforms. By selecting a deep learning model suitable for the task, preparing the corresponding data set, training the model, and exporting the trained model to the ONNX format, the user can build a flexible and portable model library. The models registered to the model library are platform-independent, allowing users to call these models for target detection through a unified interface, thereby simplifying the deployment and calling process. The advantages of the present invention are that the portability and versatility of the model are improved, a rich model library is built, and the opportunity for flexible selection is provided to users, while simplifying the implementation and migration process of target detection tasks. In addition, by building a model library, the present invention makes full use of the advantages of ONNX and provides users with a diverse and rich model selection pool to meet the target detection requirements of different tasks and needs. The present invention lowers the threshold for deploying and using deep learning models. This not only helps to improve production efficiency and reduce the complexity of technical implementation, but also provides practitioners in various industries with a wider range of choices and more convenient tools.
[0007] Technical solution: A method for building a target detection model library system based on ONNX, including the following contents:
[0008] (1) Dataset construction and model training: Based on the image dataset, an object detection model suitable for the dataset is used for training or fine-tuning to obtain a trained model.
[0009] (2) Based on ONNX model format conversion and deployment: According to the model input, the trained model is converted into the open neural network exchange ONNX format, and the model is uniformly deployed to the server ONNX Runtime environment to realize cross-framework deep learning model deployment;
[0010] (3) Reasoning based on ONNXRuntime model results: Based on the input image data, use ONNXRuntime to obtain the model reasoning results, write independent reasoning code for each model, and convert the ONNXRuntime reasoning results into the unified format required by the model library system;
[0011] (4) Result visualization: Visualize the test results based on the model standardization, and display the detected images and corresponding evaluation indicators in the user interface;
[0012] (5) Model library system construction: The model library system includes three modules: model registration, model display, and model service. Model registration is to upload the ONNX format model to the model library system; model display is to display all registered models in the model library system; model service is for users to call the model according to their needs to infer in the ONNX Runtiem environment and display the inference results.
[0013] Furthermore, the step (1) of data set construction and model training includes:
[0014] Select the target detection model that is suitable for the target detection data according to the user's target detection task. ONNX supports frameworks such as TensorFlow, Pytorch, Keras, MxNet, and MATLAB. The selected target detection model must be written based on the above ONNX-supported frameworks.
[0015] Build a target detection dataset containing multiple categories. The dataset usually comes from images collected by humans and intelligent devices such as drones. The target detection dataset needs to cover various target types and scenes to ensure the balance of the dataset. Train or fine-tune the model according to the selected target detection model and the constructed dataset. After training, save the model .pth or .pt file locally.
[0016] Furthermore, the step (2) is based on ONNX model format conversion and deployment, including:
[0017] After obtaining the trained model, it is necessary to export the trained model to the ONNX format to ensure the versatility of the model on different deep learning frameworks and platforms. Load the trained model file obtained in the above step (1), define the model input format, and call the corresponding export interface to export the model to the ONNX format. For the pytorch framework, the format conversion interface torch.onnx.export() is used for format conversion. After the model is exported to the ONNX format, the structure of the exported model can be checked to verify whether the ONNX model is a valid model. In actual application scenarios, the verification function check_model provided by ONNX is used for verification. Before exporting the ONNX format, it is also necessary to ensure that the exported ONNX model is compatible with the ONNXRuntime version of the inference environment on the server. The version number can be set through the parameter opset_version=xxx, where xxx represents the version number.
[0018] Save the exported ONNX model file locally for subsequent model registration and calling. During the saving process, the file name and model name need to be kept the same (x.pt and x.onnx) to better organize and manage the model library. Through this export process, the trained model is stored in the ONNX format, enabling efficient and seamless deployment on different deep learning frameworks and platforms, reflecting the portability and versatility of the model.
[0019] Furthermore, the step (3) is based on the ONNXRuntime model result reasoning, including:
[0020] Call the ONNX model file obtained in step (2) and deploy it to the ONNXRuntime reasoning environment. The ONNXRuntime library can be installed by executing the installation command in the Python environment, such as by using the Python command pipinstall onnxruntime==version, where version is the version number corresponding to ONNXRuntime. Load the ONNX model through the InferenceSession() function call provided by ONNXRuntime, read the input image, and obtain the target detection results. The results include the coordinates, category, and confidence of each detected target in the image. Use the model quantization optimization function of ONNXRuntime to optimize the target detection model to improve reasoning performance. ONNXRuntime provides a variety of optimization options that can be adjusted according to the target platform and hardware. After deployment, the performance of the model integrated with ONNXRuntime is evaluated on the target platform to verify the effect of the model on the reasoning task. The performance of the deployed model is measured using reasoning time and memory usage. The reasoning time is calculated as follows:
[0021]
[0022] Where start_time indicates the time before the inference starts, end_time indicates the time when the inference ends, and time.time() is a time function provided by Python, which is used to obtain the current time. The inference time is the time when the inference ends minus the time when the inference starts. The memory usage is calculated as follows:
[0023]
[0024] Among them, psutil is the memory calculation library provided by Python, and memory_usage_psutil() is the memory calculation function. The memory occupied by the model inference is the memory occupied by the model after the inference is completed minus the memory occupied by the model before the inference. In actual situations, the following formula is used to calculate the model score:
[0025]
[0026] Weighted calculation is used to rank model performance. Since detection time can more intuitively reflect model performance, α is set to 0.7 to make the time account for a larger proportion. Finally, the score is calculated. The lower the sum, the better the model performance. The calculation results will be returned to the user interface for reference.
[0027] Due to the differences in model structure, even under the same task and the same input, the output of each model will be different due to its structural differences. The differences in the output results include but are not limited to: the inference result outputs the prediction probability of all categories or the highest prediction probability; the inference result outputs the height, width and center point of the prediction box or the coordinate point of the prediction box. Therefore, it is necessary to format the output results. The present invention defines a standardized processing template, the purpose of which is to convert different initial output results into standardized results (x1, y1, x2, y2, class, score):
[0028]
[0029] The first four values of the standardized result (x1, y1, x2, y2, class, score) represent the size of the target detection prediction box, class represents the predicted category, and score represents the confidence. The model library system does not limit the image size input by the user, but each model has a fixed input and output size. Therefore, in order to accurately display the target detection results on the original image, the prediction box coordinates need to be proportionally transformed. The process of standardizing the inference results is saved locally in .py format and is strictly named according to model_handle.py. Model represents the model name. When the model is registered with the model library system, it is bound to the ONNX file corresponding to the model.
[0030] Furthermore, the visual display of the results in step (4) includes:
[0031] Based on the inference results in step (3), draw a bounding box or other shape on the image to highlight the detected target area. The color and line type of the annotation can be set according to the type of target; the detection result display should include the type label of each detected target; for each detection result, the corresponding confidence or probability score is displayed; in the detection result display, a comparison between the original image and the annotated detection result image should also be provided; provide statistical information about the overall detection results, such as the total number of detected targets in the target detection task, etc.
[0032] Furthermore, the model library system construction in step (5) includes:
[0033] Model registration: This invention defines a set of specifications for model registration, as follows:
[0034] 1. Model name: model_name. The model name is the model registration name, which is a unique identifier assigned to the model to ensure that each model in the model library can be uniquely identified.
[0035] 2. Input data format: size. The format is the image size required by the model for target detection tasks. OpenCV is called to format the input before model inference. It is not the image size uploaded by the user. The model library system does not limit the input image size.
[0036] 3. Task type: type. The specific task field to which the target detection model belongs, including but not limited to dam defect detection, highway crack detection, etc., so as to better distinguish the target detection model in a specific field.
[0037] 4. Model indicators: evaluation, the evaluation indicators of the model trained on the data set. In the target detection category task, mAP is usually used: the average precision of all categories. The model indicators are for subsequent model call services.
[0038] 5. Model introduction: Introduction is a description of the model, which allows users to understand the model from more perspectives. In addition to basic information about the model, it can also describe its structure and other information.
[0039] 6. Model upload: model_code, upload a .zip or .rar compressed file, including the model inferential code model.onnx and model_handle.py. The model name and compressed file name must be the same as the entered model name.
[0040] Complete the model registration steps according to the above template, and the system will save the above information in the model management database for subsequent display and call. After the model is uploaded, the database saves the field model_code which is the same as the model name. The uploaded compressed file will be decompressed on the system server, and the string matching method will be used to check whether the folder contains the required file.
[0041] Model display: Define and maintain a clear model library directory structure so that users can easily browse and search for the required models. Model display includes organizing the structure of models by specific domain tasks and sources (registrants). At the same time, the permission control mechanism is introduced during the system construction process to ensure that only authorized users can perform model registration and management operations, and ordinary users can only view and call models.
[0042] Model service: This invention designs a dynamic reasoning system for model service:
[0043]
[0044] The user prepares the image x to be detected and describes the task type z. The system provides selectable task types including but not limited to dam target detection and highway target detection. After determining the task type, the system queries the model library for the best model m with the highest mAP value according to the task type selected by the user, and obtains model-related information. Then the input image is standardized to match the model input, and the onnx model is called to infer the initial result y0 in the onnxruntime environment. The result processing method of the corresponding model is called by the dynamic import method import_module to obtain the normalized result y1. Finally, y1 is used to draw a picture to obtain the result graph y. The fifth column value of y1 is calculated and the total score of reasoning score is obtained. At the same time, the reasoning time time is calculated. The present invention uses the total score of reasoning instead of the average score avg_score to judge the reasoning result. The reason is that some models cannot detect all the targets in the image, which will cause a high average score, so the total score can better reflect the model performance. Finally, the detection results and other information are returned to the user interface. At the same time, the user can also manually select other recommended models for reasoning to compare the model performance in the current situation. Through the effective management of model library registration and model calling, users can easily select, call and apply different models to meet specific target detection needs. This provides greater flexibility and convenience for the practical application of the model.
[0045] The target detection model in the model library is compatible with multiple frameworks using different conversion rules, including at least one of the following:
[0046] TensorFlow and PyTorch.
[0047] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for constructing a system based on an ONNX target detection model library as described above is implemented.
[0048] A computer-readable storage medium stores a computer program for executing the method for building a system based on an ONNX target detection model library as described above.
[0049] In the example of this application, according to different target detection data sets, appropriate target model training is adopted to obtain a trained model; according to the actual model input, the trained model is converted into the open neural network exchange ONNX format, and the model is uniformly deployed to the server ONNXRuntime environment to realize cross-framework deep learning model deployment; the model inference results are obtained using ONNXRuntime, and independent inference code is written for each model, and the results are converted into the unified format required by the system; visualization is performed based on the detection results, and the detected images and corresponding evaluation indicators are displayed in the system; the model library system includes three modules: model registration, model display, and model service. Model registration is to upload the ONNX format model to the system; model display is to display all registered models in the model library system; model service is that users call the model according to their needs to infer in the ONNXRuntiem environment and display the inference results. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 is a flow chart of a method according to an embodiment of the present invention;
[0051] Figure 2 A flowchart of a method for exporting a multi-frame target detection model to ONNX according to an embodiment of the present invention;
[0052] Figure 3 This is a flow chart of the ONNXRuntime model reasoning of an embodiment of the present invention;
[0053] Figure 4 A schematic diagram of target detection model registration and model display according to an embodiment of the present invention;
[0054] Figure 5 The figure is a schematic diagram of system use according to an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The present invention is further explained below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0056] like Figure 1 As shown in the figure, the method for building a target detection model library system based on ONNX includes the following contents:
[0057] (1) Dataset construction and model training: Based on the image dataset, an object detection model suitable for the dataset is used for training or fine-tuning to obtain a trained model.
[0058] (2) Based on ONNX model format conversion and deployment: According to the model input, the trained model is converted into the open neural network exchange ONNX format, and the model is uniformly deployed to the server ONNX Runtime environment to realize cross-framework deep learning model deployment;
[0059] (3) Reasoning based on ONNXRuntime model results: Based on the input image data, use ONNXRuntime to obtain the model reasoning results, write independent reasoning code for each model, and convert the ONNXRuntime reasoning results into the unified format required by the model library system;
[0060] (4) Result visualization: Visualize the test results based on the model standardization, and display the detected images and corresponding evaluation indicators in the user interface;
[0061] (5) Model library system construction: The model library system includes three modules: model registration, model display, and model service. Model registration is to upload the ONNX format model to the model library system; model display is to display all registered models in the model library system; model service is for users to call the model according to their needs to infer in the ONNX Runtiem environment and display the inference results.
[0062] like Figure 2 As shown in the figure, the method of exporting the target detection model to ONNX includes the following steps:
[0063] (1) Dataset construction and model training
[0064] In the process of implementing the target detection model, the data set used for target detection needs to cover multiple types of targets to be detected, and the currently available public data sets can be directly selected. Data sets can also be constructed based on specific tasks including but not limited to dam defect detection, highway crack detection, etc. The construction of the data set requires annotating the location and type of each target in each sample. For situations where there are few data set samples and small feature differences, random rotation, flipping, scaling, etc. are used for data enhancement to improve the model's generalization ability for defects of different angles and scales.
[0065] Select a model trained using a deep learning framework supported by ONNX. This includes but is not limited to classic models that have been pre-trained on large-scale image datasets, such as ResNet and YOLO series. After training is completed, save the trained model locally. For example, the yolov7 model trained with the pytorch framework is saved as yolov7.pt.
[0066] (2) Export the model to ONNX format
[0067] Export the trained pytorch model to ONNX format. Use the format export function torch.onnx.export(model,x,'yolov7.onnx',input_names=inp,output_names=outp,verbose=True) provided by pytorch. First, load the above trained model yolov7.pt as model, then define the input format x=torch.randn(1,3,640,640). The third parameter is the file name after the model is exported, and the next two parameters are the input and output names respectively. The above are some commonly used parameters. When exporting, you can use the verification function onnx.checker.check_model("yolov7.onnx") to check whether the model is valid. At the same time, when exporting, you need to ensure that ONNX is compatible with the subsequent ONNXRuntime version so that the model can be loaded and run correctly. Save the exported ONNX model file locally for subsequent model registration and calling. During the saving process, you need to keep the file name and model name the same to better organize and manage the model library. The exported ONNX format model can be efficiently and seamlessly deployed on different deep learning frameworks and platforms, reflecting the portability and versatility of the model.
[0068] The model reasoning process based on ONNX Runtime is as follows Figure 3 As shown, the following steps are included:
[0069] (1) Obtain the initial inference results: Deploy the above-exported ONNX format model in the ONNXRuntime environment to achieve a unified deployment process across frameworks. First, you need to load the ONNX model and use the function provided by ONNXRuntiem, session = onnxruntime.InferenceSession (model_path), where model_path represents the path where the ONNX model is saved. Then read the input image. Make sure that the format, shape, and range of the input data match the input expected by the model. For example, for image data, preprocessing may be required to make it meet the input requirements of the model. When inferring the yolov7 model, the input image is required to be (640, 640). Use the opencv library provided by python to transform the input image dimension to meet the model requirements and convert the image into an array format. Finally, use the run() method provided by ONNXRuntime to obtain the initial inference results outputs = ort_session.run (None, ort_inputs).
[0070] (2) Initial result formatting: Format the initial inference results obtained above into the results required by the system. Referring to the inference result formatting method proposed in the present invention, the inference result of yolov7 is a vector containing 7 values, and the final inference result visualization only requires 6 values. In order to uniformly execute the visualization of the inference results, it is necessary to extract the required 6 values from the initial 7 values. The specific process is as follows:
[0071]
[0072] The visualization of inference results is uniformly executed. For different models in the same task requirement, the same code is used for visualization operations to simplify the model deployment workload to the greatest extent. For example, for detection models such as yolov7 and FasterRCNN, the codes of steps (1) and (3) are the same, while the code of step (2) is independent.
[0073] (3) Visualization of inference results: The formatted results obtained above are visualized and displayed on the input image. For the target detection task, the inference results include the detection box coordinates x1, x2, y1, y2, the detection category and the category probability (score). Traverse the two-dimensional array and use the drawing tool library to overlay the processed results on the original image, use highlight colors to highlight the location of the target, and attach the category and confidence next to each rectangular box. Finally, save the annotated image to a specific result processing folder to facilitate subsequent return to the user interface for reference.
[0074] The ONNX-based model library system includes:
[0075] (1) Model registration module: Figure 4As shown, the user fills in the metadata about each model. For the above yolov7 model, these metadata include the name of the model: yolov7, the type: dam defect detection, uploader: administrator A, training data set: dam defect data set, input data format and range: 640, evaluation index (mAP): 56.8%. The model name is used as the unique identifier of the registered model to ensure that each model in the model library can be uniquely identified. The target detection task contains a variety of subtasks, such as dam defect detection, highway crack detection, water pollution detection, etc. The model type is selected according to the specific task field. The exported ONNX format model file and model result inference are packaged into a compressed file and uploaded to the specified location of the model library, including yolov7.onnx and yolov7_handle.py, and the decompression operation is performed to facilitate subsequent model calls. The purpose of this naming is to enable quick retrieval by model name, which is also a form of normalization. When the user clicks to register the model, the model library system automatically updates the database of the model library, records the information of each model and the corresponding unique identifier, and facilitates subsequent model calls and runs.
[0076] (2) Model display module: Define and maintain a clear model library directory structure so that users can easily browse and search for the required models. Model display includes the structure of organizing models by task type, etc. At the same time, a permission control mechanism is introduced during the system construction process to ensure that only authorized users can perform model registration and management operations, and ordinary users can only view and call models.
[0077] (3) Model service module: Figure 5As shown, the user prepares the image data to be detected and describes the task type, such as to perform a dam defect detection task. Based on the input dam defect image, the system calls the best performance model for matching target detection in the model library for reasoning, and the system gives the yolov7 model. First, the ONNXRuntime reasoning file of the corresponding target detection task is called according to the task type, and then the yolov7.onnx model is called according to the model name for reasoning. Then, the corresponding result processing handle file-yolov7_handle.py is called by the model name to format the initial result. Finally, the result is visualized and the corresponding image and other processed results are saved, and the image and evaluation index results are returned to the user interface. In this process, the system allows users to manually select other recommended models for reasoning, such as selecting the DETR model. The intermediate process is the same as yolov7. The only difference is that the result processing handle file corresponding to DETR-detr_handle.py needs to be called, and the result is finally returned and displayed in the user interface. Users can compare the quality of the model under the current task by comparing the accuracy and performance score, and decide which model to use for the detection result.
[0078] It should be noted that the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions. In this way, the embodiments of the present invention are not limited to any specific hardware and software combination.
Claims
1. A method for constructing a target detection model library system based on ONNX, characterized in that: It includes the following: (1) Dataset construction and model training: Based on the image dataset, an object detection model suitable for the dataset is used for training or fine-tuning to obtain a trained model. (2) Based on ONNX model format conversion and deployment: According to the model input, the trained model is converted into the open neural network exchange ONNX format, and the model is uniformly deployed to the server ONNX Runtime environment to realize cross-framework deep learning model deployment; (3) Reasoning based on ONNXRuntime model results: Based on the input image data, use ONNXRuntime to obtain the model reasoning results, write independent reasoning code for each model, and convert the ONNXRuntime reasoning results into the unified format required by the model library system; (4) Result visualization: Visualize the test results based on the model standardization, and display the detected images and corresponding evaluation indicators in the user interface; (5) Model library system construction: The model library system includes three modules: model registration, model display, and model service. Model registration is to upload the ONNX format model to the model library system. Model display is to display all registered models in the model library system; Model service is when users call the model to infer in the ONNXRuntime environment according to their needs and display the inference results; The step (3) is based on the ONNX Runtime model result reasoning, and includes: Call the ONNX model file and deploy it to the ONNXRuntime inference environment; install the ONNXRuntime library by executing the installation command in the Python environment, and use the Python command pip install onnxruntime==version to achieve this, where version is the version number corresponding to ONNXRuntime; load the ONNX model through the InferenceSession() function call provided by ONNXRuntime, read the input image, and obtain the target detection results, which include the coordinates, category, and confidence of each detected target in the image; use the model quantization optimization function of ONNXRuntime to optimize the target detection model; After deployment, the performance evaluation is performed on the target platform to verify the effect of the model integrated with ONNXRuntime on the inference task. The inference time and memory usage are used to measure the performance of the deployed model. The inference time is the time when the inference ends minus the time when the inference starts. The memory usage mem is the memory occupied by the model after the inference ends minus the memory occupied by the model before the inference. The model score is calculated using the following formula: A weighted calculation is used to rank model performance. The lower the sum, the better the model performance. The calculation results will be returned to the user interface for reference.
2. The method for constructing an ONNX-based target detection model library system according to claim 1, characterized in that: The step (1) of data set construction and model training includes: Select a target detection model suitable for target detection data based on the user's target detection task; the selected target detection model is written based on the framework supported by ONNX; Build a multi-category target detection dataset. The target detection dataset needs to cover various target types and scenarios. Train or fine-tune the model based on the selected target detection model and the constructed dataset. After training, save the "model.pth or .pt" file locally.
3. The method for constructing a target detection model library system based on ONNX according to claim 1, characterized in that: The step (2) is based on ONNX model format conversion and deployment, and includes: After obtaining the trained model, it is necessary to export the trained model to the ONNX format; load the trained model file obtained in step (1), define the model input format, and call the corresponding export interface to export the model to the ONNX format; after the model is exported to the ONNX format, check the structure of the exported model to verify whether the ONNX model is a valid model; before exporting the ONNX format, it is also necessary to ensure that the exported ONNX model is compatible with the ONNXRuntime version of the inference environment on the server; Save the exported ONNX model file locally for subsequent model registration and calling. During the saving process, the file name and model name must be kept the same.
4. The method for constructing an ONNX-based target detection model library system according to claim 3, characterized in that: For the pytorch framework, the format conversion interface torch.onnx.export() is used for format conversion; after the model is exported to the ONNX format, the structure of the exported model can be checked to verify whether the ONNX model is a valid model. In actual application scenarios, the verification function check_model provided by ONNX is used for verification; before exporting the ONNX format, it is also necessary to ensure that the exported ONNX model is compatible with the inference environment ONNXRuntime version on the server, and set the version number through the parameter opset_version=xxx, where xxx represents the version number.
5. The method for constructing a target detection model library system based on ONNX according to claim 1, characterized in that: Due to the differences in model structures, even under the same task and the same input, the output of each model will be different due to its structural differences; therefore, the output results need to be formatted; a standardized processing template is defined to convert different initial output results into standardized results (x1, y1, x2, y2, class, score); the first four values of the standardized results (x1, y1, x2, y2, class, score) represent the size of the target detection prediction box, class represents the prediction category, and score represents the confidence level; the process of standardizing the inference results is saved locally in .py format and named according to model_handle.py, where model represents the model name, and is bound and registered with the ONNX file corresponding to the model when the model is registered to the model library system.
6. The method for constructing a target detection model library system based on ONNX according to claim 1, characterized in that: The target detection model in the model library is compatible with multiple frameworks that use different conversion rules, including at least one of the following: TensorFlow and PyTorch.
7. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method for constructing an ONNX-based target detection model library system is implemented as described in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method for building an ONNX-based target detection model library system as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Neural network transfer learning automatic training scheduling method based on ONNX model
CN111539527A
Electronic component defect detection method and device, equipment and storage medium
CN116309513A