WO2024234986A1 - Method for customizing sensor function and smart device comprising sensor - Google Patents
Method for customizing sensor function and smart device comprising sensor Download PDFInfo
- Publication number
- WO2024234986A1 WO2024234986A1 PCT/CN2024/090359 CN2024090359W WO2024234986A1 WO 2024234986 A1 WO2024234986 A1 WO 2024234986A1 CN 2024090359 W CN2024090359 W CN 2024090359W WO 2024234986 A1 WO2024234986 A1 WO 2024234986A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- post
- mathematical model
- processing
- output data
- runtime
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/362—Debugging of software
- G06F11/3624—Debugging of software by performing operations on the source code, e.g. via a compiler
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
Definitions
- the present invention relates to the field of computers, and in particular to a technology for customizing sensor functions based on Wasm technology.
- sensors can be used in autonomous driving, equipment detection, environmental detection, logistics detection, security detection, health detection, smart home appliances, retail industry, health care, agriculture, smart cities, etc.
- the sensors in smart devices contain computing models or AI models that are developed, trained, or customized for specific purposes. These models are collectively referred to as mathematical models in this article.
- the sensors can use the corresponding mathematical models to provide computing or reasoning results based on the sensor's detection.
- the format of the computing or reasoning results may vary depending on the model.
- a typical post-processing method is to convert the calculation or reasoning results into a readable, visible and structured metadata character stream.
- model developers usually do not understand the software and hardware architecture of smart devices, and developers pay more attention to the logic of post-processing and ensure its adaptation to the model.
- the Camera Remote SDK a software development kit provided by Sony, does not provide a general API for sensor control.
- Waft WebAssembly Framework for Things
- a new development framework proposed by Facebook engineers does not provide an API for accessing AI sensors or general sensors to read data.
- Wasm technology is suitable for task sharing to reduce the burden on the main computing node, but no method is provided for task simulation on child nodes.
- CN202210944973, CN202210096203, etc. lack sandbox control, have security issues, or do not comply with wasi specifications.
- the purpose of the present invention is to propose a method and a module for customizing sensor functions based on Wasm technology, which do not have the disadvantages of the prior art and have additional advantages.
- the present invention allows developers to focus only on the logic of model post-processing without having to pay attention to the specific implementation and deployment of the model.
- One aspect of the present invention relates to a method for customizing sensor functions based on Wasm technology, which includes: providing a mathematical model trained for a sensor in a smart device and a post-processing program customized for the mathematical model, wherein the post-processing program is used to perform post-processing on output data of the mathematical model; deploying the mathematical model in the smart device; compiling the post-processing program into a Wasm program and deploying it in the smart device; providing an interface defined based on the WASI specification in the smart device, and the Wasm program can access and operate the sensor through the interface.
- Another aspect of the present invention relates to a smart device comprising a sensor, wherein the functionality of the sensor is customized according to the method of the present invention.
- a debugging tool for debugging a mathematical model which includes a post-processing module and a compiler stack, wherein the post-processing module generates a post-processing template file for post-processing the mathematical model, provides the post-processing template file to the compiler stack, and receives output data of the mathematical model from a runtime running the mathematical model and provides it to a developer, wherein the compiler stack compiles the received post-processing template file into an executable file that can be executed by the runtime, and provides the executable file to the runtime, so that the runtime can generate the output data using the mathematical model.
- Wasm technology is used to enable the post-processing function to be deployed across platforms and in a modular manner, thereby enabling it to be deployed on smart devices. Customize sensor specific functions in
- developers can easily debug post-processing, and have the following advantages: no need to compulsorily learn low-level languages or employ specific hardware engineers for debugging; guaranteed execution efficiency; easy to transplant.
- Figure 1 shows the creation and training of the mathematical model and the development of the post-processing procedure.
- FIG. 2 shows the development process of a mathematical model according to the prior art.
- FIG. 3 shows a debugging tool for debugging a mathematical model according to an embodiment of the present invention.
- FIG. 4 shows a flow chart of a process for debugging a mathematical model according to an embodiment of the present invention.
- sensors like image sensors, sound sensors, light sensors etc. These sensors can be used to achieve different purposes depending on the smart device.
- the developer can create and train the corresponding mathematical model in, for example, a host.
- the developer can use a model framework tool to create and train the mathematical model.
- model framework tools For example, development platforms such as tensorflow, pytorch, and onnx can be used as model framework tools.
- the sensor can use the mathematical model to calculate or infer the sensor's detection results to obtain a calculation result or an inference result. The sensor then outputs the obtained calculation result or inference result as output data in a specific format.
- developers also need to develop a post-processing program for post-processing in, for example, a host computer. Developers can develop post-processing programs in their favorite programming languages, such as Python, C/C++, Java, Go, or Rust. Through the post-processing program, the smart device can post-process the output data of the sensor (such as format conversion, etc.) to provide a post-processing result containing the desired information.
- a post-processing program for post-processing in, for example, a host computer. Developers can develop post-processing programs in their favorite programming languages, such as Python, C/C++, Java, Go, or Rust.
- the smart device can post-process the output data of the sensor (such as format conversion, etc.) to provide a post-processing result containing the desired information.
- FIG1 shows a case where an IoT device including a camera is used as a smart device.
- the camera is a sensor in the sense of the present invention.
- the smart device of the present invention is not limited to IoT devices. According to the technical inspiration of the present invention, those skilled in the art can also apply the present invention to the fields of autonomous driving, equipment detection, environmental detection, logistics detection, security detection, health detection, smart home appliances, retail industry, health care, agriculture, smart cities, etc. Here, they are not listed one by one.
- the left side of Figure 1 shows the creation and training of the mathematical model of the camera and the development of the post-processing program.
- the mathematical model of the camera can be an object detection model, such as a pedestrian detection model, a face recognition model, etc.
- the completed mathematical model and post-processing program are usually directly deployed on the hardware of the smart device, for example, in the example of FIG1, they are respectively deployed in the digital signal processor (DSP) of the camera and the processor of the IoT device.
- DSP digital signal processor
- the mathematical model When deploying the mathematical model, the power consumption, performance, and resources of the camera are taken into consideration, and the mathematical model can be lightweighted, for example, by using methods such as deep separable convolution, grouped convolution, adjustable hyperparameters to reduce spatial resolution, knowledge distillation, low-rank pruning, and model compression.
- the camera uses the mathematical model to calculate or infer the camera detection results and outputs the calculation or inference results as output data. Then, the IoT device including the camera can use the post-processing program to post-process the camera output data to obtain the desired information.
- the programming environment of the mathematical model can be Python, C/C++, Java, Rust, Go, etc.
- the present invention proposes a technical solution for customizing sensor functions based on Wasm technology.
- Wasm or WebAssembly, is a new bytecode format that is gradually being widely recognized due to its portability, small size, and high security.
- Wasm allows users to write in a language they are familiar with (currently supports programming languages such as python, C/C++, Rust, Java, or Go), and then use a virtual machine engine to run on the web.
- Wasm technology supports running Wasm programs in a sandbox environment.
- the post-processing program is compiled into a Wasm program and deployed in an IoT device (e.g., a processor) to run in a virtual machine provided by the IoT device.
- an IoT device e.g., a processor
- various compilers such as the LLVM backend, can be used.
- WASI WebAssembly System Interface
- WASI WebAssembly System Interface
- WASI WebAssembly System Interface
- Wasm programs can also run in non-web environments. As long as the WASI standard is supported, any runtime that runs Wasm programs can Implement system calls in the host environment of the IoT device.
- the runtime library provides the execution environment of the program, such as memory allocation, variable assignment, function call, etc. It can also be used to manage threads or processes, execute interpreted code, dynamic link libraries and shared libraries, etc.
- the Wasm program can correctly parse the output data generated by the sensor's mathematical model, and can access and operate the sensor (for example, turn it on, turn it off, perform reasoning, retrieve results, etc.).
- the Wasm program can access and control the various functions provided by the sensor through the Wasi interface through the sandbox boundary, such as obtaining reasoning data, controlling the life cycle of the sensor, etc., which can not only ensure the security and reliability of the program, but also protect the security of various types of information and equipment.
- the Wasm program needs to access sensor resources, it can pass the access request to the sensor through the interface.
- the sensor responds to the access request and returns the reasoning data to the Wasm program.
- each sensor may be provided with at least one mathematical model to achieve a specific purpose.
- multiple mathematical models may be provided for the camera, including but not limited to a pedestrian detection model, a face recognition model, a text recognition model, a license plate information recognition model, etc.
- a post-processing program may be provided for each mathematical model to perform post-processing on the output data of the mathematical model.
- a post-processing program may also be provided for multiple mathematical models to perform post-processing on the output data of these mathematical models in combination.
- the present invention customizes sensor functions based on Wasm technology, developers can also develop post-processing programs in any language they like, without having to consider what platform it runs on and how to adjust the program in different devices.
- Wasm technology restricts Wasm programs to run in a sandbox environment, so it has high security.
- the present invention provides a sensor system interface based on the WASI specification. It runs in a sandbox environment to control the entire life cycle, which becomes safer.
- the present invention also implements modular sensor control functions, and the function of the sensor can be expanded or changed by updating a single Wasm program instead of updating the entire platform.
- the present invention proposes a set of cross-platform sensor control interfaces, which developers can use to connect mathematical model development locally and implement specific post-processing functions.
- the Wasm technology enables the post-processing function to be deployed cross-platform and modularly, so that specific functions of sensors can be customized in smart devices.
- FIG. 2 shows a process of developing a mathematical model using, for example, the Python programming language according to the prior art.
- Model developers can use model framework tools to train mathematical models.
- development platforms such as tensorflow, pytorch, and onnx can be used as model framework tools in the Python programming environment.
- Programming tools are not limited to Python, but can also be C/C++, Java, Rust, and Go.
- the model framework tool is first used to generate an initial model, and then the generated initial model is trained through machine learning. After the initial model is trained, the trained initial model is exported.
- the edge device can be the camera in Figure 1.
- the deployed mathematical model can be run in the edge device to obtain calculation results or inference results.
- developers mainly focus on model design creation without ensuring the efficiency requirements of industrial software.
- the present invention proposes a debugging tool that can be created in a Docker image to provide developers with out-of-the-box services.
- development platforms for various programming languages can be created, such as Python, Java, Go, and other programming languages. This article uses the Python programming language as an example for illustration.
- a runtime e.g., WAMR Runtime
- edge devices e.g., the smart devices mentioned above
- FIG3 shows a debugging tool according to an embodiment of the present invention, which is used to debug a mathematical model to obtain a higher task index, a faster running speed, and a smaller model volume.
- developers can, for example, create the entire debugging tool in a Docker image on their own host to provide a Docker container service from the Docker image, so developers can provide this service at any time on almost all PC or server operating system platforms, such as in x86 or arm hardware structures.
- Docker container is an open source application container engine that allows developers to package their applications and dependent packages into portable containers in a unified manner.
- first write a Dockerfile file which is used to define the environment and application in the Docker image; then, in the Dockerfile file Add the required debugging tools.
- the debugging tool may include a post-processing module, a compiler stack and an optional optimizer.
- the post-processing module may include a post-processing code module, a decoder and a raw data viewer.
- the compiler stack may include a C++ converter, a WASM compiler and a publisher.
- the optimizer may include a standard analyzer, a comparator and a scheduler.
- a runtime e.g., WAMR runtime
- WAMR runtime can be used to run the mathematical model in the edge device.
- the Docker runtime environment of the debugging tool can be connected to the runtime of the edge device via a connector interface, and the connector interface can be used to handle communication protocols, data format conversion, security authentication and other issues to achieve communication and interaction. If necessary, data encryption, identity authentication and other issues need to be considered to ensure the security of communication and the integrity of data.
- the connection can be automatically performed using various communication protocols, such as wired or wireless communication protocols.
- the developer can fill the Python post-processing code for post-processing into the template Python file through the post-processing code module.
- the Python post-processing code may include instructions for post-processing the output data of the mathematical model.
- the post-processing code can be customized by the developer according to the desired post-processing function.
- the C++ converter in the compiler stack converts the Python post-processing code from the post-processing code module into C++ code.
- the WASM compiler in the compiler stack converts the C++ code into a Wasm executable file.
- the compiler stack uses the publisher to publish the converted Wasm executable file to the Runtime that runs the mathematical model via the connector interface.
- the mathematical model outputs the calculation or reasoning result (i.e., output data), and outputs the calculation or reasoning result to the decoder in the post-processing module via the connector interface.
- the decoder decodes the calculation or reasoning result.
- the raw data viewer in the post-processing module displays the decoded calculation or reasoning data to the developer in the form of, for example, images, sounds, text, etc. If the calculation or reasoning result is incorrect or unsatisfactory, the developer can adjust the mathematical model and then repeat the process as shown in marks 1 to 7 until the correct or ideal calculation or reasoning result is obtained.
- the developer can also optimize the mathematical model.
- developers can submit performance criteria, trial time cost constraints, and current results to the optimizer.
- the standard analyzer parses the performance standard configuration to extract parameters and time costs, and the comparator compares the standard request and the current result. If the result meets the request, then as shown in mark As shown, the current result and time cost are directly returned to the developer. Otherwise, as shown in mark 9, the scheduler is started to test various optimization hyperparameters and scheduling strategies, and the publisher is controlled to run the optimized test code on the edge device in the process shown in marks 3 to 5, and the result of each test case is sent to the comparator in the manner shown in mark 10 until a satisfactory value is reached or the best result within the set time is found, and then it is sent back to the developer together with the time cost.
- FIG. 4 shows a flow chart of a process for debugging a mathematical model according to an embodiment of the present invention.
- the template file is converted into an execution file through the compiler stack.
- the connector interface is ready for connection. If this is not the case, the device is restarted to connect until the connection is successful. In the case of a successful connection, the executable file is published to the runtime via the connector interface through the compiler stack.
- the mathematical model outputs the calculation or reasoning result (ie, output data) to the post-processing module via the connector interface.
- the post-processing module decodes the calculation or reasoning result and displays the decoded calculation or reasoning result to the developer.
- the developer can adjust the mathematical model and repeat the above process until the correct or ideal calculation or inference result is obtained.
- the performance standard configuration, experimental time cost limit, and current result can be submitted to the optimizer.
- the parameters and time limits are extracted, and the standard request and initial results are compared. If the result meets the request, the current result and time cost are directly returned to the developer. Otherwise, the scheduler is started to test various optimization hyperparameters and scheduling strategies, the publisher is controlled to run the optimized test code on the edge device, and the results of each test case are sent to the comparator until a satisfactory value is reached or the best result within the set time is found, and then it is sent back to the developer together with the time cost. At this point, the debugging process ends.
- a method for customizing sensor functions based on Wasm technology comprising:
- An interface defined based on the WASI specification is provided in the smart device, and the Wasm program can access and operate the sensor through the interface.
- the post-processing program and the mathematical model are developed using any one of the programming languages selected from Python, C/C++, Java, Rust and Go.
- the method further comprises the step of debugging the mathematical model in the step of deploying the mathematical model in the smart device, wherein the debugging comprises:
- the debugging tool fills the post-processing code for the post-processing into the template file
- the debugging tool compiles the template file into an execution file that can be executed by the runtime
- the runtime receives the execution file from the Docker runtime environment and executes the execution file to generate the output data using the mathematical model;
- the debugging tool receives the output data from the runtime, decodes the output data, and provides the decoded output data to the developer;
- the debugging tool converts the template file into C++ code, converts the C++ code into the execution file, and publishes the execution file to the runtime.
- the debugging tool analyzes the standard request set by the developer, compares the standard request and the output data, and when the result of the comparison is unsatisfactory, tests multiple scheduling strategies and finds the best scheduling strategy.
- a smart device including a sensor
- the function of the sensor is customized according to any one of the methods described in (1) to (12) above.
- a debugging tool for debugging a mathematical model comprising a post-processing module and a compiler stack,
- the post-processing module generates a post-processing template file for post-processing the mathematical model, provides the post-processing template file to the compiler stack, and receives output data of the mathematical model from a runtime running the mathematical model and provides it to a developer.
- the compiler stack compiles the received post-processing template file into an execution file executable by the runtime, and provides the execution file to the runtime, so that the runtime can generate the output data using the mathematical model.
- a post-processing code module which is used to generate the post-processing template file and provide it to the compiler stack;
- a decoder for receiving the output data of the mathematical model from the runtime and decoding the output data
- a raw result viewer is used to provide the decoded output data to the developer.
- a C++ converter which is used to convert the post-processing template file into C++ code
- a WASM compiler which is used to convert the C++ code into the execution file
- a publisher is used to publish the execution file to the runtime.
- the debugging tool according to (14) above further includes an optimizer, wherein the optimizer includes:
- the scheduler is used to test multiple scheduling strategies and find the best scheduling strategy when the result of the comparison is not satisfactory.
- the debugging tool is created in a Docker image.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Computing Systems (AREA)
- Stored Programmes (AREA)
Abstract
Description
相关申请的引用Citation of Related Applications
本申请要求于2023年05月16日向中华人民共和国国家知识产权局提交的第202310552597.X号中国专利申请的权益,在此将其全部内容以援引的方式整体并入本文中。This application claims the benefit of Chinese Patent Application No. 202310552597.X filed with the State Intellectual Property Office of the People's Republic of China on May 16, 2023, the entire contents of which are hereby incorporated by reference into this document in their entirety.
本发明涉及计算机领域,尤其涉及基于Wasm技术定制传感器功能的技术。The present invention relates to the field of computers, and in particular to a technology for customizing sensor functions based on Wasm technology.
在智能技术领域,传感器可以应用在自动驾驶、设备检测、环境检测、物流检测、安保检测、健康检测、智能家电、零售行业、卫生保健、农业、智慧城市等方面。In the field of intelligent technology, sensors can be used in autonomous driving, equipment detection, environmental detection, logistics detection, security detection, health detection, smart home appliances, retail industry, health care, agriculture, smart cities, etc.
智能设备中的传感器包含针对特定目的开发、训练或定制的计算模型或AI模型等。在本文中将这些模型统称为数学模型。传感器可以利用相应数学模型基于传感器的检测提供计算或推理结果。在此,计算或推理结果的格式可能随着模型的不同而不同。The sensors in smart devices contain computing models or AI models that are developed, trained, or customized for specific purposes. These models are collectively referred to as mathematical models in this article. The sensors can use the corresponding mathematical models to provide computing or reasoning results based on the sensor's detection. Here, the format of the computing or reasoning results may vary depending on the model.
针对这些不同格式,智能设备需要在现场对后处理结果进行后处理,以获得期望的信息。一种典型的后处理方式是将计算或推理结果转换为可读可视并且结构化的元数据字符流。For these different formats, smart devices need to post-process the post-processing results on site to obtain the expected information. A typical post-processing method is to convert the calculation or reasoning results into a readable, visible and structured metadata character stream.
如上所述,不同的模型可能输出不同格式的计算或推理结果。由此,为模型定制后处理功能变得比较困难。后处理功能需要由模型开发人员提供。然而,模型开发人员通常并不了解智能设备的软硬件架构,并且开发人员更多地关注后处理的逻辑并确保其与模型的适配。As mentioned above, different models may output calculation or reasoning results in different formats. As a result, it becomes difficult to customize the post-processing function for the model. The post-processing function needs to be provided by the model developer. However, model developers usually do not understand the software and hardware architecture of smart devices, and developers pay more attention to the logic of post-processing and ensure its adaptation to the model.
为了定制后处理功能,应当知晓如何识别特定模型中的数据以及如何与传感器通信。然而,开发人员通常不知晓智能设备的工作环境,并因此很难部署匹配的能够运行在任何智能设备上的后处理功能。当前存在各种利用Wasm技术定制后处理功能的方式,但它们都或多或少地存在一些问题。In order to customize the post-processing function, you should know how to identify the data in a specific model and how to communicate with the sensor. However, developers usually do not know the working environment of smart devices, and therefore it is difficult to deploy matching post-processing functions that can run on any smart device. There are currently various ways to customize post-processing functions using Wasm technology, but they all have some problems to a greater or lesser extent.
例如,索尼公司提供的软件开发工具包Camera Remote SDK并未提供用于传感器控制的通用API。阿里工程师提出的新开发框架Waft(WebAssembly Framework for Things)不能提供用于访问AI传感器或普遍传感器以读取数据的API。在US20220198071A1中,Wasm技术适用于任务分享以减轻主计算节点的负担,但未提供用于子节点上的任务模拟的方法。CN202210944973、CN202210096203等缺乏沙箱控制,存在安全问题,或者不遵从wasi规格。For example, the Camera Remote SDK, a software development kit provided by Sony, does not provide a general API for sensor control. Waft (WebAssembly Framework for Things), a new development framework proposed by Alibaba engineers, does not provide an API for accessing AI sensors or general sensors to read data. In US20220198071A1, Wasm technology is suitable for task sharing to reduce the burden on the main computing node, but no method is provided for task simulation on child nodes. CN202210944973, CN202210096203, etc. lack sandbox control, have security issues, or do not comply with wasi specifications.
另外,目前的模型开发高度依赖几款主流软件框架,例如tensorflow、pytorch、onnx等。一方面,这些框架在某种程度上确实加速了模型的开发过程,但另一方面,数学模型以及可能的后处理程序在部署阶段往往会出现一些问题,而且难以调试,尤其对于一些低级的、有成本效益的工业设备。In addition, current model development is highly dependent on several mainstream software frameworks, such as tensorflow, pytorch, onnx, etc. On the one hand, these frameworks do accelerate the model development process to some extent, but on the other hand, mathematical models and possible post-processing programs often have some problems during the deployment phase and are difficult to debug, especially for some low-level, cost-effective industrial equipment.
发明内容Summary of the invention
本发明的目的是提出用于基于Wasm技术定制传感器功能的方法和模块,这些方法和模块不具备现有技术中的缺点,且还具有额外的优点。本发明运行开发人员可以只专注于模型后处理的逻辑,而不必关注模型的具体实现和部署。The purpose of the present invention is to propose a method and a module for customizing sensor functions based on Wasm technology, which do not have the disadvantages of the prior art and have additional advantages. The present invention allows developers to focus only on the logic of model post-processing without having to pay attention to the specific implementation and deployment of the model.
本发明的一个方面涉及一种基于Wasm技术定制传感器功能的方法,其包括:提供针对智能设备中的传感器训练的数学模型以及为所述数学模型定制的后处理程序,其中,所述后处理程序用于对所述数学模型的输出数据执行后处理;将所述数学模型部署在所述智能设备中;将所述后处理程序编译为Wasm程序并部署在所述智能设备中;在所述智能设备中提供基于WASI规范定义的接口,所述Wasm程序能够通过所述接口访问和操作所述传感器。One aspect of the present invention relates to a method for customizing sensor functions based on Wasm technology, which includes: providing a mathematical model trained for a sensor in a smart device and a post-processing program customized for the mathematical model, wherein the post-processing program is used to perform post-processing on output data of the mathematical model; deploying the mathematical model in the smart device; compiling the post-processing program into a Wasm program and deploying it in the smart device; providing an interface defined based on the WASI specification in the smart device, and the Wasm program can access and operate the sensor through the interface.
本发明的另一个方面涉及一种包括传感器的智能设备,其中,传感器的功能是根据本发明的方法定制的。Another aspect of the present invention relates to a smart device comprising a sensor, wherein the functionality of the sensor is customized according to the method of the present invention.
本发明的又一个方面涉及一种用于调试数学模型的调试工具,其包括后处理模块和编译器栈,其中,所述后处理模块生成用于所述数学模型的后处理的后处理模板文件,将所述后处理模板文件提供给所述编译器栈,并从运行所述数学模型的运行时接收所述数学模型的输出数据提供给开发人员,其中,所述编译器栈将接收的所述后处理模板文件编译成所述运行时能够执行的执行文件,并将所述执行文件提供给所述运行时,使得所述运行时能够利用所述数学模型生成所述输出数据。Another aspect of the present invention relates to a debugging tool for debugging a mathematical model, which includes a post-processing module and a compiler stack, wherein the post-processing module generates a post-processing template file for post-processing the mathematical model, provides the post-processing template file to the compiler stack, and receives output data of the mathematical model from a runtime running the mathematical model and provides it to a developer, wherein the compiler stack compiles the received post-processing template file into an executable file that can be executed by the runtime, and provides the executable file to the runtime, so that the runtime can generate the output data using the mathematical model.
根据本发明,利用Wasm技术使得该后处理功能实现跨平台和模块化部署,从而能够在智能设备 中定制传感器的特定功能。According to the present invention, Wasm technology is used to enable the post-processing function to be deployed across platforms and in a modular manner, thereby enabling it to be deployed on smart devices. Customize sensor specific functions in
另外,根据本发明,开发人员可以很容易地调试后期处理,并有以下好处:不需要强制学习低级语言或雇用特定的硬件工程师来调试;保证执行效率;易于移植。In addition, according to the present invention, developers can easily debug post-processing, and have the following advantages: no need to compulsorily learn low-level languages or employ specific hardware engineers for debugging; guaranteed execution efficiency; easy to transplant.
图1示出了数学模型的创建和训练以及后处理程序的开发。Figure 1 shows the creation and training of the mathematical model and the development of the post-processing procedure.
图2示出了根据现有技术的数学模型的开发过程。FIG. 2 shows the development process of a mathematical model according to the prior art.
图3示出了根据本发明实施例的用于调试数学模型的调试工具。FIG. 3 shows a debugging tool for debugging a mathematical model according to an embodiment of the present invention.
图4示出了根据本发明实施例的调试数学模型的过程流程图。FIG. 4 shows a flow chart of a process for debugging a mathematical model according to an embodiment of the present invention.
下面结合附图和具体实施例对本发明作进一步说明,以使本领域的技术人员可以更好地理解本发明并能予以实施,但所举实施例不作为对本发明的限定,在不冲突的情况下,本发明实施例以及实施例中的技术特征可以相互结合。The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
在物联网的各种智能设备中存在诸如图像传感器、声音传感器、光传感器等各种传感器。取决于智能设备,这些传感器可用于实现不同的目的。In various smart devices of IoT there are various sensors like image sensors, sound sensors, light sensors etc. These sensors can be used to achieve different purposes depending on the smart device.
为了将传感器用于特定目的,开发人员可以在例如主机中创建并训练相应的数学模型。开发人员可以利用模型框架工具来创建和训练数学模型。例如,可以利用tensorflow、pytorch、onnx等开发平台,作为模型框架工具。传感器可以利用数学模型对传感器的检测结果进行计算或推理,以获得计算结果或推理结果。然后,传感器将获得的计算结果或推理结果以特定格式作为输出数据输出。In order to use the sensor for a specific purpose, the developer can create and train the corresponding mathematical model in, for example, a host. The developer can use a model framework tool to create and train the mathematical model. For example, development platforms such as tensorflow, pytorch, and onnx can be used as model framework tools. The sensor can use the mathematical model to calculate or infer the sensor's detection results to obtain a calculation result or an inference result. The sensor then outputs the obtained calculation result or inference result as output data in a specific format.
对于输出数据,开发人员还需要在例如主机中开发用于后处理的后处理程序。开发人员可以使用其喜好的编程语言来开发后处理程序,例如Python、C/C++、Java、Go或Rust等。通过后处理程序,智能设备可以对传感器的输出数据进行后处理(例如格式转换等),以提供包含期望信息的后处理结果。For the output data, developers also need to develop a post-processing program for post-processing in, for example, a host computer. Developers can develop post-processing programs in their favorite programming languages, such as Python, C/C++, Java, Go, or Rust. Through the post-processing program, the smart device can post-process the output data of the sensor (such as format conversion, etc.) to provide a post-processing result containing the desired information.
作为示例,图1示出了采用包含相机的物联网设备作为智能设备的情况。这里,相机为本发明意义上的传感器。注意,本发明的智能设备不限于物联网设备。根据本发明的技术启示,本领域技术人员可以将本发明也应用到自动驾驶、设备检测、环境检测、物流检测、安保检测、健康检测、智能家电、零售行业、卫生保健、农业、智慧城市等领域。在此,不再一一列举。As an example, FIG1 shows a case where an IoT device including a camera is used as a smart device. Here, the camera is a sensor in the sense of the present invention. Note that the smart device of the present invention is not limited to IoT devices. According to the technical inspiration of the present invention, those skilled in the art can also apply the present invention to the fields of autonomous driving, equipment detection, environmental detection, logistics detection, security detection, health detection, smart home appliances, retail industry, health care, agriculture, smart cities, etc. Here, they are not listed one by one.
图1的左侧示出了相机的数学模型的创建和训练以及后处理程序的开发。在此,相机的数学模型可以是目标检测模型,例如行人检测模型、人脸识别模型等。The left side of Figure 1 shows the creation and training of the mathematical model of the camera and the development of the post-processing program. Here, the mathematical model of the camera can be an object detection model, such as a pedestrian detection model, a face recognition model, etc.
在现有技术中,通常直接将完成后的数学模型和后处理程序部署在智能设备的硬件上,例如在图1的示例中分别部署在相机的数字信号处理器(DSP)和物联网设备的处理器中。在部署数学模型时,考虑到相机的功耗、性能以及资源等因素,例如通过深度可分离卷积、分组卷积、可调超参数降低空间分辨率、知识蒸馏、低秩剪枝、模型压缩等方法,可以对数学模型进行轻量化。In the prior art, the completed mathematical model and post-processing program are usually directly deployed on the hardware of the smart device, for example, in the example of FIG1, they are respectively deployed in the digital signal processor (DSP) of the camera and the processor of the IoT device. When deploying the mathematical model, the power consumption, performance, and resources of the camera are taken into consideration, and the mathematical model can be lightweighted, for example, by using methods such as deep separable convolution, grouped convolution, adjustable hyperparameters to reduce spatial resolution, knowledge distillation, low-rank pruning, and model compression.
相机利用数学模型对相机检测结果进行计算或推理并将计算或推理结果作为输出数据输出。然后,包括相机的物联网设备可以利用后处理程序对相机的输出数据进行后处理,以获得期望信息。数学模型的编程环境可以是Python、C/C++、Java、Rust和Go等。The camera uses the mathematical model to calculate or infer the camera detection results and outputs the calculation or inference results as output data. Then, the IoT device including the camera can use the post-processing program to post-process the camera output data to obtain the desired information. The programming environment of the mathematical model can be Python, C/C++, Java, Rust, Go, etc.
然而,不同于现有技术,本发明提出了基于Wasm技术定制传感器功能的技术方案。Wasm,即WebAssembly,是一种新的字节码格式,由于其可移植、体积小,安全性高等优点被渐渐广泛认可。Wasm允许用户采用自己熟悉的语言书写(目前支持python、C/C++、Rust、Java或Go等编程语言),再利用虚拟机引擎在web上运行。Wasm技术支持在沙箱环境中运行Wasm程序。However, unlike the prior art, the present invention proposes a technical solution for customizing sensor functions based on Wasm technology. Wasm, or WebAssembly, is a new bytecode format that is gradually being widely recognized due to its portability, small size, and high security. Wasm allows users to write in a language they are familiar with (currently supports programming languages such as python, C/C++, Rust, Java, or Go), and then use a virtual machine engine to run on the web. Wasm technology supports running Wasm programs in a sandbox environment.
如图1所示,在本发明中,将后处理程序编译成Wasm程序并部署在物联网设备(例如,处理器)中,以在物联网设备提供的虚拟机中运行。根据后处理程序的编程语言以及Wasm程序的嵌入环境,可以使用各种编译器,例如LLVM后端。As shown in Figure 1, in the present invention, the post-processing program is compiled into a Wasm program and deployed in an IoT device (e.g., a processor) to run in a virtual machine provided by the IoT device. Depending on the programming language of the post-processing program and the embedded environment of the Wasm program, various compilers, such as the LLVM backend, can be used.
为了使Wasm程序实现与后处理程序一致的功能,本发明利用WASI(WebAssembly System Interface)规范为Wasm程序定义了一套统一的传感器系统接口,在此称之为WASI传感器。WASI是新的API体系,其是为WASM程序设计的一套与引擎无关的、面向非Web系统的API标准,即WASM程序如何与主机环境交互的标准,例如,包括文件系统、网络栈、时间和随机数生成器等标准系统调用,这些系统调用通过预定义的API接口提供给Wasm程序,使其可以在沙箱环境中访问传感器内的数据资源。基于WASI的支持,Wasm程序也可以运行在非web环境中。只要支持WASI标准,运行Wasm程序的任何运行时(runtime)都可以 实现物联网设备的主机环境中的系统调用,运行时(runtime)库中提供了程序的执行环境,例如,内存分配、变量赋值、函数调用等,还可用于管理线程或进程、执行解释性代码、动态链接库和共享库等。In order to enable the Wasm program to implement functions consistent with the post-processing program, the present invention uses the WASI (WebAssembly System Interface) specification to define a unified sensor system interface for the Wasm program, which is referred to as WASI sensor. WASI is a new API system, which is a set of engine-independent, non-Web system-oriented API standards designed for WASM programs, that is, the standard for how WASM programs interact with the host environment, for example, including standard system calls such as file system, network stack, time, and random number generator. These system calls are provided to the Wasm program through predefined API interfaces, allowing it to access data resources in the sensor in a sandbox environment. Based on the support of WASI, Wasm programs can also run in non-web environments. As long as the WASI standard is supported, any runtime that runs Wasm programs can Implement system calls in the host environment of the IoT device. The runtime library provides the execution environment of the program, such as memory allocation, variable assignment, function call, etc. It can also be used to manage threads or processes, execute interpreted code, dynamic link libraries and shared libraries, etc.
通过该传感器系统接口,Wasm程序可以正确解析传感器的数学模型生成的输出数据,并且可以访问和操作传感器(例如,打开、关闭、执行推理、取出结果等)。由此,Wasm程序可以通过Wasi接口透过沙箱边界访问并控制传感器所提供的各个功能,例如获得推理数据、控制传感器的寿命周期等,不仅可以保证程序的安全性和可靠性,同时可以保护各类信息和设备安全。具体地,当Wasm程序需要访问传感器资源时,可以将访问请求通过该接口传递给传感器,传感器响应此访问请求,并将推理数据返回到Wasm程序中。Through the sensor system interface, the Wasm program can correctly parse the output data generated by the sensor's mathematical model, and can access and operate the sensor (for example, turn it on, turn it off, perform reasoning, retrieve results, etc.). As a result, the Wasm program can access and control the various functions provided by the sensor through the Wasi interface through the sandbox boundary, such as obtaining reasoning data, controlling the life cycle of the sensor, etc., which can not only ensure the security and reliability of the program, but also protect the security of various types of information and equipment. Specifically, when the Wasm program needs to access sensor resources, it can pass the access request to the sensor through the interface. The sensor responds to the access request and returns the reasoning data to the Wasm program.
在本发明中,智能设备中可以存在多个传感器,并且每个传感器可以设置有至少一个数学模型,以用于实现特定目的。例如,对于图1的示例,可以为相机提供多个数学模型,包括但不限于行人检测模型、人脸识别模型、文字识别模型、车牌信息识别模型等。In the present invention, there may be multiple sensors in the smart device, and each sensor may be provided with at least one mathematical model to achieve a specific purpose. For example, for the example of FIG1 , multiple mathematical models may be provided for the camera, including but not limited to a pedestrian detection model, a face recognition model, a text recognition model, a license plate information recognition model, etc.
可以针对每个数学模型提供一个后处理程序,以对该数学模型的输出数据执行后处理。当然,也可以针对多个数学模型提供一个后处理程序,以对这些数学模型的输出数据组合地执行后处理。A post-processing program may be provided for each mathematical model to perform post-processing on the output data of the mathematical model. Of course, a post-processing program may also be provided for multiple mathematical models to perform post-processing on the output data of these mathematical models in combination.
由于本发明基于Wasm技术定制传感器功能,因此开发人员也可以用他喜欢的任何语言开发后处理程序,而无需要考虑它在什么平台上运行,并且无需考虑如何在不同设备中调整程序。另外,Wasm技术将Wasm程序限制在沙箱环境中运行,因此具有很高的安全性。Since the present invention customizes sensor functions based on Wasm technology, developers can also develop post-processing programs in any language they like, without having to consider what platform it runs on and how to adjust the program in different devices. In addition, Wasm technology restricts Wasm programs to run in a sandbox environment, so it has high security.
另外,本发明基于WASI规范提供了传感器系统接口。它在沙箱环境中运行以控制整个生命周期,这变得更加安全。本发明还实现了模块化的传感器控制功能,无需更新整个平台,而是只需更新单个Wasm程序即可扩展或更改传感器的功能。In addition, the present invention provides a sensor system interface based on the WASI specification. It runs in a sandbox environment to control the entire life cycle, which becomes safer. The present invention also implements modular sensor control functions, and the function of the sensor can be expanded or changed by updating a single Wasm program instead of updating the entire platform.
总之,本发明提出了一套跨平台的传感器控制接口,开发人员利用该接口能够在本地衔接数学模型开发,实现特定的后处理功能。利用Wasm技术使得该后处理功能实现跨平台和模块化部署,从而能够在智能设备中定制传感器的特定功能。In summary, the present invention proposes a set of cross-platform sensor control interfaces, which developers can use to connect mathematical model development locally and implement specific post-processing functions. The Wasm technology enables the post-processing function to be deployed cross-platform and modularly, so that specific functions of sensors can be customized in smart devices.
下文,本发明将详细说明Wasm程序的部署和调试。Hereinafter, the present invention will explain the deployment and debugging of Wasm programs in detail.
图2示出了根据现有技术的利用例如Python编程语言开发数学模型的过程。FIG. 2 shows a process of developing a mathematical model using, for example, the Python programming language according to the prior art.
如图2所示,首先,创建并训练数学模型。模型开发人员可以利用模型框架工具来训练数学模型。例如,这里可以在Python编程环境中利用tensorflow、pytorch、onnx等开发平台,作为模型框架工具。编程工具不限于Python,也可以是C/C++、Java、Rust和Go等。As shown in Figure 2, first, create and train a mathematical model. Model developers can use model framework tools to train mathematical models. For example, here, development platforms such as tensorflow, pytorch, and onnx can be used as model framework tools in the Python programming environment. Programming tools are not limited to Python, but can also be C/C++, Java, Rust, and Go.
具体地,首先使用模型框架工具生成初始模型,然后通过机器学习对生成的初始模型进行训练。在将初始模型训练完毕后,导出训练完成的初始模型。Specifically, the model framework tool is first used to generate an initial model, and then the generated initial model is trained through machine learning. After the initial model is trained, the trained initial model is exported.
接着,取决于模型的类型及运行环境,开发人员可以利用相应的模型部署工具将完成的数学模型部署在特定环境中,例如诸如个人计算机或智能手机等边缘设备。这里,边缘设备可以是图1中的相机。Next, depending on the type of model and the operating environment, developers can use the corresponding model deployment tools to deploy the completed mathematical model in a specific environment, such as an edge device such as a personal computer or a smartphone. Here, the edge device can be the camera in Figure 1.
最后,可以在边缘设备中运行部署的数学模型,以获得计算结果或推理结果。Finally, the deployed mathematical model can be run in the edge device to obtain calculation results or inference results.
然而,目前,大多数开发人员只熟悉基于软件框架要求的编程语言,例如python,但不熟悉硬件级编程语言。这种现象导致算法开发人员难以直接调试Wasm程序,严重限制了数学模型的丰富性。However, at present, most developers are only familiar with programming languages based on software framework requirements, such as Python, but are not familiar with hardware-level programming languages. This phenomenon makes it difficult for algorithm developers to directly debug Wasm programs, which seriously limits the richness of mathematical models.
此外,即使数学模型可以用特定于硬件平台的软件栈来部署,但通常也是通过一系列复杂的人工操作来实现的,很难被移植到其他设备上。Furthermore, even if mathematical models can be deployed using a hardware platform-specific software stack, they are usually implemented through a series of complex manual operations and are difficult to port to other devices.
此外,开发人员主要关注模型设计创作,而没有确保工业软件的效率要求。Furthermore, developers mainly focus on model design creation without ensuring the efficiency requirements of industrial software.
为解决上述问题,本发明提出了一种调试工具,该调试工具可以创建在Docker镜像中,以能够为开发人员提供开箱即用的服务。众所周知,利用Docker镜像,可以创建用于各种编程语言的开发平台,例如Python、Java、Go等编程语言。本文以Python编程语言为示例进行了说明。To solve the above problems, the present invention proposes a debugging tool that can be created in a Docker image to provide developers with out-of-the-box services. As is known to all, using Docker images, development platforms for various programming languages can be created, such as Python, Java, Go, and other programming languages. This article uses the Python programming language as an example for illustration.
另外,对于数学模型的运行,边缘设备(例如,上面提到的智能设备)中的运行时(例如,WAMR Runtime)也是必要的,以便将所述服务应用于广泛的硬件平台,并在需要时顺利移植整个方案。In addition, for the operation of mathematical models, a runtime (e.g., WAMR Runtime) in edge devices (e.g., the smart devices mentioned above) is also necessary so that the services can be applied to a wide range of hardware platforms and the entire solution can be smoothly ported when necessary.
具体地,图3示出了根据本发明实施例的调试工具,该调试工具用于调试数学模型,以获得更高的任务指标、更快的运行速度、更小的模型体积。Specifically, FIG3 shows a debugging tool according to an embodiment of the present invention, which is used to debug a mathematical model to obtain a higher task index, a faster running speed, and a smaller model volume.
根据本发明,开发人员可以例如在自己的主机上将整个调试工具创建在Docker镜像中,以从Docker镜像提供Docker容器服务,所以开发人员可以在几乎所有的PC或服务器操作系统平台上,例如在x86或arm的硬件结构中随时提供这个服务。Docker容器是开源的应用容器引擎,让开发人员可以以统一的方式将他们的应用以及依赖包打包到可移植的容器中。具体地,为了将调试工具创建在Docker镜像中,例如,首先编写Dockerfile文件,其用于定义Docker镜像中的环境和应用程序;接着,在Dockerfile文件中 添加所需的调试工具,比如,根据需要可以选择添加gdb、strace、tcpdump等工具,另外,取决于使用的调试工具类型和应用程序的要求,还可能需要在Dockerfile文件中设置相应的环境变量或暴露容器的端口;然后,构建Docker镜像,比如,在包含Dockerfile文件的目录中执行“docker build-t<镜像名>”命令,此命令会开始构建Docker镜像;下一步,启动Docker容器,比如运行以下命令来启动Docker容器:“docker run-it–name<容器名><镜像名>”;最后,测试调试工具,在启动的容器中运行所需的应用程序,然后使用所添加的调试工具进行调试。According to the present invention, developers can, for example, create the entire debugging tool in a Docker image on their own host to provide a Docker container service from the Docker image, so developers can provide this service at any time on almost all PC or server operating system platforms, such as in x86 or arm hardware structures. Docker container is an open source application container engine that allows developers to package their applications and dependent packages into portable containers in a unified manner. Specifically, in order to create a debugging tool in a Docker image, for example, first write a Dockerfile file, which is used to define the environment and application in the Docker image; then, in the Dockerfile file Add the required debugging tools. For example, you can choose to add gdb, strace, tcpdump and other tools as needed. In addition, depending on the type of debugging tools used and the requirements of the application, you may also need to set the corresponding environment variables in the Dockerfile file or expose the port of the container. Then, build the Docker image. For example, execute the "docker build -t <image name>" command in the directory containing the Dockerfile file. This command will start building the Docker image. Next, start the Docker container. For example, run the following command to start the Docker container: "docker run -it –name <container name><imagename>"; Finally, test the debugging tool, run the required application in the started container, and then use the added debugging tool for debugging.
根据本发明的调试工具可以包括后处理模块、编译器栈以及可选的优化器。后处理模块可以包括后处理代码模块、解码器以及原始数据查看器。编译器栈可以包括C++转换器、WASM编译器和发布器。优化器可以包括标准分析器、比较器和调度器。The debugging tool according to the present invention may include a post-processing module, a compiler stack and an optional optimizer. The post-processing module may include a post-processing code module, a decoder and a raw data viewer. The compiler stack may include a C++ converter, a WASM compiler and a publisher. The optimizer may include a standard analyzer, a comparator and a scheduler.
根据本发明,为了调试数学模型,可以在边缘设备中利用运行时(例如WAMR runtime)来运行数学模型。According to the present invention, in order to debug the mathematical model, a runtime (e.g., WAMR runtime) can be used to run the mathematical model in the edge device.
根据本发明,调试工具的Docker运行环境可以经由连接器接口连接到边缘设备的运行时,连接器接口可用于处理通信协议、数据格式转换、安全认证等问题,以实现通信和交互,必要时还需要考虑数据加密、身份认证等问题,以确保通信的安全性和数据的完整性。这里,连接可以利用各种通信协议自动进行,例如有线或无线通信协议。According to the present invention, the Docker runtime environment of the debugging tool can be connected to the runtime of the edge device via a connector interface, and the connector interface can be used to handle communication protocols, data format conversion, security authentication and other issues to achieve communication and interaction. If necessary, data encryption, identity authentication and other issues need to be considered to ensure the security of communication and the integrity of data. Here, the connection can be automatically performed using various communication protocols, such as wired or wireless communication protocols.
在图3中,如标记①所示,开发人员可以通过后处理代码模块将用于后处理的Python后处理代码填入模板Python文件。Python后处理代码可以包括用于对数学模型的输出数据进行后处理的指令。后处理代码可以是开发人员根据期望的后处理功能自定义的。In FIG. 3 , as shown in mark ①, the developer can fill the Python post-processing code for post-processing into the template Python file through the post-processing code module. The Python post-processing code may include instructions for post-processing the output data of the mathematical model. The post-processing code can be customized by the developer according to the desired post-processing function.
如标记②所示,编译器栈中的C++转换器将来自后处理代码模块的Python后处理代码转换成C++代码。接着,编译器栈中的WASM编译器将C++代码转换成Wasm执行文件。最后,如标记③和④所示,编译器栈利用发布器将转换后的Wasm执行文件经由连接件器接口发布到运行数学模型的Runtime。As shown in mark ②, the C++ converter in the compiler stack converts the Python post-processing code from the post-processing code module into C++ code. Then, the WASM compiler in the compiler stack converts the C++ code into a Wasm executable file. Finally, as shown in marks ③ and ④, the compiler stack uses the publisher to publish the converted Wasm executable file to the Runtime that runs the mathematical model via the connector interface.
如标记⑤和⑥所示,数学模型输出计算或推理结果(即,输出数据),并将计算或推理结果经由连接器接口输出到后处理模块中的解码器。解码器对计算或推理结果进行解码。如标记⑦所示,后处理模块中的原始数据查看器将解码后的计算或推理数据以例如图像、声音、文字等形式显示给开发人员。如果计算或推理结果不正确或不理想,开发人员可以调整数学模型,并接着重复如标记①至⑦所示的过程,直至获得正确或理想的计算或推理结果。As shown in marks ⑤ and ⑥, the mathematical model outputs the calculation or reasoning result (i.e., output data), and outputs the calculation or reasoning result to the decoder in the post-processing module via the connector interface. The decoder decodes the calculation or reasoning result. As shown in mark ⑦, the raw data viewer in the post-processing module displays the decoded calculation or reasoning data to the developer in the form of, for example, images, sounds, text, etc. If the calculation or reasoning result is incorrect or unsatisfactory, the developer can adjust the mathematical model and then repeat the process as shown in marks ① to ⑦ until the correct or ideal calculation or reasoning result is obtained.
可选地,在获得正确或理想的计算或推理结果之后,开发人员还可以对数学模型进行优化。Optionally, after obtaining the correct or ideal calculation or inference results, the developer can also optimize the mathematical model.
如标记⑧所示,开发人员可以将性能标准、试验时间成本限制和当前结果提交给优化器。在优化器中,标准分析器解析性能标准配置以提取参数和时间成本,并且比较器比较标准请求和当前结果。如果结果满足请求,则如标记所示,直接将当前结果和时间成本返回给开发人员。否则,如标记⑨所示,启动调度器测试各种优化超参数和调度策略,控制发布器在边缘设备在如标记③~⑤所示的过程中运行优化的测试代码,并按照如标记⑩所示的方式将每个测试情况的结果发送给比较器,直到达到满意值或找到设定时间内的最佳结果,然后将其连同时间成本送回给开发人员。As shown in mark ⑧, developers can submit performance criteria, trial time cost constraints, and current results to the optimizer. In the optimizer, the standard analyzer parses the performance standard configuration to extract parameters and time costs, and the comparator compares the standard request and the current result. If the result meets the request, then as shown in mark As shown, the current result and time cost are directly returned to the developer. Otherwise, as shown in mark ⑨, the scheduler is started to test various optimization hyperparameters and scheduling strategies, and the publisher is controlled to run the optimized test code on the edge device in the process shown in marks ③ to ⑤, and the result of each test case is sent to the comparator in the manner shown in mark ⑩ until a satisfactory value is reached or the best result within the set time is found, and then it is sent back to the developer together with the time cost.
图4示出了根据本发明实施例的调试数学模型的过程流程图。FIG. 4 shows a flow chart of a process for debugging a mathematical model according to an embodiment of the present invention.
判断是否启动调试。在启动调试的情况下,通过后处理代码模块将后处理代码填入模板文件。Determine whether to start debugging. When debugging is started, fill the post-processing code into the template file through the post-processing code module.
接着,通过编译器栈将模板文件转换成执行文件。Next, the template file is converted into an execution file through the compiler stack.
接着,判断连接器接口是否准好连接。如果不是这种情况,则重启设备以进行连接,直至连接成功。在成功连接的情况下,通过编译器栈将执行文件经由连接件器接口发布到运行时。Next, it is determined whether the connector interface is ready for connection. If this is not the case, the device is restarted to connect until the connection is successful. In the case of a successful connection, the executable file is published to the runtime via the connector interface through the compiler stack.
接着,数学模型输出计算或推理结果(即,输出数据)经由连接器接口输出到后处理模块。然后,后处理模块将计算或推理结果解码,并将解码后的计算或推理结果显示给开发人员。Next, the mathematical model outputs the calculation or reasoning result (ie, output data) to the post-processing module via the connector interface. Then, the post-processing module decodes the calculation or reasoning result and displays the decoded calculation or reasoning result to the developer.
如果推理结果不正确或不理想,开发人员可以调整数学模型,并接着重复上面的过程,直至获得正确或理想的计算或推理结果。If the inference result is incorrect or unsatisfactory, the developer can adjust the mathematical model and repeat the above process until the correct or ideal calculation or inference result is obtained.
在获得正确或理想的计算或推理结果之后,判断是否进一步优化数学模型。After obtaining the correct or ideal calculation or reasoning results, determine whether to further optimize the mathematical model.
如果不需要优化,则直接结束调试过程。If optimization is not required, the debugging process ends directly.
如果需要优化,则可以将性能标准配置、实验时间成本限制和当前结果提交给优化器。在优化器中,提取参数和时间限制,并且比较标准请求和初始结果。如果结果满足请求,则直接将当前结果和时间成本返回给开发人员。否则,启动调度器测试各种优化超参数和调度策略,控制发布者在边缘设备运行优化的测试代码,并将每个测试情况的结果发送给比较器,直到达到满意值或找到设定时间内的最佳结果,然后将其连同时间成本送回给开发人员。此时,调试过程结束。 If optimization is required, the performance standard configuration, experimental time cost limit, and current result can be submitted to the optimizer. In the optimizer, the parameters and time limits are extracted, and the standard request and initial results are compared. If the result meets the request, the current result and time cost are directly returned to the developer. Otherwise, the scheduler is started to test various optimization hyperparameters and scheduling strategies, the publisher is controlled to run the optimized test code on the edge device, and the results of each test case are sent to the comparator until a satisfactory value is reached or the best result within the set time is found, and then it is sent back to the developer together with the time cost. At this point, the debugging process ends.
根据本发明,可以采用以下配置。According to the present invention, the following configuration may be adopted.
(1)一种基于Wasm技术定制传感器功能的方法,其包括:(1) A method for customizing sensor functions based on Wasm technology, comprising:
提供针对智能设备中的传感器训练的数学模型以及为所述数学模型定制的后处理程序,其中,所述后处理程序用于对所述数学模型的输出数据执行后处理;Providing a mathematical model trained for a sensor in an intelligent device and a post-processing program customized for the mathematical model, wherein the post-processing program is used to perform post-processing on output data of the mathematical model;
将所述数学模型部署在所述智能设备中;Deploying the mathematical model in the smart device;
将所述后处理程序编译为Wasm程序并部署在所述智能设备中;Compiling the post-processing program into a Wasm program and deploying it in the smart device;
在所述智能设备中提供基于WASI规范定义的接口,所述Wasm程序能够通过所述接口访问和操作所述传感器。An interface defined based on the WASI specification is provided in the smart device, and the Wasm program can access and operate the sensor through the interface.
(2)根据上述(1)所述的方法,其中,所述Wasm程序与所述后处理程序具有一致的后处理功能。(2) The method according to (1) above, wherein the Wasm program and the post-processing program have the same post-processing function.
(3)根据上述(1)所述的方法,其中,所述数学模型被部署在所述传感器中。(3) The method according to (1) above, wherein the mathematical model is deployed in the sensor.
(4)根据上述(1)所述的方法,其中,所述Wasm程序在所述智能设备提供的虚拟机中运行。(4) The method according to (1) above, wherein the Wasm program runs in a virtual machine provided by the smart device.
(5)根据上述(1)所述的方法,其中,所述后处理为所述输出数据的格式转换。(5) The method according to (1) above, wherein the post-processing is a format conversion of the output data.
(6)根据上述(1)所述的方法,所述后处理程序和所述数学模型是通过Python、C/C++、Java、Rust和Go中的任一种编程语言开发的。(6) According to the method described in (1) above, the post-processing program and the mathematical model are developed using any one of the programming languages selected from Python, C/C++, Java, Rust and Go.
(7)根据上述(1)所述的方法,其中,所述方法在将所述数学模型部署在所述智能设备中的步骤中还包括调试所述数学模型的步骤,所述调试包括:(7) According to the method described in (1) above, the method further comprises the step of debugging the mathematical model in the step of deploying the mathematical model in the smart device, wherein the debugging comprises:
在合适的运行时中运行所述数学模型;executing the mathematical model in a suitable runtime;
在Docker镜像中创建调试工具,并在Docker运行环境中运行所述调试工具;Creating a debugging tool in a Docker image and running the debugging tool in a Docker runtime environment;
所述调试工具将用于所述后处理的后处理代码填入模板文件;The debugging tool fills the post-processing code for the post-processing into the template file;
所述调试工具将所述模板文件编译成能够被所述运行时执行的执行文件;The debugging tool compiles the template file into an execution file that can be executed by the runtime;
所述运行时从所述Docker运行环境接收所述执行文件,并执行所述执行文件以利用所述数学模型生成所述输出数据;The runtime receives the execution file from the Docker runtime environment and executes the execution file to generate the output data using the mathematical model;
所述调试工具从所述运行时接收所述输出数据,解码所述输出数据,并将解码后的所述输出数据提供给开发人员;The debugging tool receives the output data from the runtime, decodes the output data, and provides the decoded output data to the developer;
在所述输出数据不正确的情况下,所述开发人员调整所述数学模型;In case the output data is incorrect, the developer adjusts the mathematical model;
重复以上步骤,直到获得正确的所述输出数据。Repeat the above steps until the correct output data is obtained.
(8)根据上述(7)所述的方法,其中,在编译所述执行文件时,(8) The method according to (7) above, wherein when compiling the execution file,
所述调试工具将所述模板文件转换为C++代码,将所述C++代码转换成所述执行文件,并且将所述执行文件发布给所述运行时。The debugging tool converts the template file into C++ code, converts the C++ code into the execution file, and publishes the execution file to the runtime.
(9)根据上述(7)述的方法,其中,在获得正确的所述输出数据之后,所述调试工具分析由所述开发人员设定的标准请求,比较所述标准请求和所述输出数据,并且在所述比较的结果不满意时,测试多种调度策略并找到最佳的调度策略。(9) According to the method described in (7) above, after obtaining the correct output data, the debugging tool analyzes the standard request set by the developer, compares the standard request and the output data, and when the result of the comparison is unsatisfactory, tests multiple scheduling strategies and finds the best scheduling strategy.
(10)根据上述(7)所述的方法,其中,所述运行时由所述智能设备提供。(10) The method according to (7) above, wherein the runtime is provided by the smart device.
(11)根据上述(7)所述的方法,其中,所述Docker运行环境时由所述开发人员的主机提供。(11) The method according to (7) above, wherein the Docker operating environment is provided by the developer's host.
(12)根据上述(7)所述的方法,其中,所述Docker镜像创建用于Python、C/C++、Java、Rust和Go中的任一种编程语言的开发环境,并且所述数学模型、所述调试工具和所述后处理程序利用同一编程语言开发或创建。(12) The method according to (7) above, wherein the Docker image creates a development environment for any one of the programming languages of Python, C/C++, Java, Rust and Go, and the mathematical model, the debugging tool and the post-processing program are developed or created using the same programming language.
(13)一种包括传感器的智能设备,(13) A smart device including a sensor,
其中,所述传感器的功能是根据上述(1)至(12)中任一项所述的方法定制的。The function of the sensor is customized according to any one of the methods described in (1) to (12) above.
(14)一种用于调试数学模型的调试工具,其包括后处理模块和编译器栈,(14) A debugging tool for debugging a mathematical model, comprising a post-processing module and a compiler stack,
其中,所述后处理模块生成用于所述数学模型的后处理的后处理模板文件,将所述后处理模板文件提供给所述编译器栈,并从运行所述数学模型的运行时接收所述数学模型的输出数据提供给开发人员,The post-processing module generates a post-processing template file for post-processing the mathematical model, provides the post-processing template file to the compiler stack, and receives output data of the mathematical model from a runtime running the mathematical model and provides it to a developer.
其中,所述编译器栈将接收的所述后处理模板文件编译成所述运行时能够执行的执行文件,并将所述执行文件提供给所述运行时,使得所述运行时能够利用所述数学模型生成所述输出数据。The compiler stack compiles the received post-processing template file into an execution file executable by the runtime, and provides the execution file to the runtime, so that the runtime can generate the output data using the mathematical model.
(15)根据上述(14)所述的调试工具,其中,所述调试工具和所述数学模型利用同一编程语言开发或创建。 (15) The debugging tool according to (14) above, wherein the debugging tool and the mathematical model are developed or created using the same programming language.
(16)根据上述(14)所述的调试工具,其中,所述后处理模块包括:(16) The debugging tool according to (14) above, wherein the post-processing module comprises:
后处理代码模块,其用于生成后所述后处理模板文件并提供给所述编译器栈;A post-processing code module, which is used to generate the post-processing template file and provide it to the compiler stack;
解码器,其用于从所述运行时接收所述数学模型的所述输出数据,将解码所述输出数据;和a decoder for receiving the output data of the mathematical model from the runtime and decoding the output data; and
原始结果查看器,其用于将解码的所述输出数据提供给所述开发人员。A raw result viewer is used to provide the decoded output data to the developer.
(17)根据上述(14)所述的调试工具,其中,所述编译器栈包括:(17) The debugging tool according to (14) above, wherein the compiler stack comprises:
C++转换器,其用于将所述后处理模板文件转换为C++代码;A C++ converter, which is used to convert the post-processing template file into C++ code;
WASM编译器,其用于将所述C++代码转换成所述执行文件;和A WASM compiler, which is used to convert the C++ code into the execution file; and
发布器,其用于将所述执行文件发布给所述运行时。A publisher is used to publish the execution file to the runtime.
(18)根据上述(14)所述的调试工具,其还包括优化器,所述优化器包括:(18) The debugging tool according to (14) above further includes an optimizer, wherein the optimizer includes:
标准分析器,其用于分析由所述开发人员设定的标准请求;A standard analyzer for analyzing standard requests set by the developer;
比较器,其用于比较所述标准请求和所述数学模型的所述输出数据;以及a comparator for comparing the standard request with the output data of the mathematical model; and
调度器,其用于在所述比较的结果不满意时,测试多种调度策略并找到最佳的调度策略。The scheduler is used to test multiple scheduling strategies and find the best scheduling strategy when the result of the comparison is not satisfactory.
(19)根据上述(14)所述的调试工具,其中,(19) The debugging tool according to (14) above, wherein:
所述调试工具被创建在Docker镜像中。The debugging tool is created in a Docker image.
对于本领域技术人员而言,显然本发明不限于上述示范性实施例的细节,而且在不背离本发明的精神或基本特征的情况下,能够以其他的具体形式实现本发明。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本发明的范围由所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化囊括在本发明内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
此外,应当理解,虽然本说明书按照实施方式加以描述,但并非每个实施方式仅包含一个独立的技术方案,说明书的这种叙述方式仅仅是为清楚起见,本领域技术人员应当将说明书作为一个整体,各实施例中的技术方案也可以经适当组合,形成本领域技术人员可以理解的其他实施方式。 In addition, it should be understood that although the present specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
Claims (19)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202480025957.3A CN121039645A (en) | 2023-05-16 | 2024-04-28 | Methods for customizing sensor functionality and intelligent devices including sensors |
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310552597.X | 2023-05-16 | ||
| CN202310552597.XA CN119003317A (en) | 2023-05-16 | 2023-05-16 | Method for customizing sensor functions and smart device comprising sensor |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2024234986A1 true WO2024234986A1 (en) | 2024-11-21 |
Family
ID=93493477
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2024/090359 Pending WO2024234986A1 (en) | 2023-05-16 | 2024-04-28 | Method for customizing sensor function and smart device comprising sensor |
Country Status (2)
| Country | Link |
|---|---|
| CN (2) | CN119003317A (en) |
| WO (1) | WO2024234986A1 (en) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113282378A (en) * | 2021-07-23 | 2021-08-20 | 奥特酷智能科技(南京)有限公司 | Vehicle-mounted system based on environment isolation subsystem |
| CN114186243A (en) * | 2021-12-17 | 2022-03-15 | 中国工商银行股份有限公司 | WebAssembly-based Trusted Execution Environment Runtime Apparatus, Device, Method and Medium |
| CN114596305A (en) * | 2022-03-22 | 2022-06-07 | 康键信息技术(深圳)有限公司 | Picture detection method, device and equipment based on browser and storage medium |
| US20220198071A1 (en) * | 2021-12-23 | 2022-06-23 | Intel Corporation | Methods and apparatus for secure execution on smart network interface cards |
| CN115659333A (en) * | 2022-10-13 | 2023-01-31 | 南方科技大学 | Sandbox based on binary instrumentation, memory isolation method and storage medium |
-
2023
- 2023-05-16 CN CN202310552597.XA patent/CN119003317A/en active Pending
-
2024
- 2024-04-28 WO PCT/CN2024/090359 patent/WO2024234986A1/en active Pending
- 2024-04-28 CN CN202480025957.3A patent/CN121039645A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113282378A (en) * | 2021-07-23 | 2021-08-20 | 奥特酷智能科技(南京)有限公司 | Vehicle-mounted system based on environment isolation subsystem |
| CN114186243A (en) * | 2021-12-17 | 2022-03-15 | 中国工商银行股份有限公司 | WebAssembly-based Trusted Execution Environment Runtime Apparatus, Device, Method and Medium |
| US20220198071A1 (en) * | 2021-12-23 | 2022-06-23 | Intel Corporation | Methods and apparatus for secure execution on smart network interface cards |
| CN114596305A (en) * | 2022-03-22 | 2022-06-07 | 康键信息技术(深圳)有限公司 | Picture detection method, device and equipment based on browser and storage medium |
| CN115659333A (en) * | 2022-10-13 | 2023-01-31 | 南方科技大学 | Sandbox based on binary instrumentation, memory isolation method and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN119003317A (en) | 2024-11-22 |
| CN121039645A (en) | 2025-11-28 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US12393423B2 (en) | Methods and apparatus for intentional programming for heterogeneous systems | |
| CN110149800B (en) | An apparatus for processing an abstract syntax tree associated with source code of a source program | |
| CN113076143B (en) | A method for adapting artificial intelligence environment on a domestic platform and a compatibility testing method | |
| CN111736954B (en) | Multi-intelligent contract virtual machine implementation method, multi-intelligent contract virtual machine and system | |
| US10324729B2 (en) | Machine intelligence and learning for graphic chip accessibility and execution | |
| CN106233251A (en) | The dynamic materialization of metadata driven | |
| EP2482184A1 (en) | Adaptive obfuscated virtual machine | |
| KR101644653B1 (en) | A apparatus and method of application optimized on demand | |
| CN111770202B (en) | Method for executing intelligent contract, block chain node and storage medium | |
| CN106293687B (en) | A kind of control method and device being packaged process | |
| CN118394409A (en) | Instruction processing method, instruction processing system and system on chip | |
| Bergmayr et al. | fREX: fUML-based reverse engineering of executable behavior for software dynamic analysis | |
| Acosta et al. | Towards a unified heterogeneous development model in androidtm | |
| CN115469879A (en) | An Automatic Scheduling Generation Method Based on Polyhedron Model | |
| WO2024234986A1 (en) | Method for customizing sensor function and smart device comprising sensor | |
| CN109271237B (en) | Simulation control method and device | |
| Rak et al. | Comparison of ESP programming platforms | |
| Di Marco et al. | Model-driven approach to Agilla Agent generation | |
| KR101083271B1 (en) | System and method for converting active x control | |
| Ahmadifarsani et al. | Towards Rapid Exploration of Heterogeneous TinyML Systems using Virtual Platforms and TVM's UMA | |
| CN114127681B (en) | Method and apparatus for autonomous acceleration of data stream AI applications | |
| CN120315689B (en) | Simulation program generation method, simulation test method and related equipment | |
| CN114968186A (en) | A Unified Programming Method for Universal Neural Network Tensor Processor | |
| Handziski et al. | Hardware abstraction architecture | |
| US8843906B1 (en) | Inferring data types from compiler call site |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 24806342 Country of ref document: EP Kind code of ref document: A1 |