Tengine
Tengine is a lite, high performance, modular inference engine for embedded device
Top Related Projects
MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba
ncnn is a high-performance neural network inference framework optimized for the mobile platform
MACE is a deep learning inference framework optimized for mobile heterogeneous computing platforms.
The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
Open deep learning compiler stack for cpu, gpu and specialized accelerators
TNN: developed by Tencent Youtu Lab and Guangying Lab, a uniform deep learning inference framework for mobile、desktop and server. TNN is distinguished by several outstanding features, including its cross-platform capability, high performance, model compression and code pruning. Based on ncnn and Rapidnet, TNN further strengthens the support and performance optimization for mobile devices, and also draws on the advantages of good extensibility and high performance from existed open source efforts. TNN has been deployed in multiple Apps from Tencent, such as Mobile QQ, Weishi, Pitu, etc. Contributions are welcome to work in collaborative with us and make TNN a better framework.
Quick Overview
Tengine is a high-performance, open-source, and production-ready deep learning inference engine. It is designed to be efficient, flexible, and easy to use, making it a popular choice for deploying deep learning models in various applications, including edge computing, mobile devices, and cloud-based services.
Pros
- High Performance: Tengine is optimized for both CPU and GPU, delivering efficient inference with low latency and high throughput.
- Flexibility: Tengine supports a wide range of deep learning models, including popular frameworks like TensorFlow, PyTorch, and ONNX.
- Ease of Use: Tengine provides a user-friendly API and comprehensive documentation, making it easy for developers to integrate and deploy deep learning models.
- Cross-Platform Compatibility: Tengine can run on a variety of platforms, including Linux, Android, and iOS, making it a versatile choice for diverse deployment environments.
Cons
- Limited Community Support: Compared to some other deep learning inference engines, Tengine may have a smaller community and fewer resources available for troubleshooting and support.
- Fewer Pre-Trained Models: While Tengine supports a wide range of models, it may not have as many pre-trained models available as some other popular deep learning frameworks.
- Potential Compatibility Issues: As with any cross-platform software, there may be occasional compatibility issues or challenges when deploying Tengine on specific hardware or software configurations.
- Ongoing Maintenance: As with any active project, Tengine requires ongoing maintenance and updates to keep up with the rapidly evolving deep learning landscape.
Code Examples
Here are a few code examples demonstrating the usage of Tengine:
- Loading and Executing a TensorFlow Model:
#include <iostream>
#include "tengine_c_api.h"
int main(int argc, char* argv[]) {
init_tengine();
graph_t graph = create_graph(nullptr, "tensorflow", "model.pb");
run_graph(graph, true);
release_graph(graph);
release_tengine();
return 0;
}
This code demonstrates how to load a TensorFlow model, create a Tengine graph, and execute the model using the Tengine C API.
- Executing an ONNX Model:
#include <iostream>
#include "tengine_c_api.h"
int main(int argc, char* argv[]) {
init_tengine();
graph_t graph = create_graph(nullptr, "onnx", "model.onnx");
run_graph(graph, true);
release_graph(graph);
release_tengine();
return 0;
}
This code shows how to load an ONNX model, create a Tengine graph, and execute the model using the Tengine C API.
- Performing Inference on a PyTorch Model:
import torch
from tengine.pytorch.wrapper import TengineWrapper
# Load the PyTorch model
model = torch.load("model.pth")
# Create a Tengine wrapper for the PyTorch model
tengine_model = TengineWrapper(model)
# Run inference using the Tengine wrapper
output = tengine_model(input_data)
This Python code demonstrates how to use the Tengine PyTorch wrapper to perform inference on a PyTorch model.
Getting Started
To get started with Tengine, follow these steps:
-
Install Tengine: Depending on your platform, you can install Tengine using the provided packages or by building it from source. Refer to the Tengine installation guide for detailed instructions.
-
Load and Execute a Model: Once Tengine is installed, you can load and execute deep learning models using the Tengine C API or the provided language-specific wrappers (e.g., Python, C++). The code examples above demonstrate the basic usage.
-
Optimize Model Performance: Tengine provides various optimization techniques, such as quantization and graph optimization, to improve the inference performance of your models. Refer to the [Tengine documentation](https://github.
Competitor Comparisons
MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba
Pros of MNN
- More extensive platform support, including iOS, Android, Windows, and Linux
- Better performance optimization, especially on mobile devices
- More active development and frequent updates
Cons of MNN
- Steeper learning curve due to more complex architecture
- Less focus on embedded systems compared to Tengine
- Larger binary size, which may be a concern for some embedded applications
Code Comparison
MNN example:
auto input = _Input({1, 3, 224, 224}, NC4HW4);
auto conv = _Conv(3, 16, {3, 3}, VALID);
auto output = conv(input);
Tengine example:
struct tensor* input = get_graph_input_tensor(graph, 0, 0);
struct tensor* conv = create_tensor(graph, "conv", TENGINE_DT_FP32);
struct node* conv_node = create_node(graph, "conv", "CONV");
Both libraries offer C/C++ APIs for model deployment, but MNN's API tends to be more high-level and object-oriented, while Tengine's API is more C-style and lower-level. MNN generally provides more abstraction and ease of use for complex models, while Tengine offers finer control over low-level operations, which can be beneficial for embedded systems.
ncnn is a high-performance neural network inference framework optimized for the mobile platform
Pros of ncnn
- Wider platform support, including mobile and embedded devices
- More optimized for mobile and edge computing scenarios
- Larger community and more frequent updates
Cons of ncnn
- Steeper learning curve due to more complex API
- Less focus on high-level abstractions, requiring more low-level implementation
Code Comparison
ncnn:
ncnn::Net net;
net.load_param("model.param");
net.load_model("model.bin");
ncnn::Mat in = ncnn::Mat::from_pixels(image_data, ncnn::Mat::PIXEL_BGR, w, h);
ncnn::Mat out;
net.extract("output", out);
Tengine:
graph_t graph = create_graph(NULL, "tengine", model_file);
tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0);
set_tensor_shape(input_tensor, dims, 4);
set_tensor_buffer(input_tensor, input_data, input_size);
run_graph(graph, 1);
Both libraries offer efficient inference for deep learning models, but ncnn is more focused on mobile and embedded scenarios, while Tengine provides a simpler API with a focus on ease of use. ncnn has a larger community and more frequent updates, but may require more low-level implementation. Tengine offers a more straightforward approach but with potentially less optimization for specific platforms.
MACE is a deep learning inference framework optimized for mobile heterogeneous computing platforms.
Pros of mace
- More extensive documentation and examples
- Better support for mobile platforms, especially Android
- Active community and regular updates
Cons of mace
- Steeper learning curve for beginners
- Limited support for some less common neural network operations
Code comparison
mace:
MaceEngine mace_engine(device_type);
mace_engine.Init(net_def, input_nodes, output_nodes, device_context);
mace_engine.Run(inputs, &outputs);
Tengine:
graph_t graph = create_graph(NULL, "tengine", model_file);
prerun_graph(graph);
run_graph(graph, 1);
Summary
mace offers better mobile support and documentation, while Tengine provides a simpler API and easier integration for embedded systems. mace's code is more object-oriented, while Tengine uses a C-style API. Both projects aim to optimize deep learning models for edge devices, but cater to slightly different use cases and developer preferences.
The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
Pros of ComputeLibrary
- Extensive support for ARM-based architectures, optimized for ARM CPUs and GPUs
- Comprehensive documentation and examples for various use cases
- Active development and regular updates from ARM
Cons of ComputeLibrary
- Limited cross-platform support compared to Tengine
- Steeper learning curve for developers not familiar with ARM architectures
- Larger codebase and potentially higher resource requirements
Code Comparison
Tengine example (inference):
graph_t graph = create_graph(NULL, "tengine", model_file);
tensor_t input_tensor = get_graph_input_tensor(graph, 0, 0);
set_tensor_shape(input_tensor, dims, 4);
prerun_graph(graph);
run_graph(graph, 1);
ComputeLibrary example (convolution):
NEConvolutionLayer conv;
conv.configure(&src, &weights, &biases, &dst, conv_info, weights_info);
NEScheduler::get().schedule(&conv, Window::DimY);
Open deep learning compiler stack for cpu, gpu and specialized accelerators
Pros of TVM
- Broader ecosystem support with multiple frontends (e.g., PyTorch, TensorFlow, ONNX)
- More extensive documentation and community resources
- Advanced optimization techniques, including AutoTVM and AutoScheduler
Cons of TVM
- Steeper learning curve due to its complexity and extensive features
- Potentially higher resource requirements for compilation and optimization
Code Comparison
TVM example (tensor addition):
import tvm
from tvm import te
n = te.var("n")
A = te.placeholder((n,), name="A")
B = te.placeholder((n,), name="B")
C = te.compute(A.shape, lambda i: A[i] + B[i], name="C")
Tengine example (tensor addition):
struct tensor* A = get_graph_tensor(graph, "input1");
struct tensor* B = get_graph_tensor(graph, "input2");
struct tensor* C = get_graph_tensor(graph, "output");
float* a_data = (float*)get_tensor_buffer(A);
float* b_data = (float*)get_tensor_buffer(B);
float* c_data = (float*)get_tensor_buffer(C);
Both TVM and Tengine aim to optimize deep learning models for various hardware platforms. TVM offers a more comprehensive solution with advanced features and broader ecosystem support, while Tengine focuses on lightweight deployment for embedded systems. TVM's code tends to be more high-level and abstract, whereas Tengine's code is closer to traditional C programming.
TNN: developed by Tencent Youtu Lab and Guangying Lab, a uniform deep learning inference framework for mobile、desktop and server. TNN is distinguished by several outstanding features, including its cross-platform capability, high performance, model compression and code pruning. Based on ncnn and Rapidnet, TNN further strengthens the support and performance optimization for mobile devices, and also draws on the advantages of good extensibility and high performance from existed open source efforts. TNN has been deployed in multiple Apps from Tencent, such as Mobile QQ, Weishi, Pitu, etc. Contributions are welcome to work in collaborative with us and make TNN a better framework.
Pros of TNN
- More extensive model support, including popular architectures like ResNet, MobileNet, and YOLO
- Better optimization for mobile and embedded devices, with specific support for ARM and OpenCL
- More active development and frequent updates
Cons of TNN
- Steeper learning curve due to more complex architecture
- Less focus on lightweight deployment for IoT devices
- Potentially higher resource requirements for some use cases
Code Comparison
TNN example (C++):
auto net = std::make_shared<TNN::TNN>();
TNN::Status status = net->Init(proto, model);
auto instance = net->CreateInst(network_config, status);
instance->Forward();
Tengine example (C):
graph_t graph = create_graph(NULL, "tengine", model_file);
prerun_graph(graph);
run_graph(graph, 1);
Summary
TNN offers more extensive model support and optimization for mobile devices, while Tengine focuses on lightweight deployment for IoT. TNN has a more complex architecture but provides better performance on mobile platforms. Tengine is simpler to use and more suitable for resource-constrained environments. The code examples demonstrate that TNN uses a C++ interface with object-oriented design, while Tengine employs a C-style API with a more procedural approach.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ç®ä½ä¸æ | English
Tengine
ç®ä»
Tengine ç± OPEN AI LAB 主导å¼åï¼è¯¥é¡¹ç®å®ç°äºæ·±åº¦å¦ä¹ ç¥ç»ç½ç»æ¨¡åå¨åµå ¥å¼è®¾å¤ä¸çå¿«éãé«æé¨ç½²éæ±ã为å®ç°å¨ä¼å¤ AIoT åºç¨ä¸ç跨平å°é¨ç½²ï¼æ¬é¡¹ç®ä½¿ç¨ C è¯è¨è¿è¡æ ¸å¿æ¨¡åå¼åï¼é对åµå ¥å¼è®¾å¤èµæºæéçç¹ç¹è¿è¡äºæ·±åº¦æ¡æ¶è£åªãåæ¶éç¨äºå®å ¨å离çåå端设计ï¼æå©äº CPUãGPUãNPU çå¼æ计ç®åå çå¿«é移æ¤åé¨ç½²ï¼éä½è¯ä¼°ãè¿ç§»ææ¬ã
Tengine æ ¸å¿ä»£ç ç± 4 个模åç»æï¼
- deviceï¼NN Operators å端模åï¼å·²æä¾ CPUãGPUãNPU åè代ç ï¼
- schedulerï¼æ¡æ¶æ ¸å¿é¨ä»¶ï¼å æ¬ NNIRã计ç®å¾ã硬件èµæºã模å解æå¨çè°åº¦åæ§è¡æ¨¡åï¼
- operatorï¼NN Operators å端模åï¼å®ç° NN Operators 注åãåå§åï¼
- serializerï¼æ¨¡å解æå¨ï¼å®ç° tmfile æ ¼å¼çç½ç»æ¨¡ååæ°è§£æã
æ¶æç®æ
å¿«éä¸æ
ç¼è¯
- å¿«éç¼è¯ åºäº cmake å®ç°ç®åç跨平å°ç¼è¯ã
示ä¾
- examples æä¾åºç¡çåç±»ãæ£æµç®æ³ç¨ä¾ï¼æ ¹æ® issue éæ±æç»æ´æ°ã
- æºå®è£ æä¾ubuntuç³»ç»çapt-getå½ä»¤è¡å®è£ åè¯ç¨ï¼ç®åæ¯æx86/A311D硬件ã
模åä»åº
-
ç¾åº¦ç½ç ï¼æåç ï¼7ke5ï¼
转æ¢å·¥å ·
- é¢ç¼è¯çæ¬ ï¼æä¾ Ubuntu 18.04 ç³»ç»ä¸é¢ç¼è¯å¥½ç模å转æ¢å·¥å ·ï¼
- å¨çº¿è½¬æ¢çæ¬ ï¼åºäº WebAssembly å®ç°ï¼æµè§å¨æ¬å°è½¬æ¢ï¼æ¨¡åä¸ä¼ä¸ä¼ ï¼
- æºç ç¼è¯ ï¼å»ºè®®å¨æå¡å¨æè
PCä¸ç¼è¯ï¼æ令å¦ä¸ï¼
mkdir build && cd build cmake -DTENGINE_BUILD_CONVERT_TOOL=ON .. make -j`nproc`
éåå·¥å ·
- æºç ç¼è¯ï¼å·²å¼æºéåå·¥å ·æºç ï¼å·²æ¯æ uint8/int8ã
é度è¯ä¼°
- Benchmark åºç¡ç½ç»é度è¯ä¼°å·¥å ·ï¼æ¬¢è¿å¤§å®¶æ´æ°ã
NPU Plugin
- TIM-VX VeriSilicon NPU 使ç¨æåã
AutoKernel Plugin
- AutoKernel æ¯ä¸ä¸ªç®åæç¨ï¼ä½é¨æ§çèªå¨ç®åä¼åå·¥å ·ï¼AutoKernel Pluginå®ç°äºèªå¨ä¼åç®åä¸é®é¨ç½²å° Tengine ä¸ã
Container
- SuperEdge åå© SuperEdge è¾¹ç¼è®¡ç®çå¼æºå®¹å¨ç®¡çç³»ç»ï¼æä¾æ´ä¾¿æ·çä¸å¡ç®¡çæ¹æ¡ï¼
- How to use Tengine with SuperEdge 容å¨ä½¿ç¨æåï¼
- Video Capture user manual Demo ä¾èµæ件çææåã
Roadmap
è´è°¢
Tengine Lite åèååé´äºä¸å项ç®ï¼
- Caffe
- Tensorflow
- MegEngine
- ONNX
- ncnn
- FeatherCNN
- MNN
- Paddle Lite
- ACL
- stb
- convertmodel
- TIM-VX
- SuperEdge
License
æ¾æ¸ 说æ
- [å¨çº¿ä¸æ¥åè½] å¨çº¿ä¸æ¥åè½ä¸»è¦ç®çæ¯äºè§£Tengineç使ç¨ä¿¡æ¯ï¼ä¿¡æ¯ç¨äºä¼ååè¿ä»£Tengineï¼ä¸ä¼å½±åä»»ä½æ£å¸¸åè½ã该åè½é»è®¤å¼å¯ï¼å¦éå ³éï¼å¯ä¿®æ¹å¦ä¸é ç½®å ³éï¼(主ç®å½ CMakeLists.txt ) OPTION (TENGINE_ONLINE_REPORT "online report" OFF)
FAQ
ææ¯è®¨è®º
- Github issues
- QQ 群: 829565581
- Email: Support@openailab.com
Top Related Projects
MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba
ncnn is a high-performance neural network inference framework optimized for the mobile platform
MACE is a deep learning inference framework optimized for mobile heterogeneous computing platforms.
The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
Open deep learning compiler stack for cpu, gpu and specialized accelerators
TNN: developed by Tencent Youtu Lab and Guangying Lab, a uniform deep learning inference framework for mobile、desktop and server. TNN is distinguished by several outstanding features, including its cross-platform capability, high performance, model compression and code pruning. Based on ncnn and Rapidnet, TNN further strengthens the support and performance optimization for mobile devices, and also draws on the advantages of good extensibility and high performance from existed open source efforts. TNN has been deployed in multiple Apps from Tencent, such as Mobile QQ, Weishi, Pitu, etc. Contributions are welcome to work in collaborative with us and make TNN a better framework.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot